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-2022 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
31
32// clear temporary block vectors
37
48
49
51{
52 return (getHeader16(NSamples)>>8);
53}
54
55
56
57
58int LArRodBlockCalibrationV3::getNextRawData(int& channelNumber, std::vector<short>& samples, uint32_t& gain)
59{
60#ifdef LARBSDBGOUTPUT
61 MsgStream logstr(Athena::getMessageSvc(), BlockType());
62#endif
63 //Debug output
64 /*
65 LARBSDBG("GetNextRawData for FEB 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
66 LARBSDBG("m_RawDataCounter=" << m_RawDataCounter << " m_RawDataIndex="<< m_RawDataIndex
67 << " m_channelsPerFEB=" << m_channelsPerFEB);
68 LARBSDBG("requested gain= " << m_fixedGain);
69 */
70 if (m_RawDataCounter>=m_channelsPerFEB) { //Already beyond maximal number of channels
71 LARBSDBG("Maximum number of channels reached");
72 return 0;
73 }
74 //const uint16_t block = getHeader16(m_RawDataOff);//Position of the raw FEB data block
75 const uint16_t block = getHeader16(RawDataBlkOff);
76 if (!block) { //Block does not exist
77 LARBSDBG("No Raw Data Block in this FEB");
78 return 0;
79 }
80 //The m_RawDataChannel keeps track of the last read channel
81 //std::cout << "endtag=" << endtag << " m_iHeadBlockSize=" << m_iHeadBlockSize << std::endl;
82
83 // Get next channel
84 channelNumber=m_RawDataCounter;
85 uint32_t febgain;
86 const unsigned int nsamples = getHeader16(NSamples) & 0xff;
87 const unsigned int ngains = getHeader16(NGains);
88 /*
89 LARBSDBG("This FEB has " << nsamples << " samples");
90 LARBSDBG("This FEB has " << ngains << " gains");
91 */
92 if(ngains==0 || nsamples==0) return 0;
93 // Loop over gains to look for m_fixedGain
94 unsigned int this_gain=0;
95 int offset;
96 LARBSDBG(" ===> fixedGain= " << m_fixedGain << " CaloGain = " << CaloGain::LARNGAIN);
97 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
98 offset=block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3);
99 for(this_gain=0;this_gain<ngains;this_gain++) {
100 int index = offset + 64*this_gain;
101 uint32_t x = m_FebBlock[index];
102 if(channelNumber>=64)
103 x = (x & 0x3000) >> 12;
104 else
105 x = (x & 0x30000000) >> 28;
106 unsigned data_gain = RawToOfflineGain(x);
107 if(data_gain==m_fixedGain) break;
108 }
109 }
110 if (this_gain<ngains) { //Gain found in this fragment
111 int s_size = 8 + 64 * ngains; // Size of one sample block 16 RADD of 16 bit + 128 channels (16 bit data)
112 offset = block + 8 + ((channelNumber&0x3F)>>3) + ((channelNumber & 0x7)<<3) + 64*this_gain;
113 int index = offset;
114 uint32_t x = m_FebBlock[index];
115 if(channelNumber>=64) { //low channels on lower bits
116 // First decode gain
117 febgain = (x & 0x3000) >> 12; // gain on bits 12 and 13
118 // Than samples
119 for(unsigned int s=0;s<nsamples;s++) {
120 index = offset + s*s_size;
121 x = m_FebBlock[index];
122 // if((s==0) && (channelNumber==64)) std::cout << "===> " << std::dec << channelNumber << " " << (x&0xfff) << " " << std::endl;
123 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
124 }
125 } else { //high channels on higher bits
126 // First decode gain
127 febgain = (x & 0x30000000) >> 28; // gain on bits 12 and 13
128 // Than samples
129 for(unsigned int s=0;s<nsamples;s++) {
130 index = offset + s*s_size;
131 x = (m_FebBlock[index]) >> 16;
132 samples.push_back((short) (x & 0x0fff)); // sample on bits 0 to 11
133 }
134 }
135 gain=RawToOfflineGain(febgain);
136 }
138 unsigned rearrangeFirstSample=0;
140 rearrangeFirstSample=m_rearrangeFirstSample; //Overwrite by jobOptions
141 else
142 rearrangeFirstSample=getFirstSampleIndex();
143 if (rearrangeFirstSample && rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
144 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
145 short movedSample=samples[0];
146 for (unsigned i=1;i<=rearrangeFirstSample;i++)
147 samples[i-1]=samples[i];
148 samples[rearrangeFirstSample]=movedSample;
149 }
150 LARBSDBG("GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
151 return 1;
152}
153
154
155
156int LArRodBlockCalibrationV3::getNextAccumulatedCalibDigit(int& channelNumber, std::vector < uint64_t >& samplesSum , std::vector < uint64_t >& samples2Sum, uint32_t& /*idummy*/, uint32_t& gain )
157{
158#ifdef LARBSDBGOUTPUT
159 MsgStream logstr(Athena::getMessageSvc(), BlockType());
160#endif
161 //Debug output
162 LARBSDBG("m_Result1Counter" << m_Result1Counter << " m_Result1Index="<< m_Result1Index
163 << " m_channelsPerFEB=" << m_channelsPerFEB);
164 LARBSDBG("requested gain= " << m_fixedGain);
165 if (m_Result1Counter>=m_channelsPerFEB) { //Already beyond maximal number of channels
166 LARBSDBG("Maximum number of channels reached");
167 return 0;
168 }
169 const uint16_t block = getHeader16(ResultsOff1);//Position of the AccumulatedCalibDigits FEB data block
170 if (!block) { //Block does not exist
171 LARBSDBG("No Accumulated Calib Digit Block in this FEB");
172 // std::cout << "index= " << ResultsOff1 << "word= " << getHeader16(ResultsOff1) << std::endl;
173 return 0;
174 }
175 //The m_Result1Channel keeps track of the last read channel
176 //std::cout << "endtag=" << endtag << " m_iHeadBlockSize=" << m_iHeadBlockSize << std::endl;
177
178 // Get next channel
179 channelNumber=m_Result1Counter;
180 // This is just for fun; these data are not stored here but in RodBlockDecoder.cxx
181 // IWS 08.08.2005 This part is useless in fact - just for debugging
182 const unsigned int nsamples = getHeader16(NSamples);
183 const unsigned int ngains = getHeader16(NGains);
184 //const unsigned int ntriggers = (int) getNTrigger();
185 //const unsigned int dac = (int) getDAC();
186 //const unsigned int stepindex = (int) getStepIndex();
187 //const unsigned int nstep = (int) getNStep();
188 //const unsigned int delay = (int) getDelay();
189
190 const unsigned int FebConfig = (int) getFebConfig();
191// LARBSDBG("This FEB has " << nsamples << " samples");
192// LARBSDBG("This FEB has " << ngains << " gains");
193// LARBSDBG("This FEB has " << ntriggers << " ntriggers");
194// LARBSDBG("This FEB has " << dac << " dac");
195// LARBSDBG("This FEB has " << delay << " delay");
196// LARBSDBG("This FEB has " << std::hex << FebConfig << " FebConfig");
197 if(ngains==0 || nsamples==0) return 0;
198 // Loop over gains to look for m_fixedGain
199 //unsigned int this_gain=0;
200 int offset;
201 uint32_t x,x2;
202 uint32_t febgain;
203
204 if (FebConfig==0 || FebConfig>3) {
205 //Converter can currently not deal with this situation
206 //LARBSDBG("Suspicious FebConfig value" << FebConfig << ", don't know what to do for Accumulated Calib Digit - return 0");
207 //return 0;
208
209 // to be done better when this is understood
210 febgain=1;
211 gain=RawToOfflineGain(febgain);
213 gain=m_fixedGain;
214
215 } else {
216 febgain=FebConfig&0x3;
217 gain=RawToOfflineGain(febgain);
218 }
219
221 LARBSDBG("Requested gain: " << m_fixedGain << " got " << gain << " data ingored.");
222 return 0;
223 }
224
225 // nsamples*2 for Sum + Sum2
226 // 12 is the size of the calibration header
227 offset=block + 12 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
228 uint32_t index=offset;
229
230 samplesSum.resize(nsamples);
231 samples2Sum.resize(nsamples);
232
233 for (size_t i=0;i<nsamples;++i) {
235 x2=m_FebBlock[index+1];
236
237 samplesSum[i]=x;
238 samples2Sum[i]=x2;
239 // std::cout << "isample=" << i << " x= " << std::hex << x << " x2=" << std::hex << x2 << std::endl;
240 index+=2;
241 }
242
244 return 1;
245}
246
247
252
254{
255 return getHeader16(NGains);
256}
257
259{
260
262 uint32_t x=m_FebBlock[index+NTrigger/2];
263 return (uint16_t) x;
264}
265
267{
269 uint32_t x = m_FebBlock[index+Dac/2];
270 return (uint16_t) x;
271}
272
274{
276 uint32_t x = m_FebBlock[index+Delay/2];
277 return (uint32_t) x;
278}
279
281{
283 uint32_t x = m_FebBlock[index+StepIndex/2]&0xffff;
284 return (uint16_t) x;
285}
286
291
296
301
303{
305 uint32_t x = m_FebBlock[index+StepIndex/2]>>16;
306 return (uint16_t) x;
307}
308
309uint32_t LArRodBlockCalibrationV3::getRadd(uint32_t adc, uint32_t sample) const
310{
311 int ngain=getHeader16(NGains);
313 if(index<=0) return 0;
314 index+=(8+64*ngain)*sample+adc/2;
315 uint32_t x=m_FebBlock[index];
316 if(adc&0x1) return x>>16;
317 return x&0xffff;
318}
319
320uint16_t LArRodBlockCalibrationV3::getCtrl1(uint32_t adc) const
321{
322 int index=getHeader16(RawDataBlkOff)-16+adc/2;
323 uint32_t x=m_FebBlock[index];
324 if(adc&0x1) x=x>>16;
325 else x=x&0xffff;
326 uint16_t ctrl=x;
327 return ctrl;
328 /*
329 int index=getHeader16(RawDataBlkOff)-16;
330 uint32_t x=m_FebBlock[index];
331 if(adc&0x1) return x>>16;
332 return x&0xffff;
333 */
334}
335
336uint16_t LArRodBlockCalibrationV3::getCtrl2(uint32_t adc) const
337{
338 int index=getHeader16(RawDataBlkOff)-8+adc/2;
339 uint32_t x=m_FebBlock[index];
340 if(adc&0x1) x=x>>16;
341 else x=x&0xffff;
342 uint16_t ctrl=x;
343 return ctrl;
344 /*
345 int index=getHeader16(RawDataBlkOff)-8 ;
346 uint32_t x=m_FebBlock[index];
347 if(adc&0x1) return x>>16;
348 return x&0xffff;
349 */
350}
351
352uint16_t LArRodBlockCalibrationV3::getCtrl3(uint32_t adc) const
353{
354 int nsamples=getHeader16(NSamples);
355 int ngains=getHeader16(NGains);
356 int offset=nsamples*(8+64*ngains)+adc/2;
357 int index=getHeader16(RawDataBlkOff)+offset;
358 uint32_t x=m_FebBlock[index];
359 if(adc&0x1) x=x>>16;
360 else x=x&0xffff;
361 uint16_t ctrl=x;
362 return ctrl;
363 /*
364 int index=getHeader16(RawDataBlkOff)-3;
365 uint32_t x=m_FebBlock[index];
366 x=x>>16;
367 uint16_t ctrl=x;
368 return ctrl;
369 */
370}
371
373{
374 // Old version: get Dsp status word
375 if(getNumberOfWords()<EventStatus/2) return 0;
376 uint32_t x=getHeader32(EventStatus);
377 return x;
378
379 // New verion: get Rod status word
380 //int nsamples = getHeader16(NSamples);
381 //int ngains = getHeader16(NGains);
382 //int offset = nsamples*(8+64*ngains)+8;
383 //int index = getHeader16(RawDataBlkOff)+offset;
384 //uint32_t x = m_FebBlock[index];
385 //return x;
386}
387
388
389#ifdef LARBSDBGOUTPUT
390#undef LARBSDBGOUTPUT
391#endif
392#undef LARBSDBG
#define LARBSDBG(text)
This class provides decoding/encoding from/to ROD format.
#define x
virtual uint8_t getTDCPhase() const
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
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