Skip to content

Commit 8ae952b

Browse files
committed
trd fix zero suppressed digit data and speed up
1 parent 61e2e8e commit 8ae952b

9 files changed

Lines changed: 268 additions & 192 deletions

File tree

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

Lines changed: 3 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
312-
uint32_t adcmask : 21;
313310
uint32_t j : 4; // unused always 0xc
311+
uint32_t adcmask : 21;
312+
uint32_t c : 5; // unused always 0x1f
313+
uint32_t n : 2; // unused always 0x3
314314
} __attribute__((__packed__));
315315
};
316316
};

DataFormats/Detectors/TRD/src/RawData.cxx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -440,14 +444,15 @@ void setNumberOfTrackletsInHeader(o2::trd::TrackletMCMHeader& header, int number
440444
int nextmcmadc(unsigned int& bp, int channel)
441445
{
442446
//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) {
446-
break;
447-
}
447+
if(bp==0) return 22;
448+
int position=channel;
449+
int m=1<<channel;
450+
while (!(bp & m)) {
451+
m= m<<1;
452+
position++;
448453
}
449-
bp &= ~(1UL << (channel));
450-
return channel; // zero based
454+
bp &= ~(1UL << (position));
455+
return position;
451456
}
452457

453458
} // namespace trd

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class DigitsParser
112112
uint16_t mChannel;
113113
uint16_t mEventCounter;
114114
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;
115+
std::array<uint16_t, constants::TIMEBINS> mADCValues{};
116116
//uint32_t mCurrentLinkDataPosition256; // count of data read for current link in units of 256 bits
117117
//uint32_t mCurrentLinkDataPosition; // count of data read for current link in units of 256 bits
118118
//uhint32_t mCurrentHalfCRUDataPosition256; //count of data read for this half cru.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class TrackletsParser
104104
bool mReturnVector{false}; // whether weare returing a vector or the raw data buffer.
105105

106106
uint16_t mEventCounter;
107+
std::chrono::duration<double>mTrackletparsetime; // store the time it takes to parse
107108
std::array<uint32_t, o2::trd::constants::HBFBUFFERMAX>::iterator mStartParse, mEndParse; // limits of parsing, effectively the link limits to parse on.
108109
//uint32_t mCurrentLinkDataPosition256; // count of data read for current link in units of 256 bits
109110

Detectors/TRD/reconstruction/src/CruRawReader.cxx

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ bool CruRawReader::processHBFs(int datasizealreadyread, bool verbose)
7070
{
7171
if (mVerbose) {
7272
LOG(info) << "PROCESS HBF starting at " << std::hex << (void*)mDataPointer;
73-
LOG(info) << "PROCESS HBF from payload starting at " << std::hex << (void*)&mHBFPayload[0];
7473
}
7574
mDataRDH = reinterpret_cast<const o2::header::RDHAny*>(mDataPointer);
7675
mOpenRDH = reinterpret_cast<o2::header::RDHAny*>((char*)mDataPointer);
@@ -86,8 +85,6 @@ bool CruRawReader::processHBFs(int datasizealreadyread, bool verbose)
8685
if (mVerbose) {
8786
LOG(info) << "--- RDH open/continue detected loopcount :" << loopcount;
8887
LOG(info) << " rdh first word 0x" << std::hex << (uint32_t)*mDataPointer;
89-
90-
// o2::raw::RDHUtils::printRDH(rdh);
9188
for (int i = 0; i < 64; ++i) {
9289
LOG(info) << std::hex << " 0x" << *(mDataPointer + i);
9390
}
@@ -130,7 +127,7 @@ bool CruRawReader::processHBFs(int datasizealreadyread, bool verbose)
130127
int counthalfcru = 0;
131128
mHBFoffset32 = 0;
132129

133-
while ((mHBFoffset32 < ((mTotalHBFPayLoad) / 4))) {
130+
while ((mHBFoffset32 < ((mTotalHBFPayLoad) / 4))) {// the blank event of eeeeee at the end
134131
if (mVerbose) {
135132
LOG(info) << "Looping over cruheaders in HBF, loop count " << counthalfcru << " current offset is" << mHBFoffset32 << " total payload is " << mTotalHBFPayLoad / 4 << " raw :" << mTotalHBFPayLoad;
136133
}
@@ -146,11 +143,19 @@ bool CruRawReader::processHBFs(int datasizealreadyread, bool verbose)
146143
case 1:
147144
LOG(info) << "all good parsing half cru";
148145
break;
146+
default : return true;
149147
}
150148
}
149+
//take care of the case where there is an "empty" rdh containing all 0xeeeeeeee as payload.
150+
if(mTotalHBFPayLoad/4 - mHBFoffset32 == 8 && mHBFPayload[mHBFoffset32+7]== o2::trd::constants::CRUPADDING32){
151+
mHBFoffset32+=8;
152+
}
151153
counthalfcru++;
154+
if(counthalfcru==1)break;
152155
} // loop of halfcru's while there is still data in the heart beat frame.
153-
mDatareadfromhbf = totaldataread;
156+
if(totaldataread>0){
157+
mDatareadfromhbf = totaldataread;
158+
}
154159
return true; //totaldataread;
155160
}
156161

