Skip to content

Commit 2fa3ba2

Browse files
authored
speed up and fix up trd raw data reading. (#6799)
* trd fix zero suppressed digit data and speed up * try to remove erroneous digit data at start of tracklet parsing * fix possible bug in bitpattern counting, streamline debug output * moved HCheader parsing, and handle config event * move erroneous adc channels to a more descriptive output, dumping raw data as read * transform headerverbose to useful? and spreadout errors for extra adc * channel determination now at first timebin, sanity checks ruthless. * fix parsing, and dumping data bug
1 parent 5aac19d commit 2fa3ba2

15 files changed

Lines changed: 686 additions & 346 deletions

File tree

DataFormats/Detectors/TRD/include/DataFormatsTRD/Constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ constexpr int TRACKLETENDMARKER = 0x10001000; // marker for the end of tracklets
7272
constexpr int DIGITENDMARKER = 0x0; // marker for the end of digits in raw data, 2 of these
7373
constexpr int MAXDATAPERLINK32 = 13824; // max number of 32 bit words per link ((21x12+2+4)*64) 64 mcm, 21 channels, 10 words per channel 2 header words(DigitMCMHeader DigitMCMADCmask) 4 words for tracklets.
7474
constexpr int MAXDATAPERLINK256 = 1728; // max number of linkwords per cru link. (256bit words)
75-
75+
constexpr int MAXEVENTCOUNTERSEPERATION = 200; // how far appart can subsequent mcmheader event counters be before we flag for concern, used as a sanity check in rawreader.
76+
constexpr int MAXMCMCOUNT = 69120; // at most mcm count maxchamber x nrobc1 nmcmrob
7677
} //namespace constants
7778
} // namespace trd
7879
} // namespace o2

DataFormats/Detectors/TRD/include/DataFormatsTRD/HelperMethods.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ struct HelperMethods {
7171
static int getStack(int det)
7272
{
7373
return det % (constants::NSTACK * constants::NLAYER) / constants::NLAYER;
74-
};
74+
}
7575
static int getLayer(int det)
7676
{
7777
return det % constants::NLAYER;
78-
};
78+
}
7979

8080
static int getORIinSuperModule(int detector, int readoutboard)
8181
{
@@ -112,7 +112,7 @@ struct HelperMethods {
112112
}
113113
//see TDP for explanation of mapping TODO should probably come from CCDB
114114
return ori;
115-
};
115+
}
116116

117117
static int getLinkIDfromHCID(int hcid)
118118
{
@@ -125,7 +125,23 @@ struct HelperMethods {
125125
int ori = -1;
126126
// now offset for supermodule (+60*supermodule);
127127
return HelperMethods::getORIinSuperModule(detector, chamberside) + 60 * supermodule; // it takes readoutboard but only cares if its odd or even hence side here.
128-
};
128+
}
129+
130+
inline static void swapByteOrder(unsigned int& word)
131+
{
132+
word = (word >> 24) |
133+
((word << 8) & 0x00FF0000) |
134+
((word >> 8) & 0x0000FF00) |
135+
(word << 24);
136+
}
137+
inline static unsigned int swapByteOrderreturn(unsigned int word)
138+
{
139+
// word = (word >> 24) |
140+
// ((word << 8) & 0x00FF0000) |
141+
// ((word >> 8) & 0x0000FF00) |
142+
// (word << 24);
143+
return word;
144+
}
129145
};
130146

131147
} // namespace trd

DataFormats/Detectors/TRD/include/DataFormatsTRD/RawData.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ struct DigitMCMADCMask {
307307
union {
308308
uint32_t word; //MCM ADC MASK header
309309
struct {
310-
uint32_t n : 2; // unused always 0x3
311-
uint32_t c : 5; // unused always 0x1f
310+
uint32_t j : 4; // 0xc
312311
uint32_t adcmask : 21;
313-
uint32_t j : 4; // unused always 0xc
312+
uint32_t c : 5; // ~(number of bits set in adcmask)
313+
uint32_t n : 2; // 0b01
314314
} __attribute__((__packed__));
315315
};
316316
};
@@ -440,6 +440,8 @@ std::ostream& operator<<(std::ostream& stream, const HalfCRUHeader& halfcru);
440440
bool trackletMCMHeaderSanityCheck(o2::trd::TrackletMCMHeader& header);
441441
bool trackletHCHeaderSanityCheck(o2::trd::TrackletHCHeader& header);
442442
bool digitMCMHeaderSanityCheck(o2::trd::DigitMCMHeader* header);
443+
bool digitMCMADCMaskSanityCheck(o2::trd::DigitMCMADCMask& mask, int numberofbitsset);
444+
bool digitMCMWordSanityCheck(o2::trd::DigitMCMData* word, int adcchannel);
443445
void printDigitMCMHeader(o2::trd::DigitMCMHeader& header);
444446
void printDigitHCHeader(o2::trd::DigitHCHeader& header);
445447
DigitMCMADCMask buildBlankADCMask();

