ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
9#include <iostream>
10
11
12int 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
34std::array< std::vector<float>, 3 >
35TileDigits2Bytes::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
55int
56TileDigits2Bytes::getGain(const uint32_t *data, int chan) const {
57 return ((*data)>>(12+chan)) & 0x1;
58}
59
64int
65TileDigits2Bytes::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
88int
89TileDigits2Bytes::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
127inline bool
129 return (calculateParity(data) == 1);
130}
131
132inline 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
144inline uint32_t
145TileDigits2Bytes::checkParity(const uint32_t *data, int length) const {
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
161inline bool
162TileDigits2Bytes::checkStartBit(const uint32_t *data, int length, uint32_t startbit) const {
163 bool result = true;
164 for(int i=0;result && (i<length);++i) {
165 result = (data[i]>>31 == startbit);
166 }
167 return result;
168}
double length(const pvec &v)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::pair< std::vector< unsigned int >, bool > res
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>
uint32_t checkParity(const uint32_t *data, int length) const
Verify parity for <length> words.
bool checkWordParity(const uint32_t *data) const
Verify ODD parity for one word.
int getBCID(const uint32_t *data, int chipCount, int wordsPerChip) const
Get BCID from Chip header, bit 0-11.
std::array< std::vector< float >, 3 > getDigits(const uint32_t *data, int dataWordsPerChip) const
Extract samples(digits) for 3 channels, stored in 9 words.
int getBytes(const TileDigits *digi, const TileHWID *tileHWID, std::vector< unsigned int > &v)
uint32_t calculateParity(const uint32_t *data) const
Calculate parity for one word.
int getGain(const uint32_t *data, int chan) const
Extract gain for <chip> in chip header.
int getDigiMode(const uint32_t *data, int chipCount, int wordsPerChip) const
Determine digitizer mode for a number of channels.
const std::vector< float > & samples() const
Definition TileDigits.h:58
Helper class for TileCal online (hardware) identifiers.
Definition TileHWID.h:49
int channel(const HWIdentifier &id) const
extract channel field from HW identifier
Definition TileHWID.h:189
bool is_low_gain(const HWIdentifier &id) const
Test ID for low gain.
Definition TileHWID.cxx:98
HWIdentifier adc_HWID(void) const
Definition TileRawData.h:53