Skip to content

Commit 4b94f71

Browse files
noferinishahor02
authored andcommitted
fix for tof pattern in CTF (8bits words)
1 parent 1f5cc84 commit 4b94f71

14 files changed

Lines changed: 94 additions & 43 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ struct CompressedInfos {
6767
std::vector<uint16_t> stripID; /// increment of stripID wrt that of prev. strip
6868
std::vector<uint8_t> chanInStrip; /// channel in strip 0-95 (ordered in time)
6969
std::vector<uint16_t> tot; /// Time-Over-Threshold in TOF channel (about 48.8 ps)
70-
std::vector<uint32_t> pattMap; /// explict patterns container
70+
std::vector<uint8_t> pattMap; /// explict patterns container
7171

7272
CompressedInfos() = default;
7373

7474
void clear();
7575

76-
ClassDefNV(CompressedInfos, 2);
76+
ClassDefNV(CompressedInfos, 3);
7777
};
7878

7979
/// wrapper for the Entropy-encoded clusters of the TF

Detectors/CTF/test/test_ctf_io_tof.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)
3030

3131
std::vector<Digit> digits;
3232
std::vector<ReadoutWindowData> rows;
33-
std::vector<uint32_t> pattVec;
33+
std::vector<uint8_t> pattVec;
3434

3535
TStopwatch sw;
3636
sw.Start();
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(CompressedClustersTest)
117117

118118
std::vector<Digit> digitsD;
119119
std::vector<ReadoutWindowData> rowsD;
120-
std::vector<uint32_t> pattVecD;
120+
std::vector<uint8_t> pattVecD;
121121
sw.Start();
122122
const auto ctfImage = CTF::getImage(vec.data());
123123
{

Detectors/TOF/base/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ o2_add_library(TOFBase
1616
src/Strip.cxx
1717
src/WindowFiller.cxx
1818
PUBLIC_LINK_LIBRARIES Boost::serialization FairRoot::Base ms_gsl::ms_gsl
19-
O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw)
19+
O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw
20+
O2::DataFormatsTOF)
2021

2122
o2_target_root_dictionary(TOFBase
2223
HEADERS include/TOFBase/Geo.h include/TOFBase/Digit.h

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class WindowFiller
7575
memset(mChannelCounts, 0, o2::tof::Geo::NCHANNELS * sizeof(mChannelCounts[0]));
7676
}
7777

78-
std::vector<uint32_t>& getPatterns() { return mPatterns; }
78+
std::vector<uint8_t>& getPatterns() { return mPatterns; }
7979
void addPattern(const uint32_t val, int icrate, int orbit, int bc) { mCratePatterns.emplace_back(val, icrate, orbit * 3 + (bc + 100) / Geo::BC_IN_WINDOW); }
8080
void addCrateHeaderData(unsigned long orbit, int crate, int32_t bc, uint32_t eventCounter);
8181

@@ -111,7 +111,7 @@ class WindowFiller
111111
// arrays with digit and MCLabels out of the current readout windows (stored to fill future readout window)
112112
std::vector<Digit> mFutureDigits;
113113

114-
std::vector<uint32_t> mPatterns;
114+
std::vector<uint8_t> mPatterns;
115115
std::vector<uint64_t> mErrors;
116116

117117
std::vector<PatternData> mCratePatterns;

Detectors/TOF/base/src/WindowFiller.cxx

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <algorithm>
2222
#include <cassert>
2323
#include "FairLogger.h"
24+
#include "DataFormatsTOF/CompressedDataFormat.h"
2425

2526
using namespace o2::tof;
2627

@@ -190,18 +191,51 @@ void WindowFiller::fillOutputContainer(std::vector<Digit>& digits)
190191
int npatterns = 0;
191192

