10 #include <mysql/mysql.h>
11 #include "StEvent/StEventTypes.h"
12 #include "StMuDSTMaker/COMMON/StMuTypes.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"
51 StFmsTriggerMaker::StFmsTriggerMaker(
const char* name)
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))
65 , fp201(l1.boardAt(FP201_BASE_ADDRESS))
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))
86 , fe101(mix.boardAt(FE101_BASE_ADDRESS))
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))
107 fp201.setName(
"FP201");
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");
128 fe101.setName(
"FE101");
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");
142 fe001.bitmask = 0x01010101;
143 fe002.bitmask = 0xff010101;
144 fe003.bitmask = 0x01010101;
145 fe004.bitmask = 0xff010101;
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));
175 int StFmsTriggerMaker::Init()
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);
185 int StFmsTriggerMaker::InitRun(
int runNumber){
188 return loadRegisters(runNumber);
192 printf(
"%12d Number of ADC=0xFFF\n",mNFFF);
197 if (mUseTrgData) MakeTrgData();
198 if (mUseMuDst) MakeMuDst();
199 if (mUseStEvent) MakeStEvent();
200 if (Debug()) fillQtHistograms();
201 for(
int t=0; t<MAXT; t++){
203 if(-x>mNPre || x>mNPost)
continue;
205 if(mDBTime.GetYear()<2015){
207 writeFpeQtLayerToFpeLayer1(mix,t);
209 writeFpeLayer1ToFpdLayer2(l1,t);
212 writeFmsQtLayerToFmsLayer0(fms,t);
214 writeFmsLayer0ToFmsLayer1(fms,t);
216 writeFmsLayer1ToFpdLayer2(l1,t);
224 int StFmsTriggerMaker::MakeMuDst()
228 for (
size_t i = 0; i < fms->numberOfHits(); ++i) writeQtCrate(fms->getHit(i));
234 int StFmsTriggerMaker::MakeStEvent()
238 if (event && event->fmsCollection()) {
240 const StSPtrVecFmsHit& hits =
event->fmsCollection()->hits();
241 for (
size_t i = 0; i < hits.size(); ++i) writeQtCrate(hits[i]);
247 int StFmsTriggerMaker::MakeTrgData(){
249 if(!trgd) {printf(
"MakeTrgData found no trigger data\n");
return kStErr;}
250 mNPre=trgd->numberOfPreXing();
251 mNPost=trgd->numberOfPostXing();
254 for(
int t=0; t<MAXT; t++){
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);
262 writeQtCrate(crt,adr,ch,adc,t);
265 printf(
"0xFFF problem : Crt=%2d Adr=%2d ch=%2d ADC=%4d\n",crt,adr,ch,adc);
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};
293 int add=slot*16+chadd[ch];
294 return dFMS[add] + (dFMS[add-1]<<8) + (dFMS[add-2]<<16) + (dFMS[add-3]<<24);
297 return dFP201[add] + (dFP201[add-1]<<16);
302 void StFmsTriggerMaker::writeDsmData(
int t){
304 if(!trgd) {printf(
"writeDsmData found no trigger data\n");
return; }
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);
329 ((
int*)fm006.dsmdata[t])[3] = 0xFFFFFFFF;
331 ((
int*)fm010.dsmdata[t])[2] = 0xFFFFFFFF;
333 if(mForceRun>=16056024)
334 ((
int*)fp201.dsmdata[t])[3] = (((
int*)fp201.dsmdata[t])[3]) & 0xfffffffe;
340 void StFmsTriggerMaker::writeQtCrate(
const T*
hit,
int t){
341 switch (hit->detectorId()) {
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;
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;
363 fe002.channels[t][24+hit->channel()-1] = hit->adc();
366 fe004.channels[t][24+hit->channel()-1] = hit->adc();
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;
390 void StFmsTriggerMaker::writeQtCrate(
int crate,
int slot,
int ch,
int adc,
int t){
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;
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);
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);
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);
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);
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);
440 void StFmsTriggerMaker::runFmsLayer0(
int t){
441 switch (mDBTime.GetYear()) {
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);
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);
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);
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);
502 void StFmsTriggerMaker::runFpeLayer1(
int t){
503 mix_fe101_2009_a(fe101,t);
506 void StFmsTriggerMaker::runFmsLayer1(
int t){
507 switch (mDBTime.GetYear()) {
509 fms_fm101_2011_a(fm101,t);
510 fms_fm102_2011_a(fm102,t);
511 fms_fm102_2011_a(fm103,t);
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);
519 if(mForceRun<16056024){
520 fms_fm101_2015_a(fm101,t,mUseDsmData);
521 fms_fm101_2015_a(fm102,t,mUseDsmData);
523 fms_fm101_2015_b(fm101,t,mUseDsmData);
524 fms_fm101_2015_b(fm102,t,mUseDsmData);
526 fms_fm103_2015_a(fm103,t,mUseDsmData);
527 fms_fm103_2015_a(fm104,t,mUseDsmData);
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);
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;
545 if(mForceRun<16056024) {l1_fp201_2015_a(fp201,t,mUseDsmData);}
546 else {l1_fp201_2015_b(fp201,t,mUseDsmData);}
549 default: l1_fp201_2017_a(fp201,t,mUseDsmData);
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];
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);
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);
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);
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];
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];
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];
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];
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;
649 void StFmsTriggerMaker::writeFmsLayer0ToFmsLayer1(
Crate& sim,
int t)
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);
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];
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];
688 void StFmsTriggerMaker::writeFpeLayer1ToFpdLayer2(
Crate& sim,
int t)
690 Board& fp201sim = sim.boardAt(FP201_BASE_ADDRESS);
691 fp201sim.channels[t][6] = 0xffff;
692 fp201sim.channels[t][7] = fe101.output[t];
695 void StFmsTriggerMaker::writeFmsLayer1ToFpdLayer2(
Crate& sim,
int t)
697 Board& fp201sim = sim.boardAt(FP201_BASE_ADDRESS);
698 int* fp201simchannels= (
int*)fp201sim.channels[t];
700 if(mDBTime.GetYear()<2015){
701 fp201simchannels[0] = fm101.output[t];
702 fp201simchannels[1] = fm102.output[t];
703 fp201simchannels[2] = fm103.output[t];
705 fp201simchannels[0] = fm102.output[t];
706 fp201simchannels[1] = fm103.output[t];
707 fp201simchannels[2] = fm104.output[t];
708 fp201simchannels[3] = fm101.output[t];
712 int StFmsTriggerMaker::loadRegisters(
int runNumber)
715 const char* host1 =
"db04.star.bnl.gov";
716 const char* host2 =
"onldb2.starp.bnl.gov";
717 const char* user =
"";
718 const char* pass =
"";
720 const char* host = host1;
724 year=mDBTime.GetYear();
726 int date=(mForceRun%1000000)/1000;
727 year=mForceRun/1000000+1999;
729 LOG_INFO << Form(
"DB Year=%d forceYear=%d\n",mDBTime.GetYear(),year) <<endm;
731 unsigned int port = 3400+year%100-1;
732 if(year==2018) {port=3501; host=host2;}
733 if(year>2018) {printf(
"NO RUN19 DB yet.... Skip for now...\n");
return kStOK; }
735 const char* database =
"Conditions_rts";
736 const char* unix_socket = NULL;
737 unsigned long client_flag = 0;
740 LOG_INFO << Form(
"host=%s user=\"%s\" pass=\"%s\" port=%d database=%s",host,user,pass,port,database) << endm;
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;
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]);
759 mysql_free_result(result);
763 sprintf(query,
"select beginTime from run where idx_rn=%d",mForceRun);
764 LOG_INFO << query << endm;
765 mysql_query(&mysql,query);
767 if (MYSQL_RES* result = mysql_store_result(&mysql)) {
768 while (MYSQL_ROW row = mysql_fetch_row(result)) {
771 mysql_free_result(result);
773 LOG_INFO <<
"StFmsTriggerMaker Ignoring run# from DB timestamp and Forcing run#="<<mForceRun<<endm;
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;
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]);
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];
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;
808 mysql_free_result(result);
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;
824 int StFmsTriggerMaker::FM0xxoutput(
int number,
int t)
const{
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];
842 int StFmsTriggerMaker::FM1xxoutput(
int number,
int t)
const{
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];
852 int StFmsTriggerMaker::FP201input(
int ch,
int t)
const{
853 return ((
int*)fp201.channels[t])[ch];
856 int StFmsTriggerMaker::FM0xxinput(
int number,
int ch,
int t)
const{
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];
874 int StFmsTriggerMaker::FM1xxinput(
int number,
int ch,
int t)
const{
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];
884 int StFmsTriggerMaker::FP201data(
int ch)
const{
885 return ((
int*)fp201.dsmdata[MAXPP])[ch];
888 int StFmsTriggerMaker::FM0xxdata(
int number,
int ch,
int t)
const{
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];
906 int StFmsTriggerMaker::FM1xxdata(
int number,
int ch,
int t)
const{
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];
916 int StFmsTriggerMaker::FM0xxuserdata(
int number,
int ch,
int t)
const{
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];
934 int StFmsTriggerMaker::FM1xxuserdata(
int number,
int ch,
int t)
const{
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];
944 int StFmsTriggerMaker::FP201userdata(
int ch,
int t)
const{
945 return fp201.userdata[MAXPP][ch];
static StMuFmsCollection * muFmsCollection()
returns pointer to current StMuFmsCollection
void Clear(Option_t *option="")
User defined functions.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)