ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockStructure.h
Go to the documentation of this file.
1//Dear emacs, this is -*- c++ -*-
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7
8#ifndef LARBYTESTREAM_LARRODBLOCKSTRUCTURE_H
9#define LARBYTESTREAM_LARRODBLOCKSTRUCTURE_H
28
30#include "GaudiKernel/MsgStream.h"
31#include <stdint.h>
32#include <iostream>
33#include <vector>
34#include <map>
35#include <utility>
36
37
38class LArOnlineID;
39class LArRawChannel;
40class LArDigit;
42class LArCalibDigit;
44class IMessageSvc;
45
47{
48protected:
49 // ----------------- Header words indexes -----------------
50 enum {
51 NWTot, // Number of words in DSP block
53 FEBID, // FEB ID
55 FEBSN, // FEB Serial Number
57 endtag // This tag needs to be an odd number, see *) for constructor
58 };
59
60public :
61 // constructor
62 LArRodBlockStructure(IMessageSvc* msgSvc,
63 const std::string& blockType);
64 virtual ~LArRodBlockStructure();
65
66 // ----------------- Encoding methods -----------------
67 // Never to be used while decoding!
68 virtual void initializeFragment(std::vector<uint32_t>& fragment);
69 virtual void initializeFEB(const uint32_t id);
70 virtual void setNumberOfSamples(const uint8_t n);
71 virtual void setNumberOfGains(const uint8_t n);
72 virtual void setTDCPhase(const uint8_t n); //useful only TB SW validation
73 virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain);
74 virtual void setRawData(const int channel, const std::vector<short>& samples, const uint32_t gain);
75 virtual void setRawDataFixed(const int channel, const std::vector<short>& samples, const uint32_t gain);
76 virtual void setEtQ(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain);
77 virtual void setDAC(const uint16_t DACValue);
78 virtual void setDelay(const uint16_t DelayValue);
79 virtual void setPulsed (const unsigned channelNumber);
80 virtual void setNTrigger (const uint16_t NTrigger);
81 virtual void finalizeFEB();
82 virtual void setEx(double);
83 virtual void setEy(double);
84 virtual void setEz(double);
85 virtual void setSumE(double);
86 //Function to sort RawData Container before encoding. Unfortunatly, virtal template member functions are not allowed.
87 virtual void sortDataVector(std::vector<const LArRawChannel*>& );
88 virtual void sortDataVector( std::vector<const LArDigit*>& );
89 virtual void sortDataVector( std::vector<const LArCalibDigit*>& );
90 virtual void sortDataVector( std::vector<const LArAccumulatedCalibDigit*>& );
91 virtual void sortDataVector( std::vector<const LArAccumulatedDigit*>& );
92 // build full ROD fragment
93 virtual void concatinateFEBs( );
94 //Check features of this RodBlock
95 virtual bool canSetEnergy() { return false;}
96 virtual bool canSetRawData() {return false;}
97 virtual bool canSetRawDataFixed() {return false;}
98 virtual bool canSetCalibration() {return false;}
99 virtual bool canSetNTrigger() {return false;}
100 virtual bool canIncludeRawData() {return false;}
101
102 // ----------------- Decoding methods -----------------
103 // Never to be used while encoding!
104 // set full ROD fragment before trying to get anything!
105 inline bool setFragment(const uint32_t* p, uint32_t n);
106 inline bool nextFEB ( );
107 inline uint32_t getNumberOfWords() const;
108 inline uint32_t getFEBID() const;
109 inline uint32_t getFEBSN() const;
110
111 virtual inline int32_t getEx() const;
112 virtual inline int32_t getEy() const;
113 virtual inline int32_t getEz() const;
114 virtual inline int32_t getSumE() const;
115 virtual inline uint32_t getVROBFebId();
116 virtual inline int32_t getVROBEx() const;
117 virtual inline int32_t getVROBEy() const;
118 virtual inline int32_t getVROBEz() const;
119 virtual inline int32_t getVROBSumE() const;
120 virtual inline uint32_t hasCalibBlock() const {return 0;} ;
121 virtual inline uint32_t hasAccumBlock() const {return 0;} ;
122 virtual inline uint32_t hasPhysicsBlock() const {return 0;} ;
123 virtual inline uint32_t hasRawDataBlock() const {return 0;} ;
124 virtual inline uint32_t hasControlWords() const {return 0;} ;
125
126 virtual inline int getNextEnergy(int& channelNumber, int32_t& energy, int32_t& time,int32_t& quality,uint32_t& gain);
127 virtual int getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain);
128 virtual int getNextAccumulatedCalibDigit(int& channelNumber, std::vector < uint64_t >& SamplesSum, std::vector < uint64_t >& Samples2Sum, uint32_t& nStepTriggers, uint32_t& gain);
129 virtual int getNextAccumulatedDigit(int& channelNumber, std::vector<uint64_t>& SamplesSum, std::vector < uint64_t >& corr2Sum, uint32_t& gain);
130
131 // Get functions related to hasCalibBlock
132 virtual inline bool getPulsed(unsigned channelNumber) const;
133 virtual inline uint16_t getDAC() const;
134 virtual inline uint16_t getDelay() const;
135 virtual inline uint16_t getNTrigger() const;
136 virtual inline uint16_t getStepIndex() const;
137 virtual inline uint16_t getNStep() const;
138
139 virtual uint8_t getTDCPhase() const; //useful only TB SW validation
140 virtual int setGain(const int GainValue); //Define fixed gain in case of fixed gain mode.
141
142 virtual uint32_t getNumberOfSamples() const;
143 virtual uint32_t getNumberOfGains() const;
144
145 // Information access for Dsp and Feb headers decoding return 0 if information is absent
146 virtual uint16_t getResults1Size() const;
147 virtual uint16_t getResults2Size() const;
148 virtual uint16_t getRawDataSize() const;
149 virtual uint16_t getNbSweetCells1() const;
150 virtual uint16_t getNbSweetCells2() const;
151 virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const;
152 virtual uint16_t getCtrl1(uint32_t adc) const;
153 virtual uint16_t getCtrl2(uint32_t adc) const;
154 virtual uint16_t getCtrl3(uint32_t adc) const;
155 virtual uint32_t getStatus() const;
156 virtual uint32_t getDspCodeVersion() const;
157 virtual int32_t getDspEventCounter() const;
158
159 virtual uint32_t onlineCheckSum() const;
160 virtual uint32_t offlineCheckSum() const;
161 // To decode the virtual ROB fragment
162 virtual int setFragmentVirtualROB(const uint32_t* p, uint32_t n);
163
164 // print the full ROD fragment
165 virtual void dumpFragment();
166 inline void setFirstSample(const int rearrangeFirstSample)
167 {m_rearrangeFirstSample=rearrangeFirstSample;}
168
169 inline uint32_t RawToOfflineGain(const uint32_t gain) const;
170 inline uint32_t OfflineToRawGain(const uint32_t gain) const;
171 virtual inline int FebToRodChannel(int ch) const
172 { return (ch>>3) + ((ch&0x7)<<4); };
173 inline bool report_error ( void ) const { return m_error_next_feb;}
174
175 protected:
176 // ----------------- Encoding methods -----------------
177 // The following functions write to m_vFragment (vector)
178 inline void setHeader16(const unsigned n, const uint16_t w); // n should be chosen from the above enum
179 inline void setHeader32(const unsigned n, const uint32_t w); // n should be chosen from the above enum
180
181 // ----------------- Decoding methods -----------------
182 // The method to call to reset pointers and counters
183 virtual void resetPointers() { return; }
184 // The method to call to set pointers and counters
185 virtual bool setPointers() { return true;}
186 // The following functions read from m_vFragment (vector) (to be used during encoding)
187 inline uint16_t getVectorHeader16(const unsigned n) const; // n should be chosen from the above enum
188 inline uint32_t getVectorHeader32(const unsigned n) const; // n should be chosen from the above enum
189 // The following functions read from m_FebBlock (uint32_t*) (to be used during decoding)
190 inline uint16_t getHeader16(const unsigned n) const; // n should be chosen from the above enum
191 inline uint32_t getHeader32(const unsigned n) const; // n should be chosen from the above enum
192 // The following funcitons are Little Endian versions for backward compatibility
193 inline uint16_t LE_getHeader16(const unsigned n) const; // n should be chosen from the above enum
194 inline void LE_setHeader16(const unsigned n, const uint16_t w); // n should be chosen from the above enum
195 inline uint16_t LE_getVectorHeader16(const unsigned n) const; // n should be chosen from the above enum
196
197 // set/read the bitmap for a ROD channel
198 inline void setBit(uint32_t *const p, const unsigned chan);
199 inline int getBit(const uint32_t *const p, const unsigned chan) const;
200
201 // ----------------- Data members -----------------
202
203 int32_t m_Ex;
204 int32_t m_Ey;
205 int32_t m_Ez;
206 int32_t m_SumE;
207#ifndef NDEBUG
208 // In Debug mode, many messages are printed for the setEx/y/z method
209 // Let's avoid them
210 uint32_t m_numberOfEx;
211 uint32_t m_numberOfEy;
212 uint32_t m_numberOfEz;
214#endif
215
216 //Offsets for the fixed size Blocks..
217 unsigned short m_iHeadBlockSize;
218 //Number of channels per FEB
220 //Full ROD fragment for decoding
221 const uint32_t* m_FebBlock; //Pointer to the first element of the current FEB-Fragement (used only for decoding!)
222 const uint32_t* m_RodBlock; //Pointer to the very beginning of the ROD-Block
225 std::vector<uint32_t> *m_vFragment; //Pointer to the vector that holds the current FEB-block (used only for encoding!)
226 std::vector<uint32_t> *m_pRODblock; //Pointer to the ROD data vector
227 typedef std::map<uint32_t, std::vector<uint32_t> > FEBMAPTYPE;
228 FEBMAPTYPE m_mFebBlocks; //Map of feb-Blocks (for encoding only);
229 //static uint32_t FebToOfflineGainMap[3];
230 //static uint32_t OfflineToFebGainMap[3];
231 static const uint32_t m_RawToOfflineGainMap[4];
232 static const uint32_t m_OfflineToRawGainMap[3];
234 // Free gain mode needs raw data to be rearranged
236 // error in the next FEB
238 // Jump from one virtual ROB
241 const uint32_t* m_virtualROBPointer;
243
244 MsgStream m_logstr;
245};
246
247// Implementation of inline-functions:
248inline bool LArRodBlockStructure::setFragment(const uint32_t* p, uint32_t n)
249{
251 m_FebBlock = p;
253 m_RodBlockSize = n;
254 uint32_t BlockSize = 0;
255
256 if (n==0) {
257 m_logstr << MSG::ERROR << "Error while decoding LArByteStream: Got Rod block size 0" << endmsg;
258 return false;
259 }
260
261 BlockSize = getNumberOfWords();
262 if (BlockSize>n) {
263 m_logstr << MSG::ERROR << "Error while decoding LArByteStream: Found FEB block of size " << BlockSize << " in a ROD block of size " << n << endmsg;
264 return false;
265 }
266 m_FebBlockSize = BlockSize;
267
268 m_error_next_feb = false;
269
270 return setPointers();
271}
272
273/* Decode the virtual ROB fragment. If data is inconsistent with
274 data size, return 0 */
276 uint32_t n)
277{
282 if ( n<2 ) { m_logstr << MSG::ERROR << "Error" << endmsg; return 0;}
283 m_virtualROBJump = ((*p)>>16)>>1; // Divide by two (two FEBs-1ROB)
284 m_ROB_to_decode = ( (*p) & 0xFFFF )<<1; // Multiply by two
285 if ( (n - m_virtualROBJump*m_ROB_to_decode-1) ){
286 m_logstr << MSG::ERROR << "Error AGAIN" << endmsg;
287 return 0;
288 }
289 m_virtualROBPointer = (uint32_t*)(p+1);
290 return m_ROB_to_decode;
291}
292
293inline uint32_t LArRodBlockStructure::getFEBID() const
294{
295 return getHeader32(FEBID);
296}
297
298inline uint32_t LArRodBlockStructure::getFEBSN() const
299{
300 return getHeader32(FEBSN);
301}
302
303inline int32_t LArRodBlockStructure::getEx() const {
304 return 0;
305}
306
307inline int32_t LArRodBlockStructure::getEy() const {
308 return 0;
309}
310
311inline int32_t LArRodBlockStructure::getEz() const {
312 return 0;
313}
314
315inline int32_t LArRodBlockStructure::getSumE() const {
316 return 0;
317}
318
320 return 0;
321}
322
323inline int32_t LArRodBlockStructure::getVROBEx() const{
324 return 0;
325}
326
327inline int32_t LArRodBlockStructure::getVROBEy() const{
328 return 0;
329}
330
331inline int32_t LArRodBlockStructure::getVROBEz() const{
332 return 0;
333}
334
336 return 0;
337}
338
339inline uint32_t LArRodBlockStructure::RawToOfflineGain(const uint32_t gain) const
340{return m_RawToOfflineGainMap[gain];} //For efficency, don't check range
341
342inline uint32_t LArRodBlockStructure::OfflineToRawGain(const uint32_t gain) const
343{return m_OfflineToRawGainMap[gain];} //For efficency, don't check range
344
345inline uint16_t LArRodBlockStructure::getHeader16(const unsigned n) const // n should be chosen from the above enum
346{
347 if (n&0x1) //n is an odd number
348 return m_FebBlock[n>>1] & 0xffff; //1,3,5... are fetched from lower bits
349 else //n is a even number
350 return m_FebBlock[n>>1] >> 16; //0,2,4... are fetched from higher bits
351}
352
353inline uint32_t LArRodBlockStructure::getHeader32(const unsigned n) const // n should be chosen from the above enum
354{return m_FebBlock[n>>1];}
355
356inline uint16_t LArRodBlockStructure::getVectorHeader16(const unsigned n) const // n should be chosen from the above enum
357{
358 if (n&0x1) //n is an odd number
359 return (std::as_const(*m_vFragment).at(n>>1) & 0xffff);
360 else //n is a even number
361 return (std::as_const(*m_vFragment).at(n>>1) >> 16);
362}
363
364inline uint32_t LArRodBlockStructure::getVectorHeader32(const unsigned n) const // n should be chosen from the above enum
365{
366 return (*m_vFragment)[n>>1];
367}
368
369inline void LArRodBlockStructure::setHeader16(const unsigned n, const uint16_t w)
370{
371#ifdef LARBYTESTREAMRODBLOCK_CHCKBOUNDARIES
372 if ((unsigned)n>=m_vFragment->size()*2) {
373 m_logstr << MSG::ERROR << "Error WRITE BEYOND ARRAY BOUNDARY!" << endmsg;
374 std::abort();
375 }
376#endif
377 if (n&0x1) // n is an odd number
378 m_vFragment->at(n>>1)=((m_vFragment->at(n>>1) & 0xffff0000) | w);
379 else
380 m_vFragment->at(n>>1)=((m_vFragment->at(n>>1) & 0xffff) | (w << 16));
381}
382
383inline void LArRodBlockStructure::setHeader32(const unsigned n, const uint32_t w)
384{
385#ifdef LARBYTESTREAMRODBLOCK_CHCKBOUNDARIES
386 if ((unsigned)n>=m_vFragment->size()*2) {
387 m_logstr << MSG::ERROR << "Error WRITE BEYOND ARRAY BOUNDARY!" << endmsg
388 std::abort();
389 }
390#endif
391 m_vFragment->at(n>>1) = w;
392}
393
394inline uint16_t LArRodBlockStructure::LE_getHeader16(const unsigned n) const // n should be chosen from the above enum
395{
396 return (reinterpret_cast<const uint16_t*>(m_FebBlock))[n];
397}
398
399inline uint16_t LArRodBlockStructure::LE_getVectorHeader16(const unsigned n) const // n should be chosen from the above enum
400{
401 const uint32_t* data32 = std::as_const(*m_vFragment).data();
402 const uint16_t* data16 = reinterpret_cast<const uint16_t*> (data32);
403 return data16[n];
404}
405
406inline void LArRodBlockStructure::LE_setHeader16(const unsigned n, const uint16_t w)
407{
408#ifdef LARBYTESTREAMRODBLOCK_CHCKBOUNDARIES
409 if ((unsigned)n>=m_vFragment->size()*2) {
410 m_logstr << MSG::ERROR << "LArRodBlockStructure::LE_setHeader16 Error: WRITE BEYOND ARRAY BOUNDARY!" << endmsg;
411 std::abort();
412 }
413#endif
414 reinterpret_cast<uint16_t*>(m_vFragment->data())[n] = w;
415}
416
418{
419 return getHeader32(NWTot);
420}
421
422inline int LArRodBlockStructure::getBit(const uint32_t *const p, const unsigned chan) const
423{// chan = (0,127)
424 // int a = chan/32;
425 // int r = chan%32;
426 int a = chan>>5;
427 int r = chan&0x1f;
428 // a = (0,3), r = ( 0, 31 )
429 return (*(p+a)>>r) & 0x1;
430}
431
432
433inline void LArRodBlockStructure::setBit(uint32_t *const p, const unsigned chan)
434{
435 // chan = (0,127)
436 // int a = chan/32;
437 // int r = chan%32;
438 int a = chan>>5;
439 int r = chan&0x1f;
440 // a = (0,3), r = ( 0, 31 )
441 *(p+a) |= (1<<r) ;
442 return;
443}
444
445inline int LArRodBlockStructure::getNextEnergy(int&, int32_t&, int32_t&, int32_t&,uint32_t&)
446{
447 m_logstr << MSG::ERROR << "Error: Function getNextEnergy not implemented in this instance of LArRodBlockStructure!" << endmsg;
448 return 0;
449}
450
451inline bool LArRodBlockStructure::getPulsed(unsigned) const
452{
453 return 0;
454}
455
456inline uint16_t LArRodBlockStructure::getDAC() const
457{
458 return 0;
459}
460
461inline uint16_t LArRodBlockStructure::getDelay() const
462{
463 return 0;
464}
465
467{
468 return 0;
469}
470
472{
473 return 0;
474}
475inline uint16_t LArRodBlockStructure::getNStep() const
476{
477 return 0;
478}
479
481{
483
484 const int32_t FebOffset = m_FebBlockSize+m_MiddleHeaderSize;
485 const int32_t LeftSize = m_RodBlockSize-FebOffset+m_RodBlock-m_FebBlock;
486 if ( LeftSize<=0 ) return false; //No next feb
487
488 m_FebBlock += FebOffset; //Jump to the next FEB fragment
489 const int32_t BlockSize = getNumberOfWords();
490 if (BlockSize>LeftSize) {
491 m_logstr << MSG::ERROR << "Error while decoding LArByteStream: Found FEB block of size " << BlockSize << " in a ROD block of size " << LeftSize << endmsg;
492 m_error_next_feb = true;
493 return false;
494 }
495
496 m_FebBlockSize=BlockSize;
497
498 setPointers();
499 return true;
500}
501
502#endif
#define endmsg
static Double_t a
Data class for calibration ADC samples preprocessed by the DSP.
Data class for ADC samples and autocorr preprocessed by the DSP.
Base class for LArDigits taken during calibration runs.
Liquid Argon digit base class.
Definition LArDigit.h:25
Liquid Argon ROD output object base class.
virtual void sortDataVector(std::vector< const LArRawChannel * > &)
virtual uint16_t getCtrl1(uint32_t adc) const
bool setFragment(const uint32_t *p, uint32_t n)
virtual uint32_t hasPhysicsBlock() const
virtual bool canSetRawDataFixed()
virtual uint16_t getNStep() const
virtual int32_t getEz() const
virtual int32_t getVROBEx() const
virtual uint32_t hasCalibBlock() const
virtual void setRawDataFixed(const int channel, const std::vector< short > &samples, const uint32_t gain)
virtual void setSumE(double)
virtual void setEy(double)
uint16_t getVectorHeader16(const unsigned n) const
virtual int32_t getVROBEy() const
virtual void setEtQ(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain)
virtual int32_t getVROBEz() const
virtual void setDAC(const uint16_t DACValue)
virtual uint16_t getDelay() const
const uint32_t * m_virtualROBPointerLocal
virtual int32_t getEy() const
virtual uint16_t getCtrl3(uint32_t adc) const
virtual uint16_t getResults1Size() const
virtual bool getPulsed(unsigned channelNumber) const
int getBit(const uint32_t *const p, const unsigned chan) const
virtual void setTDCPhase(const uint8_t n)
virtual uint16_t getDAC() const
virtual int getNextEnergy(int &channelNumber, int32_t &energy, int32_t &time, int32_t &quality, uint32_t &gain)
bool report_error(void) const
virtual uint16_t getRawDataSize() const
virtual uint32_t hasAccumBlock() const
uint16_t getHeader16(const unsigned n) const
virtual int getNextAccumulatedCalibDigit(int &channelNumber, std::vector< uint64_t > &SamplesSum, std::vector< uint64_t > &Samples2Sum, uint32_t &nStepTriggers, uint32_t &gain)
virtual uint32_t getNumberOfGains() const
void setHeader32(const unsigned n, const uint32_t w)
virtual void setEx(double)
virtual uint32_t hasRawDataBlock() const
virtual bool canSetCalibration()
virtual int32_t getVROBSumE() const
uint16_t LE_getVectorHeader16(const unsigned n) const
virtual uint32_t getVROBFebId()
virtual void initializeFragment(std::vector< uint32_t > &fragment)
const uint32_t * m_virtualROBPointer
virtual void setNTrigger(const uint16_t NTrigger)
virtual uint32_t getDspCodeVersion() const
void LE_setHeader16(const unsigned n, const uint16_t w)
virtual int FebToRodChannel(int ch) const
virtual uint16_t getCtrl2(uint32_t adc) const
std::map< uint32_t, std::vector< uint32_t > > FEBMAPTYPE
virtual uint8_t getTDCPhase() const
uint32_t getHeader32(const unsigned n) const
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
virtual void setPulsed(const unsigned channelNumber)
virtual uint16_t getStepIndex() const
virtual int32_t getSumE() const
virtual int32_t getEx() const
virtual uint16_t getNTrigger() const
void setBit(uint32_t *const p, const unsigned chan)
void setHeader16(const unsigned n, const uint16_t w)
uint32_t getVectorHeader32(const unsigned n) const
virtual void initializeFEB(const uint32_t id)
std::vector< uint32_t > * m_pRODblock
virtual int setGain(const int GainValue)
virtual void setDelay(const uint16_t DelayValue)
LArRodBlockStructure(IMessageSvc *msgSvc, const std::string &blockType)
virtual uint32_t offlineCheckSum() const
static const uint32_t m_OfflineToRawGainMap[3]
uint32_t OfflineToRawGain(const uint32_t gain) const
void setFirstSample(const int rearrangeFirstSample)
virtual void setNumberOfSamples(const uint8_t n)
std::vector< uint32_t > * m_vFragment
static const uint32_t m_RawToOfflineGainMap[4]
virtual uint16_t getNbSweetCells2() const
virtual void setRawData(const int channel, const std::vector< short > &samples, const uint32_t gain)
virtual uint32_t getNumberOfSamples() const
virtual void setNumberOfGains(const uint8_t n)
virtual uint32_t hasControlWords() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual void setEz(double)
virtual int setFragmentVirtualROB(const uint32_t *p, uint32_t n)
virtual uint32_t getStatus() const
uint16_t LE_getHeader16(const unsigned n) const
uint32_t RawToOfflineGain(const uint32_t gain) const
virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain)
uint32_t getNumberOfWords() const
virtual uint16_t getResults2Size() const
virtual uint16_t getNbSweetCells1() const
virtual int32_t getDspEventCounter() const
virtual uint32_t onlineCheckSum() const
virtual int getNextAccumulatedDigit(int &channelNumber, std::vector< uint64_t > &SamplesSum, std::vector< uint64_t > &corr2Sum, uint32_t &gain)
int r
Definition globals.cxx:22