21#include "FairRootManager.h"
23#include "FairRunOnline.h"
24#include "FairRuntimeDb.h"
28#include "TClonesArray.h"
30#include "THttpServer.h"
123 LOG(info) <<
"Initializing flib StsXyter unpacker for STS";
125 FairRootManager* ioman = FairRootManager::Instance();
126 if (ioman ==
nullptr) { LOG(fatal) <<
"No FairRootManager instance"; }
133 LOG(info) <<
"Setting parameter containers for " << GetName();
141 LOG(info) <<
"Init parameter containers for " << GetName();
153 LOG(info) <<
"ReInit parameter containers for " << GetName();
162 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x" << std::setw(4) << std::hex
180 LOG(info) <<
"GDPB Id of TOF " << i <<
" : " << std::hex <<
fUnpackParTof->GetGdpbId(i) << std::dec;
197 switch (usDetectorId) {
209 LOG(warning) <<
"CbmMcbm2018MonitorStsSync::AddMsComponentToList => "
210 <<
"Ignore component " << component <<
" as detector id " << usDetectorId
211 <<
" is not supported by this unpacker.";
245 TString sHistName {
""};
305 LOG(info) <<
"Done Creating STS Histograms";
312 TString sHistName {
""};
380 LOG(info) <<
"Done Creating TOF Histograms";
387 TString sHistName {
""};
388 TString sHistTitle {
""};
392 sHistName =
"hMcbmHitsNbPerMs";
393 sHistTitle =
"Nb of hits per DPB; Nb of hits []; DPB []";
397 sHistName = Form(
"hMcbmTimeDiffToDpb%02u", uDpb);
398 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against "
399 "any hits in DPB %02u; <tn - tRef> [ns]; DPB []",
403 sHistName = Form(
"hMcbmTimeDiffToDpb%02uWide", uDpb);
404 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against any hits in "
405 "DPB %02u, wide range; <tn - tRef> [us]; DPB []",
409 sHistName = Form(
"hMcbmTimeDiffToDpb%02uTs", uDpb);
410 sHistTitle = Form(
"Time difference for STS and TOF hits, per DPB, against any hits in "
411 "DPB %02u, TS range; <tn - tRef> [ms]; DPB []",
416 sHistName = Form(
"hMcbmTimeDiffToDiamondEvoDpb%02u", uDpb);
417 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
418 "against any Diamond hit; TS []; <tn - tDia> [ns]",
424 sHistName = Form(
"hMcbmTimeDiffToDiamondWideEvoDpb%02u", uDpb);
425 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
426 "against any Diamond hit, wide range; TS []; <tn - tDia> [us]",
429 new TH2D(sHistName, sHistTitle, 2000.0, 0., 200000., 4000.0, -200., 200.));
431 sHistName = Form(
"hMcbmTimeDiffToDiamondTsEvoDpb%02u", uDpb);
432 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
433 "against any Diamond hit, TS range; TS []; <tn - tDia> [ms]",
437 sHistName = Form(
"hMcbmTimeDiffToTofEvoDpb%02u", uDpb);
438 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from "
439 "DPB %02u against any Tof hit; TS []; <tn - tTof> [ns]",
444 sHistName = Form(
"hMcbmTimeDiffToTofWideEvoDpb%02u", uDpb);
445 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
446 "against any Tof hit, wide range; TS []; <tn - tTof> [us]",
450 sHistName = Form(
"hMcbmTimeDiffToTofTsEvoDpb%02u", uDpb);
451 sHistTitle = Form(
"Evolution of time difference for STS or TOF hits from DPB %02u "
452 "against any Tof hit, TS range; TS []; <tn - tTof> [ms]",
456#ifdef USE_HTTP_SERVER
457 THttpServer* server = FairRunOnline::Instance()->GetHttpServer();
475 server->RegisterCommand(
"/Reset_All",
"bMcbm2018ResetPulser=kTRUE");
476 server->RegisterCommand(
"/Save_All",
"bMcbm2018WritePulser=kTRUE");
478 server->Restrict(
"/Reset_All",
"allow=admin");
479 server->Restrict(
"/Save_All",
"allow=admin");
487 TCanvas* cSyncMcbmDpb =
new TCanvas(Form(
"cSyncMcbmDpb%02u", uDpb),
488 Form(
"Time difference for STS and TOF hits, per DPB, against "
492 cSyncMcbmDpb->Divide(3);
514 LOG(info) <<
"Done Creating mCBM Histograms";
530 LOG(debug) <<
"Timeslice contains " << ts.num_microslices(component) <<
"microslices.";
543 for (UInt_t uMsIdx = 0; uMsIdx < uNbMsLoop; uMsIdx++) {
548 if (kFALSE ==
ProcessStsMs(ts, uMsComp, uMsIdx))
return kFALSE;
555 if (kFALSE ==
ProcessTofMs(ts, uMsComp, uMsIdx))
return kFALSE;
573 for (UInt_t uRefSdpb = 0; uRefSdpb <
fuStsNrOfDpbs; ++uRefSdpb) {
575 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
583 Double_t dBestDt = 1e9;
585 UInt_t uNbIncrDt = 0;
587 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
588 if (uRefSdpb == uSdpb && uHitRef == uHit)
continue;
595 Double_t dDt = dHitTime - dRefTime;
599 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) {
603 else if (dBestDt < dDt)
607 if (5 == dBestDt)
break;
623 Double_t dBestDt = 1e9;
624 UInt_t uNbIncrDt = 0;
626 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
629 Double_t dDt = dHitTime - dRefTime;
633 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
634 else if (dBestDt < dDt)
638 if (5 == dBestDt)
break;
655 for (UInt_t uRefGdpb = 0; uRefGdpb <
fuTofNrOfDpbs; ++uRefGdpb) {
657 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
662 Double_t dBestDt = 1e9;
663 UInt_t uNbIncrDt = 0;
665 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
671 Double_t dDt = dHitTime - dRefTime;
675 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
676 else if (dBestDt < dDt)
680 if (5 == dBestDt)
break;
715 Double_t dBestDt = 1e9;
716 UInt_t uNbIncrDt = 0;
718 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
720 if (uRefGdpb == uGdpb && uHitRef == uHit)
continue;
724 Double_t dDt = dHitTime - dRefTime;
728 if (TMath::Abs(dDt) < TMath::Abs(dBestDt)) dBestDt = dDt;
729 else if (dBestDt < dDt)
733 if (5 == dBestDt)
break;
792 for (UInt_t uRefSdpb = 0; uRefSdpb <
fuStsNrOfDpbs; ++uRefSdpb) {
794 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
806 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
807 if (uRefSdpb == uSdpb && uHitRef == uHit)
continue;
814 Double_t dDt = dHitTime - dRefTime;
817 if (300e3 < dDt)
break;
828 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
831 Double_t dDt = dHitTime - dRefTime;
834 if (300e3 < dDt)
break;
843 for (UInt_t uRefGdpb = 0; uRefGdpb <
fuTofNrOfDpbs; ++uRefGdpb) {
845 for (UInt_t uHitRef = 0; uHitRef < uNbRefHits; uHitRef++) {
850 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
853 Double_t dDt = dHitTime - dRefTime;
856 if (300e3 < dDt)
break;
868 for (UInt_t uHit = 0; uHit < uNbHits; ++uHit) {
869 if (uRefGdpb == uGdpb && uHitRef == uHit)
continue;
873 Double_t dDt = dHitTime - dRefTime;
876 if (300e3 < dDt)
break;
899 if (0 == ts.index() % 1000) {
900 LOG(info) <<
"End of TS " << std::setw(7) << ts.index();
909 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
911 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
913 uint32_t uSize = msDescriptor.size;
917 <<
" has size: " << uSize;
930 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
933 << uTsMsbCycleHeader;
939 LOG(error) <<
"The input microslice buffer does NOT "
940 <<
"contain only complete nDPB messages!";
946 const uint32_t* pInBuff =
reinterpret_cast<const uint32_t*
>(msContent);
948 for (uint32_t uIdx = 0; uIdx < uNbMessages; ++uIdx) {
950 uint32_t ulData =
static_cast<uint32_t
>(pInBuff[uIdx]);
975 LOG(info) <<
"CbmMcbm2018MonitorMcbmPulser::DoUnpack => "
976 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
985 LOG(fatal) <<
"CbmMcbm2018MonitorMcbmPulser::DoUnpack => "
986 <<
"Unknown message type, should never happen, stopping here!";
1001 UInt_t uAsicIdx = 0;
1030 if (usRawAdc < 15)
return;
1034 UInt_t uChanIdx = usChan +
fUnpackParSts->GetNbChanPerAsic() * uAsicIdx;
1045 if ((0 == uChanIdx % 2) && (543 < uChanIdx) && (uChanIdx < 633)) {
return; }
1050 Long64_t ulStsHitTime = usRawTs;
1081 LOG(info) <<
"TS MSb Jump in "
1083 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
1085 << std::setw(5) << uVal;
1106 auto msDescriptor = ts.descriptor(uMsComp, uMsIdx);
1109 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts.content(uMsComp, uMsIdx));
1111 uint32_t
size = msDescriptor.size;
1113 if (
size > 0) LOG(debug) <<
"Microslice: " << msDescriptor.idx <<
" has size: " <<
size;
1115 Int_t messageType = -111;
1119 LOG(error) <<
"The input microslice buffer does NOT "
1120 <<
"contain only complete nDPB messages!";
1130 const uint64_t* pInBuff =
reinterpret_cast<const uint64_t*
>(msContent);
1131 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
1133 uint64_t ulData =
static_cast<uint64_t
>(pInBuff[uIdx]);
1142 if (fair::Logger::Logging(fair::Severity::debug2)) {
1151 switch (messageType) {
1171 LOG(error) <<
"Message type " << std::hex << std::setw(2) << static_cast<uint16_t>(messageType)
1172 <<
" not included in Get4 unpacker.";
1196 if (0 < ulCurEpochGdpbGet4) ulCurEpochGdpbGet4--;
1229 if (0 < iBufferSize) {
1230 LOG(debug) <<
"Now processing stored messages for for gDPB " <<
fuTofGdpbNr <<
" with epoch number "
1237 for (
Int_t iMsgIdx = 0; iMsgIdx < iBufferSize; iMsgIdx++) {
1265 LOG(info) <<
"-------------------------------------";
1275 TFile* oldFile = gFile;
1276 TDirectory* oldDir = gDirectory;
1278 TFile* histoFile =
nullptr;
1279 if (
"" != sFileName) {
1281 histoFile =
new TFile(sFileName,
"RECREATE");
1295 gDirectory->mkdir(
"mcbmDt");
1296 gDirectory->cd(
"mcbmDt");
1312 gDirectory->cd(
"..");
1315 if (
"" != sFileName) {
1322 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)
Int_t fiRunStartDateTimeSec
Index of the DPB from which the MS currently unpacked is coming.
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.
uint64_t fulTofCurrentTsIndex
Running indices.
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)
Int_t fiBinSizeDatePlots
Start of run time since "epoch" in s, for the plots with date as X axis.
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()
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