ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockCalibrationV3.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 <iostream>
15
16#ifdef LARBSDBGOUTPUT
17#define LARBSDBG(text) logstr<<MSG::DEBUG<<text<<endmsg
18#else
19#define LARBSDBG(text)
20#endif
21
22
25{
26 m_iHeadBlockSize=endtag/2; // The implicit cast rounds down to the right size
29}
30
31// clear temporary block vectors
36
47
48
50{
51 return (getHeader16(NSamples)>>8);
52}
53
54
55
56
57int LArRodBlockCalibrationV3::getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain)
58{
59#ifdef LARBSDBGOUTPUT
60 MsgStream logstr(Athena::getMessageSvc(), BlockType());
61#endif
62 if (m_RawDataCounter>=m_channelsPerFEB) { //Already beyond maximal number of channels
63 LARBSDBG("Maximum number of channels reached");
64 return 0;
65 }
66 const uint16_t block = getHeader16(RawDataBlkOff);
67 if (!block) { //Block does not exist
68 LARBSDBG("No Raw Data Block in this FEB");
69 return 0;
70 }
71 //The m_RawDataChannel keeps track of the last read channel
72
73 // Get next channel
74 channelNumber=m_RawDataCounter;
75 uint32_t febgain;
76 const unsigned int nsamples = getHeader16(NSamples) & 0xff;
77 const unsigned int ngains = getHeader16(NGains);
78 if(ngains==0 || nsamples==0) return 0;
79 // Loop over gains to look for m_fixedGain
80 unsigned int this_gain=0;
81 int offset;
82 LARBSDBG(" ===> fixedGain= " << m_fixedGain << " CaloGain = " << CaloGain::LARNGAIN);
83 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
84 offset=block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3);
85 for(this_gain=0;this_gain<ngains;this_gain++) {
86 int index = offset + 64*this_gain;
87 uint32_t x = m_FebBlock[index];
88 if(channelNumber>=64)
89 x = (x & 0x3000) >> 12;
90 else
91 x = (x & 0x30000000) >> 28;
92 unsigned data_gain = RawToOfflineGain(x);
93 if(data_gain==m_fixedGain) break;
94 }
95 }
96 if (this_gain<ngains) { //Gain found in this fragment
97 int s_size = 8 + 64 * ngains; // Size of one sample block 16 RADD of 16 bit + 128 channels (16 bit data)
98 offset = block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3) + 64*this_gain;
99 int index = offset;
100 uint32_t x = m_FebBlock[index];
101 if(channelNumber>=64) { //low channels on lower bits
102 // First decode gain
103 febgain = (x & 0x3000) >> 12; // 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];
108 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
109 }
110 } else { //high channels on higher bits
111 // First decode gain
112 febgain = (x & 0x30000000) >> 28; // gain on bits 12 and 13
113 // Than samples
114 for(unsigned int s=0;s<nsamples;s++) {
115 index = offset + s*s_size;
116 x = (m_FebBlock[index]) >> 16;
117 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
118 }
119 }
120 gain=RawToOfflineGain(febgain);
121 }
123 unsigned rearrangeFirstSample=0;
125 rearrangeFirstSample=m_rearrangeFirstSample; //Overwrite by jobOptions
126 else
127 rearrangeFirstSample=getFirstSampleIndex();
128 if (rearrangeFirstSample && rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
129 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
130 short movedSample=samples[0];
131 for (unsigned i=1;i<=rearrangeFirstSample;i++)
132 samples[i-1]=samples[i];
133 samples[rearrangeFirstSample]=movedSample;
134 }
135 LARBSDBG("GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
136 return 1;
137}
138
139
140
141int LArRodBlockCalibrationV3::getNextAccumulatedCalibDigit(int& channelNumber, std::vector < uint64_t >& samplesSum , std::vector < uint64_t >& samples2Sum, uint32_t& /*idummy*/, uint32_t& gain )
142{
143#ifdef LARBSDBGOUTPUT
144 MsgStream logstr(Athena::getMessageSvc(), BlockType());
145#endif
146 //Debug output
147 LARBSDBG("m_Result1Counter" << m_Result1Counter << " m_Result1Index="<< m_Result1Index
148 << " m_channelsPerFEB=" << m_channelsPerFEB);
149 LARBSDBG("requested gain= " << m_fixedGain);
150 if (m_Result1Counter>=m_channelsPerFEB) { //Already beyond maximal number of channels
151 LARBSDBG("Maximum number of channels reached");
152 return 0;
153 }
154 const uint16_t block = getHeader16(ResultsOff1);//Position of the AccumulatedCalibDigits FEB data block
155 if (!block) { //Block does not exist
156 LARBSDBG("No Accumulated Calib Digit Block in this FEB");
157 return 0;
158 }
159 //The m_Result1Channel keeps track of the last read channel
160
161 // Get next channel
162 channelNumber=m_Result1Counter;
163 // This is just for fun; these data are not stored here but in RodBlockDecoder.cxx
164 // IWS 08.08.2005 This part is useless in fact - just for debugging
165 const unsigned int nsamples = getHeader16(NSamples);
166 const unsigned int ngains = getHeader16(NGains);
167
168 const unsigned int FebConfig = (int) getFebConfig();
169 if(ngains==0 || nsamples==0) return 0;
170 // Loop over gains to look for m_fixedGain
171 int offset;
172 uint32_t x,x2;
173 uint32_t febgain;
174
175 if (FebConfig==0 || FebConfig>3) {
176 // to be done better when this is understood
177 febgain=1;
178 gain=RawToOfflineGain(febgain);
180 gain=m_fixedGain;
181
182 } else {
183 febgain=FebConfig&0x3;
184 gain=RawToOfflineGain(febgain);
185 }
186
188 LARBSDBG("Requested gain: " << m_fixedGain << " got " << gain << " data ingored.");
189 return 0;
190 }
191
192 // nsamples*2 for Sum + Sum2
193 // 12 is the size of the calibration header
194 offset=block + 12 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
195 uint32_t index=offset;
196
197 samplesSum.resize(nsamples);
198 samples2Sum.resize(nsamples);
199
200 for (size_t i=0;i<nsamples;++i) {
202 x2=m_FebBlock[index+1];
203
204 samplesSum[i]=x;
205 samples2Sum[i]=x2;
206 index+=2;
207 }
208
210 return 1;
211}
212
213
218
220{
221 return getHeader16(NGains);
222}
223
225{
226
228 uint32_t x=m_FebBlock[index+NTrigger/2];
229 return (uint16_t) x;
230}
231
233{
235 uint32_t x = m_FebBlock[index+Dac/2];
236 return (uint16_t) x;
237}
238
240{
242 uint32_t x = m_FebBlock[index+Delay/2];
243 return (uint32_t) x;
244}
245
247{
249 uint32_t x = m_FebBlock[index+StepIndex/2]&0xffff;
250 return (uint16_t) x;
251}
252
257
262
267
269{
271 uint32_t x = m_FebBlock[index+StepIndex/2]>>16;
272 return (uint16_t) x;
273}
274
275uint32_t LArRodBlockCalibrationV3::getRadd(uint32_t adc, uint32_t sample) const
276{
277 int ngain=getHeader16(NGains);
279 if(index<=0) return 0;
280 index+=(8+64*ngain)*sample+adc/2;
281 uint32_t x=m_FebBlock[index];
282 if(adc&0x1) return x>>16;
283 return x&0xffff;
284}
285
286uint16_t LArRodBlockCalibrationV3::getCtrl1(uint32_t adc) const
287{
288 int index=getHeader16(RawDataBlkOff)-16+adc/2;
289 uint32_t x=m_FebBlock[index];
290 if(adc&0x1) x=x>>16;
291 else x=x&0xffff;
292 uint16_t ctrl=x;
293 return ctrl;
294}
295
296uint16_t LArRodBlockCalibrationV3::getCtrl2(uint32_t adc) const
297{
298 int index=getHeader16(RawDataBlkOff)-8+adc/2;
299 uint32_t x=m_FebBlock[index];
300 if(adc&0x1) x=x>>16;
301 else x=x&0xffff;
302 uint16_t ctrl=x;
303 return ctrl;
304}
305
306uint16_t LArRodBlockCalibrationV3::getCtrl3(uint32_t adc) const
307{
308 int nsamples=getHeader16(NSamples);
309 int ngains=getHeader16(NGains);
310 int offset=nsamples*(8+64*ngains)+adc/2;
311 int index=getHeader16(RawDataBlkOff)+offset;
312 uint32_t x=m_FebBlock[index];
313 if(adc&0x1) x=x>>16;
314 else x=x&0xffff;
315 uint16_t ctrl=x;
316 return ctrl;
317}
318
320{
321 // Get Dsp status word
322 if(getNumberOfWords()<EventStatus/2) return 0;
323 uint32_t x=getHeader32(EventStatus);
324 return x;
325}
326
327
328#ifdef LARBSDBGOUTPUT
329#undef LARBSDBGOUTPUT
330#endif
331#undef LARBSDBG
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
#define x
virtual uint8_t getTDCPhase() const
LArRodBlockCalibrationV3(IMessageSvc *msgSvc)
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
virtual uint16_t getResults1Size() const
virtual uint16_t getRawDataSize() const
virtual int getNextAccumulatedCalibDigit(int &channelNumber, std::vector< uint64_t > &samplesSum, std::vector< uint64_t > &samples2Sum, uint32_t &iStepTrigger, uint32_t &gain)
virtual uint32_t getStatus() const
virtual uint32_t getNumberOfSamples() const
virtual uint16_t getCtrl1(uint32_t adc) const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual uint32_t getNumberOfGains() const
virtual uint16_t getCtrl2(uint32_t adc) const
virtual uint16_t getResults2Size() const
std::vector< uint32_t > m_RawDataBlock
virtual uint16_t getCtrl3(uint32_t adc) 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