20 #include "FairLogger.h"
21 #include "FairRootManager.h"
23 #include "FairRunOnline.h"
24 #include "FairRuntimeDb.h"
27 #include "TClonesArray.h"
28 #include "THttpServer.h"
52 , fvbMaskedComponents()
53 , fvMsComponentsList()
58 fbIgnoreOverlapMs(kFALSE)
59 , fUnpackParMuch(NULL)
75 fsHistoFileFullname(
"data/HistosMonitorMuch.root")
76 , fbPrintMessages(kFALSE)
81 , fuCurrentEquipmentId(0)
84 , fiRunStartDateTimeSec(-1)
85 , fiBinSizeDatePlots(-1)
87 , fvuCurrentTsMsbCycle()
88 , fvuInitialHeaderDone()
89 , fvuInitialTsMsbCycleHeader()
91 , fvulChanLastHitTime()
92 , fvdChanLastHitTime()
96 , fvdChanLastHitTimeInMs()
97 , fvusChanLastHitAdcInMs()
105 , fdStartTimeMsSz(-1.0)
106 , ftStartTimeUnix(std::chrono::steady_clock::now())
110 , fuMaxNbMicroslices(100)
111 , fiTimeIntervalRateUpdate(10)
112 , fviFebTimeSecLastRateUpdate()
113 , fviFebCountsSinceLastRateUpdate()
114 , fvdFebChanCountsSinceLastRateUpdate()
123 , fhMuchMessType(NULL)
124 , fhMuchSysMessType(NULL)
125 , fhMuchFebChanAdcRaw_combined(NULL)
126 , fhMuchMessTypePerDpb(NULL)
127 , fhMuchSysMessTypePerDpb(NULL)
128 , fhStatusMessType(NULL)
129 , fhMsStatusFieldType(NULL)
130 , fhMuchHitsElinkPerDpb(NULL)
134 , fRealHistPadDistr()
135 , fhMuchFebChanCntRaw()
138 fhMuchFebChanAdcRaw()
139 , fhMuchFebChanAdcRawProf()
140 , fhMuchFebChanRawTs()
141 , fhMuchFebChanHitRateEvo()
142 , fhMuchFebChanHitRateProf()
145 fhMuchFebHitRateEvo()
146 , fhMuchFebHitRateEvo_mskch()
147 , fhMuchFebHitRateEvo_mskch_adccut()
148 , fhMuchFebHitRateEvo_WithoutDupli()
149 , fdMuchFebChanLastTimeForDist()
150 , fhMuchFebChanDistT()
151 , fhMuchFebDuplicateHitProf()
152 , fcMsSizeAll(NULL) {}
159 LOG(info) <<
"Initializing flib StsXyter unpacker for MUCH";
161 FairRootManager* ioman = FairRootManager::Instance();
162 if (ioman == NULL) { LOG(fatal) <<
"No FairRootManager instance"; }
168 LOG(info) <<
"Setting parameter containers for " << GetName();
171 "CbmMcbm2018MuchPar"));
175 LOG(info) <<
"Init parameter containers for " << GetName();
184 LOG(info) <<
"ReInit parameter containers for " << GetName();
193 LOG(info) <<
"Nr. of MUCH DPBs: " <<
fuNrOfDpbs;
196 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
198 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x"
200 << std::dec <<
" => "
205 LOG(info) <<
"Nr. of FEBs: " <<
fuNbFebs;
213 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
226 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
229 LOG(info) << Form(
"DPB #%02u CROB #%02u Active: ", uDpb, uCrobIdx)
235 LOG(info) <<
"Unpacking data in bin sorter FW mode";
237 LOG(info) <<
"Unpacking data in full time sorter FW mode (legacy)";
245 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
267 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbFebs; ++uXyterIdx) {
293 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::ReInitContainers => Changed "
294 "fvuChanNbHitsInMs size "
296 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::ReInitContainers => Changed "
297 "fvuChanNbHitsInMs size "
300 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::ReInitContainers => Changed "
301 "fvuChanNbHitsInMs size "
309 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
333 LOG(error) <<
"CbmMcbm2018MonitorMuchLite::AddMsComponentToList => "
334 <<
"Ignored the addition of component " << component
335 <<
" as it is above the hadcoded limit of "
338 <<
" To change this behavior check kiMaxNbFlibLinks in "
339 "CbmMcbm2018MonitorMuchLite.cxx";
347 <<
"CbmMcbm2018MonitorMuchLite::AddMsComponentToList => Added component: "
351 if (NULL ==
fhMsSz[component]) {
352 TString sMsSzName = Form(
"MsSz_link_%02lu", component);
354 Form(
"Size of MS for nDPB of link %02lu; Ms Size [bytes]", component);
356 new TH1F(sMsSzName.Data(), sMsSzTitle.Data(), 160000, 0., 20000.);
359 sMsSzName = Form(
"MsSzTime_link_%02lu", component);
361 "Size of MS vs time for gDPB of link %02lu; Time[s] ; Ms Size [bytes]",
364 new TProfile(sMsSzName.Data(), sMsSzTitle.Data(), 15000, 0., 300.);
372 LOG(info) <<
"Added MS size histo for component: " << component <<
" (DPB)";
374 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
376 server->Register(
"/FlibRaw",
fhMsSz[component]);
377 server->Register(
"/FlibRaw",
fhMsSzTime[component]);
383 size_t uOverlapMsNb) {
396 for (UInt_t uXyterIdx = 0; uXyterIdx <
fuNbStsXyters; ++uXyterIdx) {
414 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => Changed "
415 "fvuChanNbHitsInMs size "
417 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => Changed "
418 "fvuChanNbHitsInMs size "
421 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => Changed "
422 "fvuChanNbHitsInMs size "
428 TString sHistName {
""};
431 sHistName =
"hMessageType";
432 title =
"Nb of message for each type; Type";
442 sHistName =
"hSysMessType";
443 title =
"Nb of system message for each type; System Type";
446 sHistName =
"hMuchFebChanAdcRaw_combined";
447 title =
"ADC hist combined";
454 LOG(debug) <<
"Initialized 1st Histo";
455 sHistName =
"hMessageTypePerDpb";
456 title =
"Nb of message of each type for each DPB; DPB; Type";
466 for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) {
468 sHistName = Form(
"HistPadDistr_Module_%01u", uModuleId);
469 title = Form(
"Pad distribution for, Module #%01u; ", uModuleId);
473 new TH2I(sHistName, title, 23, -0.5, 22.5, 97, -0.5, 96.5));
475 sHistName = Form(
"RealHistPadDistr_Module_%01u", uModuleId);
476 title = Form(
"Progressive Pad distribution for, Module #%01u; ", uModuleId);
479 new TH2D(sHistName, title, 500, -0.5, 499.5, 1000, -0.5, 999.5));
483 sHistName = Form(
"hMuchFebDuplicateHitProf_%01u", uModuleId);
484 title = Form(
"FEB wise Duplicate Hit for Module #%01u; FEB []; Hit []",
489 new TProfile(sHistName, title, 18, -0.5, 18 - 0.5));
493 new TProfile(sHistName, title, 18, -0.5, 18 - 0.5));
497 title =
"Rate in kHz";
498 fhRate =
new TH1I(sHistName, title, 10000, -0.5, 9999.5);
500 sHistName =
"hRateAdcCut";
501 title =
"Rate in kHz with Adc cut";
502 fhRateAdcCut =
new TH1I(sHistName, title, 10000, -0.5, 9999.5);
505 sHistName =
"hFEBcount";
506 title =
"Count vs FEB number; FEB Number; Count";
507 fhFEBcount =
new TH1I(sHistName, title, 40, -0.5, 39.5);
510 sHistName =
"hSysMessTypePerDpb";
511 title =
"Nb of system message of each type for each DPB; DPB; System Type";
515 sHistName =
"hStatusMessType";
516 title =
"Nb of status message of each type for each DPB; ASIC; Status Type";
521 sHistName =
"hMsStatusFieldType";
523 "For each flag in the MS header, ON/OFF counts; Flag bit []; ON/OFF; MS []";
525 new TH2I(sHistName, title, 16, -0.5, 15.5, 2, -0.5, 1.5);
528 sHistName =
"hMuchHitsElinkPerDpb";
529 title =
"Nb of hit messages per eLink for each DPB; DPB; eLink; Hits nb []";
533 LOG(debug) <<
"Initialized 2nd Histo";
569 LOG(debug) <<
"Initialized 3rd Histo";
590 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
592 sHistName = Form(
"hMuchFebChanCntRaw_%03u", uFebIdx);
594 Form(
"Hits Count per channel, FEB #%03u; Channel; Hits []", uFebIdx);
607 sHistName = Form(
"fhMuchFebSpill_%03u", uFebIdx);
609 Form(
"Time distribution of hits, FEB #%03u; Time ; Counts ", uFebIdx);
610 fhMuchFebSpill.push_back(
new TH1I(sHistName, title, 1000, 0, 1000));
613 sHistName = Form(
"hMuchChannelTime_FEB%03u", uFebIdx);
614 title = Form(
"Time vs Channel, FEB #%03u; TIME(s) ; CHANNEL ", uFebIdx);
616 new TH2I(sHistName, title, 1000, 0, 1000, 129, -0.5, 128.5));
619 sHistName = Form(
"hMuchFebADC_%03u", uFebIdx);
620 title = Form(
"CHANNEL vs ADC, FEB #%03u; CHANNEL ; ADC ", uFebIdx);
622 new TH2I(sHistName, title, 129, -0.5, 128.5, 34, -0.5, 33.5));
626 sHistName = Form(
"hMuchFebChanAdcRaw_%03u", uFebIdx);
627 title = Form(
"Raw Adc distribution per channel, FEB #%03u; Channel []; Adc "
641 sHistName = Form(
"hMuchFebChanAdcRawProfc_%03u", uFebIdx);
642 title = Form(
"Raw Adc prodile per channel, FEB #%03u; Channel []; Adc []",
645 new TProfile(sHistName,
665 sHistName = Form(
"hMuchFebChanRawTs_%03u", uFebIdx);
666 title = Form(
"Raw Timestamp distribution per channel, FEB #%03u; Channel "
667 "[]; Ts []; Hits []",
680 sHistName = Form(
"hMuchFebChanRateEvo_%03u", uFebIdx);
682 "Hits per second & channel in FEB #%03u; Time [s]; Channel []; Hits []",
695 sHistName = Form(
"hMuchFebChanRateProf_%03u", uFebIdx);
697 "Hits per second for each channel in FEB #%03u; Channel []; Hits/s []",
700 new TProfile(sHistName,
713 sHistName = Form(
"hMuchFebRateEvo_%03u", uFebIdx);
714 title = Form(
"Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx);
719 sHistName = Form(
"hMuchFebRateEvo_mskch_%03u", uFebIdx);
720 title = Form(
"Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx);
722 new TH1I(sHistName, title, 1800, 0, 1800));
725 sHistName = Form(
"hMuchFebRateEvo_mskch_adcut_%03u", uFebIdx);
726 title = Form(
"Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx);
728 new TH1I(sHistName, title, 1800, 0, 1800));
731 sHistName = Form(
"hMuchFebRateEvo_WithoutDupli_%03u", uFebIdx);
732 title = Form(
"Hits per second in FEB #%03u; Time [s]; Hits []", uFebIdx);
734 new TH1I(sHistName, title, 50000, 0, 5000));
757 sHistName = Form(
"hMuchFebChanDistT_%03u", uFebIdx);
758 title = Form(
"Time distance between hits on same channel in between FEB "
759 "#%03u; Time difference [ns]; Channel []; ",
775 "; DPB []; Error type []; Counts []",
790 LOG(debug) <<
"Initialized 6th Histo before FairRunOnlne Instance";
791 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
793 for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) {
810 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
830 LOG(debug) <<
"Initialized fhMuchFebHitRateEvo_WithoutDupli number "
841 LOG(debug) <<
"Initialized FEB 8th Histo";
842 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetMuchLite=kTRUE");
843 server->RegisterCommand(
"/Write_All",
"bMcbm2018WriteMuchLite=kTRUE");
844 server->RegisterCommand(
"/ScanNoisyCh",
"bMcbm2018ScanNoisyMuchLite=kTRUE");
845 server->Restrict(
"/Reset_All",
"allow=admin");
846 server->Restrict(
"/Write_All",
"allow=admin");
847 server->Restrict(
"/ScanNoisyCh",
"allow=admin");
850 LOG(debug) <<
"Initialized All Histos 8th Histo";
854 LOG(debug) <<
"Initialized 7th Histo before Summary per FEB";
856 TCanvas* cChannel =
new TCanvas(Form(
"CHANNELS"),
859 cChannel->Divide(4, 9);
861 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
863 cChannel->cd(uFebIdx + 1);
872 server->Register(
"/canvases", cChannel);
875 TCanvas* cspill =
new TCanvas(Form(
"SPILLS"), Form(
"SPILLS"));
876 cspill->Divide(4, 9);
878 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
880 UInt_t flPad = 1 + uFebIdx;
889 server->Register(
"/canvases", cspill);
891 TCanvas* cadc =
new TCanvas(Form(
"ADC"), Form(
"ADC"), w,
h);
894 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
896 UInt_t flPad = 1 + uFebIdx;
904 server->Register(
"/canvases", cadc);
906 TCanvas* cChanneltime =
907 new TCanvas(Form(
"ChannelvsTime"), Form(
"ChannelvsTime"), w,
h);
908 cChanneltime->Divide(4, 9);
910 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
912 UInt_t flPad = 1 + uFebIdx;
913 cChanneltime->cd(flPad);
920 server->Register(
"/canvases", cChanneltime);
922 LOG(debug) <<
"Initialized Last Histo before exiting CreateHistograms";
927 fcMsSizeAll =
dynamic_cast<TCanvas*
>(gROOT->FindObject(
"cMsSizeAll"));
930 "Evolution of MS size in last 300 s");
932 LOG(info) <<
"Created MS size canvas in Much monitor";
936 LOG(info) <<
"Recovered MS size canvas in Much monitor";
957 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component)
967 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
974 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
985 uint32_t uEqId =
static_cast<uint32_t
>(msDescriptor.eq_id & 0xFFFF);
989 <<
"Could not find the sDPB index for AFCK id 0x" << std::hex
990 << uEqId << std::dec <<
" component " << uMsCompIdx <<
"\n"
991 <<
"If valid this index has to be added in the TOF parameter file "
992 "in the RocIdArray field"
994 <<
"For now we remove it from the list of components analyzed";
1005 if (kFALSE ==
ProcessMuchMs(ts, uMsComp, uMsIdx))
return kFALSE;
1016 std::vector<stsxyter::FinalHit>::iterator itA;
1017 std::vector<stsxyter::FinalHit>::iterator itB;
1026 UShort_t usAsicIdx = (*itA).GetAsic();
1051 if (0 == ts.index() % 1000) {
1052 for (UInt_t uDpb = 0; uDpb <
fuNrOfDpbs; ++uDpb) {
1053 Double_t dTsMsbTime =
1068 LOG(info) <<
"End of TS " << std::setw(7) << ts.index() <<
" eDPB "
1069 << std::setw(2) << uDpb <<
" current TS MSB counter is "
1071 <<
" current TS MSB cycle counter is " << std::setw(12)
1073 << std::setw(12) << dTsMsbTime <<
" s";
1086 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1088 const uint8_t* msContent =
1089 reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1111 <<
"Could not find the sDPB index for AFCK id 0x" << std::hex
1113 <<
"If valid this index has to be added in the TOF parameter file in "
1114 "the RocIdArray field"
1116 <<
"For now we remove it from the list of components analyzed";
1124 uint32_t uSize = msDescriptor.size;
1127 LOG(debug) <<
"Microslice: " <<
fulCurrentMsIdx <<
" from EqId " << std::hex
1136 fhMsSz[uMsComp]->Fill(uSize);
1142 <
static_cast<Int_t
>(dMsTime)) {
1147 UInt_t uFebIdxInSyst = uFebIdxOffset + uFebIdx;
1152 static_cast<Int_t
>(dMsTime);
1160 Int_t iTimeInt =
static_cast<Int_t
>(dMsTime)
1166 static_cast<Int_t
>(dMsTime);
1180 static_cast<Int_t
>(dMsTime);
1190 uint16_t uMsHeaderFlags = msDescriptor.flags;
1191 for (UInt_t uBit = 0; uBit < 16; ++uBit)
1195 UInt_t uTsMsbCycleHeader =
1226 LOG(error) <<
"The input microslice buffer does NOT "
1227 <<
"contain only complete nDPB messages!";
1230 uint32_t uNbMessages =
1234 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
1236 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1238 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1266 if (kTRUE ==
fbMuchMode) uFebIdx = usElinkIdx;
1268 if (-1 == uFebIdx) {
1269 LOG(warning) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => "
1270 <<
"Wrong elink Idx! Elink raw "
1271 << Form(
"%d remap %d", usElinkIdx, uFebIdx);
1292 LOG(info) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => "
1293 <<
"EPOCH message at unexpected position in MS: message "
1294 << uIdx <<
" VS message 0 expected!";
1310 std::cout << Form(
"DPB %2u TS %12llu MS %12llu mess %5u ",
1334 LOG(fatal) <<
"CbmMcbm2018MonitorMuchLite::DoUnpack => "
1335 <<
"Unknown message type, should never happen, stopping "
1336 "here! Type found was: "
1337 <<
static_cast<int>(typeMess);
1348 const UInt_t& uAsicIdx,
1349 const UInt_t& uMsIdx) {
1363 UInt_t uFebIdx = uAsicIdx;
1366 UInt_t uChanInFeb = usChan
1380 ActualX = 1000 - ActualX;
1381 channel = 96 - channel;
1383 LOG(debug) <<
"Module Nr " << ModuleNr <<
" Sector Nr " << sector
1384 <<
" Channel Nr " << channel <<
"Actual X " << ActualX
1385 <<
"Actual Y " << ActualY <<
"uAsicIdx " << uAsicIdx;
1430 Long64_t dHitTimeNs =
1466 if (constime < 10000000) {
1479 Double_t dTimeSinceStartSec =
1548 LOG(info) <<
"-------------------------------------";
1549 LOG(info) <<
"CbmMcbm2018MonitorMuchLite statistics are ";
1558 <<
" Empty messages: "
1561 LOG(info) <<
"-------------------------------------";
1569 TDirectory* oldDir = NULL;
1570 TFile* histoFile = NULL;
1571 if (
"" != sFileName) {
1573 oldDir = gDirectory;
1575 histoFile =
new TFile(sFileName,
"RECREATE");
1580 gDirectory->mkdir(
"Much_Raw");
1581 gDirectory->cd(
"Much_Raw");
1583 for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) {
1600 gDirectory->cd(
"..");
1604 gDirectory->mkdir(
"Much_Feb");
1605 gDirectory->cd(
"Much_Feb");
1606 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
1635 gDirectory->cd(
"..");
1640 gDirectory->mkdir(
"Flib_Raw");
1641 gDirectory->cd(
"Flib_Raw");
1643 TString sMsSzName = Form(
"MsSz_link_%02u", uLinks);
1644 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
H1(sMsSzName.Data())->Write();
1646 sMsSzName = Form(
"MsSzTime_link_%02u", uLinks);
1647 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
P1(sMsSzName.Data())->Write();
1652 if (
"" != sFileName) {
1660 LOG(info) <<
"Reseting all Much histograms.";
1662 for (UInt_t uModuleId = 0; uModuleId < 2; ++uModuleId) {
1680 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
1712 TString sMsSzName = Form(
"MsSz_link_%02u", uLinks);
1713 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
H1(sMsSzName.Data())->Reset();
1715 sMsSzName = Form(
"MsSzTime_link_%02u", uLinks);
1716 if (
fHM->
Exists(sMsSzName.Data()))
fHM->
P1(sMsSzName.Data())->Reset();
1726 TDatime* fRunStartDateTime =
new TDatime(dateIn, timeIn);
1730 LOG(info) <<
"Assigned new MUCH Run Start Date-Time: "
1731 << fRunStartDateTime->AsString();
1737 for (UInt_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
1740 " ------------------ Noisy channels scan for FEB %2d ------------",
1752 "Noisy Channel ASIC %d channel %3d (%4d) level %6.0f",
1761 <<
" ---------------------------------------------------------------";