CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018RawConverterSdpb.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5// -----------------------------------------------------------------------------
6// ----- -----
7// ----- CbmMcbm2018RawConverterSdpb -----
8// ----- Created 28.06.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
15#include "CbmMcbm2018StsPar.h"
16#include "CbmStsDigi.h"
17
18#include "FairParGenericSet.h"
19#include "FairRootManager.h"
20#include "FairRun.h"
21#include "FairRunOnline.h"
22#include "FairRuntimeDb.h"
23#include <Logger.h>
24
25#include <iomanip>
26
29 , fParCList(nullptr)
30 , fUnpackPar(nullptr)
31 , fuNrOfDpbs(0)
32 , fDpbIdIndexMap()
33 , fvbMaskedComponents()
34 , fvMsComponentsList()
35 , fuNbCoreMsPerTs(0)
36 , fuNbOverMsPerTs(0)
37 , fuNbMsLoop(0)
38 , fbIgnoreOverlapMs(kFALSE)
39 , fdMsSizeInNs(-1.0)
40 , fdTsCoreSizeInNs(-1.0)
41 , fulCurrentTsIdx(0)
42 , fulCurrentMsIdx(0)
43 , fdTsStartTime(0.0)
44 , fdTsStopTimeCore(0.0)
45 , fdMsTime(0.0)
46 , fuMsIndex(0)
47 , fuCurrentEquipmentId(0)
48 , fuCurrDpbId(0)
49 , fuCurrDpbIdx(0)
50 , fvSdpbMessages()
51{
52}
53
55
57{
58 LOG(info) << "CbmMcbm2018RawConverterSdpb::Init";
59 LOG(info) << "Initializing mCBM sDPB 2018 Raw Messages Converter";
60
61 return kTRUE;
62}
63
65{
66 LOG(info) << "Setting parameter containers for " << GetName();
67
68 if (nullptr == fParCList) fParCList = new TList();
69 fUnpackPar = new CbmMcbm2018StsPar("CbmMcbm2018StsPar");
71
72 for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
73 FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
74 fParCList->Remove(tempObj);
75
76 std::string sParamName {tempObj->GetName()};
77 FairParGenericSet* newObj =
78 dynamic_cast<FairParGenericSet*>(FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
79
80 if (nullptr == newObj) {
81 LOG(error) << "Failed to obtain parameter container " << sParamName << ", for parameter index " << iparC;
82 return;
83 } // if( nullptr == newObj )
84
85 fParCList->AddAt(newObj, iparC);
86 // delete tempObj;
87 } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
88}
89
91{
92 LOG(info) << "Init parameter containers for " << GetName();
93
95 fUnpackPar = dynamic_cast<CbmMcbm2018StsPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018StsPar"));
96 if (nullptr == fUnpackPar) {
97 LOG(error) << "Failed to obtain parameter container CbmMcbm2018StsPar";
98 return kFALSE;
99 } // if( nullptr == fUnpackPar )
100
102 LOG(info) << "Nr. of STS DPBs: " << fuNrOfDpbs;
103
104 fDpbIdIndexMap.clear();
105 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
106 fDpbIdIndexMap[fUnpackPar->GetDpbId(uDpb)] = uDpb;
107 LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x" << std::setw(4) << std::hex
108 << fUnpackPar->GetDpbId(uDpb) << std::dec << " => " << fDpbIdIndexMap[fUnpackPar->GetDpbId(uDpb)];
109 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
110
112 FairRootManager* ioman = FairRootManager::Instance();
113 if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
114
116 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
117 fvSdpbMessages[uDpb] = new std::vector<stsxyter::Message>;
118 if (NULL == fvSdpbMessages[uDpb]) {
119 LOG(fatal) << "Failed creating the sDPB messages vector ";
120 } // if( NULL == fvSdpbMessages[ uDpb ] )
121 ioman->RegisterAny(Form("CbmSdpbMsg%03u", uDpb), fvSdpbMessages[uDpb], kTRUE);
122 } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
123
124 return kTRUE;
125}
126
128{
129 LOG(info) << "ReInit parameter containers for " << GetName();
130
131 return kTRUE;
132}
133
134void CbmMcbm2018RawConverterSdpb::AddMsComponentToList(size_t component, UShort_t usDetectorId)
135{
137 for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
138 if (component == fvMsComponentsList[uCompIdx]) return;
139
141 fvMsComponentsList.push_back(component);
142
143 LOG(info) << "CbmMcbm2018RawConverterSdpb::AddMsComponentToList => Component " << component << " with detector ID 0x"
144 << std::hex << usDetectorId << std::dec << " added to list";
145}
146
147Bool_t CbmMcbm2018RawConverterSdpb::DoUnpack(const fles::Timeslice& ts, size_t /*component*/)
148{
149 fulCurrentTsIdx = ts.index();
150 fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx);
151
153 if (0 == fulCurrentTsIdx) { return kTRUE; } // if( 0 == fulCurrentTsIdx )
154
156 if (-1.0 == fdTsCoreSizeInNs) {
157 fuNbCoreMsPerTs = ts.num_core_microslices();
158 fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
161 LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs << " Core MS and " << fuNbOverMsPerTs
162 << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs << " ns and a full duration of "
163 << fdTsFullSizeInNs << " ns";
164
168 LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
169 } // if( -1.0 == fdTsCoreSizeInNs )
170
173
175 for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx) {
177 for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
178 UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
179
180 auto msDescriptor = ts.descriptor(uMsComp, fuMsIndex);
181 fuCurrentEquipmentId = msDescriptor.eq_id;
182 const uint8_t* msContent = reinterpret_cast<const uint8_t*>(ts.content(uMsComp, fuMsIndex));
183
184 uint32_t uSize = msDescriptor.size;
185 fulCurrentMsIdx = msDescriptor.idx;
186 // Double_t dMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
187 LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId " << std::hex << fuCurrentEquipmentId << std::dec
188 << " has size: " << uSize;
189
190 if (0 == fvbMaskedComponents.size()) fvbMaskedComponents.resize(ts.num_components(), kFALSE);
191
192 fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF);
193
195 auto it = fDpbIdIndexMap.find(fuCurrDpbId);
196 if (it == fDpbIdIndexMap.end()) {
197 if (kFALSE == fvbMaskedComponents[uMsCompIdx]) {
198 LOG(info) << "-------------------------------------------------------"
199 "--------";
200 /*
201 LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
202 LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx",
203 static_cast<unsigned int>(msDescriptor.hdr_id),
204 static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
205 static_cast<unsigned int>(msDescriptor.sys_id),
206 static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc,
207 msDescriptor.size, msDescriptor.offset );
208*/
209 LOG(info) << FormatMsHeaderPrintout(msDescriptor);
210 LOG(warning) << "Could not find the sDPB index for AFCK id 0x" << std::hex << fuCurrDpbId << std::dec
211 << " in timeslice " << fulCurrentTsIdx << " in microslice " << fuMsIndex << " component "
212 << uMsCompIdx << "\n"
213 << "If valid this index has to be added in the STS "
214 "parameter file in the DbpIdArray field";
215 fvbMaskedComponents[uMsCompIdx] = kTRUE;
216
219 if (1 == fulCurrentTsIdx) return kTRUE;
220 } // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
221 else
222 return kTRUE;
223
224 return kFALSE;
225 } // if( it == fDpbIdIndexMap.end() )
226 else
228
230 if (0 != (uSize % kuBytesPerMessage))
231 LOG(error) << "The input microslice buffer does NOT "
232 << "contain only complete sDPB messages!";
233
235 uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
236
238 const uint32_t* pInBuff = reinterpret_cast<const uint32_t*>(msContent);
239 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
241 uint32_t ulData = static_cast<uint32_t>(pInBuff[uIdx]);
242 stsxyter::Message mess(static_cast<uint32_t>(ulData & 0xFFFFFFFF));
243
246 fvSdpbMessages[fuCurrDpbIdx]->push_back(mess);
247 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
248 } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
249 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
250
251 if (0 == fulCurrentTsIdx % 10000) LOG(info) << "Processed TS " << fulCurrentTsIdx;
252
253 return kTRUE;
254}
255
257{
258 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb)
259 fvSdpbMessages[uDpb]->clear();
260}
261
263
ClassImp(CbmConverterManager)
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
ULong64_t fulCurrentTsIdx
Total size of the core MS in a TS, [nanoseconds].
std::map< UInt_t, UInt_t > fDpbIdIndexMap
Total number of sDPBs to convert.
Double_t fdTsStopTimeCore
Time in ns of current TS from the index of the first MS first component.
std::vector< size_t > fvMsComponentsList
Parameters related to FLES containers.
Double_t fdMsSizeInNs
/‍** Ignore Overlap Ms: all fuNbOverMsPerTs MS at the end of timeslice **‍/
std::vector< Bool_t > fvbMaskedComponents
Control flags.
TList * fParCList
Settings from parameter file.
std::vector< std::vector< stsxyter::Message > * > fvSdpbMessages
Index of the DPB from which the MS currently unpacked is coming.
Double_t fdTsFullSizeInNs
Total size of the core MS in a TS, [nanoseconds].
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
UInt_t fuMsIndex
Start Time in ns of current MS from its index field in header.
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
UInt_t GetDpbId(UInt_t uDpbIdx)