@@ -193,12 +198,35 @@ int CruRawReader::processHalfCRU(int cruhbfstartoffset)
193198
mCurrentHalfCRULinkLengths.end(),
194199
decltype(mCurrentHalfCRULinkLengths)::value_type(0));
195200
mTotalHalfCRUDataLength = mTotalHalfCRUDataLength256 * 32; //convert to bytes.
201+
202+
if(mDataVerbose){
203+
if(mTotalHalfCRUDataLength!=mTotalHBFPayLoad){
204+
LOG(info) << "mTotalHalfCRUDataLength ?!= mTotalHBFPayLoad " << mTotalHalfCRUDataLength << "?!=" << mTotalHBFPayLoad;
205+
}
206+
}
196207
std::array<uint32_t, 1024>::iterator currentlinkstart = mHBFPayload.begin() + cruhbfstartoffset;
208+
/*LOG(info) << "CRU dump begin ************************** ";
209+
for(int z=0;z<15;++z){
210+
LOG(info) << "link " << z << " length : " << mCurrentHalfCRULinkLengths[z]*8;
211+
}
212+
int linkzcount=0;
213+
uint64_t linkzsum=0;
214+
for(int di=0;di<mTotalHalfCRUDataLength;++di){
215+
LOG(info) << "di:" << di << " " << std::hex << mHBFPayload[di+8];
216+
if(di == cruhbfstartoffset) LOG(info) << "start there ^^^^^";
217+
if(di == mCurrentHalfCRULinkLengths[linkzcount]*8+linkzsum) {LOG(info) << "end of link "<< linkzcount; linkzsum+=mCurrentHalfCRULinkLengths[linkzcount]*8;linkzcount++;}
218+
}
219+
for(int di=mTotalHalfCRUDataLength; di < mTotalHalfCRUDataLength+16;++di){
220+
LOG(info) << "**di:" << di << " " << std::hex << mHBFPayload[di];
221+
}
222+
LOG(info) << "CRU dump end ***************";*/
197223
std::array<uint32_t, 1024>::iterator linkstart, linkend;
198224
int dataoffsetstart32 = sizeof(mCurrentHalfCRUHeader) / 4 + cruhbfstartoffset; // in uint32
199225
//CHECK 1 does rdh endpoint match cru header end point.
200226
if (mCRUEndpoint != mCurrentHalfCRUHeader.EndPoint) {
201227
LOG(warn) << " Endpoint mismatch : CRU Half chamber header endpoint = " << mCurrentHalfCRUHeader.EndPoint << " rdh end point = " << mCRUEndpoint;
228+
//disaster dump the rest of this hbf
229+
return 42;
202230
if (mVerbose) {
203231
LOG(info) << "******* LINK # " << currentlinkindex;
204232
}
@@ -224,6 +252,7 @@ int CruRawReader::processHalfCRU(int cruhbfstartoffset)
224252
linkend = mHBFPayload.begin() + dataoffsetstart32;
225253
//loop over links
226254
for (currentlinkindex = 0; currentlinkindex < constants::NLINKSPERHALFCRU; currentlinkindex++) {
255+
auto linktimerstart = std::chrono::high_resolution_clock::now(); // measure total processing time
227256
currentlinksize = mCurrentHalfCRULinkLengths[currentlinkindex];
228257
currentlinksize32 = currentlinksize * 8; //x8 to go from 256 bits to 32 bit;
229258
linkstart = mHBFPayload.begin() + dataoffsetstart32 + linksizeAccum32;
@@ -238,31 +267,23 @@ int CruRawReader::processHalfCRU(int cruhbfstartoffset)
238267
FeeParam::unpackORI(oriindex, side, stack, layer, halfchamberside);
239268
int currentdetector = stack * constants::NLAYER + layer + supermodule * constants::NLAYER * constants::NSTACK;
240269
if (mVerbose) {
241-
LOG(info) << "******* LINK # " << currentlinkindex << " and unpackORI(" << oriindex << "," << side << "," << stack << "," << layer << "," << halfchamberside << ") and an FEEID:" << std::hex << mFEEID << " det:" << std::dec << currentdetector;
270+
LOG(info) << "******* LINK # " << currentlinkindex << " and starting at "<< mHBFoffset32 << " unpackORI(" << oriindex << "," << side << "," << stack << "," << layer << "," << halfchamberside << ") and an FEEID:" << std::hex << mFEEID << " det:" << std::dec << currentdetector;
242271
}
243272
// tracklet first then digit ??
244273
// tracklets end with tracklet end marker(0x10001000 0x10001000), digits end with digit endmarker (0x0 0x0)
245274
if (linkstart != linkend) { // if link is not empty
246275

247-
if (mVerbose) {
248-
LOG(info) << "parse tracklets ";
249-
}
250276
bool cleardigits = false; //linkstart and linkend already have the multiple cruheaderoffsets built in
251-
if (mVerbose) {
252-
LOG(info) << "mem copy with offset of : " << cruhbfstartoffset << " parsing tracklets with linkstart: " << linkstart << " ending at : " << linkend;
253-
}
254277
trackletwordsread = mTrackletsParser.Parse(&mHBFPayload, linkstart, linkend, mFEEID, halfchamberside, currentdetector, stack, layer, cleardigits, mByteSwap, mTrackletHCHeaderState, mVerbose, mHeaderVerbose, mDataVerbose); // this will read up to the tracklet end marker.
278+
//LOG(info) << mTrackletsParser.getTrackletsFound()<<" Tracklets processed in time : " << std::chrono::duration_cast<std::chrono::milliseconds>(trackletprocessingtime).count() << "ms";
255279
if (mVerbose) {
256280
LOG(info) << "trackletwordsread:" << trackletwordsread << " mem copy with offset of : " << cruhbfstartoffset << " parsing with linkstart: " << linkstart << " ending at : " << linkend;
257281
}
258282
linkstart += trackletwordsread;
259-
//now we have a tracklethcheader and a digithcheader.
283+
//now we have a tracklethcheader and a digithcheader.
260284
mHBFoffset32 += trackletwordsread;
261285
mTotalTrackletsFound += mTrackletsParser.getTrackletsFound();
262286
digitwordsread = 0;
263-
if (mVerbose) {
264-
LOG(info) << "parse digits";
265-
}
266287
//linkstart and linkend already have the multiple cruheaderoffsets built in
267288
digitwordsread = mDigitsParser.Parse(&mHBFPayload, linkstart, linkend, currentdetector, cleardigits, mByteSwap, mVerbose, mHeaderVerbose, mDataVerbose);
268289
if (digitwordsread != std::distance(linkstart, linkend)) {
@@ -278,8 +299,8 @@ int CruRawReader::processHalfCRU(int cruhbfstartoffset)
278299
LOG(info) << "digitwordsread : " << digitwordsread << " mem copy with offset of : " << cruhbfstartoffset << " parsing digits with linkstart: " << linkstart << " ending at : " << linkend;
279300
}
280301
sumlinklengths += mCurrentHalfCRULinkLengths[currentlinkindex];
281-
sumtrackletwords = trackletwordsread;
282-
sumdigitwords = digitwordsread;
302+
sumtrackletwords += trackletwordsread;
303+
sumdigitwords += digitwordsread;
283304
mHBFoffset32 += digitwordsread; // all 3 in 32bit units
284305
} else {
285306
if (mVerbose) {
@@ -307,6 +328,7 @@ int CruRawReader::processHalfCRU(int cruhbfstartoffset)
307328
LOG(info) << "Event digits after eventi # : " << mEventRecords.sumDigits() << " having added : via sum=" << mDigitsParser.getDigits().size() << " digitsfound is " << mDigitsParser.getDigitsFound();
308329
}
309330
int lasttrigger = 0, lastdigit = 0, lasttracklet = 0;
331+
310332
//if we get here all is ok.
311333
return 1;
312334
}

Detectors/TRD/reconstruction/src/DataReaderTask.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ void DataReaderTask::run(ProcessingContext& pc)
106106
int inputpartscount = 0;
107107
int emptyframe = 0;
108108
for (auto const& ref : iit) {
109+
auto inputprocessingstart = std::chrono::high_resolution_clock::now(); // measure total processing time
109110
if (mVerbose) {
110111
const auto dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
111112
LOGP(info, "Found input [{}/{}/{:#x}] TF#{} 1st_orbit:{} Payload {} : ",
@@ -114,7 +115,7 @@ void DataReaderTask::run(ProcessingContext& pc)
114115
const auto* headerIn = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
115116
auto payloadIn = ref.payload;
116117
auto payloadInSize = headerIn->payloadSize;
117-
const auto dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
118+
// const auto dh = DataRefUtils::getHeader<o2::header::DataHeader*>(ref);
118119
if (std::string(headerIn->dataDescription.str) != std::string("DISTSUBTIMEFRAMEFLP")) {
119120
if (!mCompressedData) { //we have raw data coming in from flp
120121
if (mVerbose) {
@@ -134,13 +135,17 @@ void DataReaderTask::run(ProcessingContext& pc)
134135
mCompressedReader.run();
135136
}
136137
} // ignore the input of DISTSUBTIMEFRAMEFLP
138+
// auto inputprocessingtime = std::chrono::high_resolution_clock::now() - inputprocessingstart;
139+
// LOGP(info, "Input [{}/{}/{:#x}] TF#{} 1st_orbit:{} Payload {} : processed in {} us",
140+
// dh->dataOrigin.str, dh->dataDescription.str, dh->subSpecification, dh->tfCounter, dh->firstTForbit, dh->payloadSize,std::chrono::duration_cast<std::chrono::microseconds>(inputprocessingtime).count());
141+
137142
}
138143
/* output */
139144
sendData(pc, false);
140145
}
141146

142147
auto dataReadTime = std::chrono::high_resolution_clock::now() - dataReadStart;
143-
LOG(info) << "Processing time for Data reading " << std::chrono::duration_cast<std::chrono::milliseconds>(dataReadTime).count() << "ms";
148+
LOG(info) << "Processing time for Data reading " << std::chrono::duration_cast<std::chrono::microseconds>(dataReadTime).count() << "us";
144149
if (!mCompressedData) {
145150
LOG(info) << "Digits found : " << mReader.getDigitsFound();
146151
LOG(info) << "Tracklets found : " << mReader.getTrackletsFound();

0 commit comments

Comments
 (0)