Skip to content

Commit 18e9250

Browse files
committed
TRD raw reader update
1 parent a8d18d8 commit 18e9250

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include "DataFormatsTRD/Constants.h"
1616
#include <iostream>
17+
#include <string>
18+
#include <fmt/format.h>
1719

1820
namespace o2
1921
{
@@ -54,12 +56,17 @@ struct HelperMethods {
5456
printf("%02i_%i_%i\n", det / constants::NCHAMBERPERSEC, (det % constants::NCHAMBERPERSEC) / constants::NLAYER, det % constants::NLAYER);
5557
}
5658

57-
static void printSectorStackLayerSide(int hcid)
59+
static std::string getSectorStackLayerSide(int hcid)
5860
{
59-
// for a given half-chamber number prints SECTOR_STACK_LAYER_side
6061
int det = hcid / 2;
6162
std::string side = (hcid % 2 == 0) ? "A" : "B";
62-
printf("%02i_%i_%i%s\n", det / constants::NCHAMBERPERSEC, (det % constants::NCHAMBERPERSEC) / constants::NLAYER, det % constants::NLAYER, side.c_str());
63+
return fmt::format("{}_{}_{}{}", getSector(det), getStack(det), getLayer(det), side);
64+
}
65+
66+
static void printSectorStackLayerSide(int hcid)
67+
{
68+
// for a given half-chamber number prints SECTOR_STACK_LAYER_side
69+
printf("%s\n", getSectorStackLayerSide(hcid).c_str());
6370
}
6471

6572
static int getPadColFromADC(int irob, int imcm, int iadc)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ class CruRawReader
119119
// given the total link size and the hcid from the RDH
120120
// parse the tracklet data. Overwrite hcid from TrackletHCHeader if mismatch is detected
121121
// trackletWordsRejected: count the number of words which were skipped (subset of words read)
122-
// returns total number of words read (no matter if parsed successfully or not)
123-
int parseTrackletLinkData(int linkSize32, int& hcid, int& trackletWordsRejected);
122+
// trackletWordsReadOK: count the number of words which could be read consecutively w/o errors
123+
// numberOfTrackletsFound: count the number of tracklets found
124+
// returns total number of words read (no matter if parsed successfully or not) or -1 in case of failure
125+
int parseTrackletLinkData(int linkSize32, int& hcid, int& trackletWordsRejected, int& trackletWordsReadOK, int& numberOfTrackletsFound);
124126

125127
// the parsing begins after the DigitHCHeaders have been parsed already
126128
// maxWords32 is the remaining number of words for the given link

Detectors/TRD/reconstruction/src/CruRawReader.cxx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ bool CruRawReader::processHalfCRU(int iteration)
500500
mEventRecords.incLinkWords(halfChamberId, mCurrentHalfCRULinkLengths[currentlinkindex]);
501501
uint32_t currentlinksize32 = mCurrentHalfCRULinkLengths[currentlinkindex] * 8; // x8 to go from 256 bits to 32 bit;
502502
uint32_t endOfCurrentLink = mHBFoffset32 + currentlinksize32;
503-
503+
if (mOptions[TRDVerboseBit] && currentlinksize32 > 0) {
504+
LOGP(info, "Reading {} (link ID {}, HCID {}) with {} 32-bit words", HelperMethods::getSectorStackLayerSide(halfChamberId), linkIdxGlobal, halfChamberId, currentlinksize32);
505+
}
504506
linksizeAccum32 += currentlinksize32;
505507
if (currentlinksize32 == 0) {
506508
mEventRecords.incLinkNoData(halfChamberId);
@@ -521,8 +523,13 @@ bool CruRawReader::processHalfCRU(int iteration)
521523
LOGF(info, "Tracklet parser starting at offset %u and processing up to %u words", mHBFoffset32, currentlinksize32);
522524
}
523525
int trackletWordsRejected = 0;
524-
int trackletWordsRead = parseTrackletLinkData(currentlinksize32, halfChamberId, trackletWordsRejected);
526+
int trackletWordsReadOK = 0;
527+
int numberOfTrackletsFound = 0; // count the number of found tracklets for this link
528+
int trackletWordsRead = parseTrackletLinkData(currentlinksize32, halfChamberId, trackletWordsRejected, trackletWordsReadOK, numberOfTrackletsFound);
525529
std::chrono::duration<float, std::micro> trackletparsingtime = std::chrono::high_resolution_clock::now() - trackletparsingstart;
530+
if (mOptions[TRDVerboseBit]) {
531+
LOGP(info, "Could read {} 32-bit words w/o errors, found {} tracklets, rejected {} 32-bit words for {}. Parsing OK? {}", trackletWordsReadOK, numberOfTrackletsFound, trackletWordsRejected, HelperMethods::getSectorStackLayerSide(halfChamberId), (trackletWordsRead != -1 && trackletWordsRejected == 0));
532+
}
526533
if (trackletWordsRead == -1) {
527534
// something went wrong bailout of here.
528535
mHBFoffset32 = hbfOffsetTmp + linksizeAccum32;
@@ -544,7 +551,7 @@ bool CruRawReader::processHalfCRU(int iteration)
544551
}
545552
mEventRecords.getCurrentEventRecord().incTrackletTime(trackletparsingtime.count());
546553
if (mOptions[TRDVerboseBit]) {
547-
LOGF(info, "Read %i tracklet words and rejected %i words", trackletWordsRead, trackletWordsRejected);
554+
LOGF(debug, "Read %i tracklet words and rejected %i words", trackletWordsRead, trackletWordsRejected);
548555
}
549556
mTrackletWordsRejected += trackletWordsRejected;
550557
mTrackletWordsRead += trackletWordsRead;
@@ -836,10 +843,9 @@ int CruRawReader::parseDigitLinkData(int maxWords32, int hcid, int& wordsRejecte
836843
}
837844

838845
// Returns number of words read (>=0) or error state (<0)
839-
int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRejected)
846+
int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRejected, int& wordsReadOK, int& trackletsFound)
840847
{
841848
int wordsRead = 0; // count the number of words which were parsed (both successful and not successful)
842-
int numberOfTrackletsFound = 0; // count the number of found tracklets for this link
843849
int state = StateTrackletHCHeader; // we expect to always see a TrackletHCHeader at the beginning of the link
844850
// tracklet data for one link is expected to arrive ordered
845851
// first MCM in row=0, column=0, then row=0, column=1, ... row=1, column=0, ...
@@ -865,6 +871,7 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
865871
// either the TrackletHCHeader is corrupt or we have only digits on this link
866872
return 0;
867873
}
874+
++wordsReadOK;
868875
state = StateTrackletMCMHeader; // we do expect tracklets following
869876
} else {
870877
// we always expect a TrackletHCHeader as first word for a link (default)
@@ -876,12 +883,14 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
876883
++wordsRejected;
877884
continue;
878885
}
886+
++wordsReadOK;
879887
state = StateTrackletMCMHeader; // we might have tracklets following or tracklet end markers
880888
}
881889
} // StateTrackletHCHeader
882890

