ATLAS Offline Software
TileDigits2Bytes.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "TileEvent/TileDigits.h"
8 
9 #include <iostream>
10 
11 
12 int TileDigits2Bytes::getBytes(const TileDigits* digi, const TileHWID* tileHWID, std::vector<unsigned int>& v) { // Salukvadze
13  int chID = tileHWID->channel(digi->adc_HWID());
14  int gain = (tileHWID->is_low_gain(digi->adc_HWID()) ? 0 : 1);
15  std::vector<float> digits = digi->samples();
16  unsigned int w;
17  w = (gain << 15) + (digits.size() << 8) + chID;
18  for (unsigned int i=0; i+1<digits.size(); i+=2) {
19  w += (int)digits[i] << 16;
20  v.push_back(w);
21  w = (int)digits[i+1];
22  }
23  if (digits.size() % 2 != 0) {
24  w += (int)digits[digits.size()-1] << 16;
25  v.push_back(w);
26  } else {
27  v.push_back(w);
28  }
29  return digits.size() / 2 + 1;
30 
31 }
32 
33 
34 std::array< std::vector<float>, 3 >
35 TileDigits2Bytes::getDigits(const uint32_t* data, int dataWordsPerChip) const {
36  // create new containers on the heap
37  std::array< std::vector<float>, 3 > digiVec;
38 
39  digiVec[0].reserve(dataWordsPerChip);
40  digiVec[1].reserve(dataWordsPerChip);
41  digiVec[2].reserve(dataWordsPerChip);
42 
43  for(int sampl=0;sampl<dataWordsPerChip;++sampl) {
44  int word = (*data); ++data;
45  digiVec[0].push_back((float)(word & 0x3ff));
46  digiVec[1].push_back((float)((word>>10) & 0x3ff));
47  digiVec[2].push_back((float)((word>>20) & 0x3ff));
48  }
49  return digiVec;
50 }
51 
55 int
57  return ((*data)>>(12+chan)) & 0x1;
58 }
59 
64 int
65 TileDigits2Bytes::getBCID(const uint32_t *data, int chipCount, int wordsPerChip) const {
66  int BCID = 0, n;
67  int modeFound = 0;
68  const uint32_t *wordPtr = data;
69 
70  for(n=0; modeFound<5 && n<chipCount;++n) {
71  if(checkWordParity(wordPtr)) {
72  BCID = (*wordPtr) & 0xfff;
73  // this is correct if header has MSB 1 and next word has MSB 0
74  if (((wordPtr[0]>>31) == 1) && ((wordPtr[1]>>31) == 0)) ++modeFound;
75  }
76  wordPtr += wordsPerChip;
77  }
78  // if no valid mode found, take BCID from first chip
79  if(0 == modeFound) BCID = (*data & 0xfff);
80 
81  return BCID;
82 }
83 
88 int
89 TileDigits2Bytes::getDigiMode(const uint32_t *data, int chipCount, int wordsPerChip) const {
90  int digiMode = -1, n;
91  bool modeFound = false;
92  const uint32_t *wordPtr = data;
93 
94  for(n=0;!modeFound && n<chipCount;++n) {
95  if(checkWordParity(wordPtr)) {
96  digiMode = ((*wordPtr)>>15) & 0x3;
97  // this is correct if header has MSB 1 and next word has MSB 0
98  modeFound = ((wordPtr[0]>>31) == 1) && ((wordPtr[1]>>31) == 0);
99  }
100  wordPtr += wordsPerChip;
101  }
102  // if no valid mode found, ignore parity
103  if(!modeFound) {
104  wordPtr = data;
105  for(n=0;!modeFound && n<chipCount;++n) {
106  digiMode = ((*wordPtr)>>15) & 0x3;
107  // this is correct if header has MSB 1 and next word has MSB 0
108  modeFound = ((wordPtr[0]>>31) == 1) && ((wordPtr[1]>>31) == 0);
109  wordPtr += wordsPerChip;
110  }
111  }
112  // if still no valid mode found
113  if(!modeFound) {
114  if(m_verbose) std::cout<<"<TileD2B> No valid header found, assuming normal mode!"<<std::endl;
115  digiMode = -1;
116  }
117  else if(m_verbose) {
118  if(digiMode > 0) n <<= 1;
119  if(checkWordParity(wordPtr)) std::cout<<"<TileD2B> DigiMode "<<digiMode<<" found in chip header "<<n<<std::endl;
120  else std::cout<<"<TileD2B> DigiMode "<<digiMode<<" found in chip header "<<n<<" with BAD PARITY"<<std::endl;
121  if(digiMode > 0) std::cout<<"<TileD2B> Calibration mode selected!"<<std::endl;
122  }
123 
124  return digiMode;
125 }
126 
127 inline bool
129  return (calculateParity(data) == 1);
130 }
131 
132 inline uint32_t
134  uint32_t res = *data;
135  res ^= ((*data) >> 1);
136  res ^= (res >> 2);
137  res ^= (res >> 4);
138  res ^= (res >> 8);
139  res ^= (res >> 16);
140 
141  return (res & 0x1);
142 }
143 
144 inline uint32_t
146  uint32_t result = 0, tmp;
147  for(int n=0;n<length;++n) {
148  tmp = data[n] ^ (data[n]>> 1);
149  tmp ^= (tmp >> 2);
150  tmp ^= (tmp >> 4);
151  tmp ^= (tmp >> 8);
152  tmp ^= (tmp >> 16);
153  result |= (tmp & 0x1)<<n;
154  }
155  return result;
156 }
157 
161 inline bool
163  bool result = true;
164  for(int i=0;result && (i<length);++i) {
165  result = (data[i]>>31 == startbit);
166  }
167  return result;
168 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
get_generator_info.result
result
Definition: get_generator_info.py:21
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TileDigits2Bytes::getBCID
int getBCID(const uint32_t *data, int chipCount, int wordsPerChip) const
Get BCID from Chip header, bit 0-11.
Definition: TileDigits2Bytes.cxx:65
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TileHWID::is_low_gain
bool is_low_gain(const HWIdentifier &id) const
Test ID for low gain.
Definition: TileHWID.cxx:98
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
TileDigits2Bytes.h
TileDigits2Bytes::checkStartBit
bool checkStartBit(const uint32_t *data, int length, uint32_t startbit) const
Check that the MSB of <length> words are equal to LSB of <startbit>
Definition: TileDigits2Bytes.cxx:162
TileRawData::adc_HWID
HWIdentifier adc_HWID(void) const
Definition: TileRawData.h:53
TileDigits2Bytes::getBytes
int getBytes(const TileDigits *digi, const TileHWID *tileHWID, std::vector< unsigned int > &v)
Definition: TileDigits2Bytes.cxx:12
TileHWID::channel
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition: TileHWID.h:189
TileDigits2Bytes::calculateParity
uint32_t calculateParity(const uint32_t *data) const
Calculate parity for one word.
Definition: TileDigits2Bytes.cxx:133
PixelByteStreamErrors::BCID
@ BCID
Definition: PixelByteStreamErrors.h:13
TileDigits2Bytes::checkWordParity
bool checkWordParity(const uint32_t *data) const
Verify ODD parity for one word.
Definition: TileDigits2Bytes.cxx:128
TileHWID
Helper class for TileCal online (hardware) identifiers.
Definition: TileHWID.h:49
TileDigits2Bytes::getGain
int getGain(const uint32_t *data, int chan) const
Extract gain for <chip> in chip header.
Definition: TileDigits2Bytes.cxx:56
TileHWID.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
beamspotman.n
n
Definition: beamspotman.py:731
TileDigits2Bytes::checkParity
uint32_t checkParity(const uint32_t *data, int length) const
Verify parity for <length> words.
Definition: TileDigits2Bytes.cxx:145
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
TileDigits2Bytes::getDigiMode
int getDigiMode(const uint32_t *data, int chipCount, int wordsPerChip) const
Determine digitizer mode for a number of channels.
Definition: TileDigits2Bytes.cxx:89
TileDigits2Bytes::m_verbose
bool m_verbose
Definition: TileDigits2Bytes.h:96
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TileDigits::samples
const std::vector< float > & samples() const
Definition: TileDigits.h:58
TileDigits
Definition: TileDigits.h:30
TileDigits2Bytes::getDigits
std::array< std::vector< float >, 3 > getDigits(const uint32_t *data, int dataWordsPerChip) const
Extract samples(digits) for 3 channels, stored in 9 words.
Definition: TileDigits2Bytes.cxx:35
python.PyAthena.v
v
Definition: PyAthena.py:154
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
TileDigits.h
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26