43 , fbUseChannelMask(false)
44 , fvvbMaskedChannels()
49 , fdStartTimeMsSz(-1.0)
50 , ftStartTimeUnix(
std::chrono::steady_clock::now())
55 , fvvusLastTsMsbCycleChan()
69 LOG(info) <<
"Initializing mCBM STS 2019 unpacker algo";
80 LOG(info) << fName <<
"::initParSet - for container " << parset->ClassName();
85 << fName <<
"::initParSet - for container " << parset->ClassName()
86 <<
" failed, since CbmStsUnpackAlgoLegacy::initParSet() does not know the derived ParSet and what to do with it!";
105 std::vector<int32_t> viModuleType;
108 std::vector<int32_t> viModAddress;
111 std::vector<std::vector<std::vector<int32_t>>> viFebModuleIdx;
114 std::vector<std::vector<bool>> vbCrobActiveFlag;
117 std::vector<std::vector<std::vector<int32_t>>> viFebModuleSide;
121 LOG(info) <<
"Nr. of STS Modules: " << uNbModules;
124 InitTempVectors(&viModuleType, &viModAddress, &viFebModuleIdx, &vbCrobActiveFlag, &viFebModuleSide);
128 LOG(info) <<
"Nr. of STS DPBs: " << uNbOfDpbs;
135 LOG(info) <<
"Nr. of FEBs: " <<
fuNbFebs;
139 LOG(info) <<
"Nr. of StsXyter ASICs: " << uNbStsXyters;
148 for (uint32_t uDpb = 0; uDpb < uNbOfDpbs; ++uDpb) {
157 if (0 <= viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]
158 &&
static_cast<uint32_t
>(viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]) < uNbModules
159 && 0 <= viFebModuleSide[uDpb][uCrobIdx][uFebIdx] && viFebModuleSide[uDpb][uCrobIdx][uFebIdx] < 2) {
160 switch (viModuleType[viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]]) {
165 fviFebType[uDpb][uCrobIdx][uFebIdx] = viFebModuleSide[uDpb][uCrobIdx][uFebIdx];
173 fviFebAddress.push_back(viModAddress[viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]]);
175 fviFebSide.push_back(viFebModuleSide[uDpb][uCrobIdx][uFebIdx]);
182 fviFebType[uDpb][uCrobIdx][uFebIdx] = !(viFebModuleSide[uDpb][uCrobIdx][uFebIdx]);
190 fviFebAddress.push_back(viModAddress[viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]]);
192 fviFebSide.push_back(viFebModuleSide[uDpb][uCrobIdx][uFebIdx]);
196 LOG(fatal) << Form(
"Bad module type for DPB #%02u CROB #%u FEB %02u: %d", uDpb, uCrobIdx, uFebIdx,
197 viModuleType[viFebModuleIdx[uDpb][uCrobIdx][uFebIdx]]);
201 else if (-1 == viFebModuleIdx[uDpb][uCrobIdx][uFebIdx] || -1 == viFebModuleSide[uDpb][uCrobIdx][uFebIdx]) {
206 LOG(fatal) << Form(
"Bad module Index and/or Side for DPB #%02u CROB "
207 "#%u FEB %02u: %d %d",
208 uDpb, uCrobIdx, uFebIdx, viFebModuleIdx[uDpb][uCrobIdx][uFebIdx],
209 viFebModuleSide[uDpb][uCrobIdx][uFebIdx]);
218 LOG(info) <<
"Unpacking data in bin sorter FW mode";
230 LOG(info) <<
"Eq. ID for DPB #" << std::setw(2) << uDpb <<
" = 0x" << std::setw(4) << std::hex
237 std::vector<std::vector<std::vector<int32_t>>>* viFebModuleIdx,
238 std::vector<std::vector<bool>>* vbCrobActiveFlag,
239 std::vector<std::vector<std::vector<int32_t>>>* viFebModuleSide)
244 viModuleType->resize(uNbModules);
245 viModAddress->resize(uNbModules);
246 for (uint32_t uModIdx = 0; uModIdx < uNbModules; ++uModIdx) {
249 LOG(info) <<
"Module #" << std::setw(2) << uModIdx <<
" Type " << std::setw(4) << (*viModuleType)[uModIdx]
250 <<
" Address 0x" << std::setw(8) << std::hex << (*viModAddress)[uModIdx] << std::dec;
252 vbCrobActiveFlag->resize(uNbOfDpbs);
253 viFebModuleIdx->resize(uNbOfDpbs);
254 viFebModuleSide->resize(uNbOfDpbs);
256 for (uint32_t uDpb = 0; uDpb < uNbOfDpbs; ++uDpb) {
276 TString sPrintoutLine = Form(
"DPB #%02u CROB Active ?: ", uDpb);
278 sPrintoutLine += Form(
"%1u", (vbCrobActiveFlag[uDpb][uCrobIdx] ==
true));
280 LOG(info) << sPrintoutLine;
286 const std::vector<std::vector<std::vector<int32_t>>>& viFebModuleSide)
288 uint32_t uGlobalFebIdx = 0;
291 LOG(info) << Form(
"DPB #%02u CROB #%u: ", uDpb, uCrobIdx);
293 if (0 <= viFebModuleIdx[uDpb][uCrobIdx][uFebIdx])
294 LOG(info) << Form(
" FEB #%02u (%02u): Mod. Idx = %03d Side %c (%2d) Type %c "
295 "(%2d) (Addr. 0x%08x) ADC gain %4.0f e- ADC Offs %5.0f e-",
296 uFebIdx, uGlobalFebIdx, viFebModuleIdx[uDpb][uCrobIdx][uFebIdx],
297 1 == viFebModuleSide[uDpb][uCrobIdx][uFebIdx] ?
'N' :
'P',
298 viFebModuleSide[uDpb][uCrobIdx][uFebIdx],
302 LOG(info) << Form(
"Disabled FEB #%02u (%02u): Mod. Idx = %03d Side %c (%2d) Type %c "
303 "(%2d) (Addr. 0x%08x) ADC gain %4.0f e- ADC Offs %5.0f e-",
304 uFebIdx, uGlobalFebIdx, viFebModuleIdx[uDpb][uCrobIdx][uFebIdx],
305 1 == viFebModuleSide[uDpb][uCrobIdx][uFebIdx] ?
'N' :
'P',
306 viFebModuleSide[uDpb][uCrobIdx][uFebIdx],
323 for (uint32_t uDpb = 0; uDpb < uNbOfDpbs; ++uDpb) {
332 for (uint32_t uAsicIdx = 0; uAsicIdx < uNbStsXyters; ++uAsicIdx) {
341 std::vector<CbmStsDigi>* vDigiVectOut)
343 for (
auto itHitIn = vmHitsIn->begin(); itHitIn < vmHitsIn->end(); ++itHitIn) {
344 const uint32_t uAsicIdx = itHitIn->GetAsic();
346 uint32_t uChanInMod =
358 const uint64_t ulTimeInNs =
static_cast<uint64_t
>(dTimeInNs);
362 LOG(error) << Form(
"Digi on disabled FEB %02u has address 0x%08x and side %d", uFebIdx,
fviFebAddress[uFebIdx],
369 fOptOutAVec->emplace_back(
fviFebAddress[uFebIdx], uChanInMod, ulTimeInNs, dCalAdc);
373 vDigiVectOut->emplace_back(
fviFebAddress[uFebIdx], uChanInMod, ulTimeInNs, dCalAdc);
385 auto msDescriptor = ts->descriptor(uMsCompIdx, uMsIdx);
388 const uint32_t uCurrentEquipmentId = msDescriptor.eq_id;
389 const uint8_t* msContent =
reinterpret_cast<const uint8_t*
>(ts->content(uMsCompIdx, uMsIdx));
390 const uint32_t uSize = msDescriptor.size;
393 LOG(debug) <<
"Microslice: " <<
fulCurrentMsIdx <<
" from EqId " << std::hex << uCurrentEquipmentId << std::dec
394 <<
" has size: " << uSize;
399 const uint32_t uCurrDpbId =
static_cast<uint32_t
>(uCurrentEquipmentId & 0xFFFF);
403 if (uMsCompIdx < fMonitor->GetMaxNbFlibLinks()) {
405 fMonitor->FillMsSize(uMsCompIdx, uSize);
414 LOG(info) <<
"---------------------------------------------------------------";
416 LOG(warning) <<
"Could not find the sDPB index for AFCK id 0x" << std::hex << uCurrDpbId << std::dec
417 <<
" in timeslice " << fTsIndex <<
" in microslice " << uMsIdx <<
" component " << uMsCompIdx <<
"\n"
418 <<
"If valid this index has to be added in the STS "
419 "parameter file in the DbpIdArray field";
424 if (1 == fTsIndex)
return true;
452 for (
auto itHit = fOutputVec.begin(); itHit != fOutputVec.end(); ++itHit) {
453 fMonitor->FillDigisTimeInRun(itHit->GetTime());
455 fMonitor->FillVectorSize(ts->index(), fOutputVec.size());
470 uint32_t uTsMsbCycleHeader;
480 LOG(info) <<
" TS " << std::setw(12) << fTsIndex <<
" MS " << std::setw(12) <<
fulCurrentMsIdx <<
" MS Idx "
481 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << 0 <<
" DPB " << std::setw(2) <<
fuCurrDpbIdx
489 LOG(info) <<
" TS " << std::setw(12) << fTsIndex <<
" MS " << std::setw(12) <<
fulCurrentMsIdx <<
" MS Idx "
490 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << 0 <<
" DPB " << std::setw(2) <<
fuCurrDpbIdx
495 LOG(warning) <<
"TS MSB cycle from MS header does not match current cycle from data "
496 <<
"for TS " << std::setw(12) << fTsIndex <<
" MS " << std::setw(12) <<
fulCurrentMsIdx <<
" MsInTs "
498 << uTsMsbCycleHeader <<
" (header)";
509 LOG(error) <<
"The input microslice buffer does NOT "
510 <<
"contain only complete sDPB messages!";
518 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
537 LOG(info) <<
"CbmStsUnpackAlgoLegacy::DoUnpack => "
538 <<
"EPOCH message at unexpected position in MS: message " << uIdx <<
" VS message 0 expected!";
557 LOG(fatal) <<
"CbmStsUnpackAlgoLegacy::DoUnpack => "
558 <<
"Unknown message type, should never happen, stopping "
559 "here! Type found was: "
560 <<
static_cast<int>(typeMess);
579 LOG(warning) <<
"CbmStsUnpackAlgoLegacy::ProcessHitInfo => "
580 <<
"Wrong elink Idx! Elink raw " << Form(
"%d remap %d", usElinkIdx, uFebIdx);
583 const uint32_t uAsicIdx =
590 const uint16_t usRawAdc = mess.
GetHitAdc();
607 LOG(debug) <<
"CbmStsUnpackAlgoLegacy::ProcessHitInfo => "
608 << Form(
"Rejecting duplicate on Asic %3u channel %3u, TS %3u, MSB %lu, Cycle %u, ADC %2u", uAsicIdx,
634 fOptOutBVec->push_back(
646 const double dTimeSinceStartSec = (dHitTimeNs -
fdStartTime) * 1e-9;
648 fMonitor->FillHitMonitoringHistos(uFebIdx, usChan, uChanInFeb, usRawAdc, dCalAdc, usRawTs, mess.
IsHitMissedEvts());
649 fMonitor->FillHitEvoMonitoringHistos(uFebIdx, uAsicIdx, uAsicInFeb, uChanInFeb, dTimeSinceStartSec,
668 LOG(info) <<
" TS " << std::setw(12) << fTsIndex <<
" MS " << std::setw(12) <<
fulCurrentMsIdx <<
" MS Idx "
669 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
685 LOG(info) <<
"TS MSb Jump in "
686 <<
" TS " << std::setw(12) << fTsIndex <<
" MS " << std::setw(12) <<
fulCurrentMsIdx <<
" MS Idx "
687 << std::setw(4) << uMsIdx <<
" Msg Idx " << std::setw(5) << uMessIdx <<
" DPB " << std::setw(2)
689 << std::setw(5) << uVal;
694 if (4194303 == uVal && 1 == uMessIdx)
725 LOG(warning) <<
"CbmStsUnpackAlgoLegacy::DoUnpack => "
726 <<
"Wrong elink Idx! Elink raw " << Form(
"%d remap %d", usElinkIdx, uFebIdx);
729 const uint32_t uAsicIdx =
735 fMonitor->FillStsStatusMessType(uAsicIdx, usStatusField);
743 fOptOutBVec->push_back(
777 fOptOutBVec->push_back(
789 for (uint32_t uFebIdx = 0; uFebIdx <
fuNbFebs; ++uFebIdx) {
793 if (uFeb <
fuNbFebs && uChan < fUnpackPar->GetNbChanPerFeb())
796 LOG(fatal) <<
"CbmStsUnpackAlgoLegacy::MaskNoisyChannel => Invalid FEB "
@ kSts
Silicon Tracking System.
CbmRoot (+externals) headers.
Double_t GetFebAdcGain(UInt_t uDpbIdx, UInt_t uCrobIdx, UInt_t uFebIdx)
UInt_t GetDpbId(UInt_t uDpbIdx)
Int_t ElinkIdxToFebIdx(UInt_t uElink)
Int_t GetFebModuleIdx(UInt_t uDpbIdx, UInt_t uCrobIdx, UInt_t uFebIdx)
UInt_t GetModuleType(UInt_t uModuleIdx)
static constexpr UInt_t GetNbFebsPerCrob()
static constexpr UInt_t GetNbAsicsPerFeb()
static constexpr UInt_t GetNbElinkPerCrob()
Double_t GetFebAdcOffset(UInt_t uDpbIdx, UInt_t uCrobIdx, UInt_t uFebIdx)
static constexpr UInt_t GetNbAsicsPerCrob()
Bool_t IsCrobActive(UInt_t uDpbIdx, UInt_t uCrobIdx)
static constexpr UInt_t GetNbCrobsPerDpb()
UInt_t GetModuleAddress(UInt_t uModuleIdx)
UInt_t ElinkIdxToAsicIdx(Bool_t bFebType, UInt_t uElink)
Bool_t IsFebPulser(UInt_t uFebInSystIdx)
Int_t GetFebModuleSide(UInt_t uDpbIdx, UInt_t uCrobIdx, UInt_t uFebIdx)
static constexpr UInt_t GetNbChanPerAsic()
static constexpr UInt_t GetNbChanPerFeb()
std::vector< double > fvdTimeOffsetNsAsics
Time offsets per Asic???
bool fbUseFwBinning
Enables firmware binning (some implementations ignore this)
uint32_t fdAdcCut
Minimum adc cut to store a hit.
bool fbRejectDuplicateDigis
Enables the rejection of duplicate digis.
std::shared_ptr< CbmStsUnpackMonitor > fMonitor
Potential (online) monitor for the unpacking process.
bool fbDupliWithoutAdc
If rejecting duplicate digis, enables rejection even if ADC differs.
uint64_t GetFullTimeStamp(const uint16_t usRawTs)
Get full time stamp from raw time stamp.
std::vector< double > fvdFebAdcGain
Module side for each FEB, [ NbDpb * NbCrobPerDpb * NbFebsPerCrob ].
void PrintAddressMaps(const std::vector< std::vector< std::vector< int32_t > > > &viFebModuleIdx, const std::vector< std::vector< std::vector< int32_t > > > &viFebModuleSide)
~CbmStsUnpackAlgoLegacy()
void ProcessEpochInfo(const stsxyter::Message &mess)
void ProcessErrorInfo(const stsxyter::Message &mess)
void InitTempVectors(std::vector< int32_t > *viModuleType, std::vector< int32_t > *viModAddress, std::vector< std::vector< std::vector< int32_t > > > *viFebModuleIdx, std::vector< std::vector< bool > > *vbCrobActiveFlag, std::vector< std::vector< std::vector< int32_t > > > *viFebModuleSide)
std::vector< uint64_t > fvulCurrentTsMsb
std::map< uint32_t, uint32_t > fDpbIdIndexMap
Number of FEBs with StsXyter ASICs.
std::vector< stsxyter::FinalHit > fvmHitsInMs
Hits time-sorting.
CbmMcbm2018StsPar * fUnpackPar
Settings from parameter file.
bool initParSet(FairParGenericSet *parset)
ADC offset in e-, [ NbDpb * NbCrobPerDpb * NbFebsPerCrob ].
void InitDpbIdIndexMap()
Map of DPB Identifier to DPB index.
std::vector< bool > fvbMaskedComponents
Control flags.
std::vector< std::vector< uint16_t > > fvvusLastTsChan
std::vector< std::vector< bool > > fvvbMaskedChannels
uint32_t fuCurrDpbIdx
Current data properties.
void RefreshTsMsbFields(const size_t uMsIdx)
std::vector< int32_t > fviFebSide
STS address for each FEB, [ NbDpb * NbCrobPerDpb * NbFebsPerCrob ].
virtual void MaskNoisyChannel(const uint32_t uFeb, const uint32_t uChan, const bool bMasked=true)
Mask a Noisy Channel.
void InitInternalStatus()
void PrintActiveCrobs(const std::vector< std::vector< bool > > &vbCrobActiveFlag)
void ProcessStatusInfo(const stsxyter::Message &mess, uint32_t uIdx)
void ProcessHitInfo(const stsxyter::Message &mess)
TS MSB cycle of last hit message for each channel, [ AsicIdx ][ Chan ].
bool unpack(const fles::Timeslice *ts, std::uint16_t icomp, UInt_t imslice)
Unpack a given microslice. To be implemented in the derived unpacker algos.
std::vector< std::vector< std::vector< int32_t > > > fviFebType
std::vector< std::vector< uint32_t > > fvvuLastTsMsbChan
ADC of last hit message for each channel, [ AsicIdx ][ Chan ].
void ProcessTsMsbInfo(const stsxyter::Message &mess, uint32_t uMessIdx=0, uint32_t uMsIdx=0)
void AddHitsToDigiVect(std::vector< stsxyter::FinalHit > *vmHitsIn, std::vector< CbmStsDigi > *vDigiVectOut)
Add the hits to the output buffer as Digis.
void LoopMsMessages(const uint8_t *msContent, const uint32_t uSize, const size_t uMsIdx)
uint64_t fulCurrentMsIdx
Vector of channel masks, [ NbFeb ][ NbCHanInFeb ], used only if fbUseChannelMask is true.
std::vector< double > fvdFebAdcOffs
ADC gain in e-/b, [ NbDpb * NbCrobPerDpb * NbFebsPerCrob ].
double fdTimeOffsetNs
User settings: Data correction parameters.
std::vector< uint32_t > fvuCurrentTsMsbCycle
Current TS MSB for each DPB.
std::vector< std::vector< uint16_t > > fvvusLastTsMsbCycleChan
TS MSB of last hit message for each channel, [ AsicIdx ][ Chan ].
std::vector< int32_t > fviFebAddress
Pulser flag for each FEB, [ NbDpb * NbCrobPerDpb * NbFebsPerCrob ].
std::vector< std::vector< uint16_t > > fvvusLastAdcChan
TS of last hit message for each channel, [ AsicIdx ][ Chan ].
std::vector< bool > fvbFebPulser
FEB type, [ NbDpb ][ NbCrobPerDpb ][ NbFebsPerCrob ], 0 = A, 1 = B, -1 if inactive.
static const uint32_t kuMaxTsMsbDiffDuplicates
All hits (time in bins, ADC in bins, asic, channel) in last MS, sorted with "<" operator.
XPU_D bool IsHitMissedEvts() const
For Hit data: Returns Missed event flag (1 bit field)
XPU_D uint32_t GetTsMsbValBinning() const
For TS MSB data: Returns the TS MSB 29 bit field)
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 uint16_t GetStatusStatus() const
For Status data: Returns the Status field from ACK frame (4 bit field)
XPU_D MessType GetMessType() const
Returns the message type, see enum MessType.
XPU_D uint16_t GetLinkIndexHitBinning() const
XPU_D uint32_t GetData() const
XPU_D uint32_t GetTsMsbVal() const
For TS MSB data: Returns the TS MSB 22 bit field)
XPU_D uint16_t GetHitTimeFull() const
For Hit data: Returns Full timestamp (10 bit field including 2 bits overlap)
XPU_D uint16_t GetHitTimeBinning() const
XPU_D uint16_t GetStatusLink() const
For Status data: Returns the Link Inedx (9 bit field)
XPU_D uint16_t GetMsErrorType() const
For End of MS data: Returns the MS error type field (2 bit field)
XPU_D bool IsMsErrorFlagOn() const
For End of MS data: Returns the MS error flag (1 bit field)
static constexpr uint32_t kuHitNbTsBinsBinning
static constexpr uint64_t kulTsCycleNbBins
static constexpr uint64_t kulTsCycleNbBinsBinning
static constexpr uint32_t kuHitNbTsBins
static constexpr double kdClockCycleNs
static constexpr uint16_t kusLenStatStatus