CbmRoot
Loading...
Searching...
No Matches
CbmMcbm2018UnpackerAlgoRich.h
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Justus-Liebig-Universitaet Giessen, Giessen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Egor Ovcharenko [committer], Semen Lebedev */
4
12#ifndef CbmMcbm2018UnpackerAlgoRich_H
13#define CbmMcbm2018UnpackerAlgoRich_H
14
15#include "CbmStar2019Algo.h" // mother class
16
17// STD
18#include <bitset>
19#include <iomanip>
20#include <map>
21#include <vector>
22
23// ROOT
24#include <Logger.h>
25
26#include <TArrayD.h>
27#include <TH2D.h>
28
29// CbmRoot
30#include "CbmRichDigi.h"
31
34
35
45
47{
49 Header,
50 Epoch,
51 Trailer,
52 Debug,
53 Error
54};
55
57public:
58 uint32_t fCoarse = 0; // 11 bits
59 uint32_t fEdge = 0; // 1 bit
60 uint32_t fFine = 0; // 10 bits
61 uint32_t fChannel = 0; // 7 bits
62
63 std::string ToString()
64 {
65 std::stringstream stream;
66 stream << "channel:" << fChannel << " coarse:" << fCoarse << " fine:" << fFine
67 << " edge:" << ((fEdge == 1) ? "R" : "F");
68 return stream.str();
69 }
70
71 bool IsRisingEdge() { return (fEdge == 1); }
72};
73
75public:
77 {
78 uint32_t tdcTimeDataMarker = (tdcWord >> 31) & 0x1; // 1 bit
79 uint32_t tdcMarker = (tdcWord >> 29) & 0x7; // 3 bits
80
81 if (tdcTimeDataMarker == 0x1) {
82 // TODO: I also include tdcMarker == 0x5, some tdc time data words have this marker. Is it correct?
83 if (tdcMarker == 0x4 || tdcMarker == 0x5) { return CbmMcbm2018RichTdcWordType::TimeData; }
84 else {
86 }
87 }
88
89 if (tdcMarker == 0x0) return CbmMcbm2018RichTdcWordType::Trailer;
90 if (tdcMarker == 0x1) return CbmMcbm2018RichTdcWordType::Header;
91 if (tdcMarker == 0x2) return CbmMcbm2018RichTdcWordType::Debug;
92 if (tdcMarker == 0x3) return CbmMcbm2018RichTdcWordType::Epoch;
93
95 }
96
97 static void ProcessTimeData(uint32_t tdcWord, CbmMcbm2018RichTdcTimeData& outData)
98 {
99 outData.fCoarse = static_cast<uint32_t>(tdcWord & 0x7ff); // 11 bits
100 outData.fEdge = static_cast<uint32_t>((tdcWord >> 11) & 0x1); // 1 bit
101 outData.fFine = static_cast<uint32_t>((tdcWord >> 12) & 0x3ff); // 10 bits
102 outData.fChannel = static_cast<uint32_t>((tdcWord >> 22) & 0x7f); // 7 bits
103 }
104
105 static uint32_t ProcessEpoch(uint32_t tdcWord) { return static_cast<uint32_t>(tdcWord & 0xfffffff); }
106
107 static uint16_t ProcessHeader(uint32_t tdcWord)
108 {
109 // for the moment just extract error bits
110 return static_cast<uint16_t>(tdcWord & 0xff); //8 bits
111 }
112
113 static uint16_t ProcessTrailer(uint32_t tdcWord)
114 {
115 // for the moment just extract error bits
116 return static_cast<uint16_t>(tdcWord & 0xffff);
117 }
118
119 static void ProcessDebug(uint32_t tdcWord)
120 {
121 LOG(debug4) << "ProcessDebug is not implemented. tdcWord:0x" << std::hex << tdcWord << std::dec;
122 // for the moment do nothing
123 }
124};
125
127private:
128 const uint8_t* fData = nullptr;
129 size_t fSize = 0;
130 size_t fOffset = 0; // offset in bytes
131 size_t fWordCounter = 0;
132 uint32_t fCurWord;
133
134public:
135 void SetData(const uint8_t* data, size_t size)
136 {
137 fData = data;
138 fSize = size;
139 fOffset = 0;
140 fWordCounter = 0;
141 fCurWord = 0;
142 }
143
144 const uint8_t* GetData() { return fData; }
145
146 size_t GetSize() { return fSize; }
147
148 size_t GetOffset() { return fOffset; }
149
150 size_t GetWordCounter() { return fWordCounter; }
151
152 uint32_t GetCurWord() { return fCurWord; }
153
154 std::string GetWordAsHexString(uint32_t word)
155 {
156 std::stringstream stream;
157 stream << "0x" << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex << word;
158 return stream.str();
159 }
160
161 uint32_t NextWord()
162 {
163 //mRichSupport::SwapBytes(4, fData + fOffset);
164 //Int_t* dataPtr = (Int_t*) (fData + fOffset);
165 uint32_t i = ((uint32_t*) (fData + fOffset))[0];
166 //swap bytes
167 i = (i >> 24) | ((i << 8) & 0x00FF0000) | ((i >> 8) & 0x0000FF00) | (i << 24);
168 //i = ((i&0xFF)<<24) | (((i>>8)&0xFF)<<16) | (((i>>16)&0xFF)<<8) | (((i>>24)&0xFF)<<0);
169
170 fOffset += 4;
171 fWordCounter++;
172 fCurWord = i;
173 //return (Int_t)(dataPtr[0]);
174 return i;
175 }
176
178 {
179 uint32_t nextWord = ((uint32_t*) (fData + fOffset))[0];
180 if (nextWord == 0xffffffff) return true;
181 return false;
182 }
183
184 bool IsLastSubSubEvent(uint32_t subSubEventSize)
185 {
186 uint32_t i = ((uint32_t*) (fData + fOffset + 4 * subSubEventSize))[0];
187 i = (i >> 24) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | (i << 24);
188 if (i == 0x00015555) return true;
189 return false;
190 }
191};
192
193class CbmMcbm2018UnpackerAlgoRich : public CbmStar2019Algo<CbmRichDigi> {
194public:
196
198
199 virtual Bool_t Init();
200
201 virtual void Reset();
202
203 virtual void Finish();
204
205 virtual Bool_t InitContainers();
206
207 virtual Bool_t ReInitContainers();
208
209 virtual TList* GetParList();
210
211 Bool_t InitParameters();
212
216 void AddMsComponentToList(size_t component, UShort_t usDetectorId);
217
218 virtual Bool_t ProcessTs(const fles::Timeslice& ts);
219
220 virtual Bool_t ProcessTs(const fles::Timeslice& ts, size_t component);
221
222 virtual Bool_t ProcessMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx);
223
224 Bool_t DebugMs(const fles::Timeslice& ts, size_t uMsCompIdx, size_t uMsIdx);
225
226 void SetMonitorMode(Bool_t bFlagIn = kTRUE) { fbMonitorMode = bFlagIn; }
227
228 inline void SetTimeOffsetNs(Double_t dOffsetIn = 0.0) { fdTimeOffsetNs = dOffsetIn; }
229
230 inline void DoTotCorr(Bool_t bDoToTCorr = kTRUE) { fbDoToTCorr = bDoToTCorr; }
231
232 void SetRawDataMode(Bool_t bDebug = kFALSE) { fRawDataMode = bDebug; }
233
234 Int_t Debug(const uint8_t* ptr, const size_t size);
235
236private:
242 void InitStorage();
243
245
246 void ProcessMicroslice(size_t const size, uint8_t const* const ptr);
247
249
250 void ProcessMbs(CbmMcbm2018RichMicrosliceReader& reader, bool isPrev);
251
253
254 void ProcessCtsSubSubEvent(CbmMcbm2018RichMicrosliceReader& reader, uint32_t subSubEventSize, uint32_t subSubEventId);
255
256 void ProcessSubSubEvent(CbmMcbm2018RichMicrosliceReader& reader, int nofTimeWords, uint32_t subSubEventId);
257
258 double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine);
259
260 bool IsLog();
261
262 void ProcessTimeDataWord(CbmMcbm2018RichMicrosliceReader& reader, int iTdc, uint32_t epoch, uint32_t tdcWord,
263 uint32_t subSubEventId, std::vector<double>& raisingTime);
264
268 void WriteOutputDigi(Int_t fpgaID, Int_t channel, Double_t time, Double_t tot, uint64_t MSidx);
269
273 void FinalizeTs();
274
278 void ErrorMsg(uint16_t errbits, CbmMcbm2018RichErrorType type, uint16_t tdcId = 0);
279
280 Int_t GetPixelUID(Int_t fpgaID, Int_t ch) const
281 {
282 // First 16 bits are used for the FPGA ID, then
283 // 8 bits unused and then 8 bits are used for the channel
284 return ((fpgaID << 16) | (ch & 0x00FF));
285 }
286
287private:
288 double fToTMin = -20.;
289 double fToTMax = 100.;
290
292 Bool_t fbMonitorMode = false; // Switch ON the filling of a minimal set of histograms
293 Bool_t fbDebugMonitorMode = false; // Switch ON the filling of a additional set of histograms
294 Bool_t fRawDataMode = false;
295
296 uint64_t fTsCounter = 0; //Counter of processed timeslices
297 uint32_t fMsInd = 0; // Current microslice index
298
299 double fMbsPrevTimeCh0 = 0.;
300 double fMbsPrevTimeCh1 = 0.;
301
302 std::map<uint32_t, double> fLastCh0ReTime; //key:TDC ID, value:Full time of last rising edge from ch 0
303 std::map<uint32_t, double> fPrevLastCh0ReTime; // key:TDC ID, value:Full time of previous last rising edge from ch 0
304
305 Bool_t fbDoToTCorr = true; // kTRUE activates ToT correction from Parameterfile
306
307 Double_t fdTimeOffsetNs = 0.; // User settings: Data correction parameters
308
313 Int_t fRICHcompIdx = 6;
314
316
321 uint64_t fCurMSidx;
322
323public: // histograms
327 Bool_t CreateHistograms();
328
332 Bool_t ResetHistograms();
333
334 TH1D* GetTotH1(uint32_t fpgaID, uint32_t channel);
335 TH2D* GetTotH2(uint32_t fpgaID);
336
337 std::vector<TCanvas*> fcTot2d;
338
339 TH2D* fhTdcErrors = nullptr;
340
341 TH1* fhEventSize = nullptr;
342 TH2* fhSubEventSize = nullptr;
343 TH2* fhSubSubEventSize = nullptr;
344 TH2* fhChnlSize = nullptr;
345
346 std::map<uint16_t, uint16_t> fMapFEE;
347
348 std::map<uint32_t, std::map<Int_t, TH1D*>> fhTotMap;
349 std::map<uint32_t, TH2D*> fhTot2dMap;
350
351 uint64_t fdTsStartTime = 0;
352
354};
355
356#endif // CbmMcbm2018UnpackerAlgoRich_H
static constexpr size_t size()
Definition KfSimdPseudo.h:2
bool IsLastSubSubEvent(uint32_t subSubEventSize)
std::string GetWordAsHexString(uint32_t word)
void SetData(const uint8_t *data, size_t size)
static uint16_t ProcessHeader(uint32_t tdcWord)
static CbmMcbm2018RichTdcWordType GetTdcWordType(uint32_t tdcWord)
static uint32_t ProcessEpoch(uint32_t tdcWord)
static void ProcessDebug(uint32_t tdcWord)
static void ProcessTimeData(uint32_t tdcWord, CbmMcbm2018RichTdcTimeData &outData)
static uint16_t ProcessTrailer(uint32_t tdcWord)
ClassDef(CbmMcbm2018UnpackerAlgoRich, 1)
TH1D * GetTotH1(uint32_t fpgaID, uint32_t channel)
void SetMonitorMode(Bool_t bFlagIn=kTRUE)
std::map< uint16_t, uint16_t > fMapFEE
void DoTotCorr(Bool_t bDoToTCorr=kTRUE)
std::string GetLogHeader(CbmMcbm2018RichMicrosliceReader &reader)
void AddMsComponentToList(size_t component, UShort_t usDetectorId)
void ProcessMbs(CbmMcbm2018RichMicrosliceReader &reader, bool isPrev)
Bool_t DebugMs(const fles::Timeslice &ts, size_t uMsCompIdx, size_t uMsIdx)
std::map< uint32_t, double > fPrevLastCh0ReTime
std::map< uint32_t, std::map< Int_t, TH1D * > > fhTotMap
std::map< uint32_t, TH2D * > fhTot2dMap
void ProcessTrbPacket(CbmMcbm2018RichMicrosliceReader &reader)
void WriteOutputDigi(Int_t fpgaID, Int_t channel, Double_t time, Double_t tot, uint64_t MSidx)
void ProcessMicroslice(size_t const size, uint8_t const *const ptr)
double CalculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine)
void ErrorMsg(uint16_t errbits, CbmMcbm2018RichErrorType type, uint16_t tdcId=0)
virtual Bool_t ProcessMs(const fles::Timeslice &ts, size_t uMsCompIdx, size_t uMsIdx)
void ProcessHubBlock(CbmMcbm2018RichMicrosliceReader &reader)
void SetRawDataMode(Bool_t bDebug=kFALSE)
std::map< uint32_t, double > fLastCh0ReTime
void ProcessTimeDataWord(CbmMcbm2018RichMicrosliceReader &reader, int iTdc, uint32_t epoch, uint32_t tdcWord, uint32_t subSubEventId, std::vector< double > &raisingTime)
virtual Bool_t ProcessTs(const fles::Timeslice &ts)
void ProcessCtsSubSubEvent(CbmMcbm2018RichMicrosliceReader &reader, uint32_t subSubEventSize, uint32_t subSubEventId)
void SetTimeOffsetNs(Double_t dOffsetIn=0.0)
Int_t GetPixelUID(Int_t fpgaID, Int_t ch) const
void ProcessSubSubEvent(CbmMcbm2018RichMicrosliceReader &reader, int nofTimeWords, uint32_t subSubEventId)