|
23 | 23 | import org.jlab.detector.scalers.DaqScalersSequence; |
24 | 24 | import org.jlab.detector.helicity.HelicityBit; |
25 | 25 | import org.jlab.detector.helicity.HelicitySequenceDelayed; |
| 26 | +import org.jlab.jnp.hipo4.io.HipoWriterSorted; |
| 27 | +import org.jlab.utils.options.OptionParser; |
| 28 | +import org.jlab.utils.system.ClasUtilsFile; |
26 | 29 |
|
27 | 30 | /** |
28 | 31 | * |
@@ -56,6 +59,10 @@ public Processor(String dir, String glob, boolean restream, boolean rebuild) { |
56 | 59 | configure(findPreloadFiles(dir,glob), restream, rebuild); |
57 | 60 | } |
58 | 61 |
|
| 62 | + public Processor(List<String> files, boolean restream, boolean rebuild) { |
| 63 | + configure(files, restream, rebuild); |
| 64 | + } |
| 65 | + |
59 | 66 | public Processor(SchemaFactory schema, HelicitySequenceDelayed h, DaqScalersSequence s) { |
60 | 67 | conman = new ConstantsManager(); |
61 | 68 | conman.init(CCDB_TABLES); |
@@ -295,8 +302,48 @@ private static void replace(Map<String,String> files) { |
295 | 302 | } |
296 | 303 | } |
297 | 304 |
|
| 305 | + /** |
| 306 | + * The "postprocess" program. |
| 307 | + * @param args |
| 308 | + */ |
298 | 309 | public static void main(String args[]) { |
299 | | - Processor p = new Processor(System.getenv("HOME")+"/tmp","r*.hipo",false,false); |
| 310 | + |
| 311 | + OptionParser o = new OptionParser("postprocess"); |
| 312 | + o.addOption("-f","0","reflip: rebuild the HEL::flip bank"); |
| 313 | + o.addOption("-c","0","recharge: rebuild the RUN/HEL::scaler banks"); |
| 314 | + o.addOption("-o",null,"merged output file path"); |
| 315 | + o.setRequiresInputList(true); |
| 316 | + o.parse(args); |
| 317 | + |
| 318 | + boolean restream = !o.getOption("-f").isDefault(); |
| 319 | + boolean rebuild = !o.getOption("-c").isDefault(); |
| 320 | + |
| 321 | + Processor post = new Processor(o.getInputList(), restream, rebuild); |
| 322 | + |
| 323 | + HipoWriterSorted writer = null; |
| 324 | + |
| 325 | + if (!o.getOption("-o").isDefault()) { |
| 326 | + writer = new HipoWriterSorted(); |
| 327 | + SchemaFactory schema = writer.getSchemaFactory(); |
| 328 | + schema.initFromDirectory(ClasUtilsFile.getResourceDir("CLAS12DIR", "etc/bankdefs/hipo4")); |
| 329 | + writer.setCompressionType(2); |
| 330 | + writer.open(o.getOption("-o").stringValue()); |
| 331 | + } |
| 332 | + |
| 333 | + for (String f : o.getInputList()) { |
| 334 | + HipoReader reader = new HipoReader(); |
| 335 | + reader.setTags(0); |
| 336 | + reader.open(f); |
| 337 | + Event event = new Event(); |
| 338 | + while (reader.hasNext()) { |
| 339 | + reader.nextEvent(event); |
| 340 | + post.processEvent(event); |
| 341 | + if (writer != null) writer.addEvent(event); |
| 342 | + } |
| 343 | + reader.close(); |
| 344 | + } |
| 345 | + |
| 346 | + if (writer != null) writer.close(); |
300 | 347 | } |
301 | 348 |
|
302 | 349 | } |
0 commit comments