ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockAccumulatedV3.cxx
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// 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"
14//#include <cstdio>
15#include <iostream>
16
17//#define LARBSDBGOUTPUT
18#ifdef LARBSDBGOUTPUT
19#define LARBSDBG(text) logstr<<MSG::DEBUG<<text<<endmsg
20#else
21#define LARBSDBG(text)
22#endif
23
24
27{
28 m_iHeadBlockSize=endtag/2; // The implicit cast rounds down to the right size
31}
32
42
44{
45 return (getHeader16(NSamples)>>8);
46}
47
48int LArRodBlockAccumulatedV3::getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain)
49{
50#ifdef LARBSDBGOUTPUT
51 MsgStream logstr(Athena::getMessageSvc(), BlockType());
52#endif
53 if (m_RawDataCounter>=m_channelsPerFEB) { //Already beyond maximal number of channels
54 LARBSDBG("Maximum number of channels reached");
55 return 0;
56 }
57 const uint16_t block = getHeader16(RawDataBlkOff);
58 if (!block) { //Block does not exist
59 LARBSDBG("No Raw Data Block in this FEB");
60 return 0;
61 }
62 //The m_RawDataChannel keeps track of the last read channel
63
64 // Get next channel
65 channelNumber=m_RawDataCounter;
66 uint32_t febgain=0;
67 const unsigned int nsamples = getHeader16(NSamples) & 0xff;
68 const unsigned int ngains = getHeader16(NGains);
69 if(ngains==0 || nsamples==0) return 0;
70 // Loop over gains to look for m_fixedGain
71 unsigned int this_gain=0;
72 int offset;
73 LARBSDBG(" ===> fixedGain= " << m_fixedGain << " CaloGain = " << CaloGain::LARNGAIN);
74 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
75 offset=block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3);
76 for(this_gain=0;this_gain<ngains;this_gain++) {
77 int index = offset + 64*this_gain;
78 uint32_t x = m_FebBlock[index];
79 if(channelNumber>=64)
80 x = (x & 0x3000) >> 12;
81 else
82 x = (x & 0x30000000) >> 28;
83 unsigned data_gain = RawToOfflineGain(x);
84 if(data_gain==m_fixedGain) break;
85 }
86 }
87 if (this_gain<ngains) { //Gain found in this fragment
88 int s_size = 8 + 64 * ngains; // Size of one sample block 16 RADD of 16 bit + 128 channels (16 bit data)
89 offset = block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3) + 64*this_gain;
90 int index = offset;
91 uint32_t x = m_FebBlock[index];
92 if(channelNumber>=64) { //low channels on lower bits
93 // First decode gain
94 febgain = (x & 0x3000) >> 12; // gain on bits 12 and 13
95 // Than samples
96 for(unsigned int s=0;s<nsamples;s++) {
97 index = offset + s*s_size;
99 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
100 }
101 } else { //high channels on higher bits
102 // First decode gain
103 febgain = (x & 0x30000000) >> 28; // gain on bits 12 and 13
104 // Than samples
105 for(unsigned int s=0;s<nsamples;s++) {
106 index = offset + s*s_size;
107 x = (m_FebBlock[index]) >> 16;
108 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
109 }
110 }
111 gain=RawToOfflineGain(febgain);
112 }
114 unsigned rearrangeFirstSample=0;
116 rearrangeFirstSample=m_rearrangeFirstSample; //Overwrite by jobOptions
117 else
118 rearrangeFirstSample=getFirstSampleIndex();
119 if (rearrangeFirstSample && rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
120 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
121 short movedSample=samples[0];
122 for (unsigned i=1;i<=rearrangeFirstSample;i++)
123 samples[i-1]=samples[i];
124 samples[rearrangeFirstSample]=movedSample;
125 }
126 LARBSDBG("GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
127 return 1;
128}
129
130int LArRodBlockAccumulatedV3::getNextAccumulatedDigit(int& channelNumber, std::vector<uint64_t>& samplesSum,
131 std::vector < uint64_t >& corr2Sum, uint32_t& gain )
132{
133#ifdef LARBSDBGOUTPUT
134 MsgStream logstr(Athena::getMessageSvc(), BlockType());
135#endif
136 //Debug output
137 LARBSDBG("m_Result1Counter" << m_Result1Counter << " m_Result1Index="<< m_Result1Index
138 << " m_channelsPerFEB=" << m_channelsPerFEB);
139 LARBSDBG("requested gain= " << m_fixedGain);
140 if (m_Result1Counter>=m_channelsPerFEB) { //Already beyond maximal number of channels
141 LARBSDBG("Maximum number of channels reached");
142 return 0;
143 }
144 uint16_t block = getHeader16(ResultsOff1);//Position of the AccumulatedCalibDigits FEB data block
145 uint16_t bsize = getHeader16(ResultsDim1);//Position of the AccumulatedCalibDigits FEB data block
146 uint32_t size = getNumberOfWords();
147 if (!block) { //Block does not exist
148 LARBSDBG("No Accumulated Digit Block in this FEB");
149 return 0;
150 }
151 //The m_Result1Channel keeps track of the last read channel
152
153 // Get next channel
154 channelNumber=m_Result1Counter;
155
156 // This is just for fun; these data are not stored here but in RodBlockDecoder.cxx
157 // IWS 08.08.2005 This part is useless in fact - just for debugging
158 const unsigned int nsamples = getHeader16(NSamples);
159 const unsigned int ngains = getHeader16(NGains);
160
161 const unsigned int FebConfig = (int) getFebConfig();
162 if(ngains==0 || nsamples==0) return 0;
163 // Loop over gains to look for m_fixedGain
164 int offset;
165 uint32_t x;
166
167 if (FebConfig==0 || FebConfig>3) {
168 //Converter can currently not deal with this situation
169 LARBSDBG("Suspicious FebConfig valud" << FebConfig << ", don't know what to do for Accumulated Calib Digit - return 0");
170 return 0;
171 }
172
173 const uint32_t febgain=FebConfig&0x3; // to be done better when this is better understood
174 gain=RawToOfflineGain(febgain);
175
177 gain!=m_fixedGain) {
178 LARBSDBG("Requested gain: " << m_fixedGain << " got " << gain << " data ingored.");
179 return 0;
180 }
181
182
183 // 2 is the size of the accumulated header
184 offset=block + 2 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
185 if(offset+2*nsamples>size-3) return 0;
186 if((channelNumber&0x7F)*nsamples*2>bsize) return 0;
187
188
189 samplesSum.resize(nsamples);
190 corr2Sum.resize(nsamples);
191
192 for (unsigned int i=0;i<nsamples;i++)
193 {
194 x=m_FebBlock[offset+i];
195 samplesSum[i]=x;
196 }
197 offset+=nsamples;
198 for (unsigned int i=0;i<nsamples;i++)
199 {
200 x=m_FebBlock[offset+i];
201 corr2Sum[i]=x;
202 }
203
204 gain=RawToOfflineGain(febgain);
205
207 return 1;
208}
209
210
215
217{
218 return getHeader16(NGains);
219}
220
222{
223
225 uint32_t x=m_FebBlock[index+NTrigger/2];
226 return (uint16_t) x;
227}
228
230{
232 uint32_t x = m_FebBlock[index+StepIndex/2]&0xffff;
233 return (uint16_t) x;
234}
235
240
245
250
252{
254 uint32_t x = m_FebBlock[index+StepIndex/2]>>16;
255 return (uint16_t) x;
256}
257
258uint32_t LArRodBlockAccumulatedV3::getRadd(uint32_t adc, uint32_t sample) const
259{
260 int ngain=getHeader16(NGains);
262 if(index<=0) return 0;
263 index+=(8+64*ngain)*sample+adc/2;
264 uint32_t x=m_FebBlock[index];
265 if(adc&0x1) return x>>16;
266 return x&0xffff;
267}
268
269uint16_t LArRodBlockAccumulatedV3::getCtrl1(uint32_t adc) const
270{
271 int index=getHeader16(RawDataBlkOff)-16+adc/2;
272 uint32_t x=m_FebBlock[index];
273 if(adc&0x1) x=x>>16;
274 else x=x&0xffff;
275 uint16_t ctrl=x;
276 return ctrl;
277}
278
279uint16_t LArRodBlockAccumulatedV3::getCtrl2(uint32_t adc) const
280{
281 int index=getHeader16(RawDataBlkOff)-8+adc/2;
282 uint32_t x=m_FebBlock[index];
283 if(adc&0x1) x=x>>16;
284 else x=x&0xffff;
285 uint16_t ctrl=x;
286 return ctrl;
287}
288
289uint16_t LArRodBlockAccumulatedV3::getCtrl3(uint32_t adc) const
290{
291 int nsamples=getHeader16(NSamples);
292 int ngains=getHeader16(NGains);
293 int offset=nsamples*(8+64*ngains)+adc/2;
294 int index=getHeader16(RawDataBlkOff)+offset;
295 uint32_t x=m_FebBlock[index];
296 if(adc&0x1) x=x>>16;
297 else x=x&0xffff;
298 uint16_t ctrl=x;
299 return ctrl;
300}
301
303{
304 // Get Dsp status word
305 if(getNumberOfWords()<EventStatus/2) return 0;
306 uint32_t x=getHeader32(EventStatus);
307 return x;
308}
309
310
311#ifdef LARBSDBGOUTPUT
312#undef LARBSDBGOUTPUT
313#endif
314#undef LARBSDBG
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
#define x
virtual uint8_t getTDCPhase() const
virtual uint16_t getCtrl2(uint32_t adc) const
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
virtual int getNextAccumulatedDigit(int &channelNumber, std::vector< uint64_t > &SamplesSum, std::vector< uint64_t > &corr2Sum, uint32_t &gain)
virtual uint32_t getNumberOfGains() const
virtual uint16_t getResults1Size() const
virtual uint16_t getRawDataSize() const
virtual uint32_t getStatus() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual uint16_t getCtrl3(uint32_t adc) const
LArRodBlockAccumulatedV3(IMessageSvc *msgSvc)
virtual uint16_t getCtrl1(uint32_t adc) const
virtual uint16_t getResults2Size() const
virtual uint32_t getNumberOfSamples() const
uint16_t getHeader16(const unsigned n) const
uint32_t getHeader32(const unsigned n) const
LArRodBlockStructure(IMessageSvc *msgSvc, const std::string &blockType)
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