Skip to content

Commit f47284c

Browse files
sevdokimshahor02
authored andcommitted
Renamed classes in DataFormatsCPV/RawFormats.h
1 parent d62adae commit f47284c

7 files changed

Lines changed: 148 additions & 135 deletions

File tree

DataFormats/Detectors/CPV/include/DataFormatsCPV/RawFormats.h

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,118 +28,118 @@ union PadWord {
2828
uint32_t address : 6; ///< Bits 12 - 17 : address (0..47)
2929
uint32_t gas : 3; ///< Bits 18 - 20 : gasiplex (1..10)
3030
uint32_t dil : 2; ///< Bits 21 - 22 : dilogic (1..24)
31-
uint32_t zero : 1; ///< Bits 23 - 23 : zeroed
31+
uint32_t zero : 1; ///< Bits 23 - 23 : control bit (0 -> pad word, 1 -> FEE control word)
3232
};
33-
char bytes[4];
33+
char mBytes[4];
3434
};
3535

36-
class cpvword
36+
class CpvWord
3737
{
3838
public:
39-
cpvword() = default;
40-
cpvword(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
39+
CpvWord() = default;
40+
CpvWord(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
4141
{ //Reading
4242
//resposibility of coller to esure that
4343
//array will not end while reading
4444
for (int i = 0; i < 16 && b != e; i++, b++) {
45-
bytes[i] = *b;
45+
mBytes[i] = *b;
4646
}
4747
}
48-
~cpvword() = default;
48+
~CpvWord() = default;
4949
bool isOK() const
5050
{
51-
return (bytes[9] < static_cast<unsigned char>(24)) &&
52-
(bytes[15] == 0) && (bytes[14] == 0) && (bytes[13] == 0) && (bytes[12] == 0) && (bytes[11] == 0) && (bytes[10] == 0);
51+
return (mBytes[9] < static_cast<unsigned char>(24)) &&
52+
(mBytes[15] == 0) && (mBytes[14] == 0) && (mBytes[13] == 0) && (mBytes[12] == 0) && (mBytes[11] == 0) && (mBytes[10] == 0);
5353
}
54-
short ccId() const { return short(bytes[9]); }
54+
short ccId() const { return short(mBytes[9]); }
5555
uint32_t cpvPadWord(int i) const
5656
{
5757
PadWord p = {0};
58-
p.bytes[0] = bytes[3 * i];
59-
p.bytes[1] = bytes[3 * i + 1];
60-
p.bytes[2] = bytes[3 * i + 2];
58+
p.mBytes[0] = mBytes[3 * i];
59+
p.mBytes[1] = mBytes[3 * i + 1];
60+
p.mBytes[2] = mBytes[3 * i + 2];
6161
return p.mDataWord;
6262
}
6363

6464
public:
65-
unsigned char bytes[16] = {0};
65+
unsigned char mBytes[16] = {0};
6666
};
6767

68-
class cpvheader
68+
class CpvHeader
6969
{
7070
public:
71-
cpvheader() = default;
72-
cpvheader(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
71+
CpvHeader() = default;
72+
CpvHeader(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
7373
{ //reading header from file
74-
for (int i = 0; i < 16 && b != e; i++, b++) { //read up to 16 bytes
75-
bytes[i] = *b;
74+
for (int i = 0; i < 16 && b != e; i++, b++) { //read up to 16 mBytes
75+
mBytes[i] = *b;
7676
}
7777
}
78-
cpvheader(InteractionRecord orbitBC, bool isNoDataExpected, bool isDataContinued)
78+
CpvHeader(InteractionRecord orbitBC, bool isNoDataExpected, bool isDataContinued)
7979
{ //writing header
8080
//header is 128-bit word.
8181
//|127-120|119-112|111-104|103-96|95-88 |87-80 |79-72|71-64|63-56|55-48|47-40|39-32|31-24|23-16|15-8 |7-0 |
8282
// byte15 byte14 byte13 byte12 byte11 byte10 byte9 byte8 byte7 byte6 byte5 byte4 byte3 byte2 byte1 byte0
8383
//byte = |76543210|
84-
bytes[0] = (0x010 & 0x0ff); //bits 11 - 0 trigger id (0x010 = physics trigger)
85-
bytes[1] = ((0x010 & 0xf00) >> 8) //bits 11 - 0 trigger id (0x010 = physics trigger)
86-
+ 0b00100000 * isNoDataExpected + 0b0100000 * isDataContinued; //bit 13 (no data for this trigger) + bit 14 (payload continues from previous page)
87-
bytes[2] = (orbitBC.bc & 0x00ff); //bits 27 - 16 bunch crossing
88-
bytes[3] = (orbitBC.bc & 0x0f00) >> 8; //bits 27 - 16 bunch crossing
89-
bytes[4] = (orbitBC.orbit & 0x000000ff); //bits 63 - 32 orbit
90-
bytes[5] = (orbitBC.orbit & 0x0000ff00) >> 8; //bits 63 - 32 orbit
91-
bytes[6] = (orbitBC.orbit & 0x00ff0000) >> 16; //bits 63 - 32 orbit
92-
bytes[7] = (orbitBC.orbit & 0xff000000) >> 24; //bits 63 - 32 orbit
93-
bytes[8] = 0x00; //bits 64-71 reserved
94-
bytes[9] = 0xe0; //word ID of cpv header (bits 79 - 72)
84+
mBytes[0] = (0x010 & 0x0ff); //bits 11 - 0 trigger id (0x010 = physics trigger)
85+
mBytes[1] = ((0x010 & 0xf00) >> 8) //bits 11 - 0 trigger id (0x010 = physics trigger)
86+
+ 0b00100000 * isNoDataExpected + 0b0100000 * isDataContinued; //bit 13 (no data for this trigger) + bit 14 (payload continues from previous page)
87+
mBytes[2] = (orbitBC.bc & 0x00ff); //bits 27 - 16 bunch crossing
88+
mBytes[3] = (orbitBC.bc & 0x0f00) >> 8; //bits 27 - 16 bunch crossing
89+
mBytes[4] = (orbitBC.orbit & 0x000000ff); //bits 63 - 32 orbit
90+
mBytes[5] = (orbitBC.orbit & 0x0000ff00) >> 8; //bits 63 - 32 orbit
91+
mBytes[6] = (orbitBC.orbit & 0x00ff0000) >> 16; //bits 63 - 32 orbit
92+
mBytes[7] = (orbitBC.orbit & 0xff000000) >> 24; //bits 63 - 32 orbit
93+
mBytes[8] = 0x00; //bits 64-71 reserved
94+
mBytes[9] = 0xe0; //word ID of cpv header (bits 79 - 72)
9595
for (int i = 10; i < 16; i++) {
96-
bytes[i] = 0; //bits 127-80 must be zeros
96+
mBytes[i] = 0; //bits 127-80 must be zeros
9797
}
9898
}
99-
~cpvheader() = default;
100-
bool isOK() const { return (bytes[9] == 0xe0) && (bytes[10] == 0) && (bytes[11] == 0) && (bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0) && (bytes[15] == 0); }
101-
bool isNoDataExpected() const { return bytes[1] & 0b00100000; }
102-
bool isDataContinued() const { return bytes[1] & 0b0100000; }
103-
uint16_t bc() const { return bytes[2] + ((bytes[3] & 0x0f) << 8); }
104-
uint32_t orbit() const { return bytes[4] + (bytes[5] << 8) + (bytes[6] << 16) + (bytes[7] << 24); }
99+
~CpvHeader() = default;
100+
bool isOK() const { return (mBytes[9] == 0xe0) && (mBytes[10] == 0) && (mBytes[11] == 0) && (mBytes[12] == 0) && (mBytes[13] == 0) && (mBytes[14] == 0) && (mBytes[15] == 0); }
101+
bool isNoDataExpected() const { return mBytes[1] & 0b00100000; }
102+
bool isDataContinued() const { return mBytes[1] & 0b0100000; }
103+
uint16_t bc() const { return mBytes[2] + ((mBytes[3] & 0x0f) << 8); }
104+
uint32_t orbit() const { return mBytes[4] + (mBytes[5] << 8) + (mBytes[6] << 16) + (mBytes[7] << 24); }
105105

106106
public:
107-
unsigned char bytes[16] = {0}; //0 - 127 bits (16 bytes)
107+
unsigned char mBytes[16] = {0}; //0 - 127 bits (16 bytes)
108108
};
109109

110-
class cpvtrailer
110+
class CpvTrailer
111111
{
112112
public:
113-
cpvtrailer() = default;
114-
cpvtrailer(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
113+
CpvTrailer() = default;
114+
CpvTrailer(std::vector<char>::const_iterator b, std::vector<char>::const_iterator e)
115115
{ //reading
116-
for (int i = 0; i < 16 && b != e; i++, b++) { //read up to 16 bytes
117-
bytes[i] = *b;
116+
for (int i = 0; i < 16 && b != e; i++, b++) { //read up to 16 mBytes
117+
mBytes[i] = *b;
118118
}
119119
}
120-
cpvtrailer(unsigned short wordCounter, uint16_t bunchCrossing, bool isAllDataSent)
121-
{ //writing
122-
bytes[0] = bunchCrossing & 0x00ff; //bits 11 - 0 bunch crossing
123-
bytes[1] = ((bunchCrossing & 0x0f00) >> 8) //bits 11 - 0 bunch crossing
124-
+ ((wordCounter & 0x0f) << 4); //bits 20 - 12 wordCounter
125-
bytes[2] = (wordCounter & 0b111110000) >> 4; //bits 20 - 12 wordCounter
120+
CpvTrailer(unsigned short wordCounter, uint16_t bunchCrossing, bool isAllDataSent)
121+
{ //writing
122+
mBytes[0] = bunchCrossing & 0x00ff; //bits 11 - 0 bunch crossing
123+
mBytes[1] = ((bunchCrossing & 0x0f00) >> 8) //bits 11 - 0 bunch crossing
124+
+ ((wordCounter & 0x0f) << 4); //bits 20 - 12 wordCounter
125+
mBytes[2] = (wordCounter & 0b111110000) >> 4; //bits 20 - 12 wordCounter
126126
for (int i = 3; i < 8; i++) {
127-
bytes[i] = 0; //bits 70 - 21 reserved
127+
mBytes[i] = 0; //bits 70 - 21 reserved
128128
}
129-
bytes[8] = isAllDataSent * 0b10000000; //bit 71 all data is sent for current trigger
130-
bytes[9] = char(0xf0); //word ID of cpv trailer
129+
mBytes[8] = isAllDataSent * 0b10000000; //bit 71 all data is sent for current trigger
130+
mBytes[9] = char(0xf0); //word ID of cpv trailer
131131
for (int i = 10; i < 16; i++) {
132-
bytes[i] = 0;
132+
mBytes[i] = 0;
133133
}
134134
}
135-
~cpvtrailer() = default;
136-
bool isOK() const { return (bytes[9] == 0xf0) && (bytes[10] == 0) && (bytes[11] == 0) && (bytes[12] == 0) && (bytes[13] == 0) && (bytes[14] == 0) && (bytes[15] == 0); }
137-
uint16_t wordCounter() const { return (bytes[1] >> 4) + ((bytes[2] & 0b00011111) << 4); }
138-
bool isAllDataSent() const { return (bytes[8] & 0b10000000); }
139-
uint16_t bc() const { return bytes[0] + ((bytes[1] & 0x0f) << 8); }
135+
~CpvTrailer() = default;
136+
bool isOK() const { return (mBytes[9] == 0xf0) && (mBytes[10] == 0) && (mBytes[11] == 0) && (mBytes[12] == 0) && (mBytes[13] == 0) && (mBytes[14] == 0) && (mBytes[15] == 0); }
137+
uint16_t wordCounter() const { return (mBytes[1] >> 4) + ((mBytes[2] & 0b00011111) << 4); }
138+
bool isAllDataSent() const { return (mBytes[8] & 0b10000000); }
139+
uint16_t bc() const { return mBytes[0] + ((mBytes[1] & 0x0f) << 8); }
140140

141141
public:
142-
unsigned char bytes[16] = {0};
142+
unsigned char mBytes[16] = {0};
143143
};
144144

145145
} // namespace cpv

Detectors/CPV/calib/CPVCalibWorkflow/src/CPVGainCalibDevice.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void CPVGainCalibDevice::run(o2::framework::ProcessingContext& ctx)
7676
continue;
7777
}
7878
// Loop over all the channels
79-
for (std::pair<uint32_t, uint16_t> adchbc : decoder.getDigits()) {
80-
AddressCharge ac = {adchbc.first};
79+
for (auto adch : decoder.getDigits()) {
80+
AddressCharge ac = {adch};
8181
unsigned short absId = ac.Address;
8282
mMean->Fill(absId, ac.Charge);
8383
}

Detectors/CPV/calib/CPVCalibWorkflow/src/CPVPedestalCalibDevice.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void CPVPedestalCalibDevice::run(o2::framework::ProcessingContext& ctx)
6868
continue;
6969
}
7070
// Loop over all the channels
71-
for (std::pair<uint32_t, uint16_t> adchbc : decoder.getDigits()) {
72-
AddressCharge ac = {adchbc.first};
71+
for (auto adch : decoder.getDigits()) {
72+
AddressCharge ac = {adch};
7373
unsigned short absId = ac.Address;
7474
mMean->Fill(absId, ac.Charge);
7575
}

Detectors/CPV/reconstruction/include/CPVReconstruction/RawDecoder.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ union AddressCharge {
4747
};
4848
};
4949

50+
/// BC reference to digits
51+
struct BCRecord {
52+
BCRecord() = default;
53+
BCRecord(uint16_t bunchCrossing, unsigned int first, unsigned int last) : bc(bunchCrossing), firstDigit(first), lastDigit(last) {}
54+
uint16_t bc;
55+
unsigned int firstDigit;
56+
unsigned int lastDigit;
57+
};
58+
5059
/// \class RawDecoder
5160
/// \brief Decoder of the ALTRO data in the raw page
5261
/// \ingroup CPVreconstruction
@@ -55,9 +64,7 @@ union AddressCharge {
5564
///
5665
/// This is a base class for reading raw data digits.
5766
/// It takes raw cpv payload from RawReaderMemory and produces
58-
/// std::vector<std::pair<uint32_t, uint16_t>> mDigits
59-
/// mDigits[i].first is AddressCharge word and
60-
/// mDigits[i].second is bc number in current HBF
67+
/// std::vector<uint32_t> mDigits and std::vector<BCRecord> mBCRecords
6168

6269
class RawDecoder
6370
{
@@ -76,15 +83,16 @@ class RawDecoder
7683
/// cpvwords and cpvtrailer.
7784
/// After successfull decoding the Decoder can provide
7885
/// a reference to a vector
79-
/// with the decoded chanenels, each containing
80-
/// its BC numbers.
86+
/// with the decoded chanenels and their bc reference
8187
RawErrorType_t decode();
8288

8389
/// \brief Get the reference to the digits container
8490
/// \return Reference to the digits container
85-
const std::vector<std::pair<uint32_t, uint16_t>>& getDigits() const;
91+
const std::vector<uint32_t>& getDigits() const { return mDigits; };
8692

87-
/// \brief Get the reference to the BC
93+
/// \brief Get the reference to the BC records
94+
/// \return reference to the BC records
95+
const std::vector<o2::cpv::BCRecord>& getBCRecords() const { return mBCRecords; };
8896

8997
/// \brief Get the reference to the list of decoding errors
9098
/// \return Reference to the list of decoding errors
@@ -95,20 +103,14 @@ class RawDecoder
95103
RawErrorType_t readChannels();
96104

97105
private:
98-
/// \brief run checks on the RCU trailer
99-
/// \throw Error if the RCU trailer has inconsistencies
100-
///
101-
/// Performing various consistency checks on the RCU trailer
102-
/// In case of failure an exception is thrown.
103-
//void checkRCUTrailer();
104-
105106
void addDigit(uint32_t padWord, short ddl, uint16_t bc);
106107
void removeLastNDigits(int n);
107108

108-
RawReaderMemory& mRawReader; ///< underlying raw reader
109-
std::vector<std::pair<uint32_t, uint16_t>> mDigits; ///< vector of channels and BCs in the raw stream
110-
std::vector<RawDecoderError> mErrors; ///< vector of decoding errors
111-
bool mChannelsInitialized = false; ///< check whether the channels are initialized
109+
RawReaderMemory& mRawReader; ///< underlying raw reader
110+
std::vector<uint32_t> mDigits; ///< vector of channels and BCs in the raw stream
111+
std::vector<o2::cpv::BCRecord> mBCRecords; ///< vector of bc references to digits
112+
std::vector<RawDecoderError> mErrors; ///< vector of decoding errors
113+
bool mChannelsInitialized = false; ///< check whether the channels are initialized
112114

113115
ClassDefNV(RawDecoder, 2);
114116
};

Detectors/CPV/reconstruction/src/RawDecoder.cxx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RawErrorType_t RawDecoder::decode()
2828
auto& rdh = mRawReader.getRawHeader();
2929
short linkID = o2::raw::RDHUtils::getLinkID(rdh);
3030
mDigits.clear();
31+
mBCRecords.clear();
3132

3233
auto payloadWords = mRawReader.getPayload();
3334
if (payloadWords.size() == 0) {
@@ -51,7 +52,7 @@ RawErrorType_t RawDecoder::readChannels()
5152
auto b = payloadWords.cbegin();
5253
auto e = payloadWords.cend();
5354
while (b != e) { //payload must start with cpvheader folowed by cpvwords and finished with cpvtrailer
54-
cpvheader header(b, e);
55+
CpvHeader header(b, e);
5556
if (header.isOK()) {
5657
if (!isHeaderExpected) { //actually, header was not expected
5758
LOG(ERROR) << "RawDecoder::readChannels() : "
@@ -74,7 +75,7 @@ RawErrorType_t RawDecoder::readChannels()
7475
b += 16;
7576
continue; //continue while'ing until it's not header
7677
}
77-
cpvword word(b, e);
78+
CpvWord word(b, e);
7879
if (word.isOK()) {
7980
wordCountFromLastHeader++;
8081
for (int i = 0; i < 3; i++) {
@@ -85,7 +86,7 @@ RawErrorType_t RawDecoder::readChannels()
8586
}
8687
}
8788
} else { //this may be trailer
88-
cpvtrailer trailer(b, e);
89+
CpvTrailer trailer(b, e);
8990
if (trailer.isOK()) {
9091
int diffInCount = wordCountFromLastHeader - trailer.wordCounter();
9192
if (diffInCount > 1 ||
@@ -123,35 +124,40 @@ RawErrorType_t RawDecoder::readChannels()
123124
return kOK;
124125
}
125126

126-
const std::vector<std::pair<uint32_t, uint16_t>>& RawDecoder::getDigits() const
127-
{
128-
/*if (!mChannelsInitialized) {
129-
LOG(ERROR) << "RawDecoder::getDigits() : Channels not initialized";
130-
}*/
131-
return mDigits;
132-
}
133-
134127
void RawDecoder::addDigit(uint32_t w, short ccId, uint16_t bc)
135128
{
129+
//new bc -> add bc reference
130+
if (mBCRecords.empty() || (mBCRecords.back().bc != bc)) {
131+
mBCRecords.push_back(BCRecord(bc, mDigits.size(), mDigits.size()));
132+
} else {
133+
mBCRecords.back().lastDigit++;
134+
}
135+
136+
//add digit
136137
PadWord pad = {w};
137138
unsigned short absId;
138139
o2::cpv::Geometry::hwaddressToAbsId(ccId, pad.dil, pad.gas, pad.address, absId);
139140

140141
AddressCharge ac = {0};
141142
ac.Address = absId;
142143
ac.Charge = pad.charge;
143-
//std::pair<uint32_t, uint16_t> digitAndBC
144-
mDigits.push_back(std::pair(ac.mDataWord, bc));
144+
mDigits.push_back(ac.mDataWord);
145145
}
146146

147147
void RawDecoder::removeLastNDigits(int n)
148148
{
149-
if (n < 0)
149+
if (n < 0) {
150150
return;
151+
}
151152
int nRemoved = 0;
152153
while (nRemoved < n) {
153154
if (mDigits.size() > 0) { // still has digits to remove
154155
mDigits.pop_back();
156+
if (mBCRecords.back().lastDigit == mBCRecords.back().firstDigit) {
157+
mBCRecords.pop_back();
158+
} else {
159+
mBCRecords.back().lastDigit--;
160+
}
155161
nRemoved++;
156162
} else { // has nothing to remove already
157163
break;

0 commit comments

Comments
 (0)