ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockCalibrationV2.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
33// clear temporary block vectors
38
49
50
52{
53 return (getHeader16(NSamples)>>8);
54}
55
56
57
58
59int LArRodBlockCalibrationV2::getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain)
60{
61#ifdef LARBSDBGOUTPUT
62 MsgStream logstr(Athena::getMessageSvc(), BlockType());
63#endif
64 if (m_RawDataCounter>=m_channelsPerFEB) { //Already beyond maximal number of channels
65 LARBSDBG("Maximum number of channels reached");
66 return 0;
67 }
68 const uint16_t block = getHeader16(RawDataBlkOff);
69 if (!block) { //Block does not exist
70 LARBSDBG("No Raw Data Block in this FEB");
71 return 0;
72 }
73 //The m_RawDataChannel keeps track of the last read channel
74
75 // Get next channel
76 channelNumber=m_RawDataCounter;
77 uint32_t febgain;
78 const unsigned int nsamples = getHeader16(NSamples) & 0xff;
79 const unsigned int ngains = getHeader16(NGains);
80 if(ngains==0 || nsamples==0) return 0;
81 // Loop over gains to look for m_fixedGain
82 unsigned int this_gain=0;
83 int offset;
84 LARBSDBG(" ===> fixedGain= " << m_fixedGain << " CaloGain = " << CaloGain::LARNGAIN);
85 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
86 offset=block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3);
87 for(this_gain=0;this_gain<ngains;this_gain++) {
88 int index = offset + 64*this_gain;
89 uint32_t x = m_FebBlock[index];
90 if(channelNumber>=64)
91 x = (x & 0x3000) >> 12;
92 else
93 x = (x & 0x30000000) >> 28;
94 int data_gain = RawToOfflineGain(x);
95 if(data_gain==m_fixedGain) break;
96 }
97 }
98 if (this_gain<ngains) { //Gain found in this fragment
99 int s_size = 8 + 64 * ngains; // Size of one sample block 16 RADD of 16 bit + 128 channels (16 bit data)
100 offset = block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3) + 64*this_gain;
101 int index = offset;
102 uint32_t x = m_FebBlock[index];
103 if(channelNumber>=64) { //low channels on lower bits
104 // First decode gain
105 febgain = (x & 0x3000) >> 12; // gain on bits 12 and 13
106 // Than samples
107 for(unsigned int s=0;s<nsamples;s++) {
108 index = offset + s*s_size;
109 x = m_FebBlock[index];
110 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
111 }
112 } else { //high channels on higher bits
113 // First decode gain
114 febgain = (x & 0x30000000) >> 28; // gain on bits 12 and 13
115 // Than samples
116 for(unsigned int s=0;s<nsamples;s++) {
117 index = offset + s*s_size;
118 x = (m_FebBlock[index]) >> 16;
119 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
120 }
121 }
122 gain=RawToOfflineGain(febgain);
123 }
125 if (m_rearrangeFirstSample && m_rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
126 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
127 short movedSample=samples[0];
128 for (unsigned i=1;i<=m_rearrangeFirstSample;i++)
129 samples[i-1]=samples[i];
130 samples[m_rearrangeFirstSample]=movedSample;
131 }
132 LARBSDBG("GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
133 return 1;
134}
135int LArRodBlockCalibrationV2::getNextAccumulatedCalibDigit(int& channelNumber, std::vector< std::vector < uint32_t > >& samplesSum , std::vector< std::vector < uint32_t > >& samples2Sum, uint32_t& iStepTriggers, uint32_t& gain )
136{
137#ifdef LARBSDBGOUTPUT
138 MsgStream logstr(Athena::getMessageSvc(), BlockType());
139#endif
140 //Debug output
141 LARBSDBG("GetAccumulatedCalibDigits for FEB 0x" << MSG::hex <<
142 (uint32_t)getHeader32(FEBID) << MSG::dec << "iStepTriggers=" << iStepTriggers);
143 LARBSDBG("m_Result1Counter" << m_Result1Counter << " m_Result1Index="<< m_Result1Index
144 << " m_channelsPerFEB=" << m_channelsPerFEB);
145 LARBSDBG("requested gain= " << m_fixedGain);
146 if (m_Result1Counter>=m_channelsPerFEB) { //Already beyond maximal number of channels
147 LARBSDBG("Maximum number of channels reached");
148 return 0;
149 }
150 const uint16_t block = getHeader16(ResultsOff1);//Position of the AccumulatedCalibDigits FEB data block
151 if (!block) { //Block does not exist
152 LARBSDBG("No Accumulated Calib Digit Block in this FEB");
153 return 0;
154 }
155 //The m_Result1Channel keeps track of the last read channel
156
157 // Get next channel
158 channelNumber=m_Result1Counter;
159 uint32_t febgain=0;
160 // This is just for fun; these data are not stored here but in RodBlockDecoder.cxx
161 // IWS 08.08.2005 This part is useless in fact - just for debugging
162 const unsigned int nsamples = getHeader16(NSamples);
163 const unsigned int ngains = getHeader16(NGains);
164 unsigned int nStepTriggers = 1;
165 const unsigned int FebConfig = (int) getFebConfig();
166 if(ngains==0 || nsamples==0) return 0;
167 // IWS 11.01.2006 book vectors
168 if(!iStepTriggers)
169 {
170 samplesSum.resize(nStepTriggers);
171 samples2Sum.resize(nStepTriggers);
172 }
173 // Loop over gains to look for m_fixedGain
174 int offset;
175 uint32_t x,x2;
176 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
177 if(FebConfig==0) // free gain - dontknow what to do
178 {
179 LARBSDBG("free gain - dont know what to do Accumulated Calib Digit - return 0");
180 return 0;
181 }
182 else if(FebConfig <4 ) // one fixed gain
183 {
184 febgain=FebConfig;
185 }
186 else if ((FebConfig>3) && (FebConfig<10)) // two gains - not yet ready
187 {
188 LARBSDBG("two gains - dont know what to do yet in Accumulated Calib Digit - return 0");
189 return 0;
190 }
191 else if (FebConfig>9) // three gains - not yet ready
192 {
193 LARBSDBG("three gains - dont know what to do yet in Accumulated Calib Digit - return 0");
194 return 0;
195 }
196 }
197 else
198 {
199 febgain=FebConfig&0x3; // to be done better when this is better understood
200 }
201
202 // nsamples*2 for Sum + Sum2
203 // 11 is the size of the calibration header
204 offset=block + 12 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
205 uint32_t index=offset;
206
207 for (unsigned int i=0;i<nsamples;i++)
208 {
210 x2=m_FebBlock[index+1];
211
212 samplesSum[iStepTriggers].push_back(x);
213 samples2Sum[iStepTriggers].push_back(x2);
214 index+=2;
215 }
216
217 gain=RawToOfflineGain(febgain);
218
220 return 1;
221}
222
223
228
230{
231 return getHeader16(NGains);
232}
233
235{
236
238 uint32_t x=m_FebBlock[index+NTrigger/2];
239 return (uint16_t) x;
240}
241
243{
245 uint32_t x = m_FebBlock[index+Dac/2];
246 return (uint16_t) x;
247}
248
250{
252 uint32_t x = m_FebBlock[index+Delay/2];
253 return (uint32_t) x;
254}
255
256uint32_t LArRodBlockCalibrationV2::getRadd(uint32_t adc, uint32_t sample) const
257{
258 int ngain=getHeader16(NGains);
260 if(index<=0) return 0;
261 index+=(8+64*ngain)*sample+adc/2;
262 uint32_t x=m_FebBlock[index];
263 if(adc&0x1) return x>>16;
264 return x&0xffff;
265}
266
267uint16_t LArRodBlockCalibrationV2::getCtrl1(uint32_t adc) const
268{
269 int index=getHeader16(RawDataBlkOff)-16+adc/2;
270 uint32_t x=m_FebBlock[index];
271 if(adc&0x1) x=x>>16;
272 else x=x&0xffff;
273 uint16_t ctrl=x;
274 return ctrl;
275}
276
277uint16_t LArRodBlockCalibrationV2::getCtrl2(uint32_t adc) const
278{
279 int index=getHeader16(RawDataBlkOff)-8+adc/2;
280 uint32_t x=m_FebBlock[index];
281 if(adc&0x1) x=x>>16;
282 else x=x&0xffff;
283 uint16_t ctrl=x;
284 return ctrl;
285}
286
287uint16_t LArRodBlockCalibrationV2::getCtrl3(uint32_t adc) const
288{
289 int nsamples=getHeader16(NSamples);
290 int ngains=getHeader16(NGains);
291 int offset=nsamples*(8+64*ngains)+adc/2;
292 int index=getHeader16(RawDataBlkOff)+offset;
293 uint32_t x=m_FebBlock[index];
294 if(adc&0x1) x=x>>16;
295 else x=x&0xffff;
296 uint16_t ctrl=x;
297 return ctrl;
298}
299
301{
302 // Get Rod status word
303 int nsamples = getHeader16(NSamples);
304 int ngains = getHeader16(NGains);
305 int offset = nsamples*(8+64*ngains)+8;
306 int index = getHeader16(RawDataBlkOff)+offset;
307 uint32_t x = m_FebBlock[index];
308 return x;
309
310}
311
312
313#ifdef LARBSDBGOUTPUT
314#undef LARBSDBGOUTPUT
315#endif
316#undef LARBSDBG
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
#define x
virtual uint32_t getNumberOfSamples() const
virtual uint32_t getNumberOfGains() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual uint16_t getCtrl3(uint32_t adc) const
virtual uint16_t getCtrl2(uint32_t adc) const
virtual uint32_t getStatus() const
std::vector< uint32_t > m_RawDataBlock
virtual uint8_t getTDCPhase() const
virtual int getNextAccumulatedCalibDigit(int &channelNumber, std::vector< std::vector< uint32_t > > &samplesSum, std::vector< std::vector< uint32_t > > &samples2Sum, uint32_t &iStepTrigger, uint32_t &gain)
virtual uint16_t getCtrl1(uint32_t adc) const
LArRodBlockCalibrationV2(IMessageSvc *msgSvc)
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) 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
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
@ LARNGAIN
Definition CaloGain.h:19
Definition index.py:1