ATLAS Offline Software
Loading...
Searching...
No Matches
LArRodBlockCalibrationV1.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 LArRodBlockCalibrationV1::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 LArRodBlockCalibrationV1::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 const unsigned int ntriggers = (int) getNTrigger();
165 const unsigned int dac = (int) getDAC();
166 const unsigned int delay = (int) getDelay();
167 unsigned int nStepTriggers = 1;
168 const unsigned int FebConfig = (int) getFebConfig();
169 LARBSDBG("This FEB has " << nsamples << " samples");
170 LARBSDBG("This FEB has " << ngains << " gains");
171 LARBSDBG("This FEB has " << ntriggers << " ntriggers");
172 LARBSDBG("This FEB has " << dac << " dac");
173 LARBSDBG("This FEB has " << delay << " delay");
174 LARBSDBG("This FEB has " << std::hex << FebConfig << " FebConfig");
175 if(ngains==0 || nsamples==0) return 0;
176 // IWS 11.01.2006 book vectors
177 if(!iStepTriggers)
178 {
179 samplesSum.resize(nStepTriggers);
180 samples2Sum.resize(nStepTriggers);
181 }
182 // Loop over gains to look for m_fixedGain
183 int offset;
184 uint32_t x,x2;
185 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
186 if(FebConfig==0) // free gain - dontknow what to do
187 {
188 LARBSDBG("free gain - dont know what to do Accumulated Calib Digit - return 0");
189 return 0;
190 }
191 else if(FebConfig <4 ) // one fixed gain
192 {
193 febgain=FebConfig;
194 }
195 else if ((FebConfig>3) && (FebConfig<10)) // two gains - not yet ready
196 {
197 LARBSDBG("two gains - dont know what to do yet in Accumulated Calib Digit - return 0");
198 return 0;
199 }
200 else if (FebConfig>9) // three gains - not yet ready
201 {
202 LARBSDBG("three gains - dont know what to do yet in Accumulated Calib Digit - return 0");
203 return 0;
204 }
205 }
206 else
207 {
208 febgain=FebConfig&0x3; // to be done better when this is better understood
209 }
210
211 // nsamples*2 for Sum + Sum2
212 // 11 is the size of the calibration header
213 offset=block + 11 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
214 uint32_t index=offset;
215
216 for (unsigned int i=0;i<nsamples;i++)
217 {
219 x2=m_FebBlock[index+1];
220
221 samplesSum[iStepTriggers].push_back(x);
222 samples2Sum[iStepTriggers].push_back(x2);
223 index+=2;
224 }
225
226 gain=RawToOfflineGain(febgain);
227
229 return 1;
230}
231
232
237
239{
240 return getHeader16(NGains);
241}
242
244{
245
247 uint32_t x=m_FebBlock[index+NTrigger/2];
248 return (uint16_t) x;
249}
250
252{
254 uint32_t x = m_FebBlock[index+Dac/2];
255 return (uint16_t) x;
256}
257
259{
261 uint32_t x = m_FebBlock[index+Delay/2];
262 return (uint32_t) x;
263}
264
265uint32_t LArRodBlockCalibrationV1::getRadd(uint32_t adc, uint32_t sample) const
266{
267 int ngain=getHeader16(NGains);
269 if(index<=0) return 0;
270 index+=(8+64*ngain)*sample+adc/2;
271 uint32_t x=m_FebBlock[index];
272 if(adc&0x1) return x>>16;
273 return x&0xffff;
274}
275
276uint16_t LArRodBlockCalibrationV1::getCtrl1(uint32_t adc) const
277{
278 int index=getHeader16(RawDataBlkOff)-16+adc/2;
279 uint32_t x=m_FebBlock[index];
280 if(adc&0x1) x=x>>16;
281 else x=x&0xffff;
282 uint16_t ctrl=x;
283 return ctrl;
284}
285
286uint16_t LArRodBlockCalibrationV1::getCtrl2(uint32_t adc) const
287{
288 int index=getHeader16(RawDataBlkOff)-8+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 LArRodBlockCalibrationV1::getCtrl3(uint32_t adc) const
297{
298 int nsamples=getHeader16(NSamples);
299 int ngains=getHeader16(NGains);
300 int offset=nsamples*(8+64*ngains)+adc/2;
301 int index=getHeader16(RawDataBlkOff)+offset;
302 uint32_t x=m_FebBlock[index];
303 if(adc&0x1) x=x>>16;
304 else x=x&0xffff;
305 uint16_t ctrl=x;
306 return ctrl;
307}
308
310{
311 // Get Rod status word
312 int nsamples = getHeader16(NSamples);
313 int ngains = getHeader16(NGains);
314 int offset = nsamples*(8+64*ngains)+8;
315 int index = getHeader16(RawDataBlkOff)+offset;
316 uint32_t x = m_FebBlock[index];
317 return x;
318
319}
320
321
322#ifdef LARBSDBGOUTPUT
323#undef LARBSDBGOUTPUT
324#endif
325#undef LARBSDBG
double delay(std::size_t d)
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
#define x
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)
std::vector< uint32_t > m_RawDataBlock
virtual uint16_t getCtrl3(uint32_t adc) const
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
virtual uint32_t getNumberOfGains() const
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
virtual uint8_t getTDCPhase() const
virtual uint32_t getStatus() const
virtual uint16_t getCtrl2(uint32_t adc) const
virtual uint32_t getNumberOfSamples() const
virtual uint16_t getCtrl1(uint32_t adc) const
LArRodBlockCalibrationV1(IMessageSvc *msgSvc)
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