|
| 1 | +package org.jlab.io.utils; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.nio.file.Files; |
| 5 | +import org.jlab.io.base.DataEvent; |
| 6 | +import org.jlab.io.hipo.HipoDataSource; |
| 7 | +import org.jlab.io.hipo.HipoDataSync; |
| 8 | +import org.jlab.jnp.hipo4.data.SchemaFactory; |
| 9 | +import org.jlab.utils.options.OptionParser; |
| 10 | +import org.jlab.utils.system.ClasUtilsFile; |
| 11 | + |
| 12 | +public class DstMaker { |
| 13 | + |
| 14 | + public static void main(String args[]) { |
| 15 | + |
| 16 | + OptionParser opt = new OptionParser("dst-maker"); |
| 17 | + opt.addOption("-s","dst","schema path, or stock schema name (default=dst)"); |
| 18 | + opt.addRequired("-o","output file"); |
| 19 | + opt.setRequiresInputList(true); |
| 20 | + opt.parse(args); |
| 21 | + |
| 22 | + HipoDataSync w = new HipoDataSync(); |
| 23 | + w.setCompressionType(2); |
| 24 | + |
| 25 | + SchemaFactory schema = new SchemaFactory(); |
| 26 | + String stock = ClasUtilsFile.getResourceDir("CLAS12DIR","etc/bankdefs/hipo4/singles"); |
| 27 | + String user = opt.getOption("-s").stringValue(); |
| 28 | + if (Files.isDirectory((new File(stock+"/"+user)).toPath())) { |
| 29 | + System.out.println("Assuming -s is a stock schema: "+user); |
| 30 | + schema.initFromDirectory(stock+"/"+user); |
| 31 | + } |
| 32 | + else if (Files.isDirectory((new File(user)).toPath())) { |
| 33 | + System.out.println("Assuming -s is a schema path: "+user); |
| 34 | + schema.initFromDirectory(user); |
| 35 | + } |
| 36 | + else { |
| 37 | + System.err.println("Unable to initialize schema from -s "+user); |
| 38 | + System.exit(2); |
| 39 | + } |
| 40 | + w.open(opt.getOption("-o").stringValue()); |
| 41 | + |
| 42 | + for (String input : opt.getInputList()) { |
| 43 | + HipoDataSource r = new HipoDataSource(); |
| 44 | + r.open(input); |
| 45 | + while (r.hasEvent()) { |
| 46 | + DataEvent e = r.getNextEvent(); |
| 47 | + for (String name : e.getBankList()) { |
| 48 | + if (!schema.hasSchema(name)) { |
| 49 | + e.removeBank(name); |
| 50 | + } |
| 51 | + } |
| 52 | + w.writeEvent(e); |
| 53 | + } |
| 54 | + r.close(); |
| 55 | + } |
| 56 | + w.close(); |
| 57 | + } |
| 58 | +} |
0 commit comments