192193
// check if patterns are in the current row
194+
unsigned int initrow = mFirstIR.orbit * Geo::NWINDOW_IN_ORBIT;
193195
for (std::vector<PatternData>::reverse_iterator it = mCratePatterns.rbegin(); it != mCratePatterns.rend(); ++it) {
194-
if (it->row > mReadoutWindowCurrent) {
196+
//printf("pattern row=%ld current=%ld\n",it->row - initrow,mReadoutWindowCurrent);
197+
198+
if (it->row - initrow > mReadoutWindowCurrent) {
195199
break;
196200
}
197201

198-
if (it->row < mReadoutWindowCurrent) { // this should not happen
202+
if (it->row - initrow < mReadoutWindowCurrent) { // this should not happen
199203
LOG(ERROR) << "One pattern skipped because appears to occur early of the current row " << it->row << " < " << mReadoutWindowCurrent << " ?!";
200204
} else {
201-
mPatterns.push_back(it->pattern);
202-
info.addedDiagnostic(it->icrate);
205+
uint32_t cpatt = it->pattern;
206+
auto dpatt = reinterpret_cast<compressed::Diagnostic_t*>(&cpatt);
207+
uint8_t slot = dpatt->slotID;
208+
uint32_t cbit = 1;
203209

210+
mPatterns.push_back(slot + 28); // add slot
211+
info.addedDiagnostic(it->icrate);
204212
npatterns++;
213+
214+
for (int ibit = 0; ibit < 28; ibit++) {
215+
if (dpatt->faultBits & cbit) {
216+
mPatterns.push_back(ibit); // add bit error
217+
info.addedDiagnostic(it->icrate);
218+
npatterns++;
219+
}
220+
cbit <<= 1;
221+
}
222+
// uint8_t w1 = cpatt & 0xff;
223+
// uint8_t w2 = (cpatt >> 8) & 0xff;
224+
// uint8_t w3 = (cpatt >> 16) & 0xff;
225+
// uint8_t w4 = (cpatt >> 24) & 0xff;
226+
//// cpatt = w1 + (w2 + (w3 + uint(w4)*256)*256)*256;
227+
// mPatterns.push_back(w1);
228+
// info.addedDiagnostic(it->icrate);
229+
// npatterns++;
230+
// mPatterns.push_back(w2);
231+
// info.addedDiagnostic(it->icrate);
232+
// npatterns++;
233+
// mPatterns.push_back(w3);
234+
// info.addedDiagnostic(it->icrate);
235+
// npatterns++;
236+
// mPatterns.push_back(w4);
237+
// info.addedDiagnostic(it->icrate);
238+
// npatterns++;
205239
}
206240
mCratePatterns.pop_back();
207241
}
@@ -265,12 +299,14 @@ void WindowFiller::flushOutputContainer(std::vector<Digit>& digits)
265299
checkIfReuseFutureDigitsRO();
266300
}
267301

302+
int nwindowperTF = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * Geo::NWINDOW_IN_ORBIT;
303+
268304
for (Int_t i = 0; i < MAXWINDOWS; i++) {
269-
fillOutputContainer(digits); // fill last readout windows
305+
if (mReadoutWindowData.size() < nwindowperTF) {
306+
fillOutputContainer(digits); // fill last readout windows
307+
}
270308
}
271309

272-
int nwindowperTF = o2::raw::HBFUtils::Instance().getNOrbitsPerTF() * Geo::NWINDOW_IN_ORBIT;
273-
274310
// check that all orbits are complete in terms of number of readout windows
275311
while ((mReadoutWindowData.size() % nwindowperTF)) {
276312
fillOutputContainer(digits); // fill windows without digits to complete all orbits in the last TF
@@ -306,7 +342,7 @@ void WindowFiller::checkIfReuseFutureDigits()
306342
int isnext = Int_t(timestamp * Geo::READOUTWINDOW_INV) - (mReadoutWindowCurrent + 1); // to be replaced with uncalibrated time
307343

308344
if (isnext < 0) { // we jump too ahead in future, digit will be not stored
309-
LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
345+
LOG(DEBUG) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
310346

311347
// remove digit from array in the future
312348
int labelremoved = digit->getLabel();
@@ -375,7 +411,7 @@ void WindowFiller::checkIfReuseFutureDigitsRO() // the same but using readout in
375411
int isnext = row - mReadoutWindowCurrent;
376412

377413
if (isnext < 0) { // we jump too ahead in future, digit will be not stored
378-
LOG(INFO) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
414+
LOG(DEBUG) << "Digit lost because we jump too ahead in future. Current RO window=" << isnext << "\n";
379415

380416
// remove digit from array in the future
381417
int labelremoved = digit->getLabel();

Detectors/TOF/calibration/src/TOFFEElightConfig.cxx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,5 @@ TOFFEEchannelConfig* TOFFEElightConfig::getChannelConfig(int icrate, int itrm, i
1717

1818
// return the channel config for the given crate, trm, chain, tdc, tdcchannel
1919

20-
return icrate >= Geo::kNCrate ? nullptr : itrm >= Geo::kNTRM ? nullptr
21-
: ichain >= Geo::kNChain ? nullptr
22-
: itdc >= Geo::kNTdc ? nullptr
23-
: ichtdc >= Geo::kNCh ? nullptr
24-
: &mChannelConfig[icrate][itrm][ichain][itdc][ichtdc];
20+
return icrate >= Geo::kNCrate ? nullptr : itrm >= Geo::kNTRM ? nullptr : ichain >= Geo::kNChain ? nullptr : itdc >= Geo::kNTdc ? nullptr : ichtdc >= Geo::kNCh ? nullptr : &mChannelConfig[icrate][itrm][ichain][itdc][ichtdc];
2521
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
3939

4040
/// entropy-encode clusters to buffer with CTF
4141
template <typename VEC>
42-
void encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec);
42+
void encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec);
4343

4444
/// entropy decode clusters from buffer with CTF
4545
template <typename VROF, typename VDIG, typename VPAT>
@@ -49,14 +49,14 @@ class CTFCoder : public o2::ctf::CTFCoderBase
4949

5050
private:
5151
/// compres compact clusters to CompressedInfos
52-
void compress(CompressedInfos& cc, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec);
52+
void compress(CompressedInfos& cc, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec);
5353
size_t estimateCompressedSize(const CompressedInfos& cc);
5454
/// decompress CompressedInfos to compact clusters
5555
template <typename VROF, typename VDIG, typename VPAT>
5656
void decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdigVec, VPAT& pattVec);
5757

5858
void appendToTree(TTree& tree, CTF& ec);
59-
void readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec);
59+
void readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint8_t>& pattVec);
6060

