CbmRoot
Loading...
Searching...
No Matches
CbmRichUnpackAlgoBase.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Goethe-University Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pascal Raisig [committer] */
4
21#ifndef CbmRichUnpackAlgoBase_H
22#define CbmRichUnpackAlgoBase_H
23
24#include "CbmMcbm2018RichPar.h"
25#include "CbmRecoUnpackAlgo.tmpl"
26#include "CbmRichDigi.h"
28#include "Timeslice.hpp" // timeslice
29
30#include <Rtypes.h> // for types
31#include <RtypesCore.h>
32
33#include <cstddef>
34#include <cstdint>
35#include <iomanip>
36#include <iostream>
37#include <memory>
38#include <utility>
39
49
51{
53 Header,
54 Epoch,
55 Trailer,
56 Debug,
57 Error
58};
59
61 public:
62 uint32_t fCoarse = 0; // 11 bits
63 uint32_t fEdge = 0; // 1 bit
64 uint32_t fFine = 0; // 10 bits
65 uint32_t fChannel = 0; // 7 bits
66
67 std::string ToString()
68 {
69 std::stringstream stream;
70 stream << "channel:" << fChannel << " coarse:" << fCoarse << " fine:" << fFine
71 << " edge:" << ((fEdge == 1) ? "R" : "F");
72 return stream.str();
73 }
74
75 bool IsRisingEdge() { return (fEdge == 1); }
76};
77
79 public:
81 {
82 uint32_t tdcTimeDataMarker = (tdcWord >> 31) & 0x1; // 1 bit
83 uint32_t tdcMarker = (tdcWord >> 29) & 0x7; // 3 bits
84
85 if (tdcTimeDataMarker == 0x1) {
86 // TODO: I also include tdcMarker == 0x5, some tdc time data words have this marker. Is it correct?
87 if (tdcMarker == 0x4 || tdcMarker == 0x5) {
89 }
90 else {
92 }
93 }
94
95 if (tdcMarker == 0x0) return CbmRichUnpackAlgoTdcWordType::Trailer;
96 if (tdcMarker == 0x1) return CbmRichUnpackAlgoTdcWordType::Header;
97 if (tdcMarker == 0x2) return CbmRichUnpackAlgoTdcWordType::Debug;
98 if (tdcMarker == 0x3) return CbmRichUnpackAlgoTdcWordType::Epoch;
99
101 }
102
103 static void ProcessTimeData(uint32_t tdcWord, CbmRichUnpackAlgoTdcTimeData& outData)
104 {
105 outData.fCoarse = static_cast<uint32_t>(tdcWord & 0x7ff); // 11 bits
106 outData.fEdge = static_cast<uint32_t>((tdcWord >> 11) & 0x1); // 1 bit
107 outData.fFine = static_cast<uint32_t>((tdcWord >> 12) & 0x3ff); // 10 bits
108 outData.fChannel = static_cast<uint32_t>((tdcWord >> 22) & 0x7f); // 7 bits
109 }
110
111 static uint32_t ProcessEpoch(uint32_t tdcWord) { return static_cast<uint32_t>(tdcWord & 0xfffffff); }
112
113 static uint16_t ProcessHeader(uint32_t tdcWord)
114 {
115 // for the moment just extract error bits
116 return static_cast<uint16_t>(tdcWord & 0xff); //8 bits
117 }
118
119 static uint16_t ProcessTrailer(uint32_t tdcWord)
120 {
121 // for the moment just extract error bits
122 return static_cast<uint16_t>(tdcWord & 0xffff);
123 }
124
125 static void ProcessDebug(uint32_t tdcWord)
126 {
127 LOG(debug4) << "ProcessDebug is not implemented. tdcWord:0x" << std::hex << tdcWord << std::dec;
128 // for the moment do nothing
129 }
130};
131
133 private:
134 const uint8_t* fData = nullptr;
135 size_t fSize = 0;
136 size_t fOffset = 0; // offset in bytes
137 size_t fWordCounter = 0;
138 uint32_t fCurWord;
139
140 public:
141 void SetData(const uint8_t* data, size_t size)
142 {
143 fData = data;
144 fSize = size;
145 fOffset = 0;
146 fWordCounter = 0;
147 fCurWord = 0;
148 }
149
150 const uint8_t* GetData() { return fData; }
151
152 size_t GetSize() { return fSize; }
153
154 size_t GetOffset() { return fOffset; }
155
156 size_t GetWordCounter() { return fWordCounter; }
157
158 uint32_t GetCurWord() { return fCurWord; }
159
160 std::string GetWordAsHexString(uint32_t word)
161 {
162 std::stringstream stream;
163 stream << "0x" << std::setfill('0') << std::setw(sizeof(uint32_t) * 2) << std::hex << word;
164 return stream.str();
165 }
166
167 uint32_t NextWord()
168 {
169 //mRichSupport::SwapBytes(4, fData + fOffset);
170 //Int_t* dataPtr = (Int_t*) (fData + fOffset);
171 uint32_t i = ((uint32_t*) (fData + fOffset))[0];
172 //swap bytes
173 i = (i >> 24) | ((i << 8) & 0x00FF0000) | ((i >> 8) & 0x0000FF00) | (i << 24);
174 //i = ((i&0xFF)<<24) | (((i>>8)&0xFF)<<16) | (((i>>16)&0xFF)<<8) | (((i>>24)&0xFF)<<0);
175
176 fOffset += 4;
177 fWordCounter++;
178 fCurWord = i;
179 //return (Int_t)(dataPtr[0]);
180 return i;
181 }
182
184 {
185 uint32_t nextWord = ((uint32_t*) (fData + fOffset))[0];
186 if (nextWord == 0xffffffff) return true;
187 return false;
188 }
189
190 bool IsLastSubSubEvent(uint32_t subSubEventSize)
191 {
192 uint32_t i = ((uint32_t*) (fData + fOffset + 4 * subSubEventSize))[0];
193 i = (i >> 24) | ((i << 8) & 0x00ff0000) | ((i >> 8) & 0x0000ff00) | (i << 24);
194 if (i == 0x00015555) return true;
195 return false;
196 }
197};
198
199class CbmRichUnpackAlgoBase : public CbmRecoUnpackAlgo<CbmRichDigi> {
200 public:
202 CbmRichUnpackAlgoBase(std::string name);
203
205 virtual ~CbmRichUnpackAlgoBase();
206
209
212
222 virtual std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>*
223 GetParContainerRequest(std::string geoTag, std::uint32_t runId);
224
225 // Setters
227 void SetMonitor(std::shared_ptr<CbmRichUnpackMonitor> monitor) { fMonitor = monitor; }
228
230 void SetMaskedDiRICHes(std::vector<Int_t>* maskedDiRICHes) { fMaskedDiRICHes = maskedDiRICHes; }
231
233 void DoTotOffsetCorrection(Bool_t activate = true) { fbDoToTCorr = activate; }
234
235 protected:
236 double calculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine);
237
239 void finish()
240 {
242 // Finish the monitor if we have one
243 if (fMonitor) {
244 std::cout << "Finish Monitor" << std::endl;
245 fMonitor->Finish();
246 }
247 }
248
249 // Monitoring
251 std::shared_ptr<CbmRichUnpackMonitor> fMonitor = nullptr;
252
254 virtual void finishDerived() { return; }
255
257
258 Int_t getPixelUID(Int_t fpgaID, Int_t ch) const
259 {
260 // First 16 bits are used for the FPGA ID, then
261 // 8 bits unused and then 8 bits are used for the channel
262 return ((fpgaID << 16) | (ch & 0x00FF));
263 }
264
270 Bool_t init();
271
278 Bool_t initParSet(FairParGenericSet* parset);
279
286 Bool_t initParSet(CbmMcbm2018RichPar* parset);
287
288 bool isLog();
289
299 bool setDerivedTsParameters(size_t /*itimeslice*/) { return true; }
300
312 //bool unpack(const fles::Timeslice* ts, std::uint16_t icomp, UInt_t imslice);
313
314 bool checkMaskedDiRICH(Int_t subSubEventId);
315
318
319 std::vector<Int_t>* fMaskedDiRICHes = nullptr;
320
321 size_t fMsRefTime = 0;
322
323 double fToTMin = -20.;
324 double fToTMax = 100.;
325
326 Bool_t fbDoToTCorr = true; // kTRUE activates ToT correction from Parameterfile
327
328 private:
329 ClassDef(CbmRichUnpackAlgoBase, 2)
330};
331
332#endif // CbmRichUnpackAlgoBase
CbmRichUnpackAlgoErrorType
CbmRichUnpackAlgoTdcWordType
Monitoring historgrams class for Rich unpacker.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
CbmRichUnpackAlgoBase(std::string name)
Create the Cbm Trd Unpack AlgoBase object.
bool checkMaskedDiRICH(Int_t subSubEventId)
Unpack a given microslice. To be implemented in the derived unpacker algos.
CbmMcbm2018RichPar fUnpackPar
Parameters for the unpacking.
bool setDerivedTsParameters(size_t)
Set the Derived Ts Parameters.
void SetMonitor(std::shared_ptr< CbmRichUnpackMonitor > monitor)
Set a predefined monitor.
double calculateTime(uint32_t epoch, uint32_t coarse, uint32_t fine)
Int_t getPixelUID(Int_t fpgaID, Int_t ch) const
std::shared_ptr< CbmRichUnpackMonitor > fMonitor
Potential (online) monitor for the unpacking process.
void DoTotOffsetCorrection(Bool_t activate=true)
(De-) Activate Tot offset correction of digis
virtual std::vector< std::pair< std::string, std::shared_ptr< FairParGenericSet > > > * GetParContainerRequest(std::string geoTag, std::uint32_t runId)
Get the requested parameter containers. To be defined in the derived classes! Return the required par...
std::string getLogHeader(CbmRichUnpackAlgoMicrosliceReader &reader)
Bool_t initParSet(FairParGenericSet *parset)
Handles the distribution of the hidden derived classes to their explicit functions.
Bool_t init()
Intialisation at begin of run. Special inits of the derived algos.
std::vector< Int_t > * fMaskedDiRICHes
CbmRichUnpackAlgoBase(const CbmRichUnpackAlgoBase &)=delete
Copy constructor - not implemented.
void SetMaskedDiRICHes(std::vector< Int_t > *maskedDiRICHes)
Set Addresses of DiRICH boards to be masked.
void finish()
Finish function for this algorithm base clase.
virtual ~CbmRichUnpackAlgoBase()
Destroy the Cbm Trd Unpack Task object.
virtual void finishDerived()
Function that allows special calls during Finish in the derived algos.
CbmRichUnpackAlgoBase & operator=(const CbmRichUnpackAlgoBase &)=delete
Assignment operator - not implemented.
std::string GetWordAsHexString(uint32_t word)
bool IsLastSubSubEvent(uint32_t subSubEventSize)
void SetData(const uint8_t *data, size_t size)
static CbmRichUnpackAlgoTdcWordType GetTdcWordType(uint32_t tdcWord)
static uint16_t ProcessTrailer(uint32_t tdcWord)
static void ProcessDebug(uint32_t tdcWord)
static uint16_t ProcessHeader(uint32_t tdcWord)
static void ProcessTimeData(uint32_t tdcWord, CbmRichUnpackAlgoTdcTimeData &outData)
static uint32_t ProcessEpoch(uint32_t tdcWord)