ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockPhysicsV3.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#ifndef LARBYTESTREAM_LARRODBLOCKPYSICSV3_H
8#define LARBYTESTREAM_LARRODBLOCKPYSICSV3_H
9
14
32
33#include <stdint.h>
34#include <vector>
38
39
40#ifdef LARBSDBGOUTPUT
41#define LARBSDBG(text) m_logstr<<MSG::DEBUG<<text<<endmsg
42#else
43#define LARBSDBG(text)
44#endif
45
46#define MYLEVEL (MSG::VERBOSE)
47
49{
50public:
51 // constructor
52 LArRodBlockPhysicsV3(IMessageSvc* msgSvc);
53
54protected:
55 // ----------------- Header words indexes ----------------- Every word is a 16 bits word in the header
56 enum {
63 NGainNSamples, // number of samples sent by the FEB and used at the raw data level in the dsp to apply Optimal Filtering
64 SumBlkOffset, // summary block offset (fixed length)
65 CounterBlkOffset, // counter block offset (fixed length)
66 EBlkOffset, // Energy block offset (fixed length)
67 GainBlkOffset, // Gain block offset (fixed length)
68 FebInfoBlkOffset, // Technical FEB information usefull for offline correction
69 TimeQualityBlkOffset, // Time and quality variable length block
70 RawDataBlkOffset, // Raw data block offset
71 Status2, // This element and the ones below this are not used by the converter
75 // endtag1, // remove if the number of words is even
77 };
78
79 public:
80 std::string BlockType() { return std::string("RodBlockPhysicsV3");}
81 // ----------------- Encoding methods -----------------
82 // Never to be used while decoding!
83 virtual void initializeFragment(std::vector<uint32_t>& fragment);
84 virtual void initializeFEB(const uint32_t id);
85 virtual void setNumberOfSamples(const uint8_t n);
86 virtual void setNumberOfGains(const uint8_t n);
87 virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain);
88 virtual void setRawData(const int channel, const std::vector<short>& samples, const uint32_t gain);
89 virtual void setEx(double Ex);
90 virtual void setEy(double Ey);
91 virtual void setEz(double Ez);
92 virtual void finalizeFEB();
93 // build full ROD fragment
94 virtual void concatinateFEBs();
95 //Function to sort RawData Container before encoding:
96 using LArRodBlockStructure::sortDataVector; // avoid warnings.
97 virtual void sortDataVector(std::vector<const LArRawChannel*>& );
98 virtual void sortDataVector( std::vector<const LArDigit*>& );
99 // declare capabilities of this Rod Block Structure
100 virtual bool canSetEnergy() { return true;}
101 virtual bool canSetRawData() {return true;}
102 //Ordering relation for channels & digits
103 template<class RAWDATA>
104 bool operator () (const RAWDATA* ch1, const RAWDATA* ch2) const;
105
106 virtual void setEThreshold(uint16_t thres);
107 virtual void setOffTimeCut(uint16_t TimeCut);
108
109 // ----------------- Decoding methods -----------------
110 // Never to be used while encoding!
111 // set full ROD fragment before trying to get anything!
112 // in case there is more than 1 FEB in 1 fragment, jump to next FEB
113 virtual inline int setGain(const int /*GainValue*/) { return 1; };
114 virtual bool setPointers();
115 virtual inline int getNextEnergy(int& channelNumber, int32_t& energy, int32_t& time,int32_t& quality,uint32_t& gain);
116 virtual int getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain);
117 virtual uint32_t getNumberOfSamples() const;
118 virtual uint32_t getNumberOfGains() const;
119 virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const;
120 virtual uint16_t getCtrl1(uint32_t adc) const;
121 virtual uint16_t getCtrl2(uint32_t adc) const;
122 virtual uint16_t getCtrl3(uint32_t adc) const;
123 virtual uint32_t getStatus() const;
124
125 // Decode counter block
126 virtual inline uint16_t getNumberOfHotCells() const;
127 virtual inline uint16_t getNumberOfHotCellsInTime() const;
128 virtual inline uint16_t getHotCellThreshold() const;
129 virtual inline uint16_t getOfftimeThreshold() const;
130 virtual inline int32_t getEx() const;
131 virtual inline int32_t getEy() const;
132 virtual inline int32_t getEz() const;
133 virtual inline uint16_t getHottestCellIndex();
134 virtual inline uint32_t getHottestCellEnergy() const;
135
136 virtual inline uint32_t hasPhysicsBlock() const {return LE_getHeader16(EBlkOffset);} ;
137 virtual inline uint32_t hasRawDataBlock() const {return LE_getHeader16(RawDataBlkOffset);} ;
138 virtual inline uint32_t hasControlWordBlock() const {return LE_getHeader16(RawDataBlkOffset);} ;
139
140 private:
141 void clearBlocks();
142 virtual void resetPointers();
143 //Separated blocks for encoding
144 // SumBlkOffset, // summary block offset (fixed length)
145 // CounterBlkOffset, // counter block offset (fixed length)
146 // EBlkOffset, // Energy block offset (fixed length)
147 // GainBlkOffset, // Gain block offset (fixed length)
148 // TimeQualityBlkOffset, // Time and quality variable length block
149 // RawDataBlkOffset, // Raw data block offset (How do we know which cell is concerned ?)
150
151 std::vector<uint32_t> m_SumBlkBlock;
152 std::vector<uint32_t> m_CounterBlkBlock;
153 std::vector<uint32_t> m_EnergyBlock;
154 std::vector<uint32_t> m_GainBlock;
155 std::vector<uint32_t> m_FebInfoBlock;
156 std::vector<uint32_t> m_TimeQualityBlock;
157 std::vector<uint32_t> m_RawDataBlock;
158
159 // Counter for channels inside of a FEB
160
166 int m_GainIndex = 0;
168 int m_SumBlkIndex = 0; //For writing...
169
170 const uint32_t *m_SumBlkPtr;
171 const uint16_t *m_CounterPtr;
172 const uint16_t *m_EnergyPtr;
173 const int16_t *m_TimeQualityPtr;
174 const uint32_t *m_GainPtr;
175 const int16_t *m_FebInfoDataPtr;
176 const int16_t *m_RawDataPtr;
177 const uint32_t *m_RawDataFlagsPtr;
178
184
186
187 uint16_t m_numberHotCell = 0U;
192 uint32_t m_HottestCellEnergy; // is it a problem that this energy has to be positive ? I hope not !
193
195 static const uint32_t m_DummyBitMap[4];
196 //Private functions:
197 inline int FebToRodChannel(int ch) const;
198 void setNextEnergy(const uint16_t energy,const int16_t time, const int16_t quality, const uint32_t gain);
199};
200
202//{return ch/8 + 16 * (ch%8);}
203{return (ch>>3) + ((ch&0x7)<<4);
204}
205
206inline int LArRodBlockPhysicsV3::getNextEnergy(int& channelNumber,int32_t& energy,int32_t& time,int32_t& quality, uint32_t& gain)
207{
208 LARBSDBG("in LArRodBlockPhysicsV3::getNextEnergy.");
209 LARBSDBG("m_channelsPerFEB=" << m_channelsPerFEB);
210 if (m_EnergyIndex>=m_channelsPerFEB) //Already beyond maximal number of channels
211 return 0;
212 if (!m_EnergyPtr) //No data block present
213 return 0;
214 uint16_t tQ; // TimeQuality word
215
216 unsigned rodChannelNumber=m_EnergyIndex; // Index of Channel in ROD-Block
217 channelNumber=(rodChannelNumber>>4) + ((rodChannelNumber&0xf)<<3); //channel number of the FEB
218
219 // get information available for all cells
220 // Energy on a 16 bit word and decode ranges
221
222 uint16_t encodedEnergy; // 16 bits Encoded Energy word
223 int32_t aux;
224 uint16_t range; // 2 bits range
225 int32_t sign=1;
226
227 LARBSDBG("-------->>>> in LArRodBlockPhysicsV3::getNextEnergy : decode energy.....");
228 // decode energy
229 encodedEnergy = m_EnergyPtr[m_EnergyIndex];
231
232 if (encodedEnergy&0x8000) sign=-1;
233 range = ((encodedEnergy)>>13)&0x0003; // range is encoded in bits 14 and 13
234
235 aux = (int32_t) (encodedEnergy&0x1FFF);
236 if (range==1) aux=(aux<<3)+4; // shift left by 3 bits and add 4 MeV
237 else if (range==2) aux=(aux<<6)+32; // shift left by 6 bits and add 32 MeV
238 else if (range==3) aux=(aux<<9)+256; // shift left by 9 bits and add 256 MeV
239 energy = sign*aux;
240
241 // gain in 2 bits of a 32 bits word
242
243 gain=(uint32_t)((m_GainPtr[channelNumber/16] >> (channelNumber%16)*2) & 0x3);
244
245 // Decode Time and Quality if the information is present according to summary block
246
247 if (getBit(m_SumBlkPtr,rodChannelNumber)) // Data has Time and Quality information
248 {
250
251#ifdef LARBSDBGOUTPUT
252 m_logstr <<MSG::DEBUG<<"This cell has time and Quality information "<<endmsg;
253#endif
254
255 // Decode Time, Quality
256 // Q in bits 0-3
257 // t in bits 4-15
258
259 quality = (int32_t) (tQ & 0x003f);
260 tQ = tQ>>4;
261 time = (tQ<<4) + 8; // unit is 16 ps
263 }
264 else // Data has no Time and Quality information
265 {
266 time=0;
267 quality=-1;
268 }
269
270
271#ifdef LARBSDBGOUTPUT
272 m_logstr <<MSG::DEBUG<<"Range = "<<range<<endmsg;
273 m_logstr <<MSG::DEBUG<<"Sign = "<<sign<<endmsg;
274 m_logstr << MSG::DEBUG<<" Encoded Energy ="<< encodedEnergy << " E=" << energy
275 << " t=" << time
276 << " Q=" << quality
277 << " G=" << gain
278 << " channel Number=" << channelNumber
279 << endmsg;
280#endif
281
282 return 1;
283}
284
286{
287 return (uint16_t) (*m_CounterPtr);
288}
290{
291 return (uint16_t) *(m_CounterPtr+1);
292}
293
295{
296 return (uint16_t) (*(m_CounterPtr+2));
297}
299{
300 return (uint16_t) (*(m_CounterPtr+3));
301}
302
303inline int32_t LArRodBlockPhysicsV3::getEx() const // To be checked
304{
305 const uint32_t* copy32u = reinterpret_cast<const uint32_t*>(m_CounterPtr+4);
306 return *copy32u;
307}
308
309inline int32_t LArRodBlockPhysicsV3::getEy() const // To be checked
310{
311 const uint32_t* copy32u = reinterpret_cast<const uint32_t*>(m_CounterPtr+6);
312 return *copy32u;
313}
314
315inline int32_t LArRodBlockPhysicsV3::getEz() const
316{
317 const uint32_t* aux = reinterpret_cast<const uint32_t*>(m_CounterPtr+10);
318 return *aux;
319}
320
321inline uint16_t LArRodBlockPhysicsV3::getHottestCellIndex() // to be checked
322{
323 return ((uint16_t) (*(m_CounterPtr+8)>>9));
324}
325
326inline uint32_t LArRodBlockPhysicsV3::getHottestCellEnergy() const // to be checked
327{
328
329 uint32_t aux;
330 aux = * reinterpret_cast<const uint32_t *>(m_CounterPtr+8);
331 return (aux&0x01FFFFFF);
332}
333
334
335
336#ifdef LARBSDBGOUTPUT
337#undef LARBSDBGOUTPUT
338#endif
339#undef LARBSDBG
340
341#endif
#define endmsg
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
int sign(int a)
virtual uint16_t getCtrl3(uint32_t adc) const
virtual void setOffTimeCut(uint16_t TimeCut)
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
virtual uint16_t getOfftimeThreshold() const
virtual int setGain(const int)
virtual uint32_t hasControlWordBlock() const
virtual uint32_t getNumberOfSamples() const
std::vector< uint32_t > m_EnergyBlock
virtual void setEz(double Ez)
static const uint32_t m_DummyBitMap[4]
std::vector< uint32_t > m_RawDataBlock
virtual uint16_t getNumberOfHotCells() const
std::vector< uint32_t > m_CounterBlkBlock
std::vector< uint32_t > m_SumBlkBlock
virtual void setNextEnergy(const int channel, const int32_t energy, const int32_t time, const int32_t quality, const uint32_t gain)
virtual void setNumberOfSamples(const uint8_t n)
virtual int32_t getEz() const
LArRodBlockPhysicsV3(IMessageSvc *msgSvc)
std::vector< uint32_t > m_TimeQualityBlock
virtual uint32_t getHottestCellEnergy() const
virtual void initializeFragment(std::vector< uint32_t > &fragment)
virtual void setEy(double Ey)
virtual uint16_t getNumberOfHotCellsInTime() const
virtual uint32_t hasPhysicsBlock() const
bool operator()(const RAWDATA *ch1, const RAWDATA *ch2) const
virtual void initializeFEB(const uint32_t id)
std::vector< uint32_t > m_GainBlock
virtual uint32_t hasRawDataBlock() const
const int16_t * m_TimeQualityPtr
virtual void sortDataVector(std::vector< const LArRawChannel * > &)
const LArOnlineID * m_onlineHelper
virtual uint16_t getCtrl1(uint32_t adc) const
const uint16_t * m_CounterPtr
virtual uint32_t getNumberOfGains() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
const int16_t * m_FebInfoDataPtr
virtual uint16_t getHottestCellIndex()
int FebToRodChannel(int ch) const
virtual uint16_t getCtrl2(uint32_t adc) const
const uint32_t * m_RawDataFlagsPtr
std::vector< uint32_t > m_FebInfoBlock
virtual int32_t getEy() const
virtual void setEThreshold(uint16_t thres)
virtual uint32_t getStatus() const
virtual int32_t getEx() const
virtual uint16_t getHotCellThreshold() const
virtual int getNextEnergy(int &channelNumber, int32_t &energy, int32_t &time, int32_t &quality, uint32_t &gain)
virtual void setEx(double Ex)
virtual void setRawData(const int channel, const std::vector< short > &samples, const uint32_t gain)
virtual void setNumberOfGains(const uint8_t n)
virtual void sortDataVector(std::vector< const LArRawChannel * > &)
int getBit(const uint32_t *const p, const unsigned chan) const
LArRodBlockStructure(IMessageSvc *msgSvc, const std::string &blockType)
uint16_t LE_getHeader16(const unsigned n) const
singleton-like access to IMessageSvc via open function and helper