ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockPhysicsV4.cxx
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// Implementation of a LArRODBlockStructure class
8// This version contains LArDigits in fixed gain.
9// See .h file for more details.
10
11#include "GaudiKernel/MsgStream.h"
13//#include <cstdio>
15#include <iostream>
16
17//#define LARBSDBGOUTPUT
18#ifdef LARBSDBGOUTPUT
19#define MYLEVEL (MSG::FATAL)
20#define LARBSDBG(text) logstr<<MYLEVEL<<text<<endmsg
21#else
22#define LARBSDBG(text)
23#endif
24
31
48
50{
55
57 {
58 int off = -8;
60 if (getHeader16(ResultsDim1)>=8)
61 m_GainPointer=reinterpret_cast<const uint32_t*>(m_FebBlock+getHeader16(ResultsOff1)+off);
62 if (getHeader16(ResultsDim1)>=12)
63 m_MaskPointer=(const uint32_t*)(m_FebBlock+getHeader16(ResultsOff1)+8+off);
64 if (getHeader16(ResultsDim1)>=13)
65 m_HotCellsPointer=reinterpret_cast<const uint16_t*> (m_FebBlock+getHeader16(ResultsOff1)+12+off);
67 m_EnergyPointer=reinterpret_cast<const uint16_t*> (m_FebBlock+getHeader16(ResultsOff1)+13+off);
68 }
70 if (getHeader16(ResultsOff2)>=4)
71 m_TowerPointer=reinterpret_cast<const uint8_t*>(m_FebBlock+getHeader16(ResultsOff2)+off);
72 if (getHeader16(ResultsOff2)>=7)
73 m_SumPointer=reinterpret_cast<const int32_t*>(m_FebBlock+getHeader16(ResultsOff2)+4+off);
75 m_TimeQualityPointer=reinterpret_cast<const uint16_t*>(m_FebBlock+getHeader16(ResultsOff2)+7+off);
76 }
78 m_RawDataPointer=reinterpret_cast<const uint16_t*>(m_FebBlock+getHeader16(RawDataBlkOff)+off);
79
80#ifdef LARBSDBGOUTPUT
81 MsgStream logstr(Athena::getMessageSvc(), BlockType());
82 logstr << MYLEVEL << "***********************************************************************"<< endmsg;
83 logstr << MYLEVEL << "Header values :"<< endmsg;
84 logstr << MYLEVEL << "************************************************************************"<< endmsg;
85 logstr << MYLEVEL << "Fragment @ = 0x" << MSG::hex << m_FebBlock << endmsg;
86 logstr << MYLEVEL << "NWTot = " << MSG::dec << getNumberOfWords() << endmsg;
87 logstr << MYLEVEL << "FebID = 0x" << MSG::hex << getHeader32(FEBID) << endmsg;
88 logstr << MYLEVEL << "FebSN = 0x" << MSG::hex << getHeader32(FEB_SN) << endmsg;
89 logstr << MYLEVEL << "ResultsOff1 = 0x" << MSG::hex << getHeader16(ResultsOff1) << endmsg;
90 logstr << MYLEVEL << "ResultsDim1 = 0x" << MSG::hex << getHeader16(ResultsDim1) << endmsg;
91 logstr << MYLEVEL << "ResultsOff2 = 0x" << MSG::hex << getHeader16(ResultsOff2) << endmsg;
92 logstr << MYLEVEL << "ResultsDim2 = 0x" << MSG::hex << getHeader16(ResultsDim2) << endmsg;
93 logstr << MYLEVEL << "RawDataBlkOff = 0x" << MSG::hex << getHeader16(RawDataBlkOff) << endmsg;
94 logstr << MYLEVEL << "RawDataBlkDim = 0x" << MSG::hex << getHeader16(RawDataBlkDim) << endmsg;
95 logstr << MYLEVEL << "************************************************************************"<< MSG::dec << endmsg;
96
97 int size = getNumberOfWords();
98 for(int i=0;i<size;i++) {
99 logstr << MYLEVEL << MSG::hex << i << " : " << MSG::hex << m_FebBlock+i << " : " << MSG::hex << m_FebBlock[i] << endmsg;
100 }
101
102 if(m_MaskPointer) size = 4; else size = 0;
103 logstr << MYLEVEL << "Mask Block size = " << MSG::hex << size << endmsg;
104 logstr << MYLEVEL << "Mask Block address = " << MSG::hex << m_MaskPointer << endmsg;
105 for(int i=0;i<size;i++) {
106 logstr << MYLEVEL << i << " : " << MSG::hex << m_MaskPointer[i] << endmsg;
107 }
108 logstr << MYLEVEL << "End of Mask Block" << endmsg;
109#endif
110 }
111
112 return true;
113}
114
115int LArRodBlockPhysicsV4::getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain)
116{
117 //std::cout << " I am here !!!!!!!!!!!!!!!!!!!!!! " << std::endl;
118#ifdef LARBSDBGOUTPUT
119 MsgStream logstr(Athena::getMessageSvc(), BlockType());
120 //Debug output
121 logstr << MYLEVEL << "Let s go in getNextRawData..." << endmsg;
122 logstr << MYLEVEL << "GetNextRawData for FEB 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec << endmsg;
123 logstr << MYLEVEL << "m_RawDataPointer=" << m_RawDataPointer << " m_RawDataIndex="<< m_RawDataIndex
124 << " m_channelsPerFEB=" << m_channelsPerFEB << endmsg;
125#endif
126
127 if (m_RawDataIndex>=m_channelsPerFEB) { //Already beyond maximal number of channels
128#ifdef LARBSDBGOUTPUT
129 logstr << MYLEVEL << "Maximum number of channels reached" << endmsg;
130#endif
131 return 0;
132 }
133 //const uint16_t block = getHeader16(m_RawDataOff);//Position of the raw FEB data block
134 if (!m_RawDataPointer) { //Block does not exist
135#ifdef LARBSDBGOUTPUT
136 logstr << MYLEVEL << "No Raw Data Block in this FEB" << endmsg;
137#endif
138 return 0;
139 }
140
141 // Get next channel
142 unsigned rodChannelNumber=m_RawDataIndex; // Index of Channel in ROD-Block
143 channelNumber=((rodChannelNumber&0xe)<<2) + ((rodChannelNumber&0x1)<<6) + (rodChannelNumber>>4); //channel number of the FEB
144 //channelNumber=(rodChannelNumber>>4) + ((rodChannelNumber&0xf)<<3); //channel number of the FEB
145 uint32_t febgain;
146 const unsigned int nsamples = getHeader16(NSamples) & 0xff;
147 const unsigned int ngains = getHeader16(NGains);
148
149#ifdef LARBSDBGOUTPUT
150 logstr << MYLEVEL << "This FEB has " << nsamples << " samples" << endmsg;
151 logstr << MYLEVEL << "This FEB has " << ngains << " gains" << endmsg;
152#endif
153
154 if(ngains==0 || nsamples==0) return 0;
155 int s_size = nsamples+1;
156 int offset = 12;
157 int index;
158 index = s_size*m_RawDataIndex + offset;
159 uint16_t s[2];
160 s[0] = m_RawDataPointer[index++]>>2;
161 febgain = m_RawDataPointer[index++];
162 samples.push_back(s[0]);
163 for(unsigned int i=0;i<nsamples/2;i++) {
164 s[1] = m_RawDataPointer[index++]>>2;
165 s[0] = m_RawDataPointer[index++]>>2;
166 samples.push_back(s[0]);
167 samples.push_back(s[1]);
168 }
169 gain=RawToOfflineGain(febgain);
170
171#ifdef LARBSDBGOUTPUT
172 logstr << MYLEVEL << " ===> ROD Channel = " << m_RawDataIndex << endmsg;
173 logstr << MYLEVEL << " ===> FEB Channel = " << channelNumber << endmsg;
174 logstr << MYLEVEL << " ===> Gain = " << gain << endmsg;
175 for(int i=0;i<nsamples;i++)
176 logstr << MYLEVEL << " ===> sample " << i << " = " << samples[i] << endmsg;
177 int n = m_RawDataIndex;
178 int32_t e,t,q;
179 uint32_t g;
181#endif
182 //std::cout << "Gain= " << gain << " Febgain=" << febgain << std::endl;
184 unsigned rearrangeFirstSample=0;
186 rearrangeFirstSample=m_rearrangeFirstSample; //Overwrite by jobOptions
187 else
188 rearrangeFirstSample=getFirstSampleIndex();
189 //std::cout << "FebConfig: "<< getFebConfig() << " FirstSampleIndex " << getFirstSampleIndex() <<std::endl;
190 if (rearrangeFirstSample && rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
191 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
192 short movedSample=samples[0];
193 for (unsigned i=1;i<=rearrangeFirstSample;i++)
194 samples[i-1]=samples[i];
195 samples[rearrangeFirstSample]=movedSample;
196 }
197#ifdef LARBSDBGOUTPUT
198 logstr << MYLEVEL << "GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec << endmsg;
199#endif
200 return 1;
201}
202
204{
205 return getHeader16(NSamples);
206}
207
209{
210 return getHeader16(NGains);
211}
212
214{
215 return getHeader16(ResultsDim1);
216}
217
219{
220 return getHeader16(ResultsDim2);
221}
222
224{
226}
227
228uint32_t LArRodBlockPhysicsV4::getRadd(uint32_t adc, uint32_t sample) const
229{
230 if(!m_RawDataPointer) return 0;
231 int index;
232 if(sample==0) index=6;
233 else if(sample & 0x1) index=7+sample-1;
234 else index=7+sample+1;
235 uint32_t x=m_RawDataPointer[index];
236 if(adc>=8) return x>>8;
237 return x&0xff;
238}
239
240uint16_t LArRodBlockPhysicsV4::getCtrl1(uint32_t /*adc*/) const
241{
242 if(!m_RawDataPointer) return 0;
243 int index=5;
244 uint16_t x=m_RawDataPointer[index];
245 return x;
246}
247
248uint16_t LArRodBlockPhysicsV4::getCtrl2(uint32_t /*adc*/) const
249{
250 if(!m_RawDataPointer) return 0;
251 int index=4;
252 uint16_t x=m_RawDataPointer[index];
253 return x;
254}
255
256uint16_t LArRodBlockPhysicsV4::getCtrl3(uint32_t /*adc*/) const
257{
258 if(!m_RawDataPointer) return 0;
259 int index=7;
260 uint16_t x=m_RawDataPointer[index];
261 return x;
262}
263
265{
266 if(getNumberOfWords()<EventStatus/2) return 0;
267 uint32_t x=getHeader32(EventStatus);
268 return x;
269}
270
272{
273 //int size = getNumberOfWords();
274 int index = getNumberOfWords()-1;
275 if(index<m_iHeadBlockSize) return 0;
276 uint32_t sum = m_FebBlock[index];
277 //for(int i=size-10;i<size;i++) {
278 // std::cout << i << " : " << std::hex << m_FebBlock+i << " : " << m_FebBlock[i] << std::endl;
279 //}
280 return sum;
281}
282
284{
285 int end = getNumberOfWords()-3;
286 //int start = 0; //m_iHeadBlockSize;
287 uint32_t sum = 0;
288 for(int i=0;i<end;i++) {
289 sum += m_FebBlock[i];
290 //std::cout << i << " : " << std::hex << sum << " : " << m_FebBlock[i] << std::endl;
291 }
292 return sum & 0x7fffffff;
293}
294
295#ifdef LARBSDBGOUTPUT
296#undef LARBSDBGOUTPUT
297#endif
298#undef LARBSDBG
#define endmsg
#define MYLEVEL
#define x
const uint16_t * m_RawDataPointer
virtual uint16_t getCtrl2(uint32_t adc) const
const uint32_t * m_GainPointer
virtual uint16_t getCtrl1(uint32_t adc) const
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
uint16_t getFirstSampleIndex() const
const uint16_t * m_HotCellsPointer
virtual uint32_t getNumberOfSamples() const
virtual uint16_t getResults2Size() const
const uint16_t * m_EnergyPointer
virtual uint32_t onlineCheckSum() const
virtual uint16_t getResults1Size() const
virtual uint16_t getCtrl3(uint32_t adc) const
virtual uint32_t offlineCheckSum() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual int getNextEnergy(int &channelNumber, int32_t &energy, int32_t &time, int32_t &quality, uint32_t &gain)
virtual uint32_t getNumberOfGains() const
const uint32_t * m_MaskPointer
const uint16_t * m_TimeQualityPointer
virtual uint16_t getRawDataSize() const
virtual uint32_t getStatus() const
uint16_t getHeader16(const unsigned n) const
uint32_t getHeader32(const unsigned n) const
uint32_t RawToOfflineGain(const uint32_t gain) const
uint32_t getNumberOfWords() const
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
@ LARNGAIN
Definition CaloGain.h:19
Definition index.py:1