|
1 | 1 | package org.jlab.io.clara; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | 3 | import java.nio.file.Path; |
5 | | -import java.util.List; |
6 | | -import java.util.TreeMap; |
7 | | -import java.util.TreeSet; |
8 | 4 | import org.jlab.clara.std.services.EventWriterException; |
9 | 5 | import org.jlab.detector.calib.utils.ConstantsManager; |
10 | | -import org.jlab.detector.helicity.HelicitySequenceDelayed; |
11 | | -import org.jlab.detector.helicity.HelicityState; |
12 | | -import org.jlab.detector.scalers.DaqScalersSequence; |
13 | | -import org.jlab.detector.serial.PostProcessor; |
14 | 6 | import org.jlab.detector.serial.SerialHoncho; |
15 | | -import org.jlab.jnp.hipo4.data.Bank; |
16 | 7 | import org.jlab.jnp.hipo4.data.Event; |
17 | 8 | import org.jlab.jnp.hipo4.data.SchemaFactory; |
18 | | -import org.jlab.jnp.hipo4.io.HipoReader; |
19 | 9 | import org.jlab.jnp.hipo4.io.HipoWriterSorted; |
20 | 10 | import org.jlab.jnp.utils.file.FileUtils; |
21 | 11 | import org.json.JSONObject; |
|
25 | 15 | * 1. Copies certain banks on-the-fly to new tag-1 events |
26 | 16 | * 2. Caches helicity states, scaler readouts, and unix time |
27 | 17 | * 3. Writes HEL::flip, RUN/HEL::scaler, and RUN::unix to new tag-1 events |
28 | | - * 4. Runs post-processing, writing tag-1 information to all events |
29 | 18 | * 5. Adds .hipo to the output filename, if necessary |
30 | 19 | * |
31 | 20 | * @author baltzell |
32 | 21 | */ |
33 | 22 | public class Clas12Writer extends HipoToHipoWriter { |
34 | 23 |
|
35 | 24 | SerialHoncho serial; |
36 | | - Bank runConfig; |
37 | 25 | ConstantsManager conman; |
38 | 26 | SchemaFactory fullSchema; |
39 | | - boolean postprocess; |
40 | 27 |
|
41 | 28 | private void init(JSONObject opts) { |
42 | 29 | fullSchema = new SchemaFactory(); |
43 | 30 | fullSchema.initFromDirectory(FileUtils.getEnvironmentPath("CLAS12DIR","etc/bankdefs/hipo4")); |
44 | 31 | serial = new SerialHoncho(fullSchema); |
45 | | - runConfig = new Bank(fullSchema.getSchema("RUN::config")); |
46 | 32 | conman = new ConstantsManager(); |
47 | 33 | conman.init("/runcontrol/hwp","/runcontrol/helicity"); |
48 | | - postprocess = opts.optBoolean("postprocess", false); |
49 | 34 | if (opts.has("variation")) conman.setVariation(opts.getString("variation")); |
50 | 35 | if (opts.has("timestamp")) conman.setTimeStamp(opts.getString("timestamp")); |
51 | 36 | } |
@@ -74,47 +59,6 @@ protected void writeEvent(Object event) throws EventWriterException { |
74 | 59 | protected void closeWriter() { |
75 | 60 | serial.finish(writer); |
76 | 61 | super.closeWriter(); |
77 | | - if (postprocess) postprocess(); |
78 | 62 | serial.clear(); |
79 | 63 | } |
80 | | - |
81 | | - /** |
82 | | - * Get the first valid run number from a RUN::config bank. |
83 | | - * @return run |
84 | | - */ |
85 | | - private int getRunNumber() { |
86 | | - Event e = new Event(); |
87 | | - HipoReader r = new HipoReader(); |
88 | | - r.open(filename); |
89 | | - while (r.hasNext()) { |
90 | | - r.nextEvent(e); |
91 | | - e.read(runConfig); |
92 | | - if (runConfig.getRows()>0 && runConfig.getInt("run",0)>0) |
93 | | - return runConfig.getInt("run",0); |
94 | | - } |
95 | | - return 0; |
96 | | - } |
97 | | - |
98 | | - /** |
99 | | - * Copy helicity/charge tag-1 information to all events. |
100 | | - */ |
101 | | - private void postprocess() { |
102 | | - int d = conman.getConstants(getRunNumber(), "/runcontrol/helicity").getIntValue("delay",0,0,0); |
103 | | - HelicitySequenceDelayed helicity = new HelicitySequenceDelayed(d); |
104 | | - helicity.addStream(serial.getHelicities()); |
105 | | - PostProcessor p = new PostProcessor(List.of(filename), fullSchema, helicity, serial.getScalers()); |
106 | | - HipoReader r = new HipoReader(); |
107 | | - r.open(filename); |
108 | | - Event e = new Event(); |
109 | | - writer.open("pp_"+filename); |
110 | | - while (r.hasNext()) { |
111 | | - r.nextEvent(e); |
112 | | - p.processEvent(e); |
113 | | - HipoToHipoWriter.writeEvent(writer, e, schemaBankList); |
114 | | - } |
115 | | - writer.close(); |
116 | | - new File(filename).delete(); |
117 | | - new File("pp_"+filename).renameTo(new File(filename)); |
118 | | - } |
119 | | - |
120 | 64 | } |
0 commit comments