StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFmsTriggerMaker.cxx
1 //
2 // Pibero Djawotho <pibero@tamu.edu>
3 // Texas A&M
4 // 13 July 2012
5 //
6 
7 #include <algorithm>
8 #include <cstring>
9 #include "TH2.h"
10 #include <mysql/mysql.h>
11 #include "StEvent/StEventTypes.h"
12 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
13 #include "Board.hh"
14 #include "Crate.hh"
15 #include "qt32b_fpe_2009_a.hh"
16 #include "qt32b_fms_2009_a.hh"
17 #include "fms_fm001_2011_a.hh"
18 #include "fms_fm005_2011_a.hh"
19 #include "fms_fm006_2011_a.hh"
20 #include "mix_fe101_2009_a.hh"
21 #include "fms_fm101_2011_a.hh"
22 #include "fms_fm102_2011_a.hh"
23 #include "l1_fp201_2011_a.hh"
24 #include "fms_fm001_2012_a.hh"
25 #include "fms_fm101_2012_a.hh"
26 #include "fms_fm102_2012_a.hh"
27 #include "l1_fp201_2012_b.hh"
28 #include "qt32b_fms_2015_a.hh"
29 #include "fms_fm001_2015_a.hh"
30 #include "fms_fm005_2015_a.hh"
31 #include "fms_fm006_2015_a.hh"
32 #include "fms_fm101_2015_a.hh"
33 #include "fms_fm101_2015_b.hh"
34 #include "fms_fm103_2015_a.hh"
35 #include "l1_fp201_2015_a.hh"
36 #include "l1_fp201_2015_b.hh"
37 #include "fms_fm001_2017_a.hh"
38 #include "fms_fm005_2017_a.hh"
39 #include "fms_fm006_2017_a.hh"
40 #include "fms_fm101_2017_a.hh"
41 #include "fms_fm101_2017_a.hh"
42 #include "fms_fm103_2017_a.hh"
43 #include "l1_fp201_2017_a.hh"
44 #include "l1_fp201_2017_a.hh"
45 #include "StFmsTriggerMaker.h"
46 
47 using namespace std;
48 
49 ClassImp(StFmsTriggerMaker);
50 
51 StFmsTriggerMaker::StFmsTriggerMaker(const char* name)
52  : StMaker(name)
53 
54  // Crates
55  , l1(crateAt(L1_CONF_NUM))
56  , fms(crateAt(FMS_CONF_NUM))
57  , mix(crateAt(MIX_CONF_NUM))
58  , feq(crateAt(FEQ_CONF_NUM))
59  , qt1(crateAt(QT1_CONF_NUM))
60  , qt2(crateAt(QT2_CONF_NUM))
61  , qt3(crateAt(QT3_CONF_NUM))
62  , qt4(crateAt(QT4_CONF_NUM))
63 
64  // L1 crate
65  , fp201(l1.boardAt(FP201_BASE_ADDRESS))
66 
67  // FMS crate
68  , fm001(fms.boardAt(FM001_BASE_ADDRESS))
69  , fm002(fms.boardAt(FM002_BASE_ADDRESS))
70  , fm003(fms.boardAt(FM003_BASE_ADDRESS))
71  , fm004(fms.boardAt(FM004_BASE_ADDRESS))
72  , fm005(fms.boardAt(FM005_BASE_ADDRESS))
73  , fm006(fms.boardAt(FM006_BASE_ADDRESS))
74  , fm007(fms.boardAt(FM007_BASE_ADDRESS))
75  , fm008(fms.boardAt(FM008_BASE_ADDRESS))
76  , fm009(fms.boardAt(FM009_BASE_ADDRESS))
77  , fm010(fms.boardAt(FM010_BASE_ADDRESS))
78  , fm011(fms.boardAt(FM011_BASE_ADDRESS))
79  , fm012(fms.boardAt(FM012_BASE_ADDRESS))
80  , fm101(fms.boardAt(FM101_BASE_ADDRESS))
81  , fm102(fms.boardAt(FM102_BASE_ADDRESS))
82  , fm103(fms.boardAt(FM103_BASE_ADDRESS))
83  , fm104(fms.boardAt(FM104_BASE_ADDRESS))
84 
85  // MIX crate
86  , fe101(mix.boardAt(FE101_BASE_ADDRESS))
87 
88  // FEQ crate
89  , fe001(feq.boardAt(FE001_BASE_ADDRESS))
90  , fe002(feq.boardAt(FE002_BASE_ADDRESS))
91  , fe003(feq.boardAt(FE003_BASE_ADDRESS))
92  , fe004(feq.boardAt(FE004_BASE_ADDRESS))
93  , fs001(feq.boardAt(FS001_BASE_ADDRESS))
94  , fs002(feq.boardAt(FS002_BASE_ADDRESS))
95  , fs003(feq.boardAt(FS003_BASE_ADDRESS))
96  , fs004(feq.boardAt(FS004_BASE_ADDRESS))
97  , fs005(feq.boardAt(FS005_BASE_ADDRESS))
98  , fs006(feq.boardAt(FS006_BASE_ADDRESS))
99 
100  , mForceRun(0)
101  , mNThrOW(0)
102  , mUseDsmData(0)
103  , mNPre(0)
104  , mNPost(0)
105 {
106  // L1 crate
107  fp201.setName("FP201");
108 
109  // FMS crate
110  fm001.setName("FM001");
111  fm002.setName("FM002");
112  fm003.setName("FM003");
113  fm004.setName("FM004");
114  fm005.setName("FM005");
115  fm006.setName("FM006");
116  fm007.setName("FM007");
117  fm008.setName("FM008");
118  fm009.setName("FM009");
119  fm010.setName("FM010");
120  fm011.setName("FM011");
121  fm012.setName("FM012");
122  fm101.setName("FM101");
123  fm102.setName("FM102");
124  fm103.setName("FM103");
125  fm104.setName("FM104");
126 
127  // MIX crate
128  fe101.setName("FE101");
129 
130  // FEQ crate
131  fe001.setName("FE001");
132  fe002.setName("FE002");
133  fe003.setName("FE003");
134  fe004.setName("FE004");
135  fs001.setName("FS001");
136  fs002.setName("FS002");
137  fs003.setName("FS003");
138  fs004.setName("FS004");
139  fs005.setName("FS005");
140  fs006.setName("FS006");
141 
142  fe001.bitmask = 0x01010101;
143  fe002.bitmask = 0xff010101;
144  fe003.bitmask = 0x01010101;
145  fe004.bitmask = 0xff010101;
146 
147  //QT1-4
148  for(int i=0; i<16; i++){
149  qt1.boards[i].setName(Form("QT1.0x%02x",i+0x10));
150  qt2.boards[i].setName(Form("QT2.0x%02x",i+0x10));
151  qt3.boards[i].setName(Form("QT3.0x%02x",i+0x10));
152  qt4.boards[i].setName(Form("QT4.0x%02x",i+0x10));
153  }
154 
155  // Input mode
156  mUseTrgData = 0;
157  mUseMuDst = 0;
158  mUseStEvent = 0;
159 
160  //ADC=0xFFF counter
161  mNFFF=0;
162 }
163 
164 void StFmsTriggerMaker::Clear(Option_t* option)
165 {
166  qt1.clear();
167  qt2.clear();
168  qt3.clear();
169  qt4.clear();
170  feq.clear();
171  fms.clear();
172  l1.clear();
173 }
174 
175 int StFmsTriggerMaker::Init()
176 {
177  hqt1adc = new TH2F("hqt1adc","QT1 crate;QT channel;QT ADC",512,0,512,1024,0,1024);
178  hqt2adc = new TH2F("hqt2adc","QT2 crate;QT channel;QT ADC",512,0,512,1024,0,1024);
179  hqt3adc = new TH2F("hqt3adc","QT3 crate;QT channel;QT ADC",512,0,512,1024,0,1024);
180  hqt4adc = new TH2F("hqt4adc","QT4 crate;QT channel;QT ADC",512,0,512,1024,0,1024);
181  hfeqadc = new TH2F("hfeqadc","FEQ crate;QT channel;QT ADC",512,0,512,1024,0,1024);
182  return kStOk;
183 }
184 
185 int StFmsTriggerMaker::InitRun(int runNumber){
186  //mDBTime = GetDBTime();
187  //mDBTime = TDatime();
188  return loadRegisters(runNumber);
189 }
190 
192  printf("%12d Number of ADC=0xFFF\n",mNFFF);
193  return kStOK;
194 }
195 
197  if (mUseTrgData) MakeTrgData();
198  if (mUseMuDst) MakeMuDst();
199  if (mUseStEvent) MakeStEvent();
200  if (Debug()) fillQtHistograms();
201  for(int t=0; t<MAXT; t++){
202  int x=t-MAXPP;
203  if(-x>mNPre || x>mNPost) continue;
204  writeDsmData(t);
205  if(mDBTime.GetYear()<2015){
206  runFpeQtLayer(t);
207  writeFpeQtLayerToFpeLayer1(mix,t);
208  runFpeLayer1(t);
209  writeFpeLayer1ToFpdLayer2(l1,t);
210  }
211  runFmsQtLayer(t);
212  writeFmsQtLayerToFmsLayer0(fms,t);
213  runFmsLayer0(t);
214  writeFmsLayer0ToFmsLayer1(fms,t);
215  runFmsLayer1(t);
216  writeFmsLayer1ToFpdLayer2(l1,t);
217  runFpdLayer2(t);
218  }
219  //LOG_INFO << Form("FP201: Fms-HT-th0=%d Fms-HT-th1=%d FmsSml-Cluster-th0=%d FmsSml-Cluster-th1=%d FmsSml-Cluster-th2=%d FmsLrg-Cluster-th0=%d FmsLrg-Cluster-th1=%d FmsLrg-Cluster-th2=%d Fms-JP-th0=%d Fms-JP-th1=%d Fms-JP-th2=%d Fms-dijet=%d FPE=%d",FmsHighTowerTh0(),FmsHighTowerTh1(),FmsSmallClusterTh0(),FmsSmallClusterTh1(),FmsSmallClusterTh2(),FmsLargeClusterTh0(),FmsLargeClusterTh1(),FmsLargeClusterTh2(),FmsJetPatchTh0(),FmsJetPatchTh1(),FmsJetPatchTh2(),FmsDijet(),FPE()) << endm;
220  //LOG_INFO << Form("FP201: 0x%04x (data) / 0x%04x (simu)",StMuDst::event()->l0Trigger().lastDsmArray(5),FP201output()) << endm;
221  return kStOk;
222 }
223 
224 int StFmsTriggerMaker::MakeMuDst()
225 {
227  if (fms) {
228  for (size_t i = 0; i < fms->numberOfHits(); ++i) writeQtCrate(fms->getHit(i));
229  return kStOk;
230  }
231  return kStErr;
232 }
233 
234 int StFmsTriggerMaker::MakeStEvent()
235 {
236  StEvent* event = (StEvent*)GetDataSet("StEvent");
237  // printf("Getting StEvent and fmsCollection %x %x\n",event,event->fmsCollection());
238  if (event && event->fmsCollection()) {
239  //printf("Found StEvent and fmsCollection\n");
240  const StSPtrVecFmsHit& hits = event->fmsCollection()->hits();
241  for (size_t i = 0; i < hits.size(); ++i) writeQtCrate(hits[i]);
242  return kStOk;
243  }
244  return kStErr;
245 }
246 
247 int StFmsTriggerMaker::MakeTrgData(){
248  StTriggerData* trgd=(StTriggerData*)GetDataSet("StTriggerData")->GetObject();
249  if(!trgd) {printf("MakeTrgData found no trigger data\n"); return kStErr;}
250  mNPre=trgd->numberOfPreXing();
251  mNPost=trgd->numberOfPostXing();
252  //printf("StFmsTriggerMaker::MakeTrgData found npre=%d npost=%d\n",mNPre,mNPost);
253  int n=0;
254  for(int t=0; t<MAXT; t++){
255  int x=t-MAXPP;
256  if(-x>mNPre || x>mNPost) continue;
257  for(int crt=1; crt<=4; crt++){
258  for(int adr=0; adr<12; adr++){
259  for(int ch=0; ch<32; ch++){
260  int adc=trgd->fmsADC(crt,adr,ch,x);
261  if(adc>0) {
262  writeQtCrate(crt,adr,ch,adc,t);
263  n++;
264  if(adc==0xFFF) {
265  printf("0xFFF problem : Crt=%2d Adr=%2d ch=%2d ADC=%4d\n",crt,adr,ch,adc);
266  mNFFF++;
267  }
268  // if(crt==2 && adr==0) printf("Crt=%2d Adr=%2d ch=%2d ADC=%4d\n",crt,adr,ch,adc);
269  }
270  }
271  }
272  }
273  }
274  //printf("StFmsTriggerMaker::MakeTrgData found %d hits\n",n);
275  //hack FAKE stuck bits -akio
276  /*
277  for(int t=0; t<MAXT; t++){
278  int x=t-MAXPP;
279  if(-x>mNPre|| x>mNPost) continue;
280  writeQtCrate(3,2,16,0x115,t);
281  writeQtCrate(4,5, 0,0x040,t);
282  }
283  */
284  return kStOk;
285 }
286 
287 unsigned char* dFMS;
288 unsigned short dFP201[8];
289 inline unsigned int getDSMdata(int slot, int ch){
290  static const int chadd[4]={7,3,15,11};
291  static const int chadd2[4]={3,1,7,5};
292  if(slot<16){
293  int add=slot*16+chadd[ch];
294  return dFMS[add] + (dFMS[add-1]<<8) + (dFMS[add-2]<<16) + (dFMS[add-3]<<24);
295  }else if(slot==16){
296  int add=chadd2[ch];
297  return dFP201[add] + (dFP201[add-1]<<16);
298  }
299  return 0;
300 }
301 
302 void StFmsTriggerMaker::writeDsmData(int t){
303  StTriggerData* trgd=(StTriggerData*)GetDataSet("StTriggerData")->GetObject();
304  if(!trgd) {printf("writeDsmData found no trigger data\n"); return; }
305  int x=t-MAXPP;
306  dFMS=trgd->getDsm_FMS(x);
307  if(x==0) for(int i=0; i<8; i++) dFP201[i]=trgd->fpdLayer2DSMRaw(i);
308  for(int ch=0; ch<4; ch++){
309  ((int*)fm001.dsmdata[t])[ch] = getDSMdata(0,ch);
310  ((int*)fm002.dsmdata[t])[ch] = getDSMdata(1,ch);
311  ((int*)fm003.dsmdata[t])[ch] = getDSMdata(3,ch);
312  ((int*)fm004.dsmdata[t])[ch] = getDSMdata(4,ch);
313  ((int*)fm005.dsmdata[t])[ch] = getDSMdata(6,ch);
314  ((int*)fm006.dsmdata[t])[ch] = getDSMdata(7,ch);
315  ((int*)fm007.dsmdata[t])[ch] = getDSMdata(8,ch);
316  ((int*)fm008.dsmdata[t])[ch] = getDSMdata(9,ch);
317  ((int*)fm009.dsmdata[t])[ch] = getDSMdata(11,ch);
318  ((int*)fm010.dsmdata[t])[ch] = getDSMdata(12,ch);
319  ((int*)fm011.dsmdata[t])[ch] = getDSMdata(13,ch);
320  ((int*)fm012.dsmdata[t])[ch] = getDSMdata(14,ch);
321  ((int*)fm101.dsmdata[t])[ch] = getDSMdata(2,ch);
322  ((int*)fm102.dsmdata[t])[ch] = getDSMdata(5,ch);
323  ((int*)fm103.dsmdata[t])[ch] = getDSMdata(10,ch);
324  ((int*)fm104.dsmdata[t])[ch] = getDSMdata(15,ch);
325  if(x==0) ((int*)fp201.dsmdata[t])[ch] = getDSMdata(16,ch);
326  }
327 
328  //FAKE!!! FM006 4th int should be 0xFFFFFFFF since not connected... but shows some activities fake increasing mismatch%. Masking out -akio
329  ((int*)fm006.dsmdata[t])[3] = 0xFFFFFFFF;
330  //FAKE!!! FM010 3rd int should be 0xFFFFFFFF since not connected... but shows some activities fake increasing mismatch%. Masking out -akio
331  ((int*)fm010.dsmdata[t])[2] = 0xFFFFFFFF;
332  //FAKE!!! FP201 4th int bit0 is stuck high and not in use after 2015b algo is in. Masking out to get real mismatch% -akio
333  if(mForceRun>=16056024)
334  ((int*)fp201.dsmdata[t])[3] = (((int*)fp201.dsmdata[t])[3]) & 0xfffffffe;
335 
336  //printf("StFmsTriggerMaker::writeDsmData x=%d\n",x);
337 }
338 
339 template<class T>
340 void StFmsTriggerMaker::writeQtCrate(const T* hit, int t){
341  switch (hit->detectorId()) {
342  case 0: // fpd north
343  {
344  int qtdaughter = (hit->channel()-1)/7;
345  int qtchannel = (hit->channel()-1)%7;
346  switch (qtdaughter/4) {
347  case 0: fe001.channels[t][(qtdaughter%4)*8+qtchannel] = hit->adc(); break;
348  case 1: fe002.channels[t][(qtdaughter%4)*8+qtchannel] = hit->adc(); break;
349  }
350  }
351  break;
352  case 1: // fpd south
353  {
354  int qtdaughter = (hit->channel()-1)/7;
355  int qtchannel = (hit->channel()-1)%7;
356  switch (qtdaughter/4) {
357  case 0: fe003.channels[t][(qtdaughter%4)*8+qtchannel] = hit->adc(); break;
358  case 1: fe004.channels[t][(qtdaughter%4)*8+qtchannel] = hit->adc(); break;
359  }
360  }
361  break;
362  case 2: // fpd preshower north
363  fe002.channels[t][24+hit->channel()-1] = hit->adc();
364  break;
365  case 3: // fpd preshower south
366  fe004.channels[t][24+hit->channel()-1] = hit->adc();
367  break;
368  case 4: // fpd north smdv
369  case 5: // fpd south smdv
370  case 6: // fpd north smdh
371  case 7: // fpd south smdh
372  break;
373  case 8: // fms north large
374  case 9: // fms south large
375  case 10: // fms north small
376  case 11: // fms south small
377  switch (hit->qtCrate()) {
378  case 1: qt1.boards[hit->qtSlot()-1].channels[t][hit->qtChannel()] = hit->adc(); break;
379  case 2: qt2.boards[hit->qtSlot()-1].channels[t][hit->qtChannel()] = hit->adc(); break;
380  case 3: qt3.boards[hit->qtSlot()-1].channels[t][hit->qtChannel()] = hit->adc(); break;
381  case 4: qt4.boards[hit->qtSlot()-1].channels[t][hit->qtChannel()] = hit->adc(); break;
382  }
383  break;
384  case 12: // fhc north
385  case 13: // fhc south
386  break;
387  }
388 }
389 
390 void StFmsTriggerMaker::writeQtCrate(int crate, int slot, int ch, int adc, int t){
391  switch (crate) {
392  case 1: qt1.boards[slot].channels[t][ch] = adc; break;
393  case 2: qt2.boards[slot].channels[t][ch] = adc; break;
394  case 3: qt3.boards[slot].channels[t][ch] = adc; break;
395  case 4: qt4.boards[slot].channels[t][ch] = adc; break;
396  }
397 }
398 
399 void StFmsTriggerMaker::fillQtHistogram(const Crate& qtcrate, TH2F* hqtadc, int t){
400  for (int slot = 0; slot < 16; ++slot) {
401  for (int channel = 0; channel < 32; ++channel) {
402  int idx = slot*32+channel;
403  int adc = qtcrate.boards[slot].channels[t][channel];
404  hqtadc->Fill(idx,adc);
405  }
406  }
407 }
408 
409 void StFmsTriggerMaker::fillQtHistograms(int t){
410  fillQtHistogram(qt1,hqt1adc,t);
411  fillQtHistogram(qt2,hqt2adc,t);
412  fillQtHistogram(qt3,hqt3adc,t);
413  fillQtHistogram(qt4,hqt4adc,t);
414  fillQtHistogram(feq,hfeqadc,t);
415 }
416 
417 void StFmsTriggerMaker::runFpeQtLayer(int t){
418  qt32b_fpe_2009_a(fe001,t);
419  qt32b_fpe_2009_a(fe002,t);
420  qt32b_fpe_2009_a(fe003,t);
421  qt32b_fpe_2009_a(fe004,t);
422 }
423 
424 void StFmsTriggerMaker::runFmsQtLayer(int t){
425  for(int i=0; i<12; i++){
426  if(mDBTime.GetYear()<2015){
427  qt32b_fms_2009_a(qt1.boards[i],t);
428  qt32b_fms_2009_a(qt2.boards[i],t);
429  qt32b_fms_2009_a(qt3.boards[i],t);
430  qt32b_fms_2009_a(qt4.boards[i],t);
431  }else{
432  qt32b_fms_2015_a(qt1.boards[i],t);
433  qt32b_fms_2015_a(qt2.boards[i],t);
434  qt32b_fms_2015_a(qt3.boards[i],t);
435  qt32b_fms_2015_a(qt4.boards[i],t);
436  }
437  }
438 }
439 
440 void StFmsTriggerMaker::runFmsLayer0(int t){
441  switch (mDBTime.GetYear()) {
442  case 2011:
443  fms_fm001_2011_a(fm001,t);
444  fms_fm001_2011_a(fm002,t);
445  fms_fm001_2011_a(fm003,t);
446  fms_fm001_2011_a(fm004,t);
447  fms_fm005_2011_a(fm005,t);
448  fms_fm005_2011_a(fm007,t);
449  fms_fm005_2011_a(fm009,t);
450  fms_fm005_2011_a(fm011,t);
451  fms_fm006_2011_a(fm006,t);
452  fms_fm006_2011_a(fm008,t);
453  fms_fm006_2011_a(fm010,t);
454  fms_fm006_2011_a(fm012,t);
455  break;
456  case 2012: case 2013:
457  fms_fm001_2012_a(fm001,t);
458  fms_fm001_2012_a(fm002,t);
459  fms_fm001_2012_a(fm003,t);
460  fms_fm001_2012_a(fm004,t);
461  fms_fm005_2011_a(fm005,t);
462  fms_fm005_2011_a(fm007,t);
463  fms_fm005_2011_a(fm009,t);
464  fms_fm005_2011_a(fm011,t);
465  fms_fm006_2011_a(fm006,t);
466  fms_fm006_2011_a(fm008,t);
467  fms_fm006_2011_a(fm010,t);
468  fms_fm006_2011_a(fm012,t);
469  break;
470  case 2015:
471  fms_fm001_2015_a(fm001,t,mUseDsmData);
472  fms_fm001_2015_a(fm002,t,mUseDsmData);
473  fms_fm001_2015_a(fm003,t,mUseDsmData);
474  fms_fm001_2015_a(fm004,t,mUseDsmData);
475  fms_fm005_2015_a(fm005,t,mUseDsmData);
476  fms_fm006_2015_a(fm006,t,mUseDsmData);
477  fms_fm005_2015_a(fm007,t,mUseDsmData);
478  fms_fm006_2015_a(fm008,t,mUseDsmData);
479  fms_fm005_2015_a(fm009,t,mUseDsmData);
480  fms_fm006_2015_a(fm010,t,mUseDsmData);
481  fms_fm005_2015_a(fm011,t,mUseDsmData);
482  fms_fm006_2015_a(fm012,t,mUseDsmData);
483  break;
484  case 2017:
485  default:
486  fms_fm001_2017_a(fm001,t,mUseDsmData);
487  fms_fm001_2017_a(fm002,t,mUseDsmData);
488  fms_fm001_2017_a(fm003,t,mUseDsmData);
489  fms_fm001_2017_a(fm004,t,mUseDsmData);
490  fms_fm005_2017_a(fm005,t,mUseDsmData);
491  fms_fm006_2017_a(fm006,t,mUseDsmData);
492  fms_fm005_2017_a(fm007,t,mUseDsmData);
493  fms_fm006_2017_a(fm008,t,mUseDsmData);
494  fms_fm005_2017_a(fm009,t,mUseDsmData);
495  fms_fm006_2017_a(fm010,t,mUseDsmData);
496  fms_fm005_2017_a(fm011,t,mUseDsmData);
497  fms_fm006_2017_a(fm012,t,mUseDsmData);
498  break;
499  }
500 }
501 
502 void StFmsTriggerMaker::runFpeLayer1(int t){
503  mix_fe101_2009_a(fe101,t);
504 }
505 
506 void StFmsTriggerMaker::runFmsLayer1(int t){
507  switch (mDBTime.GetYear()) {
508  case 2011:
509  fms_fm101_2011_a(fm101,t);
510  fms_fm102_2011_a(fm102,t);
511  fms_fm102_2011_a(fm103,t);
512  break;
513  case 2012: case 2013:
514  fms_fm101_2012_a(fm101,t);
515  fms_fm102_2012_a(fm102,t);
516  fms_fm102_2012_a(fm103,t);
517  break;
518  case 2015:
519  if(mForceRun<16056024){
520  fms_fm101_2015_a(fm101,t,mUseDsmData);
521  fms_fm101_2015_a(fm102,t,mUseDsmData);
522  }else{
523  fms_fm101_2015_b(fm101,t,mUseDsmData);
524  fms_fm101_2015_b(fm102,t,mUseDsmData);
525  }
526  fms_fm103_2015_a(fm103,t,mUseDsmData);
527  fms_fm103_2015_a(fm104,t,mUseDsmData);
528  break;
529  case 2017:
530  default:
531  fms_fm101_2017_a(fm101,t,mUseDsmData);
532  fms_fm101_2017_a(fm102,t,mUseDsmData);
533  fms_fm103_2017_a(fm103,t,mUseDsmData);
534  fms_fm103_2017_a(fm104,t,mUseDsmData);
535  break;
536  }
537 }
538 
539 void StFmsTriggerMaker::runFpdLayer2(int t){
540  switch (mDBTime.GetYear()) {
541  case 2011: l1_fp201_2011_a(fp201,t); break;
542  case 2012: l1_fp201_2012_b(fp201,t); break;
543  case 2013: l1_fp201_2012_b(fp201,t); break;
544  case 2015:
545  if(mForceRun<16056024) {l1_fp201_2015_a(fp201,t,mUseDsmData);}
546  else {l1_fp201_2015_b(fp201,t,mUseDsmData);}
547  break;
548  case 2017:
549  default: l1_fp201_2017_a(fp201,t,mUseDsmData);
550  break;
551  }
552 }
553 
554 void StFmsTriggerMaker::writeFpeQtLayerToFpeLayer1(Crate& sim, int t){
555  Board& fe101sim = sim.boardAt(FE101_BASE_ADDRESS);
556  int* fe101simchannels = (int*)fe101sim.channels[t];
557  fe101simchannels[0] = fe001.output[t];
558  fe101simchannels[1] = fe002.output[t];
559  fe101simchannels[2] = fe003.output[t];
560  fe101simchannels[3] = fe004.output[t];
561 }
562 
563 void StFmsTriggerMaker::writeFmsQtLayerToFmsLayer0(Crate& sim, int t){
564  Board& fm001sim = sim.boardAt(FM001_BASE_ADDRESS);
565  Board& fm002sim = sim.boardAt(FM002_BASE_ADDRESS);
566  Board& fm003sim = sim.boardAt(FM003_BASE_ADDRESS);
567  Board& fm004sim = sim.boardAt(FM004_BASE_ADDRESS);
568 
569  Board& fm005sim = sim.boardAt(FM005_BASE_ADDRESS);
570  Board& fm006sim = sim.boardAt(FM006_BASE_ADDRESS);
571  Board& fm007sim = sim.boardAt(FM007_BASE_ADDRESS);
572  Board& fm008sim = sim.boardAt(FM008_BASE_ADDRESS);
573 
574  Board& fm009sim = sim.boardAt(FM009_BASE_ADDRESS);
575  Board& fm010sim = sim.boardAt(FM010_BASE_ADDRESS);
576  Board& fm011sim = sim.boardAt(FM011_BASE_ADDRESS);
577  Board& fm012sim = sim.boardAt(FM012_BASE_ADDRESS);
578 
579  for (int ch = 0; ch < 4; ++ch) {
580  ((int*)fm001sim.channels[t])[ch] = qt1.boards[3-ch].output[t];
581  ((int*)fm002sim.channels[t])[ch] = qt2.boards[3-ch].output[t];
582  ((int*)fm003sim.channels[t])[ch] = qt3.boards[3-ch].output[t];
583  ((int*)fm004sim.channels[t])[ch] = qt4.boards[3-ch].output[t];
584  if(mDBTime.GetYear()<2015){
585  ((int*)fm005sim.channels[t])[ch] = qt1.boards[7-ch].output[t];
586  ((int*)fm007sim.channels[t])[ch] = qt2.boards[7-ch].output[t];
587  ((int*)fm009sim.channels[t])[ch] = qt3.boards[7-ch].output[t];
588  ((int*)fm011sim.channels[t])[ch] = qt4.boards[7-ch].output[t];
589  }else{
590  ((int*)fm005sim.channels[t])[ch] = qt1.boards[9-ch].output[t];
591  ((int*)fm007sim.channels[t])[ch] = qt2.boards[9-ch].output[t];
592  ((int*)fm009sim.channels[t])[ch] = qt3.boards[9-ch].output[t];
593  ((int*)fm011sim.channels[t])[ch] = qt4.boards[9-ch].output[t];
594  }
595  }
596 
597  for (int ch = 0; ch < 2; ++ch) {
598  if(mDBTime.GetYear()<2015){
599  ((int*)fm006sim.channels[t])[ch] = qt1.boards[9-ch].output[t];
600  ((int*)fm008sim.channels[t])[ch] = qt2.boards[9-ch].output[t];
601  ((int*)fm010sim.channels[t])[ch] = qt3.boards[9-ch].output[t];
602  ((int*)fm012sim.channels[t])[ch] = qt4.boards[9-ch].output[t];
603  }else{
604  ((int*)fm006sim.channels[t])[ch] = qt1.boards[5-ch].output[t];
605  ((int*)fm008sim.channels[t])[ch] = qt2.boards[5-ch].output[t];
606  ((int*)fm010sim.channels[t])[ch] = qt3.boards[5-ch].output[t];
607  ((int*)fm012sim.channels[t])[ch] = qt4.boards[5-ch].output[t];
608  }
609  }
610 
611  //ZERO-ing out QT3A->FM003 lower 16 bits FAKE - akio
612  //((int*)fm003sim.channels[t])[3] = 0;
613  //wrong map!!!
614  /*
615  ((int*)fm005sim.channels[t])[1] = qt1.boards[4].output[t];
616  ((int*)fm005sim.channels[t])[0] = qt1.boards[5].output[t];
617  ((int*)fm006sim.channels[t])[1] = qt1.boards[6].output[t];
618  ((int*)fm006sim.channels[t])[0] = qt1.boards[7].output[t];
619  ((int*)fm005sim.channels[t])[3] = qt1.boards[8].output[t];
620  ((int*)fm005sim.channels[t])[2] = qt1.boards[9].output[t];
621  ((int*)fm007sim.channels[t])[1] = qt2.boards[4].output[t];
622  ((int*)fm007sim.channels[t])[0] = qt2.boards[5].output[t];
623  ((int*)fm008sim.channels[t])[1] = qt2.boards[6].output[t];
624  ((int*)fm008sim.channels[t])[0] = qt2.boards[7].output[t];
625  ((int*)fm007sim.channels[t])[3] = qt2.boards[8].output[t];
626  ((int*)fm007sim.channels[t])[2] = qt2.boards[9].output[t];
627  ((int*)fm009sim.channels[t])[1] = qt3.boards[4].output[t];
628  ((int*)fm009sim.channels[t])[0] = qt3.boards[5].output[t];
629  ((int*)fm010sim.channels[t])[1] = qt3.boards[6].output[t];
630  ((int*)fm010sim.channels[t])[0] = qt3.boards[7].output[t];
631  ((int*)fm009sim.channels[t])[3] = qt3.boards[9].output[t];
632  ((int*)fm009sim.channels[t])[2] = qt3.boards[10].output[t];
633  ((int*)fm011sim.channels[t])[1] = qt4.boards[4].output[t];
634  ((int*)fm011sim.channels[t])[0] = qt4.boards[5].output[t];
635  ((int*)fm012sim.channels[t])[1] = qt4.boards[6].output[t];
636  ((int*)fm012sim.channels[t])[0] = qt4.boards[7].output[t];
637  ((int*)fm011sim.channels[t])[3] = qt4.boards[9].output[t];
638  ((int*)fm011sim.channels[t])[2] = qt4.boards[10].output[t];
639  */
640 
641  for (int ch = 2; ch < 4; ++ch) {
642  ((int*)fm006sim.channels[t])[ch] = 0xffffffff;
643  ((int*)fm008sim.channels[t])[ch] = 0xffffffff;
644  ((int*)fm010sim.channels[t])[ch] = 0xffffffff;
645  ((int*)fm012sim.channels[t])[ch] = 0xffffffff;
646  }
647 }
648 
649 void StFmsTriggerMaker::writeFmsLayer0ToFmsLayer1(Crate& sim, int t)
650 {
651  Board& fm101sim = sim.boardAt(FM101_BASE_ADDRESS);
652  Board& fm102sim = sim.boardAt(FM102_BASE_ADDRESS);
653  Board& fm103sim = sim.boardAt(FM103_BASE_ADDRESS);
654  Board& fm104sim = sim.boardAt(FM104_BASE_ADDRESS);
655 
656  if(mDBTime.GetYear()<2015){
657  for (int ch = 0; ch < 4; ++ch) {
658  ((int*)fm101sim.channels[t])[ch] = fms.boards[ch ].output[t];
659  ((int*)fm102sim.channels[t])[ch] = fms.boards[ch+5 ].output[t];
660  ((int*)fm103sim.channels[t])[ch] = fms.boards[ch+10].output[t];
661  }
662  }else{
663  ((int*)fm101sim.channels[t])[0] = fms.boards[17].output[t];
664  ((int*)fm101sim.channels[t])[1] = fms.boards[0].output[t];
665  ((int*)fm102sim.channels[t])[0] = fms.boards[2].output[t];
666  ((int*)fm102sim.channels[t])[1] = fms.boards[3].output[t];
667  ((int*)fm103sim.channels[t])[0] = fms.boards[5].output[t];
668  ((int*)fm103sim.channels[t])[1] = fms.boards[6].output[t];
669  ((int*)fm103sim.channels[t])[2] = fms.boards[7].output[t];
670  ((int*)fm103sim.channels[t])[3] = fms.boards[8].output[t];
671  ((int*)fm104sim.channels[t])[0] = fms.boards[10].output[t];
672  ((int*)fm104sim.channels[t])[1] = fms.boards[11].output[t];
673  ((int*)fm104sim.channels[t])[2] = fms.boards[12].output[t];
674  ((int*)fm104sim.channels[t])[3] = fms.boards[13].output[t];
675  /*
676  for (int ch = 0; ch < 4; ++ch) {
677  if(ch<2){
678  ((int*)fm101sim.channels[t])[ch] = fms.boards[ch ].output[t];
679  ((int*)fm102sim.channels[t])[ch] = fms.boards[ch+2].output[t];
680  }
681  ((int*)fm103sim.channels[t])[ch] = fms.boards[ch+5].output[t];
682  ((int*)fm104sim.channels[t])[ch] = fms.boards[ch+10].output[t];
683  }
684  */
685  }
686 }
687 
688 void StFmsTriggerMaker::writeFpeLayer1ToFpdLayer2(Crate& sim, int t)
689 {
690  Board& fp201sim = sim.boardAt(FP201_BASE_ADDRESS);
691  fp201sim.channels[t][6] = 0xffff; // unused
692  fp201sim.channels[t][7] = fe101.output[t];
693 }
694 
695 void StFmsTriggerMaker::writeFmsLayer1ToFpdLayer2(Crate& sim, int t)
696 {
697  Board& fp201sim = sim.boardAt(FP201_BASE_ADDRESS);
698  int* fp201simchannels= (int*)fp201sim.channels[t];
699 
700  if(mDBTime.GetYear()<2015){
701  fp201simchannels[0] = fm101.output[t];
702  fp201simchannels[1] = fm102.output[t];
703  fp201simchannels[2] = fm103.output[t];
704  }else{
705  fp201simchannels[0] = fm102.output[t];
706  fp201simchannels[1] = fm103.output[t];
707  fp201simchannels[2] = fm104.output[t];
708  fp201simchannels[3] = fm101.output[t];
709  }
710 }
711 
712 int StFmsTriggerMaker::loadRegisters(int runNumber)
713 {
714  MYSQL mysql;
715  const char* host1 = "db04.star.bnl.gov"; //offline DB which has online DB copies from past year (a hack! don't tell Dmitry!)
716  const char* host2 = "onldb2.starp.bnl.gov"; //this is online DB for current run, cannot access from ofl/rcas
717  const char* user = "";
718  const char* pass = "";
719  // See http://drupal.star.bnl.gov/STAR/comp/db/onlinedb/online-sever-port-map
720  const char* host = host1;
721  int year;
722  if(mForceRun==0){
723  mDBTime=GetDBTime();
724  year=mDBTime.GetYear();
725  }else{
726  int date=(mForceRun%1000000)/1000;
727  year=mForceRun/1000000+1999;
728  if(date>250) year++;
729  LOG_INFO << Form("DB Year=%d forceYear=%d\n",mDBTime.GetYear(),year) <<endm;
730  }
731  unsigned int port = 3400+year%100-1;
732  if(year==2018) {port=3501; host=host2;} //only works at online machines
733  if(year>2018) {printf("NO RUN19 DB yet.... Skip for now...\n"); return kStOK; }
734 
735  const char* database = "Conditions_rts";
736  const char* unix_socket = NULL;
737  unsigned long client_flag = 0;
738  char query[1024];
739 
740  LOG_INFO << Form("host=%s user=\"%s\" pass=\"%s\" port=%d database=%s",host,user,pass,port,database) << endm;
741 
742  mysql_init(&mysql);
743 
744  // Open connection to online database
745  if (!mysql_real_connect(&mysql,host,user,pass,database,port,unix_socket,client_flag)) {
746  LOG_ERROR << "Can't connect to database: " << mysql_error(&mysql) << endm;
747  return kStErr;
748  }
749 
750  // Get run number associated with DB time stamp
751  if(mForceRun==0) {
752  sprintf(query,"select max(idx_rn) from triggers where beginTime <= '%s'",mDBTime.AsSQLString());
753  LOG_INFO << query << endm;
754  mysql_query(&mysql,query);
755  if (MYSQL_RES* result = mysql_store_result(&mysql)) {
756  while (MYSQL_ROW row = mysql_fetch_row(result)) {
757  runNumber = atoi(row[0]);
758  }
759  mysql_free_result(result);
760  }
761  }else{
762  //if mForceRun is set, get date/time for the run, and overwrite run# and DBdate/time.
763  sprintf(query,"select beginTime from run where idx_rn=%d",mForceRun);
764  LOG_INFO << query << endm;
765  mysql_query(&mysql,query);
766  TString newdt;
767  if (MYSQL_RES* result = mysql_store_result(&mysql)) {
768  while (MYSQL_ROW row = mysql_fetch_row(result)) {
769  newdt=row[0];
770  }
771  mysql_free_result(result);
772  }
773  LOG_INFO << "StFmsTriggerMaker Ignoring run# from DB timestamp and Forcing run#="<<mForceRun<<endm;
774  //LOG_INFO << " from "<<mDBTime.GetDate()<< " " <<mDBTime.GetTime();
775  mDBTime.Set(newdt.Data());
776  LOG_INFO << "StFmsTriggerMaker DB timestamp is taken from forced run begin time = "<<mDBTime.GetDate()<< " " <<mDBTime.GetTime()<< endm;
777  runNumber = mForceRun;
778  }
779 
780  // Get register values
781  // object=DSM crate, idx=DSM board
782  sprintf(query,"select object,idx,reg,label,value,defaultvalue from dict where hash=(select dicthash from run where idx_rn = %d)",runNumber);
783  LOG_DEBUG << query << endm;
784  mysql_query(&mysql,query);
785  if (MYSQL_RES* result = mysql_store_result(&mysql)) {
786  LOG_DEBUG<< setw(10) << "object" << setw(10) << "idx" << setw(10) << "reg" << setw(30) << "label" << setw(10) << "value" << setw(15) << "defaultvalue" << endm;
787  while (MYSQL_ROW row = mysql_fetch_row(result)) {
788  int object = atoi(row[0]);
789  int idx = atoi(row[1]);
790  int reg = atoi(row[2]);
791  TString label = row[3];
792  int value = atoi(row[4]);
793  int defaultvalue = atoi(row[5]);
794  if(mNThrOW>0){
795  for(int i=0; i<mNThrOW; i++){
796  if(label.Contains(mThrOWName[i])) {
797  LOG_INFO << "Overwriting Thr="<<mThrOWName[i].Data()<<" from " <<value<< " to "<<mThrOWValue[i]<<endm;
798  value=mThrOWValue[i];
799  }
800  }
801  }
802  LOG_DEBUG << setw(10) << object << setw(10) << idx << setw(10) << reg << setw(30) << label << setw(10) << value << setw(15) << defaultvalue << endm;
803  if (object >= 1 && object <= NCRATES && idx >= 0x10) {
804  LOG_DEBUG << object << '\t' << idx << '\t' << reg << '\t' << label << '\t' << value << '\t' << defaultvalue << endm;
805  crateAt(object).boardAt(idx<<24).registerAt(reg<<24) = (value == -1) ? defaultvalue : value;
806  }
807  }
808  mysql_free_result(result);
809  }
810 
811  // Close connection to online database
812  mysql_close(&mysql);
813 
814  return kStOk;
815 }
816 
817 void StFmsTriggerMaker::overwriteThr(char* name, int value){
818  mThrOWName[mNThrOW]=name;
819  mThrOWValue[mNThrOW]=value;
820  LOG_INFO << "Set overwriting Thr="<<mThrOWName[mNThrOW].Data()<<" to "<<mThrOWValue[mNThrOW]<<endm;
821  mNThrOW++;
822 }
823 
824 int StFmsTriggerMaker::FM0xxoutput(int number, int t) const{
825  switch(number){
826  case 1: return fm001.output[t];
827  case 2: return fm002.output[t];
828  case 3: return fm003.output[t];
829  case 4: return fm004.output[t];
830  case 5: return fm005.output[t];
831  case 6: return fm006.output[t];
832  case 7: return fm007.output[t];
833  case 8: return fm008.output[t];
834  case 9: return fm009.output[t];
835  case 10: return fm010.output[t];
836  case 11: return fm011.output[t];
837  case 12: return fm012.output[t];
838  }
839  return 0;
840 }
841 
842 int StFmsTriggerMaker::FM1xxoutput(int number, int t) const{
843  switch(number){
844  case 1: return fm101.output[t];
845  case 2: return fm102.output[t];
846  case 3: return fm103.output[t];
847  case 4: return fm104.output[t];
848  }
849  return 0;
850 }
851 
852 int StFmsTriggerMaker::FP201input(int ch, int t) const{
853  return ((int*)fp201.channels[t])[ch];
854 }
855 
856 int StFmsTriggerMaker::FM0xxinput(int number, int ch, int t) const{
857  switch(number){
858  case 1: return ((int*)fm001.channels[t])[ch];
859  case 2: return ((int*)fm002.channels[t])[ch];
860  case 3: return ((int*)fm003.channels[t])[ch];
861  case 4: return ((int*)fm004.channels[t])[ch];
862  case 5: return ((int*)fm005.channels[t])[ch];
863  case 6: return ((int*)fm006.channels[t])[ch];
864  case 7: return ((int*)fm007.channels[t])[ch];
865  case 8: return ((int*)fm008.channels[t])[ch];
866  case 9: return ((int*)fm009.channels[t])[ch];
867  case 10: return ((int*)fm010.channels[t])[ch];
868  case 11: return ((int*)fm011.channels[t])[ch];
869  case 12: return ((int*)fm012.channels[t])[ch];
870  }
871  return 0;
872 }
873 
874 int StFmsTriggerMaker::FM1xxinput(int number, int ch, int t) const{
875  switch(number){
876  case 1: return ((int*)fm101.channels[t])[ch];
877  case 2: return ((int*)fm102.channels[t])[ch];
878  case 3: return ((int*)fm103.channels[t])[ch];
879  case 4: return ((int*)fm104.channels[t])[ch];
880  }
881  return 0;
882 }
883 
884 int StFmsTriggerMaker::FP201data(int ch) const{
885  return ((int*)fp201.dsmdata[MAXPP])[ch];
886 }
887 
888 int StFmsTriggerMaker::FM0xxdata(int number, int ch, int t) const{
889  switch(number){
890  case 1: return ((int*)fm001.dsmdata[t])[ch];
891  case 2: return ((int*)fm002.dsmdata[t])[ch];
892  case 3: return ((int*)fm003.dsmdata[t])[ch];
893  case 4: return ((int*)fm004.dsmdata[t])[ch];
894  case 5: return ((int*)fm005.dsmdata[t])[ch];
895  case 6: return ((int*)fm006.dsmdata[t])[ch];
896  case 7: return ((int*)fm007.dsmdata[t])[ch];
897  case 8: return ((int*)fm008.dsmdata[t])[ch];
898  case 9: return ((int*)fm009.dsmdata[t])[ch];
899  case 10: return ((int*)fm010.dsmdata[t])[ch];
900  case 11: return ((int*)fm011.dsmdata[t])[ch];
901  case 12: return ((int*)fm012.dsmdata[t])[ch];
902  }
903  return 0;
904 }
905 
906 int StFmsTriggerMaker::FM1xxdata(int number, int ch, int t) const{
907  switch(number){
908  case 1: return ((int*)fm101.dsmdata[t])[ch];
909  case 2: return ((int*)fm102.dsmdata[t])[ch];
910  case 3: return ((int*)fm103.dsmdata[t])[ch];
911  case 4: return ((int*)fm104.dsmdata[t])[ch];
912  }
913  return 0;
914 }
915 
916 int StFmsTriggerMaker::FM0xxuserdata(int number, int ch, int t) const{
917  switch(number){
918  case 1: return ((int*)fm001.userdata[t])[ch];
919  case 2: return ((int*)fm002.userdata[t])[ch];
920  case 3: return ((int*)fm003.userdata[t])[ch];
921  case 4: return ((int*)fm004.userdata[t])[ch];
922  case 5: return ((int*)fm005.userdata[t])[ch];
923  case 6: return ((int*)fm006.userdata[t])[ch];
924  case 7: return ((int*)fm007.userdata[t])[ch];
925  case 8: return ((int*)fm008.userdata[t])[ch];
926  case 9: return ((int*)fm009.userdata[t])[ch];
927  case 10: return ((int*)fm010.userdata[t])[ch];
928  case 11: return ((int*)fm011.userdata[t])[ch];
929  case 12: return ((int*)fm012.userdata[t])[ch];
930  }
931  return 0;
932 }
933 
934 int StFmsTriggerMaker::FM1xxuserdata(int number, int ch, int t) const{
935  switch(number){
936  case 1: return ((int*)fm101.userdata[t])[ch];
937  case 2: return ((int*)fm102.userdata[t])[ch];
938  case 3: return ((int*)fm103.userdata[t])[ch];
939  case 4: return ((int*)fm104.userdata[t])[ch];
940  }
941  return 0;
942 }
943 
944 int StFmsTriggerMaker::FP201userdata(int ch, int t) const{
945  return fp201.userdata[MAXPP][ch];
946 }
947 
948 
static StMuFmsCollection * muFmsCollection()
returns pointer to current StMuFmsCollection
Definition: StMuDst.h:391
Definition: Crate.hh:193
Definition: Board.hh:14
void Clear(Option_t *option="")
User defined functions.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:40
Definition: Stypes.h:44
Definition: Stypes.h:41