883891
else if (state == StateTrackletMCMHeader) {
884892
if (currWord == TRACKLETENDMARKER) {
893+
++wordsReadOK;
885894
state = StateSecondEndmarker; // we expect a second tracklet end marker to follow
886895
} else {
887896
mcmHeader.word = currWord;
@@ -912,6 +921,7 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
912921
previousColumn = mcmHeader.col;
913922
previousRow = mcmHeader.padrow;
914923
}
924+
++wordsReadOK;
915925
state = StateTrackletMCMData; // tracklet words must be following, unless the HC header format indicates sending of empty MCM headers
916926
}
917927
++wordsRead;
@@ -935,20 +945,23 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
935945
break;
936946
}
937947
if ((currWord & 0x1) == 0x1) {
938-
// the reserved bit of the trackler MCM data is set
948+
// the reserved bit of the tracklet MCM data is set, we don't create a tracklet from this word
939949
incrementErrors(TrackletMCMDataFailure, hcid, fmt::format("Invalid word {:#010x} for the expected TrackletMCMData", currWord));
940950
++wordsRejected;
951+
++wordsRead;
952+
continue;
941953
}
942954
TrackletMCMData mcmData;
943955
mcmData.word = currWord;
944956
mEventRecords.getCurrentEventRecord().addTracklet(assembleTracklet64(hcHeader.format, mcmHeader, mcmData, iCpu, hcid));
945-
++numberOfTrackletsFound;
957+
++trackletsFound;
946958
++mTrackletsFound;
947959
addedTracklet = true;
948960
++wordsRead;
961+
++wordsReadOK;
949962
if (wordsRead == linkSize32) {
950963
incrementErrors(TrackletNoTrackletEndMarker, hcid, fmt::format("After reading the word {:#010x} we are at the end of the link data", currWord));
951-
return wordsRead;
964+
return -1;
952965
}
953966
currWord = mHBFPayload[mHBFoffset32 + wordsRead];
954967
}
@@ -978,9 +991,10 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
978991
else if (state == StateSecondEndmarker) {
979992
++wordsRead;
980993
if (currWord != TRACKLETENDMARKER) {
981-
incrementErrors(TrackletNoSecondEndMarker, hcid, fmt::format("Expected second tracklet end marker, but found {:#010x} instead", currWord));
994+
incrementErrors(TrackletNoSecondEndMarker, hcid, fmt::format("Invalid word {:#010x} for the expected second end marker", currWord));
982995
return -1;
983996
}
997+
++wordsReadOK;
984998
state = StateFinished;
985999
} // StateSecondEndmarker
9861000

@@ -1001,7 +1015,7 @@ int CruRawReader::parseTrackletLinkData(int linkSize32, int& hcid, int& wordsRej
10011015

10021016
} // end of state machine
10031017

1004-
if (mTrackletHCHeaderState == 1 && numberOfTrackletsFound == 0) {
1018+
if (mTrackletHCHeaderState == 1 && trackletsFound == 0) {
10051019
if (mMaxErrsPrinted > 0) {
10061020
LOG(error) << "We found a TrackletHCHeader in mode 1, but did not add any tracklets";
10071021
checkNoErr();

0 commit comments

Comments
 (0)