ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
TileDigits2Bytes Class Reference

This class converts TileDigits to and from bytestream in ROD format. More...

#include <TileDigits2Bytes.h>

Collaboration diagram for TileDigits2Bytes:

Public Member Functions

 TileDigits2Bytes ()
 
int getBytes (const TileDigits *digi, const TileHWID *tileHWID, std::vector< unsigned int > &v)
 
std::array< std::vector< float >, 3 > getDigits (const uint32_t *data, int dataWordsPerChip) const
 Extract samples(digits) for 3 channels, stored in 9 words. More...
 
int getBCID (const uint32_t *data, int chipCount, int wordsPerChip) const
 Get BCID from Chip header, bit 0-11. More...
 
int getDigiMode (const uint32_t *data, int chipCount, int wordsPerChip) const
 Determine digitizer mode for a number of channels. More...
 
int getGain (const uint32_t *data, int chan) const
 Extract gain for <chip> in chip header. More...
 
bool checkWordParity (const uint32_t *data) const
 Verify ODD parity for one word. More...
 
uint32_t calculateParity (const uint32_t *data) const
 Calculate parity for one word. More...
 
uint32_t checkParity (const uint32_t *data, int length) const
 Verify parity for <length> words. More...
 
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> More...
 
void setVerbose (bool verbose)
 

Private Attributes

bool m_verbose
 

Detailed Description

This class converts TileDigits to and from bytestream in ROD format.

Author
Alexander Solodkov

Definition at line 20 of file TileDigits2Bytes.h.

Constructor & Destructor Documentation

◆ TileDigits2Bytes()

TileDigits2Bytes::TileDigits2Bytes ( )
inline

Definition at line 24 of file TileDigits2Bytes.h.

24 : m_verbose(false) {}

Member Function Documentation

◆ calculateParity()

uint32_t TileDigits2Bytes::calculateParity ( const uint32_t *  data) const
inline

Calculate parity for one word.

Parameters
dataPointer to word
Returns
Parity as LSB

Definition at line 133 of file TileDigits2Bytes.cxx.

133  {
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 }

◆ checkParity()

uint32_t TileDigits2Bytes::checkParity ( const uint32_t *  data,
int  length 
) const
inline

Verify parity for <length> words.

The parity bit for each word is stored in an unsigned int LSB is parity bit from first word and so on.

Parameters
dataPointer to first data word
lengthNumber of data words
Returns
Result of check.

Definition at line 145 of file TileDigits2Bytes.cxx.

145  {
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 }

◆ checkStartBit()

bool TileDigits2Bytes::checkStartBit ( const uint32_t *  data,
int  length,
uint32_t  startbit 
) const
inline

Check that the MSB of <length> words are equal to LSB of <startbit>

MSB of datawords should is checked.

Parameters
dataPointer to forst data word
lengthNumber of words to check
startbitWord with LSB to check against
Returns
If all words were correct

Definition at line 162 of file TileDigits2Bytes.cxx.

162  {
163  bool result = true;
164  for(int i=0;result && (i<length);++i) {
165  result = (data[i]>>31 == startbit);
166  }
167  return result;
168 }

◆ checkWordParity()

bool TileDigits2Bytes::checkWordParity ( const uint32_t *  data) const
inline

Verify ODD parity for one word.

Parameters
dataPointer to data word
Returns
If word has even parity (bool)

Definition at line 128 of file TileDigits2Bytes.cxx.

128  {
129  return (calculateParity(data) == 1);
130 }

◆ getBCID()

int TileDigits2Bytes::getBCID ( const uint32_t *  data,
int  chipCount,
int  wordsPerChip 
) const

Get BCID from Chip header, bit 0-11.

Go through all chip headers, check their parity and extract BCID from them (bits 0-11)

Parameters
dataPointer to first word
chipCountNumber of chips
wordsPerChipNumber of data words per chip
Returns
BCID from chip header with good parity

Definition at line 65 of file TileDigits2Bytes.cxx.

65  {
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 }

◆ getBytes()

int TileDigits2Bytes::getBytes ( const TileDigits digi,
const TileHWID tileHWID,
std::vector< unsigned int > &  v 
)

Definition at line 12 of file TileDigits2Bytes.cxx.

12  { // 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 }

◆ getDigiMode()

int TileDigits2Bytes::getDigiMode ( const uint32_t *  data,
int  chipCount,
int  wordsPerChip 
) const

Determine digitizer mode for a number of channels.

Go through all chip headers, check their parity and extract digi mode from them (bit 15,16)

Parameters
dataPointer to first word
chipCountNumber of chips
wordsPerChipNumber of data words per chip
Returns
Digitizer mode

Definition at line 89 of file TileDigits2Bytes.cxx.

89  {
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 }

◆ getDigits()

std::array< std::vector< float >, 3 > TileDigits2Bytes::getDigits ( const uint32_t *  data,
int  dataWordsPerChip 
) const

Extract samples(digits) for 3 channels, stored in 9 words.

Parameters
dataPointer to ROD-data

Definition at line 35 of file TileDigits2Bytes.cxx.

35  {
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 }

◆ getGain()

int TileDigits2Bytes::getGain ( const uint32_t *  data,
int  chan 
) const

Extract gain for <chip> in chip header.

Gain bits are bit 12-14 in chip header.

Parameters
dataPointer to chip header word
chanis channel number in chip (0-2) return 0-low gain, 1-high gain

Bit 12 corresponds to chan with lowest #.

Definition at line 56 of file TileDigits2Bytes.cxx.

56  {
57  return ((*data)>>(12+chan)) & 0x1;
58 }

◆ setVerbose()

void TileDigits2Bytes::setVerbose ( bool  verbose)
inline

Definition at line 92 of file TileDigits2Bytes.h.

92 { m_verbose=verbose; }

Member Data Documentation

◆ m_verbose

bool TileDigits2Bytes::m_verbose
private

Definition at line 96 of file TileDigits2Bytes.h.


The documentation for this class was generated from the following files:
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
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:97
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
TileRawData::adc_HWID
HWIdentifier adc_HWID(void) const
Definition: TileRawData.h:53
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
lumiFormat.i
int i
Definition: lumiFormat.py:92
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
beamspotman.n
n
Definition: beamspotman.py:731
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
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
python.PyAthena.v
v
Definition: PyAthena.py:157
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26