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-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 LArRodBlockCalibrationV1::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 int 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 }
137 //std::cout << "Gain= " << gain << " Febgain=" << febgain << std::endl;
139 if (m_rearrangeFirstSample && m_rearrangeFirstSample<samples.size()) //FIXME: Very ugly hack! See explanation in LArRodDecoder.h file
140 {//Change e.g. 3 0 1 2 4 to 0 1 2 3 4
141 short movedSample=samples[0];
142 for (unsigned i=1;i<=m_rearrangeFirstSample;i++)
143 samples[i-1]=samples[i];
144 samples[m_rearrangeFirstSample]=movedSample;
145 }
146 LARBSDBG("GetNextRawData for FEB finished 0x" << MSG::hex << (uint32_t)getHeader32(FEBID) << MSG::dec);
147 return 1;
148}
149int LArRodBlockCalibrationV1::getNextAccumulatedCalibDigit(int& channelNumber, std::vector< std::vector < uint32_t > >& samplesSum , std::vector< std::vector < uint32_t > >& samples2Sum, uint32_t& iStepTriggers, uint32_t& gain )
150{
151#ifdef LARBSDBGOUTPUT
152 MsgStream logstr(Athena::getMessageSvc(), BlockType());
153#endif
154 //Debug output
155 LARBSDBG("GetAccumulatedCalibDigits for FEB 0x" << MSG::hex <<
156 (uint32_t)getHeader32(FEBID) << MSG::dec << "iStepTriggers=" << iStepTriggers);
157 LARBSDBG("m_Result1Counter" << m_Result1Counter << " m_Result1Index="<< m_Result1Index
158 << " m_channelsPerFEB=" << m_channelsPerFEB);
159 LARBSDBG("requested gain= " << m_fixedGain);
160 if (m_Result1Counter>=m_channelsPerFEB) { //Already beyond maximal number of channels
161 LARBSDBG("Maximum number of channels reached");
162 return 0;
163 }
164 const uint16_t block = getHeader16(ResultsOff1);//Position of the AccumulatedCalibDigits FEB data block
165 if (!block) { //Block does not exist
166 LARBSDBG("No Accumulated Calib Digit Block in this FEB");
167 // std::cout << "index= " << ResultsOff1 << "word= " << getHeader16(ResultsOff1) << std::endl;
168 return 0;
169 }
170 //The m_Result1Channel keeps track of the last read channel
171 //std::cout << "endtag=" << endtag << " m_iHeadBlockSize=" << m_iHeadBlockSize << std::endl;
172
173 // Get next channel
174 channelNumber=m_Result1Counter;
175 uint32_t febgain=0;
176 // This is just for fun; these data are not stored here but in RodBlockDecoder.cxx
177 // IWS 08.08.2005 This part is useless in fact - just for debugging
178 const unsigned int nsamples = getHeader16(NSamples);
179 const unsigned int ngains = getHeader16(NGains);
180 const unsigned int ntriggers = (int) getNTrigger();
181 const unsigned int dac = (int) getDAC();
182 const unsigned int delay = (int) getDelay();
183 // const unsigned int nStepTriggers = (int) getnStepTriggers();
184 unsigned int nStepTriggers = 1;
185 const unsigned int FebConfig = (int) getFebConfig();
186 LARBSDBG("This FEB has " << nsamples << " samples");
187 LARBSDBG("This FEB has " << ngains << " gains");
188 LARBSDBG("This FEB has " << ntriggers << " ntriggers");
189 LARBSDBG("This FEB has " << dac << " dac");
190 LARBSDBG("This FEB has " << delay << " delay");
191 LARBSDBG("This FEB has " << std::hex << FebConfig << " FebConfig");
192 if(ngains==0 || nsamples==0) return 0;
193 // IWS 11.01.2006 book vectors
194 if(!iStepTriggers)
195 {
196 samplesSum.resize(nStepTriggers);
197 samples2Sum.resize(nStepTriggers);
198 }
199 // Loop over gains to look for m_fixedGain
200 //unsigned int this_gain=0;
201 int offset;
202 uint32_t x,x2;
203 if (m_fixedGain!=CaloGain::LARNGAIN) { //Fixed gain: Search for gain
204 if(FebConfig==0) // free gain - dontknow what to do
205 {
206 LARBSDBG("free gain - dont know what to do Accumulated Calib Digit - return 0");
207 return 0;
208 }
209 else if(FebConfig <4 ) // one fixed gain
210 {
211 febgain=FebConfig;
212 }
213 else if ((FebConfig>3) && (FebConfig<10)) // two gains - not yet ready
214 {
215 LARBSDBG("two gains - dont know what to do yet in Accumulated Calib Digit - return 0");
216 return 0;
217 }
218 else if (FebConfig>9) // three gains - not yet ready
219 {
220 LARBSDBG("three gains - dont know what to do yet in Accumulated Calib Digit - return 0");
221 return 0;
222 }
223 }
224 else
225 {
226 febgain=FebConfig&0x3; // to be done better when this is better understood
227 }
228
229 // nsamples*2 for Sum + Sum2
230 // 11 is the size of the calibration header
231 offset=block + 11 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
232 uint32_t index=offset;
233
234 /*
235 if(dac==3000)
236 {
237 std::cout << "Chid" << channelNumber << " offset= " << std::dec << offset << std::endl;
238 for(int i=0; i<50; i++)
239 {
240 std::cout << " i= " << std::dec << i <<" x=" << std::hex << m_FebBlock[block+i] << std::endl;
241 }
242 }
243 */
244 /*
245 float * pfloat;
246 pfloat = (float *) &m_FebBlock[index];
247 */
248 for (unsigned int i=0;i<nsamples;i++)
249 {
250 /*
251 x = *pfloat++;
252 x2 = *pfloat++;
253 */
255 x2=m_FebBlock[index+1];
256
257 samplesSum[iStepTriggers].push_back(x);
258 samples2Sum[iStepTriggers].push_back(x2);
259 // std::cout << "isample=" << i << " x= " << std::hex << x << " x2=" << std::hex << x2 << std::endl;
260 index+=2;
261 }
262
263 gain=RawToOfflineGain(febgain);
264
266 return 1;
267}
268
269
274
276{
277 return getHeader16(NGains);
278}
279
281{
282
284 uint32_t x=m_FebBlock[index+NTrigger/2];
285 return (uint16_t) x;
286}
287
289{
291 uint32_t x = m_FebBlock[index+Dac/2];
292 return (uint16_t) x;
293}
294
296{
298 uint32_t x = m_FebBlock[index+Delay/2];
299 return (uint32_t) x;
300}
301/* IWS 06.01.2006 prepare for future data
302uint16_t LArRodBlockCalibrationV1::getnStepTriggers() const
303{
304 int index=getHeader16(ResultsOff1);
305 uint32_t x = m_FebBlock[index+nStepTriggers/2];
306 return (uint32_t) x;
307}
308*/
309uint32_t LArRodBlockCalibrationV1::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 LArRodBlockCalibrationV1::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 LArRodBlockCalibrationV1::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 LArRodBlockCalibrationV1::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
390#ifdef LARBSDBGOUTPUT
391#undef LARBSDBGOUTPUT
392#endif
393#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
uint16_t getHeader16(const unsigned n) const
uint32_t getHeader32(const unsigned n) const
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