44import java .util .Arrays ;
55import java .util .Comparator ;
66import java .util .HashMap ;
7+ import java .util .HashSet ;
78import java .util .List ;
89import java .util .Map ;
10+ import java .util .stream .Collectors ;
911import org .jlab .detector .banks .RawBank .OrderType ;
1012import org .jlab .detector .base .DetectorType ;
1113import org .jlab .detector .calib .utils .ConstantsManager ;
@@ -22,13 +24,12 @@ public class DetectorEventDecoder {
2224 ConstantsManager fitterManager = new ConstantsManager ();
2325 ConstantsManager scalerManager = new ConstantsManager ();
2426
25- List < String > tablesTrans = null ;
26- List < String > tablesFitter = null ;
27+ HashSet < DetectorType > keysFilter ;
28+ HashSet < DetectorType > keysMicromega ;
2729
28- List <DetectorType > keysTrans = null ;
29- List <DetectorType > keysFitter = null ;
30- List <DetectorType > keysFilter = null ;
31- List <DetectorType > keysMicromega = null ;
30+ HashMap <DetectorType ,String > tableTrans ;
31+ HashMap <DetectorType ,String > tableFitter ;
32+ HashMap <DetectorType ,IndexedTable > tablesFitter ;
3233
3334 private int runNumber = 10 ;
3435
@@ -71,8 +72,11 @@ public void setVariation(String variation) {
7172 public void setRunNumber (int run ){
7273 if (run != this .runNumber ) {
7374 translator = new TranslationTable ();
74- for (int i =0 ; i <keysTrans .size (); i ++)
75- translator .add (keysTrans .get (i ), translationManager .getConstants (run , tablesTrans .get (i )));
75+ tablesFitter = new HashMap <>();
76+ for (DetectorType t : tableTrans .keySet ())
77+ translator .add (t , translationManager .getConstants (run , tableTrans .get (t )));
78+ for (DetectorType t : tableFitter .keySet ())
79+ tablesFitter .put (t , fitterManager .getConstants (run , tableFitter .get (t )));
7680 }
7781 this .runNumber = run ;
7882 }
@@ -91,13 +95,26 @@ public float getRcdbSolenoidScale() {
9195 getValue ()).floatValue ();
9296 }
9397
94- public final void initDecoderDev (){
95- keysTrans = Arrays .asList (new DetectorType []{ DetectorType .HTCC ,DetectorType .BST ,DetectorType .RTPC } );
96- tablesTrans = Arrays .asList (new String []{ "/daq/tt/clasdev/htcc" ,"/daq/tt/clasdev/svt" ,"/daq/tt/clasdev/rtpc" });
97- keysFitter = Arrays .asList (new DetectorType []{DetectorType .HTCC });
98- tablesFitter = Arrays .asList (new String []{"/daq/fadc/clasdev/htcc" });
99- translationManager .init (tablesTrans );
100- fitterManager .init (tablesFitter );
98+ public DetectorEventDecoder (){
99+ this .initDecoder ();
100+ }
101+
102+ public final void initDecoderDev () {
103+
104+ keysFilter = new HashSet <>();
105+ keysMicromega = new HashSet <>();
106+ tableTrans = new HashMap <>();
107+ tableFitter = new HashMap <>();
108+ keysFilter .add (DetectorType .DC );
109+
110+ tableTrans .put (DetectorType .HTCC , "/daq/tt/clasdev/htcc" );
111+ tableTrans .put (DetectorType .BST , "/daq/tt/clasdev/svt" );
112+ tableTrans .put (DetectorType .RTPC , "/daq/tt/clasdev/rtpc" );
113+ translationManager .init (tableTrans .values ().stream ().collect (Collectors .toList ()));
114+
115+ tableFitter .put (DetectorType .HTCC , "/daq/fadc/clasdev/htcc" );
116+ fitterManager .init (tableFitter .values ().stream ().collect (Collectors .toList ()));
117+
101118 scalerManager .init (Arrays .asList (new String []{"/runcontrol/fcup" ,"/runcontrol/slm" ,"/runcontrol/hwp" ,
102119 "/runcontrol/helicity" ,"/daq/config/scalers/dsc1" }));
103120 }
@@ -108,35 +125,59 @@ public final void initDecoder() {
108125
109126 public final void initDecoder (boolean initializeManagers ){
110127
111- // Detector translation table
112- keysTrans = Arrays .asList (new DetectorType []{DetectorType .FTCAL ,DetectorType .FTHODO ,DetectorType .FTTRK ,DetectorType .LTCC ,DetectorType .ECAL ,DetectorType .FTOF ,
113- DetectorType .HTCC ,DetectorType .DC ,DetectorType .CTOF ,DetectorType .CND ,DetectorType .BST ,DetectorType .RF ,DetectorType .BMT ,DetectorType .FMT ,
114- DetectorType .RICH ,DetectorType .HEL ,DetectorType .BAND ,DetectorType .RTPC ,
115- DetectorType .RASTER ,DetectorType .ATOF ,DetectorType .AHDC
116- });
117- tablesTrans = Arrays .asList (new String []{
118- "/daq/tt/ftcal" ,"/daq/tt/fthodo" ,"/daq/tt/fttrk" ,"/daq/tt/ltcc" ,
119- "/daq/tt/ec" ,"/daq/tt/ftof" ,"/daq/tt/htcc" ,"/daq/tt/dc" ,"/daq/tt/ctof" ,"/daq/tt/cnd" ,"/daq/tt/svt" ,
120- "/daq/tt/rf" ,"/daq/tt/bmt" ,"/daq/tt/fmt" ,"/daq/tt/rich2" ,"/daq/tt/hel" ,"/daq/tt/band" ,"/daq/tt/rtpc" ,
121- "/daq/tt/raster" ,"/daq/tt/atof" ,"/daq/tt/ahdc"
122- });
123-
124- // ADC waveform fitter translation table
125- keysFitter = Arrays .asList (new DetectorType []{DetectorType .FTCAL ,DetectorType .FTHODO ,DetectorType .FTTRK ,DetectorType .FTOF ,DetectorType .LTCC ,
126- DetectorType .ECAL ,DetectorType .HTCC ,DetectorType .CTOF ,DetectorType .CND ,DetectorType .BMT ,
127- DetectorType .FMT ,DetectorType .HEL ,DetectorType .RF ,DetectorType .BAND ,DetectorType .RASTER ,
128- DetectorType .AHDC });
129- tablesFitter = Arrays .asList (new String []{
130- "/daq/fadc/ftcal" ,"/daq/fadc/fthodo" ,"/daq/config/fttrk" ,"/daq/fadc/ftof" ,"/daq/fadc/ltcc" ,
131- "/daq/fadc/ec" , "/daq/fadc/htcc" ,"/daq/fadc/ctof" ,"/daq/fadc/cnd" ,"/daq/config/bmt" ,
132- "/daq/config/fmt" ,"/daq/fadc/hel" ,"/daq/fadc/rf" ,"/daq/fadc/band" ,"/daq/fadc/raster" ,
133- "/daq/config/ahdc"
134- });
135-
136- // Data filter list
137- keysFilter = Arrays .asList (new DetectorType []{DetectorType .DC });
138-
139- keysMicromega = Arrays .asList (new DetectorType []{DetectorType .BMT ,DetectorType .FMT ,DetectorType .FTTRK });
128+ keysFilter = new HashSet <>();
129+ keysMicromega = new HashSet <>();
130+ tableTrans = new HashMap <>();
131+ tableFitter = new HashMap <>();
132+ keysFilter .add (DetectorType .DC );
133+
134+ keysMicromega .add (DetectorType .BMT );
135+ keysMicromega .add (DetectorType .FMT );
136+ keysMicromega .add (DetectorType .FTTRK );
137+
138+ tableTrans .put (DetectorType .FTCAL , "/daq/tt/ftcal" );
139+ tableTrans .put (DetectorType .FTHODO , "/daq/tt/fthodo" );
140+ tableTrans .put (DetectorType .FTTRK , "/daq/tt/fttrk" );
141+ tableTrans .put (DetectorType .LTCC , "/daq/tt/ltcc" );
142+ tableTrans .put (DetectorType .ECAL , "/daq/tt/ec" );
143+ tableTrans .put (DetectorType .FTOF , "/daq/tt/ftof" );
144+ tableTrans .put (DetectorType .HTCC , "/daq/tt/htcc" );
145+ tableTrans .put (DetectorType .DC , "/daq/tt/dc" );
146+ tableTrans .put (DetectorType .CTOF , "/daq/tt/ctof" );
147+ tableTrans .put (DetectorType .CND , "/daq/tt/cnd" );
148+ tableTrans .put (DetectorType .BST , "/daq/tt/svt" );
149+ tableTrans .put (DetectorType .RF , "/daq/tt/rf" );
150+ tableTrans .put (DetectorType .BMT , "/daq/tt/bmt" );
151+ tableTrans .put (DetectorType .FMT , "/daq/tt/fmt" );
152+ tableTrans .put (DetectorType .RICH , "/daq/tt/rich2" );
153+ tableTrans .put (DetectorType .HEL , "/daq/tt/hel" );
154+ tableTrans .put (DetectorType .BAND , "/daq/tt/band" );
155+ tableTrans .put (DetectorType .RTPC , "/daq/tt/rtpc" );
156+ tableTrans .put (DetectorType .RASTER , "/daq/tt/raster" );
157+ tableTrans .put (DetectorType .ATOF , "/daq/tt/atof" );
158+ tableTrans .put (DetectorType .AHDC , "/daq/tt/ahdc" );
159+ translationManager .init (tableTrans .values ().stream ().collect (Collectors .toList ()));
160+
161+ tableFitter .put (DetectorType .FTCAL , "/daq/fadc/ftcal" );
162+ tableFitter .put (DetectorType .FTHODO , "/daq/fadc/fthodo" );
163+ tableFitter .put (DetectorType .FTTRK , "/daq/fadc/fttrk" );
164+ tableFitter .put (DetectorType .FTOF , "/daq/fadc/ftof" );
165+ tableFitter .put (DetectorType .LTCC , "/daq/fadc/ltcc" );
166+ tableFitter .put (DetectorType .ECAL , "/daq/fadc/ec" );
167+ tableFitter .put (DetectorType .HTCC , "/daq/fadc/htcc" );
168+ tableFitter .put (DetectorType .CTOF , "/daq/fadc/ctof" );
169+ tableFitter .put (DetectorType .CND , "/daq/fadc/cnd" );
170+ tableFitter .put (DetectorType .BMT , "/daq/fadc/bmt" );
171+ tableFitter .put (DetectorType .FMT , "/daq/fadc/fmt" );
172+ tableFitter .put (DetectorType .HEL , "/daq/fadc/hel" );
173+ tableFitter .put (DetectorType .RF , "/daq/fadc/rf" );
174+ tableFitter .put (DetectorType .BAND , "/daq/fadc/band" );
175+ tableFitter .put (DetectorType .RASTER , "/daq/fadc/raster" );
176+ tableFitter .put (DetectorType .AHDC , "/daq/fadc/ahdc" );
177+ fitterManager .init (tableFitter .values ().stream ().collect (Collectors .toList ()));
178+
179+ scalerManager .init (Arrays .asList (new String []{"/runcontrol/fcup" ,
180+ "/runcontrol/slm" ,"/runcontrol/hwp" ,"/runcontrol/helicity" ,"/daq/config/scalers/dsc1" }));
140181
141182 if (initializeManagers ) {
142183 translationManager .init (tablesTrans );
@@ -149,10 +190,11 @@ public final void initDecoder(boolean initializeManagers){
149190 }
150191
151192 public void checkTables () {
152- for (int i =0 ; i <tablesTrans .size (); i ++) {
153- IndexedTable t = translationManager .getConstants (runNumber , tablesTrans .get (i ));
193+ List <String > tables = (List )tableTrans .values ().stream ().collect (Collectors .toList ());
194+ for (int i =0 ; i <tables .size (); i ++) {
195+ IndexedTable t = translationManager .getConstants (runNumber , tables .get (i ));
154196 for (int j =0 ; j <i ; j ++)
155- t .conflicts (translationManager .getConstants (runNumber , tablesTrans .get (j )));
197+ t .conflicts (translationManager .getConstants (runNumber , tables .get (j )));
156198 }
157199 }
158200
@@ -185,9 +227,9 @@ public void translate(List<DetectorDataDgtz> detectorData){
185227 public void fitPulses (List <DetectorDataDgtz > detectorData ){
186228
187229 // preload CCDB tables once:
188- ArrayList < IndexedTable > tables = new ArrayList <>();
189- for (String name : tablesFitter ) {
190- tables .add ( fitterManager .getConstants (runNumber , name ));
230+ HashMap < DetectorType , IndexedTable > tables = new HashMap <>();
231+ for (Map . Entry < DetectorType , String > e : tableFitter . entrySet () ) {
232+ tables .put ( e . getKey (), fitterManager .getConstants (runNumber , e . getValue () ));
191233 }
192234
193235 for (DetectorDataDgtz data : detectorData ){
@@ -199,9 +241,8 @@ public void fitPulses(List<DetectorDataDgtz> detectorData){
199241 long hash0 = IndexedTable .DEFAULT_GENERATOR .hashCode (0 ,0 ,0 );
200242 boolean ismm = keysMicromega .contains (data .getDescriptor ().getType ());
201243
202- for (int j =0 ; j <keysFitter .size (); ++j ) {
203- IndexedTable daq = tables .get (j );
204- DetectorType type = keysFitter .get (j );
244+ for (DetectorType type : tableFitter .keySet ()) {
245+ IndexedTable daq = tables .get (type );
205246 //custom MM fitter
206247 if (ismm && data .getDescriptor ().getType () == type ) {
207248 short adcOffset = (short ) daq .getDoubleValueByHash ("adc_offset" , hash0 );
0 commit comments