33import java .io .File ;
44import java .nio .file .Path ;
55import java .util .List ;
6- import java .util .TreeMap ;
7- import java .util .TreeSet ;
86import org .jlab .analysis .postprocess .Processor ;
97import org .jlab .clara .std .services .EventWriterException ;
108import org .jlab .detector .calib .utils .ConstantsManager ;
11- import org .jlab .detector .decode .CLASDecoder4 ;
12- import org .jlab .detector .helicity .HelicitySequence ;
139import org .jlab .detector .helicity .HelicitySequenceDelayed ;
14- import org .jlab .detector .helicity .HelicityState ;
15- import org .jlab .detector .scalers .DaqScalersSequence ;
10+ import org .jlab .detector .serial .SerialHoncho ;
1611import org .jlab .jnp .hipo4 .data .Bank ;
1712import org .jlab .jnp .hipo4 .data .Event ;
1813import org .jlab .jnp .hipo4 .data .SchemaFactory ;
3328 */
3429public class Clas12Writer extends HipoToHipoWriter {
3530
36- static final String [] TAG1BANKS = {"RUN::scaler" ,"HEL::scaler" ,"RAW::scaler" ,"RAW::epics" ,"HEL::flip" ,"COAT::config" };
37-
38- Bank [] tag1banks ;
31+ SerialHoncho serial ;
3932 Bank runConfig ;
40- Bank helicityAdc ;
4133 ConstantsManager conman ;
42- TreeMap <Integer ,Integer > eventUnix ;
43- TreeSet <HelicityState > helicities ;
44- DaqScalersSequence scalers ;
4534 SchemaFactory fullSchema ;
4635 boolean postprocess ;
4736
4837 private void init (JSONObject opts ) {
4938 fullSchema = new SchemaFactory ();
5039 fullSchema .initFromDirectory (FileUtils .getEnvironmentPath ("CLAS12DIR" ,"etc/bankdefs/hipo4" ));
40+ serial = new SerialHoncho (fullSchema );
5141 runConfig = new Bank (fullSchema .getSchema ("RUN::config" ));
52- helicityAdc = new Bank (fullSchema .getSchema ("HEL::adc" ));
53- helicities = new TreeSet <>();
54- scalers = new DaqScalersSequence (fullSchema );
5542 conman = new ConstantsManager ();
56- eventUnix = new TreeMap <>();
5743 conman .init ("/runcontrol/hwp" ,"/runcontrol/helicity" );
5844 postprocess = opts .optBoolean ("postprocess" , false );
5945 if (opts .has ("variation" )) conman .setVariation (opts .getString ("variation" ));
6046 if (opts .has ("timestamp" )) conman .setTimeStamp (opts .getString ("timestamp" ));
61- tag1banks = new Bank [TAG1BANKS .length ];
62- for (int i =0 ; i <tag1banks .length ; ++i )
63- tag1banks [i ] = new Bank (fullSchema .getSchema (TAG1BANKS [i ]));
6447 }
6548
6649 @ Override
@@ -78,29 +61,17 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
7861
7962 @ Override
8063 protected void writeEvent (Object event ) throws EventWriterException {
81- scalers .add ((Event )event );
82- ((Event )event ).read (runConfig );
83- ((Event )event ).read (helicityAdc );
84- if (runConfig .getRows () > 0 ) {
85- int unix = runConfig .getInt ("unixtime" ,0 );
86- int evno = runConfig .getInt ("event" ,0 );
87- if (unix > 0 && evno > 0 ) eventUnix .put (evno , unix );
88- }
89- helicities .add (HelicityState .createFromFadcBank (helicityAdc , runConfig , conman ));
90- Event t = CLASDecoder4 .createTaggedEvent ((Event )event , runConfig , tag1banks );
64+ Event t = serial .read ((Event )event );
9165 if (!t .isEmpty ()) writer .addEvent (t , 1 );
9266 super .writeEvent (event );
9367 }
9468
9569 @ Override
9670 protected void closeWriter () {
97- HelicitySequence .writeFlips (fullSchema , writer , helicities );
98- writer .addEvent (getUnixEvent (runConfig ),1 );
71+ serial .finish (writer );
9972 super .closeWriter ();
10073 if (postprocess ) postprocess ();
101- // keep the latest helicity/scaler reading for the next file:
102- while (helicities .size () > 60 ) helicities .pollFirst ();
103- scalers .clear (10 );
74+ serial .clear ();
10475 }
10576
10677 /**
@@ -120,35 +91,14 @@ private int getRunNumber() {
12091 return 0 ;
12192 }
12293
123- /**
124- * Get a new event with a RUN::unix bank containing event-timestamp mapping,
125- * and the latest RUN::config bank.
126- * @param config
127- * @return
128- */
129- private Event getUnixEvent (Bank config ) {
130- Bank unix = new Bank (fullSchema .getSchema ("RUN::unix" ));
131- unix .setRows (eventUnix .size ());
132- int row = 0 ;
133- for (int evno : eventUnix .keySet ()) {
134- unix .putInt ("event" , row , evno );
135- unix .putInt ("unixtime" ,row , eventUnix .get (evno ));
136- row ++;
137- }
138- Event e = new Event ();
139- e .write (config );
140- e .write (unix );
141- return e ;
142- }
143-
14494 /**
14595 * Copy helicity/charge tag-1 information to all events.
14696 */
14797 private void postprocess () {
14898 int d = conman .getConstants (getRunNumber (), "/runcontrol/helicity" ).getIntValue ("delay" ,0 ,0 ,0 );
14999 HelicitySequenceDelayed helicity = new HelicitySequenceDelayed (d );
150- helicity .addStream (helicities );
151- Processor p = new Processor (List .of (filename ), fullSchema , helicity , scalers );
100+ helicity .addStream (serial . getHelicities () );
101+ Processor p = new Processor (List .of (filename ), fullSchema , helicity , serial . getScalers () );
152102 HipoReader r = new HipoReader ();
153103 r .open (filename );
154104 Event e = new Event ();
0 commit comments