6161
protected:
6262
ClassDefNV(CTFCoder, 1);
@@ -65,7 +65,7 @@ class CTFCoder : public o2::ctf::CTFCoderBase
6565
///___________________________________________________________________________________
6666
/// entropy-encode digits to buffer with CTF
6767
template <typename VEC>
68-
void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint32_t>& pattVec)
68+
void CTFCoder::encode(VEC& buff, const gsl::span<const ReadoutWindowData>& rofRecVec, const gsl::span<const Digit>& cdigVec, const gsl::span<const uint8_t>& pattVec)
6969
{
7070
using MD = o2::ctf::Metadata::OptStore;
7171
// what to do which each field: see o2::ctd::Metadata explanation
@@ -180,7 +180,7 @@ void CTFCoder::decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdig
180180

181181
int firstDig = digCount;
182182

183-
int BCrow = prevIR.orbit * Geo::BC_IN_ORBIT + prevIR.bc;
183+
int64_t BCrow = prevIR.toLong();
184184

185185
digCopy.resize(cc.ndigROF[irof]);
186186
for (uint32_t idig = 0; idig < cc.ndigROF[irof]; idig++) {
@@ -192,7 +192,7 @@ void CTFCoder::decompress(const CompressedInfos& cc, VROF& rofRecVec, VDIG& cdig
192192
} else {
193193
ctdc += cc.timeTDCInc[digCount];
194194
}
195-
LOGF(DEBUG, "BC=%d, TDC=%d, TOT=%d, CH=%d", uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow, ctdc % 1024, cc.tot[digCount], uint32_t(cc.stripID[digCount]) * 96 + cc.chanInStrip[digCount]);
195+
LOGF(DEBUG, "BC=%ld, TDC=%d, TOT=%d, CH=%d", uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow, ctdc % 1024, cc.tot[digCount], uint32_t(cc.stripID[digCount]) * 96 + cc.chanInStrip[digCount]);
196196

197197
digit.setBC(uint32_t(ctimeframe) * 64 + ctdc / 1024 + BCrow);
198198
digit.setTDC(ctdc % 1024);

Detectors/TOF/reconstruction/src/CTFCoder.cxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void CTFCoder::appendToTree(TTree& tree, CTF& ec)
2727

2828
///___________________________________________________________________________________
2929
// extract and decode data from the tree
30-
void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint32_t>& pattVec)
30+
void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowData>& rofRecVec, std::vector<Digit>& cdigVec, std::vector<uint8_t>& pattVec)
3131
{
3232
assert(entry >= 0 && entry < tree.GetEntries());
3333
CTF ec;
@@ -39,7 +39,7 @@ void CTFCoder::readFromTree(TTree& tree, int entry, std::vector<ReadoutWindowDat
3939
void CTFCoder::compress(CompressedInfos& cc,
4040
const gsl::span<const ReadoutWindowData>& rofRecVec,
4141
const gsl::span<const Digit>& cdigVec,
42-
const gsl::span<const uint32_t>& pattVec)
42+
const gsl::span<const uint8_t>& pattVec)
4343
{
4444
// store in the header the orbit of 1st ROF
4545
cc.clear();
@@ -49,7 +49,7 @@ void CTFCoder::compress(CompressedInfos& cc,
4949
const auto& rofRec0 = rofRecVec[0];
5050
int nrof = rofRecVec.size();
5151

52-
LOGF(INFO, "TOF compress %d ReadoutWindow with %ld digits", nrof, cdigVec.size());
52+
LOGF(DEBUG, "TOF compress %d ReadoutWindow with %ld digits", nrof, cdigVec.size());
5353

5454
cc.header.nROFs = nrof;
5555
cc.header.firstOrbit = rofRec0.getBCData().orbit;
@@ -68,7 +68,7 @@ void CTFCoder::compress(CompressedInfos& cc,
6868
cc.stripID.resize(cc.header.nDigits);
6969
cc.chanInStrip.resize(cc.header.nDigits);
7070
cc.tot.resize(cc.header.nDigits);
71-
cc.pattMap.resize(cc.header.nPatternBytes);
71+
cc.pattMap.resize(pattVec.size());
7272

7373
uint16_t prevBC = cc.header.firstBC;
7474
uint32_t prevOrbit = cc.header.firstOrbit;
@@ -79,7 +79,7 @@ void CTFCoder::compress(CompressedInfos& cc,
7979
const auto& rofRec = rofRecVec[irof];
8080

8181
const auto& intRec = rofRec.getBCData();
82-
int rofInBC = intRec.toLong();
82+
int64_t rofInBC = intRec.toLong();
8383
// define interaction record
8484
if (intRec.orbit == prevOrbit) {
8585
cc.orbitIncROF[irof] = 0;
@@ -150,7 +150,6 @@ void CTFCoder::compress(CompressedInfos& cc,
150150
LOGF(DEBUG, "%d) TF=%d, TDC=%d, STRIP=%d, CH=%d, TOT=%d", idig, cc.timeFrameInc[idig], cc.timeTDCInc[idig], cc.stripID[idig], cc.chanInStrip[idig], cc.tot[idig]);
151151
}
152152
}
153-
// store explicit patters as they are
154153
memcpy(cc.pattMap.data(), pattVec.data(), cc.header.nPatternBytes); // RSTODO: do we need this?
155154
}
156155

@@ -219,6 +218,6 @@ size_t CTFCoder::estimateCompressedSize(const CompressedInfos& cc)
219218
sz += ESTSIZE(cc.pattMap, CTF::BLCpattMap);
220219
// clang-format on
221220
sz *= 2. / 3; // if needed, will be autoexpanded
222-
LOG(INFO) << "Estimated output size is " << sz << " bytes";
221+
LOG(DEBUG) << "Estimated output size is " << sz << " bytes";
223222
return sz;
224223
}

Detectors/TOF/workflow/include/TOFWorkflowUtils/CompressedDecodingTask.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class CompressedDecodingTask : public DecoderBase, public Task
6666
bool mHasToBePosted = false;
6767
bool mConetMode = false;
6868
uint32_t mInitOrbit = 0;
69+
uint32_t mCurrentOrbit = 0;
6970
bool mRowFilter = false;
7071
bool mMaskNoise = false;
7172
int mNoiseRate = 1000;

Detectors/TOF/workflow/include/TOFWorkflowUtils/DigitReaderSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DigitReader : public Task
4444
std::vector<o2::tof::Digit> mDigits, *mPdigits = &mDigits;
4545
std::vector<o2::tof::ReadoutWindowData> mRow, *mProw = &mRow;
4646
std::vector<o2::dataformats::MCTruthContainer<o2::MCCompLabel>> mLabels, *mPlabels = &mLabels;
47-
std::vector<uint32_t> mPatterns, *mPpatterns = &mPatterns;
47+
std::vector<uint8_t> mPatterns, *mPpatterns = &mPatterns;
4848
};
4949

5050
/// create a processor spec

0 commit comments

Comments
 (0)