DataFormats/Detectors/TRD/src/RawData.cxx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ uint32_t getQFromRaw(const o2::trd::TrackletMCMHeader* header, const o2::trd::Tr
124124
qa = header->pid2;
125125
break;
126126
default:
127-
LOG(warn) << " unknown trackletindex to getQFromRaw : " << pidindex;
127+
LOG(warn) << " unknown trackletindex of " << trackletindex << " to getQFromRaw : " << pidindex;
128128
break;
129129
}
130130
//qa is 6bits of Q2 and 2 bits of Q1
@@ -253,6 +253,10 @@ void printHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru)
253253
for (int i = 0; i < 15; i++) {
254254
LOGF(INFO, "Link %d size: %ul eflag: 0x%02x", i, sizes[i], errorflags[i]);
255255
}
256+
LOG(INFO) << "Raw: " << std::hex << halfcru.word0 << " " << halfcru.word12[0] << " " << halfcru.word12[1] << " " << halfcru.word3 << " " << halfcru.word47[0] << " " << halfcru.word47[1] << " " << halfcru.word47[2] << " " << halfcru.word47[3];
257+
for (int i = 0; i < 15; i++) {
258+
LOGF(INFO, "Raw: %d word: %ul x", i, sizes[i], errorflags[i]);
259+
}
256260
}
257261

258262
void dumpHalfCRUHeader(o2::trd::HalfCRUHeader& halfcru)
@@ -357,6 +361,56 @@ bool digitMCMHeaderSanityCheck(o2::trd::DigitMCMHeader* header)
357361
return goodheader;
358362
}
359363

