@@ -23,10 +23,11 @@ public class DetectorEventDecoder {
2323 ConstantsManager scalerManager = new ConstantsManager ();
2424
2525 List <String > tablesTrans = null ;
26- List <String > keysTrans = null ;
2726 List <String > tablesFitter = null ;
28- List <String > keysFitter = null ;
29- List <String > keysFilter = null ;
27+
28+ List <DetectorType > keysTrans = null ;
29+ List <DetectorType > keysFitter = null ;
30+ List <DetectorType > keysFilter = null ;
3031
3132 private int runNumber = 10 ;
3233
@@ -76,50 +77,60 @@ public DetectorEventDecoder(){
7677 }
7778
7879 public final void initDecoderDev (){
79- keysTrans = Arrays .asList (new String []{ " HTCC" , " BST" , " RTPC" } );
80+ keysTrans = Arrays .asList (new DetectorType []{ DetectorType . HTCC , DetectorType . BST , DetectorType . RTPC } );
8081 tablesTrans = Arrays .asList (new String []{ "/daq/tt/clasdev/htcc" ,"/daq/tt/clasdev/svt" ,"/daq/tt/clasdev/rtpc" });
81- keysFitter = Arrays .asList (new String []{" HTCC" });
82+ keysFitter = Arrays .asList (new DetectorType []{DetectorType . HTCC });
8283 tablesFitter = Arrays .asList (new String []{"/daq/fadc/clasdev/htcc" });
83- translationManager .init (keysTrans , tablesTrans );
84- fitterManager .init (keysFitter , tablesFitter );
84+ translationManager .init (tablesTrans );
85+ fitterManager .init (tablesFitter );
8586 scalerManager .init (Arrays .asList (new String []{"/runcontrol/fcup" ,"/runcontrol/slm" ,"/runcontrol/hwp" ,
8687 "/runcontrol/helicity" ,"/daq/config/scalers/dsc1" }));
8788 }
8889
8990 public final void initDecoder (){
9091
9192 // Detector translation table
92- keysTrans = Arrays .asList (new String []{" FTCAL" , " FTHODO" , " FTTRK" , " LTCC" , " ECAL" , " FTOF" ,
93- " HTCC" , "DC" , " CTOF" , " CND" , " BST" , "RF" , " BMT" , " FMT" ,
94- " RICH" , " HEL" , " BAND" , " RTPC" ,
95- " RASTER" , " ATOF" , " AHDC"
93+ keysTrans = Arrays .asList (new DetectorType []{DetectorType . FTCAL , DetectorType . FTHODO , DetectorType . FTTRK , DetectorType . LTCC , DetectorType . ECAL , DetectorType . FTOF ,
94+ DetectorType . HTCC , DetectorType . DC , DetectorType . CTOF , DetectorType . CND , DetectorType . BST , DetectorType . RF , DetectorType . BMT , DetectorType . FMT ,
95+ DetectorType . RICH , DetectorType . HEL , DetectorType . BAND , DetectorType . RTPC ,
96+ DetectorType . RASTER , DetectorType . ATOF , DetectorType . AHDC
9697 });
9798 tablesTrans = Arrays .asList (new String []{
9899 "/daq/tt/ftcal" ,"/daq/tt/fthodo" ,"/daq/tt/fttrk" ,"/daq/tt/ltcc" ,
99100 "/daq/tt/ec" ,"/daq/tt/ftof" ,"/daq/tt/htcc" ,"/daq/tt/dc" ,"/daq/tt/ctof" ,"/daq/tt/cnd" ,"/daq/tt/svt" ,
100101 "/daq/tt/rf" ,"/daq/tt/bmt" ,"/daq/tt/fmt" ,"/daq/tt/rich2" ,"/daq/tt/hel" ,"/daq/tt/band" ,"/daq/tt/rtpc" ,
101102 "/daq/tt/raster" ,"/daq/tt/atof" ,"/daq/tt/ahdc"
102103 });
103- translationManager .init (keysTrans , tablesTrans );
104+ translationManager .init (tablesTrans );
104105
105106 // ADC waveform fitter translation table
106- keysFitter = Arrays .asList (new String []{" FTCAL" , " FTHODO" , " FTTRK" , " FTOF" , " LTCC" ,
107- " ECAL" , " HTCC" , " CTOF" , " CND" , " BMT" ,
108- " FMT" , " HEL" , "RF" , " BAND" , " RASTER" ,
109- " AHDC" });
107+ keysFitter = Arrays .asList (new DetectorType []{DetectorType . FTCAL , DetectorType . FTHODO , DetectorType . FTTRK , DetectorType . FTOF , DetectorType . LTCC ,
108+ DetectorType . ECAL , DetectorType . HTCC , DetectorType . CTOF , DetectorType . CND , DetectorType . BMT ,
109+ DetectorType . FMT , DetectorType . HEL , DetectorType . RF , DetectorType . BAND , DetectorType . RASTER ,
110+ DetectorType . AHDC });
110111 tablesFitter = Arrays .asList (new String []{
111112 "/daq/fadc/ftcal" ,"/daq/fadc/fthodo" ,"/daq/config/fttrk" ,"/daq/fadc/ftof" ,"/daq/fadc/ltcc" ,
112113 "/daq/fadc/ec" , "/daq/fadc/htcc" ,"/daq/fadc/ctof" ,"/daq/fadc/cnd" ,"/daq/config/bmt" ,
113114 "/daq/config/fmt" ,"/daq/fadc/hel" ,"/daq/fadc/rf" ,"/daq/fadc/band" ,"/daq/fadc/raster" ,
114115 "/daq/config/ahdc"
115116 });
116- fitterManager .init (keysFitter , tablesFitter );
117+ fitterManager .init (tablesFitter );
117118
118119 // Data filter list
119- keysFilter = Arrays .asList (new String []{"DC" });
120+ keysFilter = Arrays .asList (new DetectorType []{DetectorType . DC });
120121
121122 scalerManager .init (Arrays .asList (new String []{"/runcontrol/fcup" ,"/runcontrol/slm" ,"/runcontrol/hwp" ,
122123 "/runcontrol/helicity" ,"/daq/config/scalers/dsc1" }));
124+
125+ checkTables ();
126+ }
127+
128+ public void checkTables () {
129+ for (int i =0 ; i <tablesTrans .size (); i ++) {
130+ IndexedTable t = translationManager .getConstants (runNumber , tablesTrans .get (i ));
131+ for (int j =0 ; j <i ; j ++)
132+ t .conflicts (translationManager .getConstants (runNumber , tablesTrans .get (j )));
133+ }
123134 }
124135
125136 /**
@@ -129,52 +140,74 @@ public final void initDecoder(){
129140 */
130141 public void translate (List <DetectorDataDgtz > detectorData ){
131142
132- for (DetectorDataDgtz data : detectorData ){
143+ // Preload CCDB tables:
144+ ArrayList <IndexedTable > tables = new ArrayList <>();
145+ for (String name : tablesTrans ) {
146+ tables .add (translationManager .getConstants (runNumber , name ));
147+ }
133148
149+ for (DetectorDataDgtz data : detectorData ) {
150+
151+ // Get the hardware indexing for this detector hit:
134152 int crate = data .getDescriptor ().getCrate ();
135153 int slot = data .getDescriptor ().getSlot ();
136154 int channel = data .getDescriptor ().getChannel ();
155+ long hash = IndexedTable .DEFAULT_GENERATOR .hashCode (crate ,slot ,channel );
156+
157+ // Try to find it in the translation tables:
158+ for (int j =0 ; j <tablesTrans .size (); ++j ) {
159+
160+ IndexedTable t = tables .get (j );
137161
138- for (String table : keysTrans ){
139- IndexedTable tt = translationManager .getConstants (runNumber , table );
140- DetectorType type = DetectorType .getType (table );
141- if (tt .hasEntry (crate ,slot ,channel )==true ){
142- int sector = tt .getIntValue ("sector" , crate ,slot ,channel );
143- int layer = tt .getIntValue ("layer" , crate ,slot ,channel );
144- int component = tt .getIntValue ("component" , crate ,slot ,channel );
145- int order = tt .getIntValue ("order" , crate ,slot ,channel );
162+ // Found it; now set the detector indexing for this hit:
163+ if (t .hasEntryByHash (hash )) {
164+
165+ int sector = t .getIntValueByHash (0 , hash );
166+ int layer = t .getIntValueByHash (1 , hash );
167+ int component = t .getIntValueByHash (2 , hash );
168+ int order = t .getIntValueByHash (3 , hash );
146169
147170 data .getDescriptor ().setSectorLayerComponent (sector , layer , component );
148171 data .getDescriptor ().setOrder (order );
149- data .getDescriptor ().setType (type );
172+ data .getDescriptor ().setType (keysTrans . get ( j ) );
150173
151- for (int i = 0 ; i < data .getADCSize (); i ++) {
152- data .getADCData (i ).setOrder (order );
153- }
154- for ( int i = 0 ; i < data . getTDCSize (); i ++) {
155- data . getTDCData ( i ). setOrder ( order );
156- }
174+ for (int i = 0 ; i < data .getADCSize (); i ++) data . getADCData ( i ). setOrder ( order );
175+ for ( int i = 0 ; i < data .getTDCSize (); i ++) data . getTDCData (i ).setOrder (order );
176+
177+ // Assume there's only one instance of this crate/slot/channel
178+ // in all translation tables, and we found it, so stop:
179+ break ;
157180 }
158181 }
159182 }
160183 }
161184
162185 public void fitPulses (List <DetectorDataDgtz > detectorData ){
186+
187+ // preload CCDB tables once:
188+ ArrayList <IndexedTable > tables = new ArrayList <>();
189+ for (String name : tablesFitter ) {
190+ tables .add (fitterManager .getConstants (runNumber , name ));
191+ }
192+
163193 for (DetectorDataDgtz data : detectorData ){
164194 int crate = data .getDescriptor ().getCrate ();
165195 int slot = data .getDescriptor ().getSlot ();
166196 int channel = data .getDescriptor ().getChannel ();
167- for (String table : keysFitter ){
197+ long hash = IndexedTable .DEFAULT_GENERATOR .hashCode (crate ,slot ,channel );
198+ long hash0 = IndexedTable .DEFAULT_GENERATOR .hashCode (0 ,0 ,0 );
199+ for (int j =0 ; j <keysFitter .size (); ++j ) {
200+ IndexedTable daq = tables .get (j );
201+ DetectorType type = keysFitter .get (j );
168202 //custom MM fitter
169- if ( ( (table .equals ("BMT" ))&&(data .getDescriptor ().getType ().getName ().equals ("BMT" )) )
170- || ( (table .equals ("FMT" ))&&(data .getDescriptor ().getType ().getName ().equals ("FMT" )) )
171- //|| ( (table.equals("AHDC"))&&(data.getDescriptor().getType().getName().equals("AHDC")) )
172- || ( (table .equals ("FTTRK" ))&&(data .getDescriptor ().getType ().getName ().equals ("FTTRK" )) ) ){
173- IndexedTable daq = fitterManager .getConstants (runNumber , table );
174- short adcOffset = (short ) daq .getDoubleValue ("adc_offset" , 0 , 0 , 0 );
175- double fineTimeStampResolution = (byte ) daq .getDoubleValue ("dream_clock" , 0 , 0 , 0 );
176- double samplingTime = (byte ) daq .getDoubleValue ("sampling_time" , 0 , 0 , 0 );
177- int sparseSample = daq .getIntValue ("sparse" , 0 , 0 ,0 );
203+ if ( ( (type == DetectorType .BMT )&&(data .getDescriptor ().getType ().getName ().equals ("BMT" )) )
204+ || ( (type == DetectorType .FMT )&&(data .getDescriptor ().getType ().getName ().equals ("FMT" )) )
205+ //|| ( (type == DetectorType.AHDC)&&(data.getDescriptor().getType().getName().equals("AHDC")) )
206+ || ( (type == DetectorType .FTTRK )&&(data .getDescriptor ().getType ().getName ().equals ("FTTRK" )) ) ){
207+ short adcOffset = (short ) daq .getDoubleValueByHash ("adc_offset" , hash0 );
208+ double fineTimeStampResolution = (byte ) daq .getDoubleValueByHash ("dream_clock" , hash0 );
209+ double samplingTime = (byte ) daq .getDoubleValueByHash ("sampling_time" , hash0 );
210+ int sparseSample = daq .getIntValueByHash ("sparse" , hash0 );
178211 if (data .getADCSize () > 0 ) {
179212 ADCData adc = data .getADCData (0 );
180213 mvtFitter .fit (adcOffset , fineTimeStampResolution , samplingTime , adc .getPulseArray (), adc .getTimeStamp (), sparseSample );
@@ -184,14 +217,14 @@ public void fitPulses(List<DetectorDataDgtz> detectorData){
184217 adc .setTimeStamp (mvtFitter .timestamp );
185218 }
186219 } else {
187- IndexedTable daq = fitterManager .getConstants (runNumber , table );
188- DetectorType type = DetectorType .getType (table );
189- if (daq .hasEntry (crate ,slot ,channel )==true ){
190- int nsa = daq .getIntValue ("nsa" , crate ,slot ,channel );
191- int nsb = daq .getIntValue ("nsb" , crate ,slot ,channel );
192- int tet = daq .getIntValue ("tet" , crate ,slot ,channel );
220+ if (daq .hasEntryByHash (hash )==true ){
221+ int nsa = daq .getIntValueByHash ("nsa" , hash );
222+ int nsb = daq .getIntValueByHash ("nsb" , hash );
223+ int tet = daq .getIntValueByHash ("tet" , hash );
193224 int ped = 0 ;
194- if (table .equals ("RF" )&&data .getDescriptor ().getType ().getName ().equals ("RF" )) ped = daq .getIntValue ("pedestal" , crate ,slot ,channel );
225+ if (type == DetectorType .RF &&data .getDescriptor ().getType ().getName ().equals ("RF" )) {
226+ ped = daq .getIntValueByHash ("pedestal" , hash );
227+ }
195228 if (data .getADCSize ()>0 ){
196229 for (int i = 0 ; i < data .getADCSize (); i ++){
197230 ADCData adc = data .getADCData (i );
@@ -224,10 +257,10 @@ public void fitPulses(List<DetectorDataDgtz> detectorData){
224257
225258 public void filterTDCs (List <DetectorDataDgtz > detectorData ){
226259 int maxMultiplicity = 1 ;
227- for (String table : keysFilter ){
260+ for (DetectorType type : keysFilter ){
228261 Map <Integer ,List <DetectorDataDgtz >> filteredData = new HashMap <>();
229262 for (DetectorDataDgtz data : detectorData ){
230- if (data .getDescriptor ().getType ()== DetectorType . getType ( table ) ) {
263+ if (data .getDescriptor ().getType () == type ) {
231264 int key = data .getDescriptor ().getHashCode ();
232265 if (!filteredData .containsKey (key ))
233266 filteredData .put (key , new ArrayList <>());
0 commit comments