ATLAS Offline Software
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 
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 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;
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;
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 
156 int 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);
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
229 
230  samplesSum.resize(nsamples);
231  samples2Sum.resize(nsamples);
232 
233  for (size_t i=0;i<nsamples;++i) {
234  x=m_FebBlock[index];
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 
249 {
250  return getHeader16(NSamples);
251 }
252 
254 {
255  return getHeader16(NGains);
256 }
257 
259 {
260 
263  return (uint16_t) x;
264 }
265 
267 {
270  return (uint16_t) x;
271 }
272 
274 {
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 
288 {
289  return getHeader16(ResultsDim1);
290 }
291 
293 {
294  return getHeader16(ResultsDim2);
295 }
296 
298 {
299  return getHeader16(RawDataBlkDim);
300 }
301 
303 {
306  return (uint16_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;
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
LArRodBlockCalibrationV3::getNStep
uint16_t getNStep() const
Definition: LArRodBlockCalibrationV3.cxx:302
LArRodBlockStructure
Definition: LArRodBlockStructure.h:48
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
LArRodBlockCalibrationV3::resetPointers
virtual void resetPointers()
Definition: LArRodBlockCalibrationV3.cxx:38
LArRodBlockCalibrationV3::getResults2Size
virtual uint16_t getResults2Size() const
Definition: LArRodBlockCalibrationV3.cxx:292
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
LArRodBlockCalibrationV3::getRawDataSize
virtual uint16_t getRawDataSize() const
Definition: LArRodBlockCalibrationV3.cxx:297
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
LArRodBlockCalibrationV3::getNumberOfSamples
virtual uint32_t getNumberOfSamples() const
Definition: LArRodBlockCalibrationV3.cxx:248
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
LArRodBlockCalibrationV3::m_Result1Counter
int m_Result1Counter
Definition: LArRodBlockCalibrationV3.h:119
LArRodBlockStructure::getNumberOfWords
uint32_t getNumberOfWords() const
Definition: LArRodBlockStructure.h:428
index
Definition: index.py:1
LArRodBlockCalibrationV3::Delay
@ Delay
Definition: LArRodBlockCalibrationV3.h:55
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArRodBlockCalibrationV3::getNTrigger
uint16_t getNTrigger() const
Definition: LArRodBlockCalibrationV3.cxx:258
LArRodBlockCalibrationV3::ResultsOff1
@ ResultsOff1
Definition: LArRodBlockCalibrationV3.h:34
LArRodBlockCalibrationV3::RawDataBlkOff
@ RawDataBlkOff
Definition: LArRodBlockCalibrationV3.h:38
LArRodBlockStructure::m_FebBlock
const uint32_t * m_FebBlock
Definition: LArRodBlockStructure.h:227
LArRodBlockCalibrationV3::FebConfig
@ FebConfig
Definition: LArRodBlockCalibrationV3.h:45
LArRodBlockCalibrationV3::getCtrl2
virtual uint16_t getCtrl2(uint32_t adc) const
Definition: LArRodBlockCalibrationV3.cxx:336
LArRodBlockCalibrationV3::m_RawDataCounter
int m_RawDataCounter
Definition: LArRodBlockCalibrationV3.h:123
LArRodBlockCalibrationV3::getNextAccumulatedCalibDigit
virtual int getNextAccumulatedCalibDigit(int &channelNumber, std::vector< uint64_t > &samplesSum, std::vector< uint64_t > &samples2Sum, uint32_t &iStepTrigger, uint32_t &gain)
Definition: LArRodBlockCalibrationV3.cxx:156
CaloGain::LARNGAIN
@ LARNGAIN
Definition: CaloGain.h:19
x
#define x
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
LArRodBlockCalibrationV3::getFebConfig
uint16_t getFebConfig() const
Definition: LArRodBlockCalibrationV3.h:158
LArRodBlockCalibrationV3::getStepIndex
uint16_t getStepIndex() const
Definition: LArRodBlockCalibrationV3.cxx:280
LArRodBlockCalibrationV3::m_Result1Index
int m_Result1Index
Definition: LArRodBlockCalibrationV3.h:120
LArRodBlockCalibrationV3::getStatus
virtual uint32_t getStatus() const
Definition: LArRodBlockCalibrationV3.cxx:372
LArRodBlockStructure::m_iHeadBlockSize
unsigned short m_iHeadBlockSize
Definition: LArRodBlockStructure.h:221
LArRodBlockStructure::m_rearrangeFirstSample
unsigned int m_rearrangeFirstSample
Definition: LArRodBlockStructure.h:241
LArRodBlockCalibrationV3::m_Result2Counter
int m_Result2Counter
Definition: LArRodBlockCalibrationV3.h:121
LArRodBlockStructure::getHeader32
uint32_t getHeader32(const unsigned n) const
Definition: LArRodBlockStructure.h:365
LArRodBlockCalibrationV3::getRadd
virtual uint32_t getRadd(uint32_t adc, uint32_t sample) const
Definition: LArRodBlockCalibrationV3.cxx:309
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
LArRodBlockCalibrationV3::m_Result2Index
int m_Result2Index
Definition: LArRodBlockCalibrationV3.h:122
LArRodBlockCalibrationV3::getCtrl1
virtual uint16_t getCtrl1(uint32_t adc) const
Definition: LArRodBlockCalibrationV3.cxx:320
LArRodBlockCalibrationV3::m_RawDataBlock
std::vector< uint32_t > m_RawDataBlock
Definition: LArRodBlockCalibrationV3.h:117
LArRodBlockCalibrationV3::getTDCPhase
virtual uint8_t getTDCPhase() const
Definition: LArRodBlockCalibrationV3.cxx:50
LArRodBlockCalibrationV3::getCtrl3
virtual uint16_t getCtrl3(uint32_t adc) const
Definition: LArRodBlockCalibrationV3.cxx:352
LARBSDBG
#define LARBSDBG(text)
Definition: LArRodBlockCalibrationV3.cxx:21
LArRodBlockCalibrationV3::getNumberOfGains
virtual uint32_t getNumberOfGains() const
Definition: LArRodBlockCalibrationV3.cxx:253
LArRodBlockCalibrationV3::clearBlocks
void clearBlocks()
Definition: LArRodBlockCalibrationV3.cxx:33
LArRodBlockCalibrationV3::LArRodBlockCalibrationV3
LArRodBlockCalibrationV3()
Definition: LArRodBlockCalibrationV3.cxx:25
LArRodBlockCalibrationV3::StepIndex
@ StepIndex
Definition: LArRodBlockCalibrationV3.h:65
LArRodBlockCalibrationV3::getFirstSampleIndex
uint16_t getFirstSampleIndex() const
Definition: LArRodBlockCalibrationV3.h:163
LArRodBlockCalibrationV3::m_RawDataIndex
int m_RawDataIndex
Definition: LArRodBlockCalibrationV3.h:124
LArRodBlockCalibrationV3::EventStatus
@ EventStatus
Definition: LArRodBlockCalibrationV3.h:40
ReadOfcFromCool.nsamples
nsamples
Definition: ReadOfcFromCool.py:115
LArRodBlockCalibrationV3::FEBID
@ FEBID
Definition: LArRodBlockCalibrationV3.h:30
LArRodBlockCalibrationV3::BlockType
std::string BlockType()
Definition: LArRodBlockCalibrationV3.h:80
DeMoScan.index
string index
Definition: DeMoScan.py:364
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
LArRodBlockCalibrationV3::RawDataBlkDim
@ RawDataBlkDim
Definition: LArRodBlockCalibrationV3.h:39
LArRodBlockCalibrationV3::NSamples
@ NSamples
Definition: LArRodBlockCalibrationV3.h:43
LArRodBlockCalibrationV3::NTrigger
@ NTrigger
Definition: LArRodBlockCalibrationV3.h:51
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
LArRodBlockCalibrationV3::getResults1Size
virtual uint16_t getResults1Size() const
Definition: LArRodBlockCalibrationV3.cxx:287
LArRodBlockCalibrationV3::NGains
@ NGains
Definition: LArRodBlockCalibrationV3.h:42
LArRodBlockCalibrationV3::Dac
@ Dac
Definition: LArRodBlockCalibrationV3.h:53
PlotCalibFromCool.ngain
ngain
Definition: PlotCalibFromCool.py:565
LArRodBlockCalibrationV3::getNextRawData
virtual int getNextRawData(int &channelNumber, std::vector< short > &samples, uint32_t &gain)
Definition: LArRodBlockCalibrationV3.cxx:58
LArRodBlockCalibrationV3::getDelay
uint16_t getDelay() const
Definition: LArRodBlockCalibrationV3.cxx:273
LArRodBlockStructure::m_channelsPerFEB
int m_channelsPerFEB
Definition: LArRodBlockStructure.h:225
LArRodBlockCalibrationV3::ResultsDim2
@ ResultsDim2
Definition: LArRodBlockCalibrationV3.h:37
LArRodBlockCalibrationV3::endtag
@ endtag
Definition: LArRodBlockCalibrationV3.h:48
LArRodBlockStructure::getHeader16
uint16_t getHeader16(const unsigned n) const
Definition: LArRodBlockStructure.h:355
LArRodBlockCalibrationV3::getDAC
uint16_t getDAC() const
Definition: LArRodBlockCalibrationV3.cxx:266
LArRodBlockCalibrationV3::m_fixedGain
unsigned m_fixedGain
Definition: LArRodBlockCalibrationV3.h:126
LArRodBlockCalibrationV3.h
LArRodBlockCalibrationV3::ResultsDim1
@ ResultsDim1
Definition: LArRodBlockCalibrationV3.h:35