CbmRoot
CbmMcbm2018RawConverterGdpb.cxx
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 // ----- -----
3 // ----- CbmMcbm2018RawConverterGdpb -----
4 // ----- Created 01.07.2019 by P.-A. Loizeau -----
5 // ----- -----
6 // -----------------------------------------------------------------------------
7 
9 
11 #include "CbmMcbm2018TofPar.h"
12 #include "CbmStsDigi.h"
13 
14 #include "FairLogger.h"
15 #include "FairParGenericSet.h"
16 #include "FairRootManager.h"
17 #include "FairRun.h"
18 #include "FairRunOnline.h"
19 #include "FairRuntimeDb.h"
20 
21 #include <iomanip>
22 
24  : CbmMcbmUnpack()
25  , fParCList(nullptr)
26  , fUnpackPar(nullptr)
27  , fuNrOfDpbs(0)
28  , fDpbIdIndexMap()
29  , fvbMaskedComponents()
30  , fvMsComponentsList()
31  , fuNbCoreMsPerTs(0)
32  , fuNbOverMsPerTs(0)
33  , fuNbMsLoop(0)
34  , fbIgnoreOverlapMs(kFALSE)
35  , fdMsSizeInNs(-1.0)
36  , fdTsCoreSizeInNs(-1.0)
37  , fulCurrentTsIdx(0)
38  , fulCurrentMsIdx(0)
39  , fdTsStartTime(0.0)
40  , fdTsStopTimeCore(0.0)
41  , fdMsTime(0.0)
42  , fuMsIndex(0)
43  , fuCurrentEquipmentId(0)
44  , fuCurrDpbId(0)
45  , fuCurrDpbIdx(0)
46  , fvGdpbMessages() {}
47 
49 
51  LOG(info) << "CbmMcbm2018RawConverterGdpb::Init";
52  LOG(info) << "Initializing mCBM gDPB 2018 Raw Messages Converter";
53 
54  return kTRUE;
55 }
56 
58  LOG(info) << "Setting parameter containers for " << GetName();
59 
60  if (nullptr == fParCList) fParCList = new TList();
61  fUnpackPar = new CbmMcbm2018TofPar("CbmMcbm2018TofPar");
62  fParCList->Add(fUnpackPar);
63 
64  for (Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC) {
65  FairParGenericSet* tempObj = (FairParGenericSet*) (fParCList->At(iparC));
66  fParCList->Remove(tempObj);
67 
68  std::string sParamName {tempObj->GetName()};
69  FairParGenericSet* newObj = dynamic_cast<FairParGenericSet*>(
70  FairRun::Instance()->GetRuntimeDb()->getContainer(sParamName.data()));
71 
72  if (nullptr == newObj) {
73  LOG(error) << "Failed to obtain parameter container " << sParamName
74  << ", for parameter index " << iparC;
75  return;
76  } // if( nullptr == newObj )
77 
78  fParCList->AddAt(newObj, iparC);
79  // delete tempObj;
80  } // for( Int_t iparC = 0; iparC < fParCList->GetEntries(); ++iparC )
81 }
82 
84  LOG(info) << "Init parameter containers for " << GetName();
85 
87  fUnpackPar = dynamic_cast<CbmMcbm2018TofPar*>(
88  FairRun::Instance()->GetRuntimeDb()->getContainer("CbmMcbm2018TofPar"));
89  if (nullptr == fUnpackPar) {
90  LOG(error) << "Failed to obtain parameter container CbmMcbm2018TofPar";
91  return kFALSE;
92  } // if( nullptr == fUnpackPar )
93 
95  LOG(info) << "Nr. of STS DPBs: " << fuNrOfDpbs;
96 
97  fDpbIdIndexMap.clear();
98  for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
99  fDpbIdIndexMap[fUnpackPar->GetGdpbId(uDpb)] = uDpb;
100  LOG(info) << "Eq. ID for DPB #" << std::setw(2) << uDpb << " = 0x"
101  << std::setw(4) << std::hex << fUnpackPar->GetGdpbId(uDpb)
102  << std::dec << " => "
104  } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
105 
107  FairRootManager* ioman = FairRootManager::Instance();
108  if (NULL == ioman) { LOG(fatal) << "No FairRootManager instance"; }
109 
110  fvGdpbMessages.resize(fuNrOfDpbs);
111  for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb) {
112  fvGdpbMessages[uDpb] = new std::vector<gdpbv100::Message>;
113  if (NULL == fvGdpbMessages[uDpb]) {
114  LOG(fatal) << "Failed creating the gDPB messages vector ";
115  } // if( NULL == fvGdpbMessages[ uDpb ] )
116  ioman->RegisterAny(
117  Form("CbmGdpbMsg%03u", uDpb), fvGdpbMessages[uDpb], kTRUE);
118  } // for( UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb )
119 
120  return kTRUE;
121 }
122 
124  LOG(info) << "ReInit parameter containers for " << GetName();
125 
126  return kTRUE;
127 }
128 
130  UShort_t usDetectorId) {
132  for (UInt_t uCompIdx = 0; uCompIdx < fvMsComponentsList.size(); ++uCompIdx)
133  if (component == fvMsComponentsList[uCompIdx]) return;
134 
136  fvMsComponentsList.push_back(component);
137 
138  LOG(info) << "CbmMcbm2018RawConverterGdpb::AddMsComponentToList => Component "
139  << component << " with detector ID 0x" << std::hex << usDetectorId
140  << std::dec << " added to list";
141 }
142 
143 Bool_t CbmMcbm2018RawConverterGdpb::DoUnpack(const fles::Timeslice& ts,
144  size_t /*component*/) {
145  fulCurrentTsIdx = ts.index();
146  fdTsStartTime = static_cast<Double_t>(ts.descriptor(0, 0).idx);
147 
149  if (0 == fulCurrentTsIdx) { return kTRUE; } // if( 0 == fulCurrentTsIdx )
150 
152  if (-1.0 == fdTsCoreSizeInNs) {
153  fuNbCoreMsPerTs = ts.num_core_microslices();
154  fuNbOverMsPerTs = ts.num_microslices(0) - ts.num_core_microslices();
157  LOG(info) << "Timeslice parameters: each TS has " << fuNbCoreMsPerTs
158  << " Core MS and " << fuNbOverMsPerTs
159  << " Overlap MS, for a core duration of " << fdTsCoreSizeInNs
160  << " ns and a full duration of " << fdTsFullSizeInNs << " ns";
161 
164  if (kFALSE == fbIgnoreOverlapMs) fuNbMsLoop += fuNbOverMsPerTs;
165  LOG(info) << "In each TS " << fuNbMsLoop << " MS will be looped over";
166  } // if( -1.0 == fdTsCoreSizeInNs )
167 
170 
172  for (UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size();
173  ++uMsCompIdx) {
175  for (fuMsIndex = 0; fuMsIndex < fuNbMsLoop; fuMsIndex++) {
176  UInt_t uMsComp = fvMsComponentsList[uMsCompIdx];
177 
178  auto msDescriptor = ts.descriptor(uMsComp, fuMsIndex);
179  fuCurrentEquipmentId = msDescriptor.eq_id;
180  const uint8_t* msContent =
181  reinterpret_cast<const uint8_t*>(ts.content(uMsComp, fuMsIndex));
182 
183  uint32_t uSize = msDescriptor.size;
184  fulCurrentMsIdx = msDescriptor.idx;
185  // Double_t dMsTime = (1e-9) * static_cast<double>(fulCurrentMsIdx);
186  LOG(debug) << "Microslice: " << fulCurrentMsIdx << " from EqId "
187  << std::hex << fuCurrentEquipmentId << std::dec
188  << " has size: " << uSize;
189 
190  if (0 == fvbMaskedComponents.size())
191  fvbMaskedComponents.resize(ts.num_components(), kFALSE);
192 
193  fuCurrDpbId = static_cast<uint32_t>(fuCurrentEquipmentId & 0xFFFF);
194 
196  auto it = fDpbIdIndexMap.find(fuCurrDpbId);
197  if (it == fDpbIdIndexMap.end()) {
198  if (kFALSE == fvbMaskedComponents[uMsCompIdx]) {
199  LOG(info) << "-------------------------------------------------------"
200  "--------";
201  /*
202  LOG(info) << "hi hv eqid flag si sv idx/start crc size offset";
203  LOG(info) << Form( "%02x %02x %04x %04x %02x %02x %016llx %08x %08x %016llx",
204  static_cast<unsigned int>(msDescriptor.hdr_id),
205  static_cast<unsigned int>(msDescriptor.hdr_ver), msDescriptor.eq_id, msDescriptor.flags,
206  static_cast<unsigned int>(msDescriptor.sys_id),
207  static_cast<unsigned int>(msDescriptor.sys_ver), msDescriptor.idx, msDescriptor.crc,
208  msDescriptor.size, msDescriptor.offset );
209 */
210  LOG(info) << FormatMsHeaderPrintout(msDescriptor);
211  LOG(warning) << "Could not find the gDPB index for AFCK id 0x"
212  << std::hex << fuCurrDpbId << std::dec
213  << " in timeslice " << fulCurrentTsIdx
214  << " in microslice " << fuMsIndex << " component "
215  << uMsCompIdx << "\n"
216  << "If valid this index has to be added in the TOF "
217  "parameter file in the DbpIdArray field";
218  fvbMaskedComponents[uMsCompIdx] = kTRUE;
219  } // if( kFALSE == fvbMaskedComponents[ uMsComp ] )
220  else
221  return kTRUE;
222 
225 
226  return kFALSE;
227  } // if( it == fDpbIdIndexMap.end() )
228  else
230 
232  if (0 != (uSize % kuBytesPerMessage))
233  LOG(error) << "The input microslice buffer does NOT "
234  << "contain only complete gDPB messages!";
235 
237  uint32_t uNbMessages =
238  (uSize - (uSize % kuBytesPerMessage)) / kuBytesPerMessage;
239 
241  const uint64_t* pInBuff = reinterpret_cast<const uint64_t*>(msContent);
242  for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx++) {
244  uint64_t ulData = static_cast<uint64_t>(pInBuff[uIdx]);
245 
247  if (0 == uIdx) { continue; } // if( 0 == uIdx )
248 
249  gdpbv100::Message mess(ulData);
250 
253  fvGdpbMessages[fuCurrDpbIdx]->push_back(mess);
254  } // for (uint32_t uIdx = 0; uIdx < uNbMessages; uIdx ++)
255  } // for( fuMsIndex = 0; fuMsIndex < uNbMsLoop; fuMsIndex ++ )
256  } // for( UInt_t uMsCompIdx = 0; uMsCompIdx < fvMsComponentsList.size(); ++uMsCompIdx )
257 
258  if (0 == fulCurrentTsIdx % 10000)
259  LOG(info) << "Processed TS " << fulCurrentTsIdx;
260 
261  return kTRUE;
262 }
263 
265  for (UInt_t uDpb = 0; uDpb < fuNrOfDpbs; ++uDpb)
266  fvGdpbMessages[uDpb]->clear();
267 }
268 
270 
CbmMcbm2018RawConverterGdpb::Init
virtual Bool_t Init()
Definition: CbmMcbm2018RawConverterGdpb.cxx:50
gdpbv100::Message
Definition: gDpbMessv100.h:133
CbmMcbm2018RawConverterGdpb::fuNbOverMsPerTs
size_t fuNbOverMsPerTs
Definition: CbmMcbm2018RawConverterGdpb.h:73
CbmMcbm2018RawConverterGdpb::fuCurrDpbId
UInt_t fuCurrDpbId
Current equipment ID, tells from which DPB the current MS is originating.
Definition: CbmMcbm2018RawConverterGdpb.h:98
CbmMcbm2018RawConverterGdpb::fuCurrentEquipmentId
UInt_t fuCurrentEquipmentId
Definition: CbmMcbm2018RawConverterGdpb.h:96
CbmMcbm2018RawConverterGdpb::fulCurrentMsIdx
ULong64_t fulCurrentMsIdx
Definition: CbmMcbm2018RawConverterGdpb.h:86
CbmMcbm2018RawConverterGdpb::fuNbMsLoop
size_t fuNbMsLoop
Definition: CbmMcbm2018RawConverterGdpb.h:74
CbmMcbm2018RawConverterGdpb::fvMsComponentsList
std::vector< size_t > fvMsComponentsList
Parameters related to FLES containers.
Definition: CbmMcbm2018RawConverterGdpb.h:71
CbmMcbm2018RawConverterGdpb::fvbMaskedComponents
std::vector< Bool_t > fvbMaskedComponents
Control flags.
Definition: CbmMcbm2018RawConverterGdpb.h:68
CbmMcbm2018TofPar::GetGdpbId
Int_t GetGdpbId(Int_t i)
Definition: CbmMcbm2018TofPar.h:67
CbmMcbm2018TofPar.h
CbmMcbm2018RawConverterGdpb::fUnpackPar
CbmMcbm2018TofPar * fUnpackPar
Definition: CbmMcbm2018RawConverterGdpb.h:57
CbmMcbm2018RawConverterGdpb::fdMsSizeInNs
Double_t fdMsSizeInNs
/‍** Ignore Overlap Ms: all fuNbOverMsPerTs MS at the end of timeslice **‍/
Definition: CbmMcbm2018RawConverterGdpb.h:77
CbmMcbm2018RawConverterGdpb::fdTsStopTimeCore
Double_t fdTsStopTimeCore
Time in ns of current TS from the index of the first MS first component.
Definition: CbmMcbm2018RawConverterGdpb.h:90
CbmMcbm2018RawConverterGdpb::ReInitContainers
Bool_t ReInitContainers()
Definition: CbmMcbm2018RawConverterGdpb.cxx:123
CbmMcbm2018RawConverterGdpb::fParCList
TList * fParCList
Settings from parameter file.
Definition: CbmMcbm2018RawConverterGdpb.h:56
CbmMcbm2018RawConverterGdpb::fdTsFullSizeInNs
Double_t fdTsFullSizeInNs
Total size of the core MS in a TS, [nanoseconds].
Definition: CbmMcbm2018RawConverterGdpb.h:81
CbmMcbm2018RawConverterGdpb::InitContainers
Bool_t InitContainers()
Definition: CbmMcbm2018RawConverterGdpb.cxx:83
CbmMcbm2018RawConverterGdpb::Finish
virtual void Finish()
Definition: CbmMcbm2018RawConverterGdpb.cxx:269
CbmMcbm2018TofPar::GetNrOfGdpbs
Int_t GetNrOfGdpbs()
FIXME: replace with method returning the correspondign constants! see Star2019 parameter.
Definition: CbmMcbm2018TofPar.h:66
CbmStsDigi.h
CbmMcbm2018RawConverterGdpb::fuNrOfDpbs
UInt_t fuNrOfDpbs
Definition: CbmMcbm2018RawConverterGdpb.h:59
CbmMcbm2018RawConverterGdpb::fvGdpbMessages
std::vector< std::vector< gdpbv100::Message > * > fvGdpbMessages
Index of the DPB from which the MS currently unpacked is coming.
Definition: CbmMcbm2018RawConverterGdpb.h:104
CbmMcbm2018RawConverterGdpb::AddMsComponentToList
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
Temp until we change from CbmMcbmUnpack to something else.
Definition: CbmMcbm2018RawConverterGdpb.cxx:129
CbmMcbm2018RawConverterGdpb::fuMsIndex
UInt_t fuMsIndex
Start Time in ns of current MS from its index field in header.
Definition: CbmMcbm2018RawConverterGdpb.h:93
CbmMcbm2018RawConverterGdpb::Reset
virtual void Reset()
Definition: CbmMcbm2018RawConverterGdpb.cxx:264
CbmMcbm2018RawConverterGdpb::fdTsStartTime
Double_t fdTsStartTime
Definition: CbmMcbm2018RawConverterGdpb.h:88
CbmMcbm2018RawConverterGdpb::fuCurrDpbIdx
UInt_t fuCurrDpbIdx
Temp holder until Current equipment ID is properly filled in MS.
Definition: CbmMcbm2018RawConverterGdpb.h:100
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmMcbm2018RawConverterGdpb::~CbmMcbm2018RawConverterGdpb
virtual ~CbmMcbm2018RawConverterGdpb()
Definition: CbmMcbm2018RawConverterGdpb.cxx:48
CbmMcbm2018RawConverterGdpb::fulCurrentTsIdx
ULong64_t fulCurrentTsIdx
Total size of the core MS in a TS, [nanoseconds].
Definition: CbmMcbm2018RawConverterGdpb.h:85
CbmMcbm2018RawConverterGdpb
Definition: CbmMcbm2018RawConverterGdpb.h:24
CbmMcbm2018RawConverterGdpb::fDpbIdIndexMap
std::map< UInt_t, UInt_t > fDpbIdIndexMap
Total number of gDPBs to convert.
Definition: CbmMcbm2018RawConverterGdpb.h:61
CbmMcbm2018RawConverterGdpb::fuNbCoreMsPerTs
size_t fuNbCoreMsPerTs
Definition: CbmMcbm2018RawConverterGdpb.h:72
FormatMsHeaderPrintout
std::string FormatMsHeaderPrintout(const fles::MicrosliceDescriptor &msDescriptor)
Definition: CbmFormatMsHeaderPrintout.cxx:5
CbmMcbm2018TofPar
Definition: CbmMcbm2018TofPar.h:18
CbmMcbm2018RawConverterGdpb::DoUnpack
virtual Bool_t DoUnpack(const fles::Timeslice &ts, size_t component)
Definition: CbmMcbm2018RawConverterGdpb.cxx:143
CbmMcbm2018RawConverterGdpb::kuBytesPerMessage
static const UInt_t kuBytesPerMessage
Definition: CbmMcbm2018RawConverterGdpb.h:65
CbmMcbm2018RawConverterGdpb.h
CbmMcbm2018RawConverterGdpb::fdTsCoreSizeInNs
Double_t fdTsCoreSizeInNs
Size of a single MS, [nanoseconds].
Definition: CbmMcbm2018RawConverterGdpb.h:79
CbmMcbm2018RawConverterGdpb::CbmMcbm2018RawConverterGdpb
CbmMcbm2018RawConverterGdpb(UInt_t uNbGdpb=1)
Definition: CbmMcbm2018RawConverterGdpb.cxx:23
CbmMcbmUnpack
Definition: CbmMcbmUnpack.h:15
CbmMcbm2018RawConverterGdpb::SetParContainers
void SetParContainers()
Definition: CbmMcbm2018RawConverterGdpb.cxx:57
CbmMcbm2018RawConverterGdpb::fbIgnoreOverlapMs
Bool_t fbIgnoreOverlapMs
Definition: CbmMcbm2018RawConverterGdpb.h:76
CbmFormatMsHeaderPrintout.h