11package org .jlab .detector .serial ;
22
33import java .util .TreeMap ;
4- import java .util .TreeSet ;
54import org .jlab .detector .calib .utils .ConstantsManager ;
65import org .jlab .detector .decode .CLASDecoder ;
76import org .jlab .detector .helicity .HelicityBit ;
@@ -29,7 +28,6 @@ public SerialHoncho(SchemaFactory schema) {
2928 conman .init ("/runcontrol/hwp" ,"/runcontrol/helicity" );
3029 runConfig = new Bank (schema .getSchema ("RUN::config" ));
3130 helicityAdc = new Bank (schema .getSchema ("HEL::adc" ));
32- helicities = new TreeSet <>();
3331 scalers = new DaqScalersSequence (schema );
3432 eventUnix = new TreeMap <>();
3533 tag1banks = new Bank [TAG1BANKS .length ];
@@ -42,11 +40,17 @@ public synchronized Event read(Event event) {
4240 event .read (runConfig );
4341 event .read (helicityAdc );
4442 if (runConfig .getRows () > 0 ) {
43+ if (run <= 0 && runConfig .getInt ("run" , 0 ) > 0 ) {
44+ run = runConfig .getInt ("run" ,0 );
45+ helicitySequence = new HelicitySequenceDelayed (
46+ conman .getConstants (run , "/runcontrol/helicity" ).getIntValue ("delay" ,0 ,0 ,0 ));
47+ }
4548 int unix = runConfig .getInt ("unixtime" ,0 );
4649 int evno = runConfig .getInt ("event" ,0 );
4750 if (unix > 0 && evno > 0 ) eventUnix .put (evno , unix );
4851 }
49- helicities .add (HelicityState .createFromFadcBank (helicityAdc , runConfig , conman ));
52+ if (helicitySequence != null )
53+ helicitySequence .addState (HelicityState .createFromFadcBank (helicityAdc , runConfig , conman ));
5054 return CLASDecoder .createTaggedEvent (event , runConfig , tag1banks );
5155 }
5256
@@ -68,28 +72,20 @@ public void process(Event event) {
6872
6973 public void finish (HipoWriterSorted writer ) {
7074 writer .addEvent (getUnixEvent (runConfig ),1 );
71- HelicitySequence .writeFlips (schema , writer , helicities );
75+ helicitySequence .writeFlips (writer , 1 );
7276 }
7377
7478 public void clear () {
75- while ( helicities . size () > 100 ) helicities . pollFirst ( );
79+ //helicitySequence.clear( 100);
7680 scalers .clear (100 );
7781 }
7882
7983 public DaqScalersSequence getScalers () {
8084 return scalers ;
8185 }
8286
83- public TreeSet <HelicityState > getHelicities () {
84- return helicities ;
85- }
86-
87- public HelicitySequenceDelayed getHelicitySequence () {
88- // FIXME: autogenerate if necessary
89- HelicitySequenceDelayed h = new HelicitySequenceDelayed (
90- conman .getConstants (4013 , "/runcontrol/helicity" ).getIntValue ("delay" ,0 ,0 ,0 ));
91- h .addStream (helicities );
92- return h ;
87+ public HelicitySequence getHelicities () {
88+ return helicitySequence ;
9389 }
9490
9591 public ConstantsManager getConstantsManager () {
@@ -99,16 +95,17 @@ public ConstantsManager getConstantsManager() {
9995 public SchemaFactory getSchemaFactory () {
10096 return schema ;
10197 }
102-
98+
10399 SchemaFactory schema ;
104100 Bank [] tag1banks ;
105101 // FIXME: store Schema for banks;
106102 Bank runConfig ;
107103 Bank helicityAdc ;
108104 ConstantsManager conman ;
109105 TreeMap <Integer ,Integer > eventUnix ;
110- TreeSet < HelicityState > helicities ;
106+ HelicitySequence helicitySequence ;
111107 DaqScalersSequence scalers ;
108+ int run ;
112109
113110 Event getUnixEvent (Bank config ) {
114111 Bank unix = new Bank (schema .getSchema ("RUN::unix" ));
@@ -151,16 +148,16 @@ void processScalers(Bank runConfig, Bank recEvent) {
151148 }
152149 }
153150
154- void processHelicity (Event event , Bank runcfg , Bank recevt ) {
155- HelicityBit hb = getHelicitySequence () .search (runcfg .getLong ("timestamp" , 0 ));
156- HelicityBit hbraw = getHelicitySequence () .getHalfWavePlate () ? HelicityBit .getFlipped (hb ) : hb ;
157- recevt .putByte ("helicity" ,0 ,hb .value ());
158- recevt .putByte ("helicityRaw" ,0 ,hbraw .value ());
151+ void processHelicity (Event event , Bank runConfig , Bank recEvent ) {
152+ HelicityBit hb = helicitySequence .search (runConfig .getLong ("timestamp" , 0 ));
153+ HelicityBit hbraw = helicitySequence .getHalfWavePlate () ? HelicityBit .getFlipped (hb ) : hb ;
154+ recEvent .putByte ("helicity" ,0 ,hb .value ());
155+ recEvent .putByte ("helicityRaw" ,0 ,hbraw .value ());
159156 Bank helScaler = new Bank (schema .getSchema ("HEL::scaler" ));
160157 event .read (helScaler );
161158 if (helScaler .getRows ()>0 ) {
162159 event .remove (schema .getSchema ("HEL::scaler" ));
163- SerialUtil .assignScalerHelicity (runcfg .getLong ("timestamp" ,0 ), helScaler , getHelicitySequence () );
160+ SerialUtil .assignScalerHelicity (runConfig .getLong ("timestamp" ,0 ), helScaler , helicitySequence );
164161 event .write (helScaler );
165162 }
166163 }
0 commit comments