15 #include "FairLogger.h"
16 #include "FairRootManager.h"
18 #include "FairRunOnline.h"
19 #include "FairRuntimeDb.h"
23 #include "TClonesArray.h"
28 #include "THttpServer.h"
30 #include "TPaveStats.h"
32 #include "TProfile2D.h"
49 , fvMsComponentsList()
52 , fbIgnoreOverlapMs(kFALSE)
53 , fuMsAcceptsPercent(100)
58 , fdTsCoreSizeInNs(0.0)
65 , fuNrOfChannelsPerGet4(0)
66 , fuNrOfChannelsPerFee(0)
68 , fuNrOfGet4PerGdpb(0)
69 , fuNrOfChannelsPerGdpb(0)
70 , fuDiamondDpbIdx(10000)
72 fsHistoFilename(
"data/HistosCheckGdpb.root")
73 , fulCurrentTsIndex(0)
89 fulCurrentEpochTime(0)
92 , fdStartTimeMsSz(-1.)
93 , fvhMsSzPerLink(12, NULL)
94 , fvhMsSzTimePerLink(12, NULL)
97 , fhGet4MessType(NULL)
99 , fhGet4ChanErrors(NULL)
100 , fhGet4EpochFlags(NULL)
101 , fhGdpbMessType(NULL)
102 , fhGdpbSysMessType(NULL)
103 , fhGdpbSysMessPattType(NULL)
104 , fhGdpbEpochFlags(NULL)
105 , fhGdpbEpochSyncEvo(NULL)
106 , fhGdpbEpochMissEvo(NULL)
107 , fvhGdpbGet4MessType()
108 , fhPatternMissmatch(NULL)
109 , fhPatternEnable(NULL)
110 , fhPatternResync(NULL)
111 , fvuGdpbNbEpochPerMs()
112 , fvvuChanNbHitsPerMs()
113 , fhEpochsPerMs_gDPB()
114 , fhEpochsPerMsPerTs_gDPB()
115 , fhEpochsDiff_gDPB()
116 , fhEpochsDiffPerTs_gDPB()
117 , fhEpochsJumpBitsPre_gDPB()
118 , fhEpochsJumpBitsNew_gDPB()
119 , fhEpochsJumpDigitsPre_gDPB()
120 , fhEpochsJumpDigitsNew_gDPB()
121 , fhStartEpochPerMs_gDPB()
122 , fhCloseEpochPerMs_gDPB()
123 , fhHitsPerMsFirstChan_gDPB()
124 , fvhChannelRatePerMs_gDPB()
126 , fTimeLastHistoSaving() {}
131 LOG(info) <<
"Initializing Get4 monitor";
133 FairRootManager* ioman = FairRootManager::Instance();
135 LOG(fatal) <<
"No FairRootManager instance";
142 LOG(info) <<
"Setting parameter containers for " << GetName();
145 "CbmMcbm2018TofPar"));
149 LOG(info) <<
"Init parameter containers for " << GetName();
155 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
163 LOG(info) <<
"ReInit parameter containers for " << GetName();
193 LOG(info) <<
"GDPB Id of TOF " <<
i <<
" : " << std::hex
205 LOG(info) <<
"Timeslice parameters: " <<
fuTotalMsNb
225 TString sMsSzName = Form(
"MsSz_link_%02lu", component);
227 Form(
"Size of MS from link %02lu; Ms Size [bytes]", component);
229 new TH1F(sMsSzName.Data(), sMsSzTitle.Data(), 160000, 0., 20000.);
231 sMsSzName = Form(
"MsSzTime_link_%02lu", component);
233 "Size of MS vs time for gDPB of link %02lu; Time[s] ; Ms Size [bytes]",
236 sMsSzName.Data(), sMsSzTitle.Data(), 100 * 1800, 0., 2 * 1800);
237 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
247 LOG(info) <<
"Added MS size histo for component (link): " << component;
251 size_t uOverlapMsNb) {
259 LOG(info) <<
"create Histos for " <<
fuNrOfGdpbs <<
" gDPBs ";
261 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
265 UInt_t uHistoryHistoSize = 1800;
268 name =
"hMessageType";
269 title =
"Nb of message for each type; Type";
286 name =
"hSysMessType";
287 title =
"Nb of system message for each type; System Type";
295 "SYS_GET4_SYNC_MISS");
300 name =
"hGet4MessType";
301 title =
"Nb of message for each type per GET4; GET4 chip # ; Type";
309 name =
"hGet4ChanScm";
310 title =
"SC messages per GET4 channel; GET4 channel # ; SC type";
326 name =
"hGet4ChanErrors";
327 title =
"Error messages per GET4 channel; GET4 channel # ; Error";
348 12,
"0x0b: DLL Lock error ");
350 13,
"0x0c: DLL Reset invoc.");
355 17,
"0x14: Add. Rising edge");
357 18,
"0x15: Unpaired Falling");
359 19,
"0x16: Sequence error ");
364 name =
"hGet4EpochFlags";
365 title =
"Epoch flags per GET4; GET4 chip # ; Type";
374 name =
"hGdpbMessageType";
375 title =
"Nb of message for each type per Gdpb; Type; Gdpb Idx []";
399 name =
"hGdpbSysMessType";
401 "Nb of system message for each type per Gdpb; System Type; Gdpb Idx []";
415 "SYS_GET4_SYNC_MISS");
420 name =
"hGdpbSysMessPattType";
422 "Nb of pattern message for each type per Gdpb; Pattern Type; Gdpb Idx []";
439 name =
"hGdpbEpochFlags";
440 title =
"Epoch flags per gDPB; gDPB # ; Type";
449 name = Form(
"hGdpbEpochSyncEvo");
450 title = Form(
"Epoch SYNC per second and gDPB; Time[s]; gDPB #; SYNC Nb");
461 name = Form(
"hGdpbEpochMissEvo");
463 Form(
"Epoch Missmatch per second and gDPB; Time[s]; gDPB #; Missmatch Nb");
475 name =
"hPatternMissmatch";
476 title =
"Missmatch pattern integral per Gdpb; ASIC Pattern []; Gdpb Idx []";
485 name =
"hPatternEnable";
486 title =
"Enable pattern integral per Gdpb; ASIC Pattern []; Gdpb Idx []";
495 name =
"hPatternResync";
496 title =
"Resync pattern integral per Gdpb; ASIC Pattern []; Gdpb Idx []";
510 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
512 name = Form(
"hGdpbGet4MessType_%02u", uGdpb);
514 "Nb of message for each type per GET4 in gDPB %02u; GET4 chip # ; Type",
524 name = Form(
"hGdpbGet4ChanErrors_%02u", uGdpb);
526 "Error messages per GET4 channel in gDPB %02u; GET4 channel # ; Error",
537 1,
"0x00: Readout Init ");
541 3,
"0x02: Epoch count sync");
545 5,
"0x04: FIFO Write ");
547 6,
"0x05: Lost event ");
549 7,
"0x06: Channel state ");
551 8,
"0x07: Token Ring state");
555 10,
"0x09: Error Readout ");
559 12,
"0x0b: DLL Lock error ");
561 13,
"0x0c: DLL Reset invoc.");
563 14,
"0x11: Overwrite ");
565 15,
"0x12: ToT out of range");
567 16,
"0x13: Event Discarded ");
569 17,
"0x14: Add. Rising edge");
571 18,
"0x15: Unpaired Falling");
573 19,
"0x16: Sequence error ");
575 20,
"0x17: Epoch Overflow ");
577 21,
"0x7f: Unknown ");
579 22,
"Corrupt/unsuprtd error");
584 Form(
"hEpochsPerMs_gDPB%02u", uGdpb),
585 Form(
"Epoch Counts per MS in gDPB %02u; Epochs/MS []; MS nb[]", uGdpb),
590 Form(
"hEpochsPerMsPerTs_gDPB%02u", uGdpb),
591 Form(
"Epoch Counts per MS in gDPB %02u; TS []; Epochs/MS []; MS nb[]",
600 new TH1D(Form(
"hEpochsDiff_gDPB%02u", uGdpb),
601 Form(
"Epoch index difference per MS in gDPB %02u; Ep(N) - Ep(N "
608 new TH2D(Form(
"hEpochsDiffPerTs_gDPB%02u", uGdpb),
609 Form(
"Epoch index difference per MS in gDPB %02u; TS []; Ep(N) "
610 "- Ep(N - 1) []; MS nb[]",
619 new TH2D(Form(
"hEpochsJumpBitsPre_gDPB%02u", uGdpb),
620 Form(
"Bits value in previous epoch when diff not 1 in gDPB "
621 "%02u; TS []; Bit []; Value[]",
630 new TH2D(Form(
"hEpochsJumpBitsNew_gDPB%02u", uGdpb),
631 Form(
"Bits value in new epoch when diff not 1 in gDPB %02u; TS "
632 "[]; Bit []; Value[]",
641 new TH2D(Form(
"hEpochsJumpDigitsPre_gDPB%02u", uGdpb),
642 Form(
"Digits value in previous epoch when diff not 1 in gDPB "
643 "%02u; TS []; Digit []; Value[]",
652 new TH2D(Form(
"hEpochsJumpDigitsNew_gDPB%02u", uGdpb),
653 Form(
"Digits value in new epoch when diff not 1 in gDPB %02u; "
654 "TS []; Digit []; Value[]",
663 new TH2D(Form(
"fhStartEpochPerMs_gDPB%02u", uGdpb),
664 Form(
"MS start with Epoch in gDPB %02u?; TS []; 1st Msg is "
665 "Epoch? []; MS nb[]",
674 new TH2D(Form(
"fhCloseEpochPerMs_gDPB%02u", uGdpb),
675 Form(
"MS close with Epoch in gDPB %02u?; TS []; Last Msg is "
676 "Epoch? []; MS nb[]",
685 new TH2D(Form(
"hHitsPerMsFirstChan_gDPB%02u", uGdpb),
686 Form(
"Hit Counts per MS in first channel in gDPB %02u; TS []; "
687 "Hits/MS []; MS nb[]",
696 new TProfile2D(Form(
"hChannelRatePerMs_gDPB%02u", uGdpb),
697 Form(
"Mean Hit count per MS and channel vs Time in gDPB "
698 "%02u; TS []; Channel []; <Hits/Ms> []",
727 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
746 server->RegisterCommand(
"/Reset_All_eTOF",
747 "bCheckFormatGdpbResetHistos=kTRUE");
748 server->RegisterCommand(
"/Save_All_eTof",
749 "bCheckFormatGdpbSaveHistos=kTRUE");
751 server->Restrict(
"/Reset_All_eTof",
"allow=admin");
752 server->Restrict(
"/Save_All_eTof",
"allow=admin");
758 fcSummary =
new TCanvas(
"cSummary",
"gDPB Monitoring Summary");
786 server->Register(
"/canvases",
fcSummary);
789 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
791 new TCanvas(Form(
"cFormatGdpb%02u", uGdpb),
792 Form(
"gDPB %02u Data Format Check", uGdpb)));
845 fcMsSizeAll =
dynamic_cast<TCanvas*
>(gROOT->FindObject(
"cMsSizeAll"));
848 new TCanvas(
"cMsSizeAll",
"Evolution of MS size in last 300 s", w,
h);
850 LOG(info) <<
"Created MS size canvas in TOF monitor";
853 LOG(info) <<
"Recovered MS size canvas in TOF monitor";
857 LOG(info) <<
"Leaving CreateHistograms";
863 LOG(info) <<
"Reset eTOF STAR histos ";
868 LOG(info) <<
"Start saving eTOF STAR histos ";
874 std::chrono::time_point<std::chrono::system_clock> timeCurrent =
875 std::chrono::system_clock::now();
876 std::chrono::duration<double> elapsed_seconds =
881 else if (300 < elapsed_seconds.count()) {
882 std::time_t cTimeCurrent =
883 std::chrono::system_clock::to_time_t(timeCurrent);
885 std::strftime(tempBuff, 80,
"%F %T", localtime(&cTimeCurrent));
890 LOG(debug1) <<
"Timeslice contains " << ts.num_microslices(component)
894 if (0 == ts.index())
return kTRUE;
904 Int_t messageType = -111;
908 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
917 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
934 constexpr uint32_t kuBytesPerMessage = 8;
937 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
939 fdMsIndex =
static_cast<double>(msDescriptor.idx);
941 const uint8_t* msContent =
942 reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
944 uint32_t size = msDescriptor.size;
947 LOG(debug) <<
"Microslice: " << msDescriptor.idx
948 <<
" has size: " << size;
959 if (0 != (size % kuBytesPerMessage))
960 LOG(error) <<
"The input microslice buffer does NOT "
961 <<
"contain only complete nDPB messages!";
964 uint32_t uNbMessages =
965 (size - (size % kuBytesPerMessage)) / kuBytesPerMessage;
974 <<
"---------------------------------------------------------------";
985 LOG(error) <<
"Could not find the gDPB index for AFCK id 0x" << std::hex
986 <<
fuGdpbId << std::dec <<
" in timeslice "
988 <<
" component " << uMsCompIdx <<
"\n"
989 <<
"If valid this index has to be added in the TOF "
990 "parameter file in the RocIdArray field";
997 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
998 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1000 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1023 LOG(warning) <<
"Message with Get4 ID too high: " <<
fuGet4Id
1029 if (uNbMessages - 1 == uIdx)
1033 switch (messageType) {
1086 Long64_t iEpDiff = ulEpochNr;
1092 for (UInt_t uBit = 0; uBit < 32; ++uBit) {
1096 uBit, (ulEpochNr >> uBit) & 0x1);
1100 for (UInt_t uDigit = 0; uDigit < 10; ++uDigit) {
1106 uDigit, TMath::Floor((ulEpochNr % (10 * uPower)) / uPower));
1247 LOG(error) <<
"Message type " << std::hex << std::setw(2)
1248 <<
static_cast<uint16_t
>(messageType)
1249 <<
" not included in Get4 unpacker.";
1254 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1279 TDirectory* oldDir = NULL;
1280 TFile* histoFile = NULL;
1281 if (
"" != sFileName) {
1283 oldDir = gDirectory;
1285 histoFile =
new TFile(sFileName,
"RECREATE");
1289 gDirectory->mkdir(
"Tof_Raw_gDPB");
1290 gDirectory->cd(
"Tof_Raw_gDPB");
1310 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1316 gDirectory->mkdir(
"Tof_Ep_FineCount");
1317 gDirectory->cd(
"Tof_Ep_FineCount");
1318 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1330 gDirectory->cd(
"..");
1332 gDirectory->mkdir(
"Tof_Chan_FineCount");
1333 gDirectory->cd(
"Tof_Chan_FineCount");
1334 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1338 gDirectory->cd(
"..");
1340 gDirectory->mkdir(
"Flib_Raw");
1341 gDirectory->cd(
"Flib_Raw");
1342 for (UInt_t uLinks = 0; uLinks <
fvhMsSzPerLink.size(); uLinks++) {
1349 TH1* pMissedTsH1 =
dynamic_cast<TH1*
>(gROOT->FindObjectAny(
"Missed_TS"));
1350 if (NULL != pMissedTsH1) pMissedTsH1->Write();
1352 TProfile* pMissedTsEvoP =
1353 dynamic_cast<TProfile*
>(gROOT->FindObjectAny(
"Missed_TS_Evo"));
1354 if (NULL != pMissedTsEvoP) pMissedTsEvoP->Write();
1356 gDirectory->cd(
"..");
1358 gDirectory->mkdir(
"canvases");
1359 gDirectory->cd(
"canvases");
1361 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1364 gDirectory->cd(
"..");
1366 if (
"" != sFileName) {
1374 LOG(info) <<
"Reseting all TOF histograms.";
1395 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1400 for (UInt_t uGdpb = 0; uGdpb <
fuNrOfGdpbs; ++uGdpb) {
1415 for (UInt_t uLinks = 0; uLinks <
fvhMsSzPerLink.size(); uLinks++) {