21#include "FairRootManager.h"
23#include "FairRunOnline.h"
24#include "FairRuntimeDb.h"
28#include "TClonesArray.h"
30#include "THttpServer.h"
60 , fvMsComponentsListSts()
61 , fvMsComponentsListTof()
64 , fbIgnoreOverlapMs(kFALSE)
65 , fUnpackParSts(nullptr)
67 , fmStsDpbIdIndexMap()
69 , fUnpackParTof(nullptr)
71 , fmTofDpbIdIndexMap()
74 , fdStsTofOffsetNs(0.0)
75 , fdMuchTofOffsetNs(0.0)
76 , fbUseBestPair(kFALSE)
77 , fbTsLevelAna(kFALSE)
78 , fsHistoFileFullname(
"data/mCBMsyncHistos.root")
79 , fbPrintMessages(kFALSE)
80 , fPrintMessCtrlSts(
stsxyter::MessagePrintMask::msg_print_Human)
84 , fuCurrentEquipmentId(0)
87 , fiRunStartDateTimeSec(-1)
88 , fiBinSizeDatePlots(-1)
89 , fvulStsCurrentTsMsb()
90 , fvuStsCurrentTsMsbCycle()
91 , fvmStsSdpbHitsInMs()
92 , fvmStsSdpbHitsInTs()
93 , fulTofCurrentTsIndex(0)
99 , fviTofMsgCounter(1 +
gdpbv100::MSG_STAR_TRI_D, 0)
100 , fvulTofCurrentEpoch()
101 , fvulTofCurrentEpochCycle()
102 , fvulTofCurrentEpochFull()
103 , fulTofCurrentEpochTime(0)
104 , fvmTofEpSupprBuffer()
105 , fvmTofGdpbHitsInMs()
106 , fvmTofGdpbHitsInTs()
107 , fhMcbmHitsNbPerMs()
108 , fvhMcbmTimeDiffToSelDpb()
109 , fvhMcbmTimeDiffToSelDpbWide()
110 , fvhMcbmTimeDiffToSelDpbTs()
111 , fvhMcbmTimeDiffToDiamondEvoDpb()
112 , fvhMcbmTimeDiffToDiamondWideEvoDpb()
113 , fvhMcbmTimeDiffToDiamondTsEvoDpb()
114 , fvhMcbmTimeDiffToTofEvoDpb()
115 , fvhMcbmTimeDiffToTofWideEvoDpb()
116 , fvhMcbmTimeDiffToTofTsEvoDpb()
124 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
126 FairRootManager* ioman = FairRootManager::Instance();
127 if (ioman ==
nullptr) { LOG(fatal) <<
"No FairRootManager instance"; }
134 LOG(info) <<
"Setting parameter containers for " << GetName();
142 LOG(info) <<
"Init parameter containers for " << GetName();
154 LOG(info) <<
"ReInit parameter containers for " << GetName();
163 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x" << std::setw(4) << std::hex
198 switch (usDetectorId) {
210 LOG(warning) <<
"CbmMcbm2018MonitorStsSync::AddMsComponentToList => "
211 <<
"Ignore component " << component <<
" as detector id " << usDetectorId
212 <<
" is not supported by this unpacker.";
246 TString sHistName {
""};
306 LOG(info) <<
"Done Creating STS Histograms";
313 TString sHistName {
""};
381 LOG(info) <<
"Done Creating TOF Histograms";
388 TString sHistName {
""};
389 TString sHistTitle {
""};
393 sHistName =
"hMcbmHitsNbPerMs";
394 sHistTitle =
"Nb of hits per DPB; Nb of hits []; DPB []";
398 sHistName = Form(
"hMcbmTimeDiffToDpb%02u", uDpb);
399 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against "
400 "any hits in DPB %02u; <tn - tRef> [ns]; DPB []",
404 sHistName = Form(
"hMcbmTimeDiffToDpb%02uWide", uDpb);
405 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against any hits in "
406 "DPB %02u, wide range; <tn - tRef> [us]; DPB []",
410 sHistName = Form(
"hMcbmTimeDiffToDpb%02uTs", uDpb);
411 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against any hits in "
412 "DPB %02u, TS range; <tn - tRef> [ms]; DPB []",
417 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoDpb%02u", uDpb);
418 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
419 "against any Diamond hit; TS []; <tn - tDia> [ns]",
425 sHistName = Form(
"hMcbmTimeDiffToDiamondWideEvoDpb%02u", uDpb);
426 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
427 "against any Diamond hit, wide range; TS []; <tn - tDia> [us]",
430 new TH2D(sHistName, sHistTitle, 2000.0, 0., 200000., 4000.0, -200., 200.));
432 sHistName = Form(
"hMcbmTimeDiffToDiamondTsEvoDpb%02u", uDpb);
433 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
434 "against any Diamond hit, TS range; TS []; <tn - tDia> [ms]",
438 sHistName = Form(
"hMcbmTimeDiffToTofEvoDpb%02u", uDpb);
439 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from "
440 "DPB %02u against any Tof hit; TS []; <tn - tTof> [ns]",
445 sHistName = Form(
"hMcbmTimeDiffToTofWideEvoDpb%02u", uDpb);
446 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
447 "against any Tof hit, wide range; TS []; <tn - tTof> [us]",
451 sHistName = Form(
"hMcbmTimeDiffToTofTsEvoDpb%02u", uDpb);
452 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
453 "against any Tof hit, TS range; TS []; <tn - tTof> [ms]",
457#ifdef USE_HTTP_SERVER
458 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
476 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetPulser=kTRUE");
477 server->RegisterCommand(
"/Save_All",
"bMcbm2018WritePulser=kTRUE");
479 server->Restrict(
"/Reset_All",
"allow=admin");
480 server->Restrict(
"/Save_All",
"allow=admin");
488 TCanvas* cSyncMcbmDpb =
new TCanvas(Form(
"cSyncMcbmDpb%02u", uDpb),
489 Form(
"Time difference for STS and TOF hits, per DPB, against "
493 cSyncMcbmDpb->Divide(3);
515 LOG(info) <<
"Done Creating mCBM Histograms";
531 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component) <<
"microslices.";
544 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
549 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
556 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
574 for (UInt_t uRefSdpb = 0; uRefSdpb <
fuStsNrOfDpbs; ++uRefSdpb) {
576 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
584 Double_t dBestDt = 1e9;
586 UInt_t uNbIncrDt = 0;
588 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
589 if (uRefSdpb == uSdpb && uHitRef == uHit)
continue;
596 Double_t dDt = dHitTime - dRefTime;
600 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) {
604 else if (dBestDt < dDt)
608 if (5 == dBestDt)
break;
624 Double_t dBestDt = 1e9;
625 UInt_t uNbIncrDt = 0;
627 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
630 Double_t dDt = dHitTime - dRefTime;
634 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
635 else if (dBestDt < dDt)
639 if (5 == dBestDt)
break;
656 for (UInt_t uRefGdpb = 0; uRefGdpb <
fuTofNrOfDpbs; ++uRefGdpb) {
658 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
663 Double_t dBestDt = 1e9;
664 UInt_t uNbIncrDt = 0;
666 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
672 Double_t dDt = dHitTime - dRefTime;
676 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
677 else if (dBestDt < dDt)
681 if (5 == dBestDt)
break;
716 Double_t dBestDt = 1e9;
717 UInt_t uNbIncrDt = 0;
719 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
721 if (uRefGdpb == uGdpb && uHitRef == uHit)
continue;
725 Double_t dDt = dHitTime - dRefTime;
729 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
730 else if (dBestDt < dDt)
734 if (5 == dBestDt)
break;
793 for (UInt_t uRefSdpb = 0; uRefSdpb <
fuStsNrOfDpbs; ++uRefSdpb) {
795 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
807 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
808 if (uRefSdpb == uSdpb && uHitRef == uHit)
continue;
815 Double_t dDt = dHitTime - dRefTime;
818 if (300e3 < dDt)
break;
829 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
832 Double_t dDt = dHitTime - dRefTime;
835 if (300e3 < dDt)
break;
844 for (UInt_t uRefGdpb = 0; uRefGdpb <
fuTofNrOfDpbs; ++uRefGdpb) {
846 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
851 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
854 Double_t dDt = dHitTime - dRefTime;
857 if (300e3 < dDt)
break;
869 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
870 if (uRefGdpb == uGdpb && uHitRef == uHit)
continue;
874 Double_t dDt = dHitTime - dRefTime;
877 if (300e3 < dDt)
break;
900 if (0 == ts.index() % 1000) {
901 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
910 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
912 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
914 uint32_t uSize = msDescriptor.size;
918 <<
" has size: " << uSize;
931 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
934 << uTsMsbCycleHeader;
940 LOG(error) <<
"The input microslice buffer does NOT "
941 <<
"contain only complete nDPB messages!";
947 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
949 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
951 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
976 LOG(info) <<
"CbmMcbm2018MonitorMcbmPulser::DoUnpack => "
977 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
986 LOG(fatal) <<
"CbmMcbm2018MonitorMcbmPulser::DoUnpack => "
987 <<
"Unknown message type, should never happen, stopping here!";
1002 UInt_t uAsicIdx = 0;
1031 if (usRawAdc < 15)
return;
1046 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
return; }
1051 Long64_t ulStsHitTime = usRawTs;
1082 LOG(info) <<
"TS MSb Jump in "
1084 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
1086 << std::setw(5) << uVal;
1107 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1110 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1112 uint32_t
size = msDescriptor.size;
1114 if (
size > 0) LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " <<
size;
1116 Int_t messageType = -111;
1120 LOG(error) <<
"The input microslice buffer does NOT "
1121 <<
"contain only complete nDPB messages!";
1131 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1132 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1134 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1143 if (fair::Logger::Logging(fair::Severity::debug2)) {
1152 switch (messageType) {
1172 LOG(error) <<
"Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
1173 <<
" not included in Get4 unpacker.";
1197 if (0 < ulCurEpochGdpbGet4) ulCurEpochGdpbGet4--;
1230 if (0 < iBufferSize) {
1231 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr <<
" with epoch number "
1238 for (Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1266 LOG(info) <<
"-------------------------------------";
1276 TFile* oldFile = gFile;
1277 TDirectory* oldDir = gDirectory;
1279 TFile* histoFile =
nullptr;
1280 if (
"" != sFileName) {
1282 histoFile =
new TFile(sFileName,
"RECREATE");
1296 gDirectory->mkdir(
"mcbmDt");
1297 gDirectory->cd(
"mcbmDt");
1313 gDirectory->cd(
"..");
1316 if (
"" != sFileName) {
1323 gDirectory = oldDir;
ClassImp(CbmConverterManager)
Bool_t bMcbm2018WritePulser
Bool_t bMcbm2018ResetPulser
static constexpr size_t size()
std::vector< TH2 * > fvhMcbmTimeDiffToSelDpb
std::vector< int > fviTofMsgCounter
void CreateMcbmHistograms()
void SaveAllHistos(TString sFileName="")
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInTs
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
Bool_t ProcessTofMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
TString fsHistoFileFullname
std::map< UInt_t, UInt_t > fmStsDpbIdIndexMap
Total number of Sts DPBs in system.
Double_t fdMuchTofOffsetNs
std::vector< UInt_t > fvuStsCurrentTsMsbCycle
Current TS MSB for each DPB.
std::vector< std::vector< gdpbv100::Message > > fvmTofEpSupprBuffer
Buffer for suppressed epoch processing.
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
std::vector< TH2 * > fvhMcbmTimeDiffToTofEvoDpb
void FillStsEpochInfo(stsxyter::Message mess)
void AddMsComponentToListTof(size_t component)
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInMs
Buffer for system sync check.
void FillTofEpochCycle(uint64_t ulCycleData)
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondTsEvoDpb
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondEvoDpb
UInt_t fuCurrentEquipmentId
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInMs
Current TS MSB cycle for DPB.
UInt_t fuMuchDpbIdx
Map of DPB Identifier to DPB index.
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Bool_t ReInitContainers()
void FillStsTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx=0, UInt_t uMsIdx=0)
stsxyter::MessagePrintMask fPrintMessCtrlSts
std::vector< ULong64_t > fvulStsCurrentTsMsb
Bin size in s for the plots with date as X axis.
void AddMsComponentToListSts(size_t component)
ULong64_t fulCurrentMsIdx
CbmMcbm2018TofPar * fUnpackParTof
Unpacking and mapping parameters for TOF.
std::vector< ULong64_t > fvulTofCurrentEpochFull
std::map< UInt_t, UInt_t > fmTofDpbIdIndexMap
Total number of GDPBs in the system.
void FillTofEpochInfo(gdpbv100::Message)
std::vector< TH2 * > fvhMcbmTimeDiffToSelDpbTs
CbmMcbm2018StsPar * fUnpackParSts
UInt_t fuTotalNrOfDpb
Global parameters.
CbmMcbm2018MonitorMcbmPulser()
static const UInt_t kuStsBytesPerMessage
std::vector< TH2 * > fvhMcbmTimeDiffToTofWideEvoDpb
void CreateTofHistograms()
Processing methods.
std::vector< ULong64_t > fvulTofCurrentEpochCycle
std::map< stsxyter::MessType, UInt_t > fmMsgCounter
static const UInt_t kuTofBytesPerMessage
TODO => move to the message class!!
void CreateStsHistograms()
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
std::vector< size_t > fvMsComponentsListSts
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInTs
std::vector< TH2 * > fvhMcbmTimeDiffToDiamondWideEvoDpb
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
std::vector< TH2 * > fvhMcbmTimeDiffToSelDpbWide
std::vector< size_t > fvMsComponentsListTof
Double_t fdStsTofOffsetNs
void FillStsHitInfo(stsxyter::Message mess, const UInt_t &uMsIdx)
std::vector< ULong64_t > fvulTofCurrentEpoch
std::vector< TH2 * > fvhMcbmTimeDiffToTofTsEvoDpb
void FillTofHitInfo(gdpbv100::Message)
Bool_t ProcessStsMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
ULong64_t fulCurrentTsIdx
ULong64_t fulTofCurrentEpochTime
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
virtual ~CbmMcbm2018MonitorMcbmPulser()
UInt_t GetDpbId(UInt_t uDpbIdx)
UInt_t ElinkIdxToAsicIdx(Bool_t bFebType, UInt_t uElink)
static constexpr UInt_t GetNbChanPerAsic()
Int_t GetNrOfGdpbs()
FIXME: replace with method returning the correspondign constants! see Star2019 parameter.
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 double kdClockCycleNs