CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018RawConverterGdpb.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// ----- CbmMcbm2018RawConverterGdpb -----
8// ----- Created 01.07.2019 by P.-A. Loizeau -----
9// ----- -----
10// -----------------------------------------------------------------------------
11
13
15#include "CbmMcbm2018TofPar.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 , fvGdpbMessages()
51{
52}
53
55
57{
58 LOG(info) << "CbmMcbm2018RawConverterGdpb::Init";
59 LOG(info) << "Initializing mCBM gDPB 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 CbmMcbm2018TofPar("CbmMcbm2018TofPar");
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<CbmMcbm2018TofPar*>(FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
96 if (nullptr == fUnpackPar) {
97 LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
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->GetGdpbId(uDpb)] = uDpb;
107 LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x" << std::setw(4) << std::hex
108 << fUnpackPar->GetGdpbId(uDpb) << std::dec << " => " << fDpbIdIndexMap[fUnpackPar->GetGdpbId(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 fvGdpbMessages[uDpb] = new std::vector<gdpbv100::Message>;
118 if (NULL == fvGdpbMessages[uDpb]) {
119 LOG(fatal) << "Failed creating the gDPB messages vector ";
120 } // if( NULL == fvGdpbMessages[ uDpb ] )
121 ioman->RegisterAny(Form("CbmGdpbMsg%03u", uDpb), fvGdpbMessages[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 CbmMcbm2018RawConverterGdpb::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) << "CbmMcbm2018RawConverterGdpb::AddMsComponentToList => Component " << component << " with detector ID 0x"
144 << std::hex << usDetectorId << std::dec << " added to list";
145}
146
147Bool_t CbmMcbm2018RawConverterGdpb::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 gDPB 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 TOF "
214 "parameter file in the DbpIdArray field";
215 fvbMaskedComponents[uMsCompIdx] = kTRUE;
216 } // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
217 else
218 return kTRUE;
219
222
223 return kFALSE;
224 } // if( it == fDpbIdIndexMap.end() )
225 else
227
229 if (0 != (uSize % kuBytesPerMessage))
230 LOG(error) << "The input microslice buffer does NOT "
231 << "contain only complete gDPB messages!";
232
234 uint32_t uNbMessages = (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
235
237 const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
238 for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
240 uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
241
243 if (0 == uIdx) { continue; } // if( 0 == uIdx )
244
245 gdpbv100::Message mess(ulData);
246
249 fvGdpbMessages[fuCurrDpbIdx]->push_back(mess);
250 } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
251 } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
252 } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
253
254 if (0 == fulCurrentTsIdx % 10000) LOG(info) << "Processed TS " << fulCurrentTsIdx;
255
256 return kTRUE;
257}
258
260{
261 for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb)
262 fvGdpbMessages[uDpb]->clear();
263}
264
266
ClassImp(CbmConverterManager)
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
Double_t fdMsSizeInNs
/‍** Ignore Overlap Ms: all fuNbOverMsPerTs MS at the end of timeslice **‍/
std::vector< Bool_t > fvbMaskedComponents
Control flags.
std::map< UInt_t, UInt_t > fDpbIdIndexMap
Total number of gDPBs to convert.
TList * fParCList
Settings from parameter file.
Double_t fdTsFullSizeInNs
Total size of the core MS in a TS, [nanoseconds].
ULong64_t fulCurrentTsIdx
Total size of the core MS in a TS, [nanoseconds].
std::vector< size_t > fvMsComponentsList
Parameters related to FLES containers.
Double_t fdTsStopTimeCore
Time in ns of current TS from the index of the first MS first component.
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
std::vector< std::vector< gdpbv100::Message > * > fvGdpbMessages
Index of the DPB from which the MS currently unpacked is coming.
UInt_t fuMsIndex
Start Time in ns of current MS from its index field in header.
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
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)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Int_t GetNrOfGdpbs()
FIXME: replace with method returning the correspondign constants! see Star2019 parameter.
Int_t GetGdpbId(Int_t i)