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