21#include "FairRootManager.h"
23#include "FairRunOnline.h"
24#include "FairRuntimeDb.h"
28#include "TClonesArray.h"
30#include "THttpServer.h"
135 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
137 FairRootManager* ioman = FairRootManager::Instance();
138 if (ioman ==
nullptr) { LOG(fatal) <<
"No FairRootManager instance"; }
145 LOG(info) <<
"Setting parameter containers for " << GetName();
153 LOG(info) <<
"Init parameter containers for " << GetName();
165 LOG(info) <<
"ReInit parameter containers for " << GetName();
174 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x" << std::setw(4) << std::hex
192 LOG(info) <<
"GDPB Id of TOF " << i <<
" : " << std::hex <<
fUnpackParTof->GetGdpbId(i) << std::dec;
209 switch (usDetectorId) {
221 LOG(warning) <<
"CbmMcbm2018MonitorStsSync::AddMsComponentToList => "
222 <<
"Ignore component " << component <<
" as detector id " << usDetectorId
223 <<
" is not supported by this unpacker.";
257 TString sHistName {
""};
315 LOG(info) <<
"Done Creating STS Histograms";
322 TString sHistName {
""};
388 LOG(info) <<
"Done Creating TOF Histograms";
395 TString sHistName {
""};
396 TString sHistTitle {
""};
400 sHistName =
"hMcbmHitsNbPerMs";
401 sHistTitle =
"Nb of hits per DPB; Nb of hits []; DPB []";
404 sHistName =
"hMcbmTimeDiffToDiamond";
405 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
406 "Diamond hit; <tn - tDia> [ns]; DPB []";
409 sHistName =
"hMcbmTimeDiffToDiamondWide";
410 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
411 "Diamond hit, wide range; <tn - tDia> [us]; DPB []";
414 sHistName =
"hMcbmTimeDiffToDiamondTs";
415 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
416 "Diamond hit, TS range; <tn - tDia> [ms]; DPB []";
419 sHistName =
"hMcbmTimeDiffToMuch";
420 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
421 "Much hit; <tn - tMuch> [ns]; DPB []";
424 sHistName =
"hMcbmTimeDiffToMuchWide";
425 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
426 "Much hit, wide range; <tn - tMuch> [us]; DPB []";
428 sHistName =
"hMcbmTimeDiffToMuchTs";
429 sHistTitle =
"Time difference for STS and TOF hits, per DPB, against any "
430 "Much hit, TS range; <tn - tMuch> [ms]; DPB []";
434 sHistName =
"hMcbmStsTimeDiffToMuchVsAdc";
435 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
436 "ADC; <tSts - tMuch> [ns]; ADC Sts [bin]";
440 sHistName =
"hMcbmStsTimeDiffToMuchWideVsAdc";
441 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
442 "ADC, wide range; <tSts - tMuch> [us]; ADC Sts [bin]";
445 sHistName =
"hMcbmStsTimeDiffToMuchTsVsAdc";
446 sHistTitle =
"Time difference for STS hits against any Much hit vs STS hit "
447 "ADC, TS range; <tSts - tMuch> [ms]; ADC Sts [bin]";
453 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoDpb%02u", uDpb);
454 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
455 "against any Diamond hit; TS []; <tn - tDia> [ns]",
461 sHistName = Form(
"hMcbmTimeDiffToDiamondWideEvoDpb%02u", uDpb);
462 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
463 "against any Diamond hit, wide range; TS []; <tn - tDia> [us]",
466 new TH2D(sHistName, sHistTitle, 2000.0, 0., 200000., 4000.0, -200., 200.));
468 sHistName = Form(
"hMcbmTimeDiffToDiamondTsEvoDpb%02u", uDpb);
469 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
470 "against any Diamond hit, TS range; TS []; <tn - tDia> [ms]",
475 sHistName = Form(
"hHitsTimeEvoSpillADpb%02u", uDpb);
476 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
477 "first spill; tHit [s]; counts",
482 sHistName = Form(
"hHitsTimeEvoSpillBDpb%02u", uDpb);
483 sHistTitle = Form(
"Evolution of hit counts VS time for DPB %02u in the "
484 "second spill; tHit [s]; counts",
489 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillADpb%02u", uDpb);
490 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
491 "in the first spill; tHit [s]; <tn - tDia> [us]",
496 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoSpillBDpb%02u", uDpb);
497 sHistTitle = Form(
"Evolution of Time Diff to diam VS time for DPB %02u "
498 "in the second spill; tHit [s]; <tn - tDia> [us]",
503 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillADpb%02u", uDpb);
504 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
505 "in the first spill; tHit [s]; <tn - tDia> [us]",
510 sHistName = Form(
"hMcbmTimeDiffToMuchEvoSpillBDpb%02u", uDpb);
511 sHistTitle = Form(
"Evolution of Time Diff to MUCH VS time for DPB %02u "
512 "in the second spill; tHit [s]; <tn - tDia> [us]",
518 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
538 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetSync=kTRUE");
539 server->RegisterCommand(
"/Save_All",
"bMcbm2018WriteSync=kTRUE");
541 server->Restrict(
"/Reset_All",
"allow=admin");
542 server->Restrict(
"/Save_All",
"allow=admin");
549 new TCanvas(
"cSyncMcbm",
"Time difference for STS and TOF hits, per DPB, against any Diamond hit", w,
h);
550 cSyncMcbm->Divide(2);
564 LOG(info) <<
"Done Creating mCBM Histograms";
580 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component) <<
"microslices.";
593 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
598 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
605 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
639 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
649 Double_t dBestDt = 1e9;
650 UInt_t uNbIncrDt = 0;
652 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
663 Double_t dDt = dHitTime - dDiaTime;
667 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
668 else if (dBestDt < dDt)
672 if (5 == dBestDt)
break;
696 Double_t dBestDt = 1e9;
697 UInt_t uNbIncrDt = 0;
699 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
707 Double_t dDt = dHitTime - dDiaTime;
711 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
712 else if (dBestDt < dDt)
716 if (5 == dBestDt)
break;
739 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
747 Double_t dBestDt = 1e9;
749 UInt_t uNbIncrDt = 0;
751 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
757 Double_t dDt = dHitTime - dMuchTime;
761 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) {
765 else if (dBestDt < dDt)
769 if (5 == dBestDt)
break;
791 Double_t dBestDt = 1e9;
792 UInt_t uNbIncrDt = 0;
794 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
797 Double_t dDt = dHitTime - dMuchTime;
801 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
802 else if (dBestDt < dDt)
806 if (5 == dBestDt)
break;
846 LOG(fatal) <<
"Done with the spills";
856 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
861 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
864 Double_t dDt = dHitTime - dDiaTime;
867 if (300e3 < dDt)
break;
874 Double_t dDiaTimeSec = dDiaTime * 1e-9;
887 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
890 Double_t dDt = dHitTime - dDiaTime;
893 if (300e3 < dDt)
break;
900 Double_t dDiaTimeSec = dDiaTime * 1e-9;
912 for (UInt_t uHitMuch = 0; uHitMuch < uNbMuchHits; uHitMuch++) {
924 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
930 Double_t dDt = dHitTime - dMuchTime;
933 if (300e3 < dDt)
break;
939 Double_t dMuchTimeSec = dMuchTime * 1e-9;
953 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
956 Double_t dDt = dHitTime - dMuchTime;
959 if (300e3 < dDt)
break;
963 Double_t dMuchTimeSec = dMuchTime * 1e-9;
983 if (0 == ts.index() % 1000) {
984 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
993 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
995 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
997 uint32_t uSize = msDescriptor.size;
1001 <<
" has size: " << uSize;
1014 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
1017 << uTsMsbCycleHeader;
1023 LOG(error) <<
"The input microslice buffer does NOT "
1024 <<
"contain only complete nDPB messages!";
1030 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
1032 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
1034 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
1059 LOG(info) <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1060 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
1069 LOG(fatal) <<
"CbmMcbm2018MonitorMcbmSync::DoUnpack => "
1070 <<
"Unknown message type, should never happen, stopping here!";
1085 UInt_t uAsicIdx = 0;
1114 if (usRawAdc < 15)
return;
1118 UInt_t uChanIdx = usChan +
fUnpackParSts->GetNbChanPerAsic() * uAsicIdx;
1129 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
return; }
1134 Long64_t ulStsHitTime = usRawTs;
1165 LOG(info) <<
"TS MSb Jump in "
1167 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
1169 << std::setw(5) << uVal;
1190 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1193 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1195 uint32_t
size = msDescriptor.size;
1197 if (
size > 0) LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " <<
size;
1199 Int_t messageType = -111;
1203 LOG(error) <<
"The input microslice buffer does NOT "
1204 <<
"contain only complete nDPB messages!";
1214 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1215 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1217 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1226 if (fair::Logger::Logging(fair::Severity::debug2)) {
1235 switch (messageType) {
1255 LOG(error) <<
"Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
1256 <<
" not included in Get4 unpacker.";
1280 if (0 < ulCurEpochGdpbGet4) ulCurEpochGdpbGet4--;
1313 if (0 < iBufferSize) {
1314 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr <<
" with epoch number "
1321 for (
Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1349 LOG(info) <<
"-------------------------------------";
1359 TFile* oldFile = gFile;
1360 TDirectory* oldDir = gDirectory;
1362 TFile* histoFile =
nullptr;
1363 if (
"" != sFileName) {
1365 histoFile =
new TFile(sFileName,
"RECREATE");
1376 gDirectory->mkdir(
"mcbmDt");
1377 gDirectory->cd(
"mcbmDt");
1408 gDirectory->cd(
"..");
1411 if (
"" != sFileName) {
1418 gDirectory = oldDir;
ClassImp(CbmConverterManager)
Bool_t bMcbm2018WriteSync
Bool_t bMcbm2018ResetSync
static constexpr size_t size()
void SaveAllHistos(TString sFileName="")
void CreateStsHistograms()
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
TH2 * fhMcbmStsTimeDiffToMuchVsAdc
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
TH2 * fhMcbmStsTimeDiffToMuchWideVsAdc
Bool_t ReInitContainers()
CbmMcbm2018MonitorMcbmSync()
std::vector< size_t > fvMsComponentsListTof
void FillTofHitInfo(gdpbv100::Message)
void CreateMcbmHistograms()
std::map< UInt_t, UInt_t > fmStsDpbIdIndexMap
Total number of Sts DPBs in system.
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
std::map< UInt_t, UInt_t > fmTofDpbIdIndexMap
Total number of GDPBs in the system.
TH2 * fhMcbmTimeDiffToDiamond
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoSpillB
void FillTofEpochInfo(gdpbv100::Message)
Bool_t ProcessStsMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInMs
Current TS MSB cycle for DPB.
std::vector< ULong64_t > fvulTofCurrentEpochCycle
UInt_t fuTotalNrOfDpb
Global parameters.
std::vector< TH2 * > fvhMcbmTimeDiffToMuchEvoSpillA
std::vector< size_t > fvMsComponentsListSts
std::vector< TH1 * > fvhHitsTimeEvoSpillA
TH2 * fhMcbmTimeDiffToMuchWide
void AddMsComponentToListTof(size_t component)
std::vector< ULong64_t > fvulTofCurrentEpochFull
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoDpb
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
void AddMsComponentToListSts(size_t component)
std::vector< int > fviTofMsgCounter
std::vector< TH1 * > fvhHitsTimeEvoSpillB
CbmMcbm2018TofPar * fUnpackParTof
Unpacking and mapping parameters for TOF.
std::vector< UInt_t > fvuStsCurrentTsMsbCycle
Current TS MSB for each DPB.
Bool_t ProcessTofMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
void FillTofEpochCycle(uint64_t ulCycleData)
Double_t fdStsTofOffsetNs
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoSpillA
std::vector< TH2 * > fvhMcbmTimeDiffToMuchEvoSpillB
UInt_t fuMuchDpbIdx
Map of DPB Identifier to DPB index.
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInTs
TH2 * fhMcbmTimeDiffToMuchTs
uint64_t fulTofCurrentTsIndex
Running indices.
std::vector< ULong64_t > fvulTofCurrentEpoch
ULong64_t fulTofCurrentEpochTime
std::vector< ULong64_t > fvulStsCurrentTsMsb
Bin size in s for the plots with date as X axis.
Int_t fiBinSizeDatePlots
Start of run time since "epoch" in s, for the plots with date as X axis.
ULong64_t fulCurrentMsIdx
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInMs
Buffer for system sync check.
static const UInt_t kuStsBytesPerMessage
ULong64_t fulCurrentTsIdx
TH2 * fhMcbmTimeDiffToDiamondWide
void FillStsTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx=0, UInt_t uMsIdx=0)
TH2 * fhMcbmTimeDiffToMuch
void FillStsEpochInfo(stsxyter::Message mess)
void FillStsHitInfo(stsxyter::Message mess, const UInt_t &uMsIdx)
TH2 * fhMcbmStsTimeDiffToMuchTsVsAdc
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInTs
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
TH2 * fhMcbmTimeDiffToDiamondTs
Int_t fiRunStartDateTimeSec
Index of the DPB from which the MS currently unpacked is coming.
static const UInt_t kuTofBytesPerMessage
TODO => move to the message class!!
stsxyter::MessagePrintMask fPrintMessCtrlSts
std::map< stsxyter::MessType, UInt_t > fmMsgCounter
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondWideEvoDpb
std::vector< std::vector< gdpbv100::Message > > fvmTofEpSupprBuffer
Buffer for suppressed epoch processing.
Double_t fdMuchTofOffsetNs
void CreateTofHistograms()
Processing methods.
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondTsEvoDpb
virtual ~CbmMcbm2018MonitorMcbmSync()
CbmMcbm2018StsPar * fUnpackParSts
UInt_t fuCurrentEquipmentId
TString fsHistoFileFullname
Data class with information on a STS local track.
uint16_t getGdpbHitIs24b() const
uint32_t getGdpbEpEpochNb() const
void setGdpbEpEpochNb(uint32_t v)
uint16_t getGdpbGenChipId() const
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
XPU_D uint16_t GetHitAdc() const
For Hit data: Returns ADC value (5 bit field)
XPU_D uint16_t GetHitChannel() const
For Hit data: Returns StsXYTER channel number (7 bit field)
bool PrintMess(std::ostream &os, MessagePrintMask ctrl=MessagePrintMask::msg_print_Human, bool bBinning=true) const
XPU_D uint16_t GetLinkIndex() const
For all data: Returns the (global) index of the eLink on which the message was received (n bit field)
XPU_D MessType GetMessType() const
Returns the message type, see enum MessType.
XPU_D uint16_t GetHitTime() const
For Hit data: Returns timestamp (8 bit field, 2 MSB bits overlap removed)
XPU_D uint32_t GetTsMsbVal() const
For TS MSB data: Returns the TS MSB 22 bit field)
const uint64_t kulEpochCycleBins
const uint32_t kuChipIdMergedEpoch
const uint32_t kuEpochCounterSz
const uint64_t kulEpochCycleFieldSz
static constexpr uint64_t kulTsCycleNbBins
static constexpr uint32_t kuHitNbTsBins
static constexpr uint32_t kuHitNbAdcBins
Status/properties constants.
static constexpr double kdClockCycleNs