Skip to content

Commit eae2dfd

Browse files
committed
order TOF patterns according to crate and readout window
update TOF CTF with crate info for diagnostic
1 parent 4ec16dc commit eae2dfd

File tree

13 files changed

+77
-20
lines changed

13 files changed

+77
-20
lines changed

DataFormats/Detectors/TOF/include/DataFormatsTOF/CTF.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CTFHeader {
3535
uint32_t firstOrbit = 0; /// 1st orbit of TF
3636
uint16_t firstBC = 0; /// 1st BC of TF
3737

38-
ClassDefNV(CTFHeader, 1);
38+
ClassDefNV(CTFHeader, 2);
3939
};
4040

4141
/// Compressed but not yet entropy-encoded infos
@@ -59,6 +59,7 @@ struct CompressedInfos {
5959
std::vector<uint32_t> orbitIncROF; /// increment of ROF orbit wrt orbit of previous ROF
6060
std::vector<uint32_t> ndigROF; /// number of digits in ROF
6161
std::vector<uint32_t> ndiaROF; /// number of diagnostic/pattern words in ROF
62+
std::vector<uint32_t> ndiaCrate; /// number of diagnostic/pattern words per crate in ROF
6263

6364
// Hit data
6465
std::vector<uint16_t> timeFrameInc; /// time increment with respect of previous digit in TimeFrame units
@@ -72,17 +73,18 @@ struct CompressedInfos {
7273

7374
void clear();
7475

75-
ClassDefNV(CompressedInfos, 1);
76+
ClassDefNV(CompressedInfos, 2);
7677
};
7778

7879
/// wrapper for the Entropy-encoded clusters of the TF
79-
struct CTF : public o2::ctf::EncodedBlocks<CTFHeader, 10, uint32_t> {
80+
struct CTF : public o2::ctf::EncodedBlocks<CTFHeader, 11, uint32_t> {
8081

8182
static constexpr size_t N = getNBlocks();
8283
enum Slots { BLCbcIncROF,
8384
BLCorbitIncROF,
8485
BLCndigROF,
8586
BLCndiaROF,
87+
BLCndiaCrate,
8688
BLCtimeFrameInc,
8789
BLCtimeTDCInc,
8890
BLCstripID,

DataFormats/Detectors/TOF/src/CTF.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void CompressedInfos::clear()
2222
orbitIncROF.clear();
2323
ndigROF.clear();
2424
ndiaROF.clear();
25+
ndiaCrate.clear();
2526
timeFrameInc.clear();
2627
timeTDCInc.clear();
2728
stripID.clear();

DataFormats/Detectors/TOF/src/DataFormatsTOFLinkDef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
#pragma link C++ class o2::tof::CTFHeader + ;
2929
#pragma link C++ class o2::tof::CompressedInfos + ;
3030
#pragma link C++ class o2::tof::CTF + ;
31-
#pragma link C++ class o2::ctf::EncodedBlocks < o2::tof::CTFHeader, 10, uint32_t> + ;
31+
#pragma link C++ class o2::ctf::EncodedBlocks < o2::tof::CTFHeader, 11, uint32_t> + ;
3232

3333
#endif

Detectors/TOF/base/include/TOFBase/Digit.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,23 @@ struct ReadoutWindowData {
114114
// for given trigger (or BC or RO frame)
115115
o2::dataformats::RangeReference<int, int> ref;
116116
o2::dataformats::RangeReference<int, int> refDiagnostic;
117+
118+
// crate info for diagnostic patterns
119+
int mNdiaCrate[72] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
120+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
121+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
123+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
125+
117126
InteractionRecord mFirstIR{0, 0};
118127

119128
const InteractionRecord& getBCData() const { return mFirstIR; }
120129

130+
void addedDiagnostic(int crate) { mNdiaCrate[crate]++; }
131+
void setDiagnosticInCrate(int crate, int val) { mNdiaCrate[crate] = val; }
132+
int getDiagnosticInCrate(int crate) const { return mNdiaCrate[crate]; }
133+
121134
void setBCData(int orbit, int bc)
122135
{
123136
mFirstIR.orbit = orbit;

Detectors/TOF/base/include/TOFBase/WindowFiller.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,15 @@ namespace tof
2424

2525
class WindowFiller
2626
{
27-
2827
public:
28+
struct PatternData {
29+
uint32_t pattern;
30+
int icrate;
31+
ulong row;
32+
33+
PatternData(uint32_t patt = 0, int icr = 0, ulong rw = 0) : pattern(patt), icrate(icr), row(rw) {}
34+
};
35+
2936
WindowFiller() { initObj(); };
3037
~WindowFiller() = default;
3138

@@ -62,7 +69,7 @@ class WindowFiller
6269
}
6370

6471
std::vector<uint32_t>& getPatterns() { return mPatterns; }
65-
void addPattern(const uint32_t val, int icrate) { mPatterns.push_back(val); }
72+
void addPattern(const uint32_t val, int icrate, int orbit, int bc) { mCratePatterns.emplace_back(val, icrate, orbit * 3 + (bc + 100) / 1188); }
6673

6774
protected:
6875
// info TOF timewindow
@@ -97,7 +104,9 @@ class WindowFiller
97104
std::vector<Digit> mFutureDigits;
98105

99106
std::vector<uint32_t> mPatterns;
100-
std::vector<uint32_t> mErrors;
107+
std::vector<uint64_t> mErrors;
108+
109+
std::vector<PatternData> mCratePatterns;
101110

102111
void fillDigitsInStrip(std::vector<Strip>* strips, int channel, int tdc, int tot, uint64_t nbc, UInt_t istrip, uint32_t triggerorbit = 0, uint16_t triggerbunch = 0);
103112
// void fillDigitsInStrip(std::vector<Strip>* strips, o2::dataformats::MCTruthContainer<o2::tof::MCLabel>* mcTruthContainer, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID);

Detectors/TOF/base/src/WindowFiller.cxx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,28 @@ void WindowFiller::fillOutputContainer(std::vector<Digit>& digits)
125125
int orbit_shift = mReadoutWindowData.size() / 3;
126126
int bc_shift = (mReadoutWindowData.size() % 3) * Geo::BC_IN_WINDOW;
127127
info.setBCData(mFirstIR.orbit + orbit_shift, mFirstIR.bc + bc_shift);
128-
int firstPattern = 0;
129-
int npatterns = mPatterns.size();
130-
if (mReadoutWindowData.size()) {
131-
auto prevROW = mReadoutWindowData[mReadoutWindowData.size() - 1];
132-
firstPattern = prevROW.firstDia() + prevROW.sizeDia();
133-
npatterns -= firstPattern;
128+
int firstPattern = mPatterns.size();
129+
int npatterns = 0;
130+
131+
// check if patterns are in the current row
132+
int ipatt = mCratePatterns.size() - 1;
133+
for (std::vector<PatternData>::reverse_iterator it = mCratePatterns.rbegin(); it != mCratePatterns.rend(); ++it) {
134+
if (it->row > mReadoutWindowCurrent)
135+
break;
136+
137+
if (it->row < mReadoutWindowCurrent) { // this should not happen
138+
LOG(ERROR) << "One pattern skipped because appears to occur early of the current row " << it->row << " < " << mReadoutWindowCurrent << " ?!";
139+
mCratePatterns.erase(mCratePatterns.begin() + ipatt);
140+
} else {
141+
mPatterns.push_back(it->pattern);
142+
info.addedDiagnostic(it->icrate);
143+
144+
mCratePatterns.erase(mCratePatterns.begin() + ipatt);
145+
npatterns++;
146+
}
147+
ipatt--;
134148
}
149+
135150
info.setFirstEntryDia(firstPattern);
136151
info.setNEntriesDia(npatterns);
137152
if (digits.size()) {
@@ -161,6 +176,10 @@ void WindowFiller::flushOutputContainer(std::vector<Digit>& digits)
161176
{ // flush all residual buffered data
162177
// TO be implemented
163178

179+
// sort patterns (diagnostic words) in time
180+
std::sort(mCratePatterns.begin(), mCratePatterns.end(),
181+
[](PatternData a, PatternData b) { if(a.row == b.row) return a.icrate > b.icrate; else return a.row > b.row; });
182+
164183
for (Int_t i = 0; i < MAXWINDOWS; i++) {
165184
int n = 0;
166185
for (int j = 0; j < mStrips[i].size(); j++)

Detectors/TOF/compression/src/Compressor.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ bool Compressor<RDH, verbose>::checkerCheck()
889889
for (int itrm = 0; itrm < 10; ++itrm) {
890890
mDecoderSummary.trmDataHeader[itrm] = nullptr;
891891
mDecoderSummary.trmDataTrailer[itrm] = nullptr;
892-
for (int ichain = 0; ichain < 10; ++ichain) {
892+
for (int ichain = 0; ichain < 2; ++ichain) {
893893
mDecoderSummary.trmChainHeader[itrm][ichain] = nullptr;
894894
mDecoderSummary.trmChainTrailer[itrm][ichain] = nullptr;
895895
mDecoderSummary.trmErrors[itrm][ichain] = 0;

Detectors/TOF/reconstruction/include/TOFReconstruction/CTFCoder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRe
7474
MD::EENCODE, //BLCorbitIncROF
7575
MD::EENCODE, //BLCndigROF
7676
MD::EENCODE, //BLCndiaROF
77+
MD::EENCODE, //BLCndiaCrate
7778
MD::EENCODE, //BLCtimeFrameInc
7879
MD::EENCODE, //BLCtimeTDCInc
7980
MD::EENCODE, //BLCstripID
@@ -100,6 +101,7 @@ void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRe
100101
ENCODETOF(cc.orbitIncROF, CTF::BLCorbitIncROF, 0);
101102
ENCODETOF(cc.ndigROF, CTF::BLCndigROF, 0);
102103
ENCODETOF(cc.ndiaROF, CTF::BLCndiaROF, 0);
104+
ENCODETOF(cc.ndiaCrate, CTF::BLCndiaCrate, 0);
103105
ENCODETOF(cc.timeFrameInc, CTF::BLCtimeFrameInc, 0);
104106
ENCODETOF(cc.timeTDCInc, CTF::BLCtimeTDCInc, 0);
105107
ENCODETOF(cc.stripID, CTF::BLCstripID, 0);
@@ -124,6 +126,7 @@ void CTFCoder::decode(const CTF::base& ec, VROF& rofRecVec, VDIG& cdigVec, VPAT&
124126
DECODETOF(cc.orbitIncROF, CTF::BLCorbitIncROF);
125127
DECODETOF(cc.ndigROF, CTF::BLCndigROF);
126128
DECODETOF(cc.ndiaROF, CTF::BLCndiaROF);
129+
DECODETOF(cc.ndiaCrate, CTF::BLCndiaCrate);
127130

128131
DECODETOF(cc.timeFrameInc, CTF::BLCtimeFrameInc);
129132
DECODETOF(cc.timeTDCInc, CTF::BLCtimeTDCInc);
@@ -161,6 +164,9 @@ void CTFCoder::decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdig
161164
rofRec.setNEntries(cc.ndigROF[irof]);
162165
rofRec.setFirstEntryDia(ndiagnostic);
163166
rofRec.setNEntriesDia(cc.ndiaROF[irof]);
167+
for (int icrate = 0; icrate < 72; icrate++)
168+
rofRec.setDiagnosticInCrate(icrate, cc.ndiaCrate[irof * 72 + icrate]);
169+
164170
firstEntry += cc.ndigROF[irof];
165171
ndiagnostic += cc.ndiaROF[irof];
166172

Detectors/TOF/reconstruction/include/TOFReconstruction/Decoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Decoder : public WindowFiller
7171

7272
char* nextPage(void* current, int shift = 8192);
7373

74-
std::vector<uint32_t>& getErrors() { return mErrors; }
75-
void addError(const uint32_t val, int icrate) { mErrors.push_back(val); }
74+
std::vector<uint64_t>& getErrors() { return mErrors; }
75+
void addError(const uint32_t val, int icrate) { mErrors.push_back((uint64_t(icrate) << 32) + val); }
7676

7777
protected:
7878
static const int NCRU = 4;

Detectors/TOF/reconstruction/src/CTFCoder.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void CTFCoder::compress(CompressedInfos& cc,
6161
cc.orbitIncROF.resize(cc.header.nROFs);
6262
cc.ndigROF.resize(cc.header.nROFs);
6363
cc.ndiaROF.resize(cc.header.nROFs);
64+
cc.ndiaCrate.resize(cc.header.nROFs * 72);
6465
//
6566
cc.timeFrameInc.resize(cc.header.nDigits);
6667
cc.timeTDCInc.resize(cc.header.nDigits);
@@ -92,6 +93,8 @@ void CTFCoder::compress(CompressedInfos& cc,
9293
auto ndig = rofRec.size();
9394
cc.ndigROF[irof] = ndig;
9495
cc.ndiaROF[irof] = rofRec.sizeDia();
96+
for (int icrate = 0; icrate < 72; icrate++)
97+
cc.ndiaCrate[irof * 72 + icrate] = rofRec.getDiagnosticInCrate(icrate);
9598

9699
if (!ndig) { // no hits data for this ROF --> not fill
97100
continue;
@@ -176,7 +179,8 @@ void CTFCoder::createCoders(const std::string& dictPath, o2::ctf::CTFCoderBase::
176179
MAKECODER(cc.orbitIncROF, CTF::BLCorbitIncROF);
177180
MAKECODER(cc.ndigROF, CTF::BLCndigROF);
178181
MAKECODER(cc.ndiaROF, CTF::BLCndiaROF);
179-
182+
MAKECODER(cc.ndiaCrate, CTF::BLCndiaCrate);
183+
180184
MAKECODER(cc.timeFrameInc, CTF::BLCtimeFrameInc);
181185
MAKECODER(cc.timeTDCInc, CTF::BLCtimeTDCInc);
182186
MAKECODER(cc.stripID, CTF::BLCstripID);
@@ -200,6 +204,7 @@ size_t CTFCoder::estimateCompressedSize(const CompressedInfos& cc)
200204
sz += ESTSIZE(cc.orbitIncROF, CTF::BLCorbitIncROF);
201205
sz += ESTSIZE(cc.ndigROF, CTF::BLCndigROF);
202206
sz += ESTSIZE(cc.ndiaROF, CTF::BLCndiaROF);
207+
sz += ESTSIZE(cc.ndiaCrate, CTF::BLCndiaCrate);
203208
sz += ESTSIZE(cc.timeFrameInc, CTF::BLCtimeFrameInc);
204209
sz += ESTSIZE(cc.timeTDCInc, CTF::BLCtimeTDCInc);
205210
sz += ESTSIZE(cc.stripID, CTF::BLCstripID);

0 commit comments

Comments
 (0)