ATLAS Offline Software
LArRodBlockCalibrationV2.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 
26 {
27  m_iHeadBlockSize=endtag/2; // The implicit cast rounds down to the right size
30 }
31 
32 // clear temporary block vectors
34 {
35  m_RawDataBlock.clear();
36 }
37 
39 {
46 
47 }
48 
49 
51 {
52  return (getHeader16(NSamples)>>8);
53 }
54 
55 
56 
57 
58 int LArRodBlockCalibrationV2::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;
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;
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 }
149 int LArRodBlockCalibrationV2::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 + 12 + (channelNumber&0x7F)*(nsamples*2); // needs to be updated for loop on gains
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  */
254  x=m_FebBlock[index];
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 
271 {
272  return getHeader16(NSamples);
273 }
274 
276 {
277  return getHeader16(NGains);
278 }
279 
281 {
282 
285  return (uint16_t) x;
286 }
287 
289 {
292  return (uint16_t) x;
293 }
294 
296 {
299  return (uint32_t) x;
300 }
301 /* IWS 06.01.2006 prepare for future data
302 uint16_t LArRodBlockCalibrationV2::getnStepTriggers() const
303 {
304  int index=getHeader16(ResultsOff1);
305  uint32_t x = m_FebBlock[index+nStepTriggers/2];
306  return (uint32_t) x;
307 }
308 */
310 {
311  int ngain=getHeader16(NGains);
313  if(index<=0) return 0;
314  index+=(8+64*ngain)*sample+adc/2;
316  if(adc&0x1) return x>>16;
317  return x&0xffff;
318 }
319 
321 {
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 
337 {
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 
353 {
355  int ngains=getHeader16(NGains);
356  int offset=nsamples*(8+64*ngains)+adc/2;
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
381  int ngains = getHeader16(NGains);
382  int offset = nsamples*(8+64*ngains)+8;
385  return x;
386 
387 }
388 
389 
390 #ifdef LARBSDBGOUTPUT
391 #undef LARBSDBGOUTPUT
392 #endif
393 #undef LARBSDBG
LArRodBlockStructure
Definition: LArRodBlockStructure.h:48
LArRodBlockCalibrationV2.h
LArRodBlockCalibrationV2::getTDCPhase
virtual uint8_t getTDCPhase() const
Definition: LArRodBlockCalibrationV2.cxx:50
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
LArRodBlockCalibrationV2::getNTrigger
uint16_t getNTrigger() const
Definition: LArRodBlockCalibrationV2.cxx:280
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
LArRodBlockCalibrationV2::getNextAccumulatedCalibDigit
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)
Definition: LArRodBlockCalibrationV2.cxx:149
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
LArRodBlockCalibrationV2::LArRodBlockCalibrationV2
LArRodBlockCalibrationV2()
Definition: LArRodBlockCalibrationV2.cxx:25
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
LArRodBlockCalibrationV2::resetPointers
virtual void resetPointers()
Definition: LArRodBlockCalibrationV2.cxx:38
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
LArRodBlockCalibrationV2::ResultsOff1
@ ResultsOff1
Definition: LArRodBlockCalibrationV2.h:34
LArRodBlockCalibrationV2::m_Result1Index
int m_Result1Index
Definition: LArRodBlockCalibrationV2.h:118
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArRodBlockCalibrationV2::getFebConfig
uint32_t getFebConfig() const
Definition: LArRodBlockCalibrationV2.h:137
LArRodBlockStructure::m_FebBlock
const uint32_t * m_FebBlock
Definition: LArRodBlockStructure.h:227
LArRodBlockCalibrationV2::getNumberOfGains
virtual uint32_t getNumberOfGains() const
Definition: LArRodBlockCalibrationV2.cxx:275
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
LArRodBlockCalibrationV2::RawDataBlkOff
@ RawDataBlkOff
Definition: LArRodBlockCalibrationV2.h:38
x
#define x
LArRodBlockCalibrationV2::getRadd
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
Definition: LArRodBlockCalibrationV2.cxx:309
LArRodBlockCalibrationV2::NTrigger
@ NTrigger
Definition: LArRodBlockCalibrationV2.h:50
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
LArRodBlockCalibrationV2::m_Result2Counter
int m_Result2Counter
Definition: LArRodBlockCalibrationV2.h:119
LArRodBlockCalibrationV2::getDelay
uint16_t getDelay() const
Definition: LArRodBlockCalibrationV2.cxx:295
LArRodBlockStructure::m_iHeadBlockSize
unsigned short m_iHeadBlockSize
Definition: LArRodBlockStructure.h:221
LArRodBlockStructure::m_rearrangeFirstSample
unsigned int m_rearrangeFirstSample
Definition: LArRodBlockStructure.h:241
LArRodBlockStructure::getHeader32
uint32_t getHeader32(const unsigned n) const
Definition: LArRodBlockStructure.h:365
LArRodBlockCalibrationV2::getCtrl3
virtual uint16_t getCtrl3(uint32_t adc) const
Definition: LArRodBlockCalibrationV2.cxx:352
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
LArRodBlockStructure::RawToOfflineGain
uint32_t RawToOfflineGain(const uint32_t gain) const
Definition: LArRodBlockStructure.h:349
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:113
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArRodBlockCalibrationV2::m_RawDataBlock
std::vector< uint32_t > m_RawDataBlock
Definition: LArRodBlockCalibrationV2.h:115
LArRodBlockCalibrationV2::m_Result2Index
int m_Result2Index
Definition: LArRodBlockCalibrationV2.h:120
LArRodBlockCalibrationV2::BlockType
std::string BlockType()
Definition: LArRodBlockCalibrationV2.h:80
LARBSDBG
#define LARBSDBG(text)
Definition: LArRodBlockCalibrationV2.cxx:19
LArRodBlockCalibrationV2::getNextRawData
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
Definition: LArRodBlockCalibrationV2.cxx:58
LArRodBlockCalibrationV2::endtag
@ endtag
Definition: LArRodBlockCalibrationV2.h:74
LArRodBlockCalibrationV2::getStatus
virtual uint32_t getStatus() const
Definition: LArRodBlockCalibrationV2.cxx:372
LArRodBlockCalibrationV2::Dac
@ Dac
Definition: LArRodBlockCalibrationV2.h:52
ReadOfcFromCool.nsamples
nsamples
Definition: ReadOfcFromCool.py:115
LArRodBlockCalibrationV2::getDAC
uint16_t getDAC() const
Definition: LArRodBlockCalibrationV2.cxx:288
DeMoScan.index
string index
Definition: DeMoScan.py:364
LArRodBlockCalibrationV2::FebConfig
@ FebConfig
Definition: LArRodBlockCalibrationV2.h:44
LArRodBlockCalibrationV2::m_RawDataIndex
int m_RawDataIndex
Definition: LArRodBlockCalibrationV2.h:122
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
LArRodBlockCalibrationV2::m_Result1Counter
int m_Result1Counter
Definition: LArRodBlockCalibrationV2.h:117
LArRodBlockCalibrationV2::FEBID
@ FEBID
Definition: LArRodBlockCalibrationV2.h:30
LArRodBlockCalibrationV2::NSamples
@ NSamples
Definition: LArRodBlockCalibrationV2.h:43
LArRodBlockCalibrationV2::getCtrl2
virtual uint16_t getCtrl2(uint32_t adc) const
Definition: LArRodBlockCalibrationV2.cxx:336
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LArRodBlockCalibrationV2::Delay
@ Delay
Definition: LArRodBlockCalibrationV2.h:54
PlotCalibFromCool.ngain
ngain
Definition: PlotCalibFromCool.py:565
LArRodBlockCalibrationV2::getNumberOfSamples
virtual uint32_t getNumberOfSamples() const
Definition: LArRodBlockCalibrationV2.cxx:270
LArRodBlockCalibrationV2::getCtrl1
virtual uint16_t getCtrl1(uint32_t adc) const
Definition: LArRodBlockCalibrationV2.cxx:320
LArRodBlockStructure::m_channelsPerFEB
int m_channelsPerFEB
Definition: LArRodBlockStructure.h:225
LArRodBlockCalibrationV2::NGains
@ NGains
Definition: LArRodBlockCalibrationV2.h:42
LArRodBlockStructure::getHeader16
uint16_t getHeader16(const unsigned n) const
Definition: LArRodBlockStructure.h:355
LArRodBlockCalibrationV2::clearBlocks
void clearBlocks()
Definition: LArRodBlockCalibrationV2.cxx:33
LArRodBlockCalibrationV2::m_RawDataCounter
int m_RawDataCounter
Definition: LArRodBlockCalibrationV2.h:121
LArRodBlockCalibrationV2::m_fixedGain
int m_fixedGain
Definition: LArRodBlockCalibrationV2.h:124