23#include "FairRootManager.h"
25#include "FairRunOnline.h"
26#include "FairRuntimeDb.h"
30#include "TClonesArray.h"
32#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 =
"hMcbmHitsNbPerTsEvo";
401 sHistTitle =
"Nb STS or TOF hits, per DPB and per TS; TS index []; DPB []; Nb Hits []";
404 sHistName =
"hMcbmHitsNbFineEvo";
405 sHistTitle =
"Nb STS or TOF hits, per DPB and per 100 ms; t [s]; DPB []; Hit rate [1/s]";
408 sHistName =
"hMcbmHitsRateEvo";
409 sHistTitle =
"STS or TOF hits rate per DPB as function of time in run; t "
410 "[s]; DPB []; Hit rate [1/s]";
413 sHistName =
"hDiamondHitsRateMapEvo";
414 sHistTitle =
"Counts per diamond strip and 100 ms as function of time in "
415 "run; t [s]; strip []; Counts []";
418 sHistName =
"hDiamondHitsRateDerivative";
419 sHistTitle =
"Variation of the diamond counts per s in 100 ms bins as "
420 "function of time in run; t [s]; Delta(Counts/s) []";
423 sHistName =
"hMuchVsStsHitsNbPerTimeBin";
424 sHistTitle = Form(
"Nb Hits in MUCH vs Sts in time bins of %5u ns; Nb Hits "
425 "STS []; Nb Hits TOF []; Time bins []",
428 sHistName =
"hTofVsStsHitsNbPerTimeBin";
429 sHistTitle = Form(
"Nb Hits in TOF vs Sts in time bins of %5u ns; Nb Hits STS "
430 "[]; Nb Hits MUCH []; Time bins []",
433 sHistName =
"hDiamVsStsHitsNbPerTimeBin";
434 sHistTitle = Form(
"Nb Hits in Diam vs Sts in time bins of %5u ns; Nb Hits "
435 "STS []; Nb Hits Diam []; Time bins []",
439 sHistName =
"hStsVsMuchHitsNbPerTimeBin";
440 sHistTitle = Form(
"Nb Hits in STS vs MUCH in time bins of %5u ns; Nb Hits "
441 "MUCH []; Nb Hits STS []; Time bins []",
444 sHistName =
"hTofVsMuchHitsNbPerTimeBin";
445 sHistTitle = Form(
"Nb Hits in TOF vs MUCH in time bins of %5u ns; Nb Hits "
446 "MUCH []; Nb Hits TOF []; Time bins []",
449 sHistName =
"hDiamVsMuchHitsNbPerTimeBin";
450 sHistTitle = Form(
"Nb Hits in Diam vs MUCH in time bins of %5u ns; Nb Hits "
451 "MUCH []; Nb Hits Diam []; Time bins []",
455 sHistName =
"hStsVsTofHitsNbPerTimeBin";
456 sHistTitle = Form(
"Nb Hits in STS vs TOF in time bins of %5u ns; Nb Hits TOF "
457 "[]; Nb Hits STS []; Time bins []",
460 sHistName =
"hMuchVsTofHitsNbPerTimeBin";
461 sHistTitle = Form(
"Nb Hits in MUCH vs TOF in time bins of %5u ns; Nb Hits "
462 "TOF []; Nb Hits MUCH []; Time bins []",
465 sHistName =
"hDiamVsTofHitsNbPerTimeBin";
466 sHistTitle = Form(
"Nb Hits in Diam vs TOF in time bins of %5u ns; Nb Hits "
467 "TOF []; Nb Hits Diam []; Time bins []",
471 sHistName =
"hStsVsDiamHitsNbPerTimeBin";
472 sHistTitle = Form(
"Nb Hits in STS vs Diam in time bins of %5u ns; Nb Hits "
473 "Diam []; Nb Hits STS []; Time bins []",
476 sHistName =
"hTofVsDiamHitsNbPerTimeBin";
477 sHistTitle = Form(
"Nb Hits in TOF vs Diam in time bins of %5u ns; Nb Hits "
478 "Diam []; Nb Hits TOF []; Time bins []",
481 sHistName =
"hMuchVsDiamHitsNbPerTimeBin";
482 sHistTitle = Form(
"Nb Hits in MUCH vs Diam in time bins of %5u ns; Nb Hits "
483 "Diam []; Nb Hits MUCH []; Time bins []",
487 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
521 LOG(info) <<
"Done Creating mCBM Histograms";
541 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component) <<
"microslices.";
555 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
560 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
567 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
573 for( UInt_t uSdpb = 0; uSdpb < fuStsNrOfDpbs; ++uSdpb )
574 std::sort( fvmStsSdpbHitsInMs[ uSdpb ].begin(), fvmStsSdpbHitsInMs[ uSdpb ].end() );
581 for( UInt_t uGdpb = 0; uGdpb < fuTofNrOfDpbs; ++uGdpb )
582 std::sort( fvmTofGdpbHitsInMs[ uGdpb ].begin(), fvmTofGdpbHitsInMs[ uGdpb ].end() );
585 for (UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++) {
590 case 0: uChan = 0;
break;
591 case 32: uChan = 1;
break;
592 case 64: uChan = 2;
break;
593 case 96: uChan = 3;
break;
594 case 160: uChan = 4;
break;
595 case 192: uChan = 5;
break;
596 case 224: uChan = 6;
break;
597 case 256: uChan = 7;
break;
614 for (UInt_t uHit = 0; uHit < uNbHitsInMs; ++uHit) {
615 Double_t dHitTimeInTs =
624 if (iTimeBin < 0 ||
kuNbTimeBins <=
static_cast<UInt_t
>(iTimeBin)) {
625 LOG(debug) <<
"sDPB hits with time out of the TS!! " << dHitTimeInTs <<
" " << iTimeBin;
636 fvmStsSdpbHitsInTs[ uSdpb ].insert( fvmStsSdpbHitsInTs[ uSdpb ].end(),
637 fvmStsSdpbHitsInMs[ uSdpb ].begin(),
638 fvmStsSdpbHitsInMs[ uSdpb ].end() );
658 for (UInt_t uHit = 0; uHit < uNbHitsInMs; ++uHit) {
662 if (iTimeBin < 0 ||
kuNbTimeBins <=
static_cast<UInt_t
>(iTimeBin)) {
663 LOG(debug) <<
"gDPB hits with time out of the TS!! " <<
fvmTofGdpbHitsInMs[uGdpb][uHit].GetFullTimeNs() <<
" "
686 UInt_t uNbDiaHits = fvmTofGdpbHitsInTs[ fuDiamondDpbIdx ].size();
687 for( UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++)
689 Double_t dDiaTime = fvmTofGdpbHitsInTs[ fuDiamondDpbIdx ][ uHitDia ].GetFullTimeNs();
692 for( UInt_t uSdpb = 1; uSdpb < fuStsNrOfDpbs; ++uSdpb )
694 UInt_t uNbHits = fvmStsSdpbHitsInTs[ uSdpb ].size();
695 for( UInt_t uHit = 0; uHit < uNbHits; ++uHit )
697 Double_t dHitTime = stsxyter::kdClockCycleNs * fvmStsSdpbHitsInTs[ uSdpb ][ uHit ].GetTs();
699 Double_t dDt = dHitTime - dDiaTime;
700 fhMcbmTimeDiffToDiamondTs->Fill( dDt / 1e6, uSdpb );
702 fvhMcbmTimeDiffToDiamondTsEvoDpb[ uSdpb ]->Fill( fulCurrentTsIdx, dDt / 1e6 );
703 } // for( UInt_t uHit = 0; uHit < uNbHits; ++uHit )
704 } // for( UInt_t uSdpb = 0; uSdpb < fuStsNrOfDpbs; ++uSdpb )
706 for( UInt_t uGdpb = 0; uGdpb < fuTofNrOfDpbs; ++uGdpb )
708 if( fuDiamondDpbIdx == uGdpb )
711 UInt_t uNbHits = fvmTofGdpbHitsInTs[ uGdpb ].size();
712 for( UInt_t uHit = 0; uHit < uNbHits; ++uHit )
714 Double_t dHitTime = fvmTofGdpbHitsInTs[ uGdpb ][ uHit ].GetFullTimeNs();
716 Double_t dDt = dHitTime - dDiaTime;
717 fhMcbmTimeDiffToDiamondTs->Fill( dDt / 1e6, uGdpb + fuStsNrOfDpbs );
719 fvhMcbmTimeDiffToDiamondTsEvoDpb[ uGdpb + fuStsNrOfDpbs ]->Fill( fulCurrentTsIdx, dDt / 1e6 );
720 } // for( UInt_t uHit = 0; uHit < uNbHits; ++uHit )
721 } // for( UInt_t uGdpb = 0; uGdpb < fuTofNrOfDpbs; ++uGdpb )
722 } // for( UInt_t uHitDia = 0; uHitDia < uNbDiaHits; uHitDia++)
725 for( UInt_t uSdpb = 0; uSdpb < fuStsNrOfDpbs; ++uSdpb )
727 fvmStsSdpbHitsInTs[ uSdpb ].clear();
728 } // for( UInt_t uSdpb = 0; uSdpb < fuStsNrOfDpbs; ++uSdpb )
729 for( UInt_t uGdpb = 0; uGdpb < fuTofNrOfDpbs; ++uGdpb )
731 fvmTofGdpbHitsInTs[ uGdpb ].clear();
732 } // for( UInt_t uGdpb = 0; uGdpb < fuTofNrOfDpbs; ++uGdpb )
735 for (UInt_t uTimeBin = 0; uTimeBin <
kuNbTimeBins; ++uTimeBin) {
779 if (0 == ts.index() % 1000) {
780 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
789 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
791 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
793 uint32_t uSize = msDescriptor.size;
797 <<
" has size: " << uSize;
805 LOG(info) <<
"---------------------------------------------------------------";
816 LOG(warning) <<
"Could not find the sDPB index for AFCK id 0x" << std::hex <<
fuCurrDpbId << std::dec
817 <<
" in timeslice " <<
fulCurrentTsIdx <<
" in microslice " << uMsIdx <<
" component " << uMsComp
819 <<
"If valid this index has to be added in the STS/MUCH "
820 "parameter file in the RocIdArray field";
834 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
837 << uTsMsbCycleHeader;
843 LOG(error) <<
"The input microslice buffer does NOT "
844 <<
"contain only complete nDPB messages!";
850 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
852 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
854 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
879 LOG(info) <<
"CbmMcbm2018MonitorMcbmRate::DoUnpack => "
880 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
889 LOG(fatal) <<
"CbmMcbm2018MonitorMcbmRate::DoUnpack => "
890 <<
"Unknown message type, should never happen, stopping here!";
935 UInt_t uChanIdx = usChan +
fUnpackParSts->GetNbChanPerAsic() * uAsicIdx;
946 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
return; }
951 Long64_t ulStsHitTime = usRawTs;
981 LOG(info) <<
"TS MSb Jump in "
983 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
985 << std::setw(5) << uVal;
1006 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1009 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1011 uint32_t
size = msDescriptor.size;
1013 if (
size > 0) LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " <<
size;
1015 Int_t messageType = -111;
1019 LOG(error) <<
"The input microslice buffer does NOT "
1020 <<
"contain only complete nDPB messages!";
1032 LOG(info) <<
"---------------------------------------------------------------";
1043 LOG(warning) <<
"Could not find the gDPB index for AFCK id 0x" << std::hex <<
fuTofGdpbId << std::dec
1044 <<
" in timeslice " <<
fulCurrentTsIdx <<
" in microslice " << uMsIdx <<
" component " << uMsComp
1046 <<
"If valid this index has to be added in the TOF parameter "
1047 "file in the RocIdArray field";
1054 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1055 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1057 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1066 if (fair::Logger::Logging(fair::Severity::debug2)) {
1075 switch (messageType) {
1095 LOG(error) <<
"Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
1096 <<
" not included in Get4 unpacker.";
1120 if (0 < ulCurEpochGdpbGet4) ulCurEpochGdpbGet4--;
1153 if (0 < iBufferSize) {
1154 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr <<
" with epoch number "
1161 for (
Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1189 LOG(info) <<
"-------------------------------------";
1199 TFile* oldFile = gFile;
1200 TDirectory* oldDir = gDirectory;
1202 TFile* histoFile =
nullptr;
1203 if (
"" != sFileName) {
1205 histoFile =
new TFile(sFileName,
"RECREATE");
1216 gDirectory->mkdir(
"mCbmRate");
1217 gDirectory->cd(
"mCbmRate");
1223 gDirectory->cd(
"..");
1225 gDirectory->mkdir(
"mCbmCounts");
1226 gDirectory->cd(
"mCbmCounts");
1239 gDirectory->cd(
"..");
1242 if (
"" != sFileName) {
1249 gDirectory = oldDir;
ClassImp(CbmConverterManager)
static constexpr size_t size()
TH1 * fhDiamondHitsRateDerivative
Int_t fiBinSizeDatePlots
Start of run time since "epoch" in s, for the plots with date as X axis.
Bool_t ProcessStsMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
UInt_t fuCurrentEquipmentId
void FillTofEpochInfo(gdpbv100::Message)
TH2 * fhTofVsDiamHitsNbPerTimeBin
TH2 * fhDiamVsTofHitsNbPerTimeBin
stsxyter::MessagePrintMask fPrintMessCtrlSts
TH2 * fhMcbmHitsNbPerTsEvo
ULong64_t fulCurrentTsStartTime
void FillStsHitInfo(stsxyter::Message mess, const UInt_t &uMsIdx)
TH2 * fhTofVsMuchHitsNbPerTimeBin
void AddMsComponentToListSts(size_t component)
TH2 * fhStsVsTofHitsNbPerTimeBin
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
Double_t fdMuchTofOffsetNs
static const UInt_t kuStsBytesPerMessage
UInt_t fuTotalNrOfDpb
Global parameters.
std::vector< UInt_t > fvuHitsNbInTimeBinSts
std::vector< int > fviTofMsgCounter
std::map< UInt_t, UInt_t > fmStsDpbIdIndexMap
Total number of Sts DPBs in system.
TH2 * fhTofVsStsHitsNbPerTimeBin
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
TH2 * fhDiamVsStsHitsNbPerTimeBin
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInMs
Buffer for system sync check.
std::vector< UInt_t > fvuHitsNbInTimeBinTof
std::vector< ULong64_t > fvulTofCurrentEpoch
TH2 * fhMcbmHitsNbFineEvo
void SaveAllHistos(TString sFileName="")
Bool_t ReInitContainers()
TH2 * fhDiamondHitsRateMapEvo
Int_t fiRunStartDateTimeSec
Index of the DPB from which the MS currently unpacked is coming.
Bool_t ProcessTofMs(const fles::Timeslice &ts, size_t uMsComp, UInt_t uMsIdx)
void FillTofEpochCycle(uint64_t ulCycleData)
void FillTofHitInfo(gdpbv100::Message)
CbmMcbm2018StsPar * fUnpackParSts
TH2 * fhStsVsDiamHitsNbPerTimeBin
CbmMcbm2018MonitorMcbmRate()
TH2 * fhStsVsMuchHitsNbPerTimeBin
static const UInt_t kuTimeBinSizeNs
ULong64_t fulCurrentMsIdx
std::vector< std::vector< gdpbv100::Message > > fvmTofEpSupprBuffer
Buffer for suppressed epoch processing.
TH2 * fhMuchVsDiamHitsNbPerTimeBin
virtual ~CbmMcbm2018MonitorMcbmRate()
void FillStsTsMsbInfo(stsxyter::Message mess, UInt_t uMessIdx=0, UInt_t uMsIdx=0)
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInMs
Current TS MSB cycle for DPB.
static const UInt_t kuNbTimeBins
virtual void SetNbMsInTs(size_t uCoreMsNb, size_t uOverlapMsNb)
std::map< UInt_t, UInt_t > fmTofDpbIdIndexMap
Total number of GDPBs in the system.
std::vector< UInt_t > fvuHitsNbInTimeBinMuch
TString fsHistoFileFullname
void CreateTofHistograms()
Processing methods.
Double_t fdStsTofOffsetNs
std::vector< ULong64_t > fvulTofCurrentEpochCycle
void FillStsEpochInfo(stsxyter::Message mess)
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
TH2 * fhMuchVsTofHitsNbPerTimeBin
std::vector< std::vector< stsxyter::FinalHit > > fvmStsSdpbHitsInTs
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
std::vector< size_t > fvMsComponentsListSts
void AddMsComponentToListTof(size_t component)
uint64_t fulTofCurrentTsIndex
Running indices.
virtual void AddMsComponentToList(size_t component, UShort_t usDetectorId)
std::vector< size_t > fvMsComponentsListTof
ULong64_t fulCurrentTsIdx
std::vector< UInt_t > fvuHitsNbInTimeBinDiam
std::vector< ULong64_t > fvulTofCurrentEpochFull
std::vector< ULong64_t > fvulStsCurrentTsMsb
Bin size in s for the plots with date as X axis.
void CreateStsHistograms()
All hits (time in bins, ADC in bins, asic, channel) in last TS, sorted with "<" operator.
static const UInt_t kuTofBytesPerMessage
TODO => move to the message class!!
std::map< stsxyter::MessType, UInt_t > fmMsgCounter
void CreateMcbmHistograms()
CbmMcbm2018TofPar * fUnpackParTof
Unpacking and mapping parameters for TOF.
std::vector< std::vector< gdpbv100::FullMessage > > fvmTofGdpbHitsInTs
TH2 * fhMuchVsStsHitsNbPerTimeBin
UInt_t fuMuchDpbIdx
Map of DPB Identifier to DPB index.
ULong64_t fulTofCurrentEpochTime
std::vector< UInt_t > fvuStsCurrentTsMsbCycle
Current TS MSB for each DPB.
TH2 * fhDiamVsMuchHitsNbPerTimeBin
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