364+
bool digitMCMADCMaskSanityCheck(o2::trd::DigitMCMADCMask& mask, int numberofbitsset)
365+
{
366+
bool goodadcmask = true;
367+
uint32_t count = (unsigned int)mask.c;
368+
count = ~count;
369+
/* if(count != numberofbitsset){
370+
goodadcmask=false;
371+
LOG(warn) << "***DigitMCMADCMask bad bit count maskcount:" << ~mask.c << " bitscounting:" << numberofbitsset;
372+
}*/
373+
if (mask.n != 0x1) {
374+
goodadcmask = false;
375+
LOG(warn) << "***DigitMCMADCMask bad n value should be 0x01 but:0x" << std::hex << mask.n;
376+
}
377+
if (mask.j != 0xc) {
378+
goodadcmask = false;
379+
LOG(warn) << "***DigitMCMADCMask bad j value should be 0xc but:0x" << std::hex << mask.c;
380+
}
381+
return goodadcmask;
382+
}
383+
384+
bool digitMCMWordSanityCheck(o2::trd::DigitMCMData* word, int adcchannel)
385+
{
386+
bool gooddata = true;
387+
// DigitMCMWord0x3 is odd 10 for odd adc channels and 11 for even, counted as the first of the 3.
388+
switch (word->c) {
389+
case 3: // even adc channnel
390+
if (adcchannel % 2 == 0) {
391+
gooddata = true;
392+
} else {
393+
gooddata = false;
394+
}
395+
break;
396+
case 2: // odd adc channel
397+
if (adcchannel % 2 == 1) {
398+
gooddata = true;
399+
} else {
400+
gooddata = false;
401+
}
402+
break;
403+
case 1: // error
404+
gooddata = false;
405+
break;
406+
case 0: // error
407+
gooddata = false;
408+
break;
409+
// no default all cases taken care of
410+
}
411+
return gooddata;
412+
}
413+
360414
void printDigitHCHeader(o2::trd::DigitHCHeader& header)
361415
{
362416
LOGF(INFO, "Digit HalfChamber Header\n Raw:0x%08x 0x%08x reserve:%01x side:%01x stack:0x%02x layer:0x%02x supermod:0x%02x numberHCW:0x%02x minor:0x%03x major:0x%03x version:0x%01x reserve:0x%02x pretriggercount=0x%02x pretriggerphase=0x%02x bunchxing:0x%05x number of timebins : 0x%03x\n",
@@ -440,14 +494,20 @@ void setNumberOfTrackletsInHeader(o2::trd::TrackletMCMHeader& header, int number
440494
int nextmcmadc(unsigned int& bp, int channel)
441495
{
442496
//given a bitpattern (adcmask) find next channel with in the mask starting from the current channel;
443-
while ((bp & (1 << channel)) == 0) {
444-
channel++;
445-
if (channel == 21) {
497+
if (bp == 0) {
498+
return 22;
499+
}
500+
int position = channel;
501+
int m = 1 << channel;
502+
while (!(bp & m)) {
503+
m = m << 1;
504+
position++;
505+
if (position > 31) {
446506
break;
447507
}
448508
}
449-
bp &= ~(1UL << (channel));
450-
return channel; // zero based
509+
bp &= ~(1UL << (position));
510+
return position;
451511
}
452512

453513
} // namespace trd

Detectors/TRD/reconstruction/include/TRDReconstruction/CruRawReader.h

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class CruRawReader
9898
int getTrackletsFound() { return mTotalTrackletsFound; }
9999
int sumTrackletsFound() { return mEventRecords.sumTracklets(); }
100100
int sumDigitsFound() { return mEventRecords.sumDigits(); }
101+
int getWordsRead() { return mTotalDigitWordsRead; }
102+
int getWordsRejected() { return mTotalDigitWordsRejected; }
101103
void clearall()
102104
{
103105
mEventRecords.clear();
@@ -108,6 +110,7 @@ class CruRawReader
108110
mTrackletsParser.clear();
109111
mDigitsParser.clear();
110112
}
113+
void OutputHalfCruRawData();
111114

112115
protected:
113116
bool processHBFs(int datasizealreadyread = 0, bool verbose = false);
@@ -138,6 +141,8 @@ class CruRawReader
138141
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX> mHBFPayload; //this holds the O2 payload held with in the HBFs to pass to parsing.
139142
uint32_t mHalfCRUPayLoadRead{0}; // the words current read in for the currnt cru payload.
140143
uint32_t mO2PayLoadRead{0}; // the words current read in for the currnt cru payload.
144+
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator mStartParse, mEndParse; // limits of parsing, start and end points for parsing.
145+
std::array<uint16_t, constants::TIMEBINS> mADCValues{};
141146
int mCurrentHalfCRULinkHeaderPoisition = 0;
142147
// no need to waste time doing the copy std::array<uint32_t,8> mCurrentCRUWord; // data for a cru comes in words of 256 bits.
143148
uint32_t mCurrentLinkDataPosition256; // count of data read for current link in units of 256 bits
@@ -164,7 +169,7 @@ class CruRawReader
164169
uint16_t mCRUEndpoint; // the upper or lower half of the currently parsed cru 0-14 or 15-29
165170
uint16_t mCRUID;
166171
uint16_t mHCID;
167-
uint16_t mFEEID; // current Fee ID working on
172+
TRDFeeID mFEEID; // current Fee ID working on
168173
std::array<uint32_t, 15> mCurrentHalfCRULinkLengths;
169174
std::array<uint32_t, 15> mCurrentHalfCRULinkErrorFlags;
170175
uint32_t mCRUState; // the state of what we are expecting to read currently from the data stream, *not* what we have just read.
@@ -176,6 +181,10 @@ class CruRawReader
176181
uint32_t mDatareadfromhbf;
177182
uint32_t mTotalHBFPayLoad = 0; // total data payload of the heart beat frame in question.
178183
uint32_t mHBFoffset32 = 0; // total data payload of the heart beat frame in question.
184+
uint64_t mDigitWordsRead = 0;
185+
uint64_t mDigitWordsRejected = 0;
186+
uint64_t mTotalDigitWordsRead = 0;
187+
uint64_t mTotalDigitWordsRejected = 0;
179188
//pointers to the data as we read them in, again no point in copying.
180189
HalfCRUHeader* mhalfcruheader;
181190
o2::InteractionRecord mIR;
@@ -198,20 +207,27 @@ class CruRawReader
198207

199208
EventStorage mEventRecords; // store data range indexes into the above vectors.
200209
bool mReturnBlob{0}; // whether to return blobs or vectors;
201-
struct TRDDataCounters_t { //thisis on a per event basis
210+
struct TRDDataCountersPerEvent_t { //thisis on a per event basis
202211
//TODO this should go into a dpl message for catching by qc ?? I think.
203-
std::array<uint32_t, 1080> LinkWordCounts; //units of 256bits "cru word"
204-
std::array<uint32_t, 1080> LinkPadWordCounts; // units of 32 bits the data pad word size.
205-
std::array<uint32_t, 1080> LinkFreq; //units of 256bits "cru word"
212+
std::array<uint32_t, 1080> mLinkWordCounts; //units of 256bits "cru word"
213+
std::array<uint32_t, 1080> mLinkPadWordCounts; // units of 32 bits the data pad word size.
214+
std::array<uint32_t, 1080> mLinkFreq; //units of 256bits "cru word"
215+
std::array<uint8_t, 1080> mLinkErrorFlag; //units of 256bits "cru word"
206216
//from the above you can get the stats for supermodule and detector.
207-
std::array<bool, 1080> LinkEmpty; // Link only has padding words, probably not serious in pp.
208-
uint32_t EmptyLinks;
217+
std::array<bool, 1080> LinkEmpty; // Link only has padding words only, probably not serious.
209218
//maybe change this to actual traps ?? but it will get large.
210-
std::array<uint32_t, 1080> LinkTrackletPerTrap1; // incremented if a trap on this link has 1 tracklet
211-
std::array<uint32_t, 1080> LinkTrackletPerTrap2; // incremented if a trap on this link has 2 tracklet
212-
std::array<uint32_t, 1080> LinkTrackletPerTrap3; // incremented if a trap on this link has 3 tracklet
213-
std::vector<uint32_t> EmptyTraps; // MCM indexes of traps that are empty ?? list might better
214-
} TRDStatCounters;
219+
std::array<uint32_t, 1080> mLinkTrackletPerTrap1; // incremented if a trap on this link has 1 tracklet
220+
std::array<uint32_t, 1080> mLinkTrackletPerTrap2; // incremented if a trap on this link has 2 tracklet
221+
std::array<uint32_t, 1080> mLinkTrackletPerTrap3; // incremented if a trap on this link has 3 tracklet
222+
std::array<uint32_t, 1080> mLinkMCMsWithData;
223+
std::array<uint16_t, 1080> MCMStatus;
224+
std::array<uint16_t, constants::MAXMCMCOUNT> mMCMstats; // bit pattern for errors current event for a given mcm;
225+
std::vector<uint32_t> mEmptyTraps; // MCM indexes of traps that are empty ?? list might better
226+
} TRDStatCountersPerEvent;
227+
228+
struct TRDDataCountersRunning_t { //those counters that keep counting
229+
//??
230+
} TRDStatCountersRunning;
215231

216232
/** summary data **/
217233
};

Detectors/TRD/reconstruction/include/TRDReconstruction/DataReaderTask.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class DataReaderTask : public Task
5555
bool mCompressedData{false}; // are we dealing with the compressed data from the flp (send via option)
5656
bool mByteSwap{true}; // whether we are to byteswap the incoming data, mc is not byteswapped, raw data is (too be changed in cru at some point)
5757
// o2::header::DataDescription mDataDesc; // Data description of the incoming data
58+
uint64_t mWordsRead = 0;
59+
uint64_t mWordsRejected = 0;
5860
int mTrackletHCHeaderState{0}; // what to do about tracklethcheader, 0 never there, 2 always there, 1 there iff tracklet data, i.e. only there if next word is *not* endmarker 10001000.
5961

6062
std::string mDataDesc;

Detectors/TRD/reconstruction/include/TRDReconstruction/DigitsParser.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,11 @@ class DigitsParser
3939
DigitsParser() = default;
4040
~DigitsParser() = default;
4141
void setData(std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>* data) { mData = data; }
42-
// void setLinkLengths(std::array<uint32_t, 15>& lengths) { mCurrentHalfCRULinkLengths = lengths; };
4342
int Parse(bool verbose = false); // presupposes you have set everything up already.
4443
int Parse(std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>* data, std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator start,
45-
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator end, int detector, bool cleardigits = false, bool disablebyteswap = false, bool verbose = false, bool headerverbose = false, bool dataverbose = false)
46-
{
47-
setData(data);
48-
// setLinkLengths(lengths);
49-
mStartParse = start;
50-
mEndParse = end;
51-
mDetector = detector;
52-
setVerbose(verbose, headerverbose, dataverbose);
53-
if (cleardigits) {
54-
clearDigits();
55-
}
56-
setByteSwap(disablebyteswap);
57-
mReturnVectorPos = 0;
58-
return Parse();
59-
};
44+
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator end, int detector, int stack, int layer, DigitHCHeader& hcheader,
45+
TRDFeeID& feeid, unsigned int linkindex, bool cleardigits = false, bool disablebyteswap = false, bool verbose = false,
46+
bool headerverbose = false, bool dataverbose = false);
6047
enum DigitParserState { StateDigitHCHeader, // always the start of a half chamber.
6148
StateDigitMCMHeader,
6249
StateDigitMCMData,
@@ -77,6 +64,10 @@ class DigitsParser
7764
std::vector<Digit>& getDigits() { return mDigits; }
7865
void clearDigits() { mDigits.clear(); }
7966
void clear() { mDigits.clear(); }
67+
uint64_t getDumpedDataCount() { return mWordsDumped; }
68+
uint64_t getDataWordsParsed() { return mDataWordsParsed; }
69+
void tryFindMCMHeaderAndDisplay(std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator mStartParse);
70+
void OutputIncomingData();
8071

8172
private:
8273
int mState;
@@ -85,6 +76,7 @@ class DigitsParser
8576
int mBufferLocation;
8677
int mPaddingWordsCounter;
8778
bool mSanityCheck{true};
79+
bool mDumpUnknownData{false}; // if the various sanity checks fail, bail out and dump the rest of the data, keeps stats.
8880
bool mByteOrderFix{false}; // simulated data is not byteswapped, real is, so deal with it accodringly.
8981
bool mReturnVector{true}; // whether we are returing a vector or the raw data buffer.
9082
// yes this is terrible design but it works,
@@ -96,8 +88,9 @@ class DigitsParser
9688
// this means that successive calls to Parse simply appends the new digits onto the vector.
9789
// at the end of the event the calling object must pull/copy the vector and clear or clear on next parse.
9890
//
99-
int mParsedWords{0}; // words parsed in data vector, last complete bit is not parsed, and left for another round of data update.
100-
DigitHCHeader* mDigitHCHeader;
91+
// int mParsedWords{0}; // words parsed in data vector, last complete bit is not parsed, and left for another round of data update.
92+
uint64_t mWordsDumped{0}; // words rejected for various reasons.
93+
DigitHCHeader mDigitHCHeader;
10194
DigitMCMHeader* mDigitMCMHeader;
10295
DigitMCMADCMask* mDigitMCMADCMask;
10396
uint32_t mADCMask;
@@ -109,10 +102,15 @@ class DigitsParser
109102
uint16_t mDetector;
110103
uint16_t mMCM;
111104
uint16_t mROB;
112-
uint16_t mChannel;
105+
uint16_t mCurrentADCChannel;
106+
uint16_t mDigitWordCount;
107+
uint16_t mStack;
108+
uint16_t mLayer;
113109
uint16_t mEventCounter;
110+
TRDFeeID mFEEID;
114111
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator mStartParse, mEndParse; // limits of parsing, effectively the link limits to parse on.
115-
// std::array<uint16_t, 60>/*constants::TIMEBINS>*/ mADCValues;
112+
std::array<uint16_t, constants::TIMEBINS> mADCValues{};
113+
std::array<uint16_t, constants::MAXMCMCOUNT> mMCMstats; // bit pattern for errors current event for a given mcm;
116114
//uint32_t mCurrentLinkDataPosition256; // count of data read for current link in units of 256 bits
117115
//uint32_t mCurrentLinkDataPosition; // count of data read for current link in units of 256 bits
118116
//uhint32_t mCurrentHalfCRUDataPosition256; //count of data read for this half cru.

0 commit comments

Comments
 (0)