Skip to content

Commit f76a14f

Browse files
authored
Merge pull request #10 from noferini/tof-dev
Enable conet mode in decoding and reco + fixes in CTF
2 parents 9a24d34 + eae2dfd commit f76a14f

File tree

18 files changed

+315
-43
lines changed

18 files changed

+315
-43
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/include/DataFormatsTOF/Cluster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Cluster : public o2::BaseCluster<float>
6363
double getTime() const { return mTime; } // Cluster ToF getter
6464
void setTime(double time) { mTime = time; } // Cluster ToF setter
6565
float getTot() const { return mTot; } // Cluster Charge getter
66-
void setTot(int tot) { mTot = tot; } // Cluster ToT setter
66+
void setTot(float tot) { mTot = tot; } // Cluster ToT setter
6767
int getL0L1Latency() const { return mL0L1Latency; }; // L0L1 latency
6868
void setL0L1Latency(int value) { mL0L1Latency = value; }; // L0-L1 latency
6969
int getDeltaBC() const { return mDeltaBC; }; // deltaBC

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/GlobalTrackingWorkflow/tofworkflow/src/tof-reco-workflow.cxx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
5858
workflowOptions.push_back(ConfigParamSpec{"input-desc", o2::framework::VariantType::String, "CRAWDATA", {"Input specs description string"}});
5959
workflowOptions.push_back(ConfigParamSpec{"disable-root-input", o2::framework::VariantType::Bool, false, {"disable root-files input readers"}});
6060
workflowOptions.push_back(ConfigParamSpec{"disable-root-output", o2::framework::VariantType::Bool, false, {"disable root-files output writers"}});
61+
workflowOptions.push_back(ConfigParamSpec{"conet-mode", o2::framework::VariantType::Bool, false, {"enable conet mode"}});
6162
workflowOptions.push_back(ConfigParamSpec{"configKeyValues", o2::framework::VariantType::String, "", {"Semicolon separated key=value strings ..."}});
63+
workflowOptions.push_back(ConfigParamSpec{"disable-row-writing", o2::framework::VariantType::Bool, false, {"disable ROW in Digit writing"}});
64+
workflowOptions.push_back(ConfigParamSpec{"write-decoding-errors", o2::framework::VariantType::Bool, false, {"trace errors in digits output when decoding"}});
6265
}
6366

6467
#include "Framework/runDataProcessing.h" // the main driver
@@ -84,13 +87,6 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
8487
WorkflowSpec specs;
8588

8689
if (!cfgc.helpOnCommandLine()) {
87-
std::string inputGRP = o2::base::NameConf::getGRPFileName();
88-
o2::base::Propagator::initFieldFromGRP(inputGRP);
89-
const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
90-
if (!grp) {
91-
LOG(ERROR) << "This workflow needs a valid GRP file to start";
92-
return specs;
93-
}
9490
o2::conf::ConfigurableParam::updateFromString(cfgc.options().get<std::string>("configKeyValues"));
9591
// o2::conf::ConfigurableParam::writeINI("o2tofrecoflow_configuration.ini");
9692
}
@@ -107,6 +103,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
107103
bool writedigit = 0;
108104
bool writeraw = 0;
109105
bool writectf = 0;
106+
bool writeerr = 0;
110107

111108
if (outputType.rfind("clusters") < outputType.size())
112109
writecluster = 1;
@@ -131,15 +128,31 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
131128
clusterinput = 1;
132129
} else if (inputType == "raw") {
133130
rawinput = 1;
131+
writeerr = cfgc.options().get<bool>("write-decoding-errors");
134132
} else if (inputType == "ctf") {
135133
ctfinput = 1;
136134
}
137135

136+
if (ctfinput || rawinput) {
137+
} else {
138+
if (!cfgc.helpOnCommandLine()) {
139+
std::string inputGRP = o2::base::NameConf::getGRPFileName();
140+
o2::base::Propagator::initFieldFromGRP(inputGRP);
141+
const auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
142+
if (!grp) {
143+
LOG(ERROR) << "This workflow needs a valid GRP file to start";
144+
return specs;
145+
}
146+
}
147+
}
148+
138149
auto useMC = !cfgc.options().get<bool>("disable-mc");
139150
auto useCCDB = cfgc.options().get<bool>("use-ccdb");
140151
auto useFIT = cfgc.options().get<bool>("use-fit");
141152
bool disableRootInput = cfgc.options().get<bool>("disable-root-input") || rawinput;
142153
bool disableRootOutput = cfgc.options().get<bool>("disable-root-output");
154+
bool conetmode = cfgc.options().get<bool>("conet-mode");
155+
bool disableROWwriting = cfgc.options().get<bool>("disable-row-writing");
143156

144157
LOG(INFO) << "TOF RECO WORKFLOW configuration";
145158
LOG(INFO) << "TOF input = " << cfgc.options().get<std::string>("input-type");
@@ -151,6 +164,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
151164
LOG(INFO) << "TOF use-fit = " << cfgc.options().get<std::string>("use-fit");
152165
LOG(INFO) << "TOF disable-root-input = " << disableRootInput;
153166
LOG(INFO) << "TOF disable-root-output = " << disableRootOutput;
167+
LOG(INFO) << "TOF conet-mode = " << conetmode;
168+
LOG(INFO) << "TOF disable-row-writing = " << disableROWwriting;
169+
LOG(INFO) << "TOF write-decoding-errors = " << writeerr;
154170

155171
if (clusterinput) {
156172
LOG(INFO) << "Insert TOF Cluster Reader";
@@ -167,13 +183,13 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
167183
} else if (rawinput) {
168184
LOG(INFO) << "Insert TOF Compressed Raw Decoder";
169185
auto inputDesc = cfgc.options().get<std::string>("input-desc");
170-
specs.emplace_back(o2::tof::getCompressedDecodingSpec(inputDesc));
186+
specs.emplace_back(o2::tof::getCompressedDecodingSpec(inputDesc, conetmode));
171187
useMC = 0;
172188

173189
if (writedigit && !disableRootOutput) {
174190
// add TOF digit writer without mc labels
175191
LOG(INFO) << "Insert TOF Digit Writer";
176-
specs.emplace_back(o2::tof::getTOFDigitWriterSpec(0));
192+
specs.emplace_back(o2::tof::getTOFDigitWriterSpec(0, writeerr));
177193
}
178194
} else if (ctfinput) {
179195
LOG(INFO) << "Insert TOF CTF decoder";

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: 30 additions & 1 deletion
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

@@ -42,6 +49,7 @@ class WindowFiller
4249

4350
std::vector<Digit>* getDigitPerTimeFrame() { return &mDigitsPerTimeFrame; }
4451
std::vector<ReadoutWindowData>* getReadoutWindowData() { return &mReadoutWindowData; }
52+
std::vector<ReadoutWindowData>* getReadoutWindowDataFiltered() { return &mReadoutWindowDataFiltered; }
4553

4654
void fillOutputContainer(std::vector<Digit>& digits);
4755
void flushOutputContainer(std::vector<Digit>& digits); // flush all residual buffered data
@@ -52,6 +60,17 @@ class WindowFiller
5260

5361
void setFirstIR(const o2::InteractionRecord& ir) { mFirstIR = ir; }
5462

63+
void maskNoiseRate(int val) { mMaskNoiseRate = val; }
64+
65+
void clearCounts()
66+
{
67+
for (int i = 0; i < o2::tof::Geo::NCHANNELS; i++)
68+
mChannelCounts[i] = 0;
69+
}
70+
71+
std::vector<uint32_t>& getPatterns() { return mPatterns; }
72+
void addPattern(const uint32_t val, int icrate, int orbit, int bc) { mCratePatterns.emplace_back(val, icrate, orbit * 3 + (bc + 100) / 1188); }
73+
5574
protected:
5675
// info TOF timewindow
5776
Int_t mReadoutWindowCurrent = 0;
@@ -61,13 +80,18 @@ class WindowFiller
6180
bool mContinuous = true;
6281
bool mFutureToBeSorted = false;
6382

83+
// only needed from Decoder
84+
int mMaskNoiseRate = -1;
85+
int mChannelCounts[o2::tof::Geo::NCHANNELS]; // count of channel hits in the current TF (if MaskNoiseRate enabled)
86+
6487
// digit info
6588
//std::vector<Digit>* mDigits;
6689

6790
static const int MAXWINDOWS = 2; // how many readout windows we can buffer
6891

6992
std::vector<Digit> mDigitsPerTimeFrame;
7093
std::vector<ReadoutWindowData> mReadoutWindowData;
94+
std::vector<ReadoutWindowData> mReadoutWindowDataFiltered;
7195

7296
int mIcurrentReadoutWindow = 0;
7397

@@ -79,6 +103,11 @@ class WindowFiller
79103
// arrays with digit and MCLabels out of the current readout windows (stored to fill future readout window)
80104
std::vector<Digit> mFutureDigits;
81105

106+
std::vector<uint32_t> mPatterns;
107+
std::vector<uint64_t> mErrors;
108+
109+
std::vector<PatternData> mCratePatterns;
110+
82111
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);
83112
// 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);
84113

Detectors/TOF/base/src/WindowFiller.cxx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void WindowFiller::reset()
9595

9696
mDigitsPerTimeFrame.clear();
9797
mReadoutWindowData.clear();
98+
mReadoutWindowDataFiltered.clear();
9899

99100
mFirstIR.bc = 0;
100101
mFirstIR.orbit = 0;
@@ -124,8 +125,34 @@ void WindowFiller::fillOutputContainer(std::vector<Digit>& digits)
124125
int orbit_shift = mReadoutWindowData.size() / 3;
125126
int bc_shift = (mReadoutWindowData.size() % 3) * Geo::BC_IN_WINDOW;
126127
info.setBCData(mFirstIR.orbit + orbit_shift, mFirstIR.bc + bc_shift);
127-
if (digits.size())
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--;
148+
}
149+
150+
info.setFirstEntryDia(firstPattern);
151+
info.setNEntriesDia(npatterns);
152+
if (digits.size()) {
128153
mDigitsPerTimeFrame.insert(mDigitsPerTimeFrame.end(), digits.begin(), digits.end());
154+
mReadoutWindowDataFiltered.push_back(info);
155+
}
129156
mReadoutWindowData.push_back(info);
130157
}
131158

@@ -149,6 +176,10 @@ void WindowFiller::flushOutputContainer(std::vector<Digit>& digits)
149176
{ // flush all residual buffered data
150177
// TO be implemented
151178

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+
152183
for (Int_t i = 0; i < MAXWINDOWS; i++) {
153184
int n = 0;
154185
for (int j = 0; j < mStrips[i].size(); j++)
@@ -294,7 +325,8 @@ void WindowFiller::checkIfReuseFutureDigitsRO() // the same but using readout in
294325
strips = mStripsNext[isnext - 1];
295326
}
296327

297-
fillDigitsInStrip(strips, digit->getChannel(), digit->getTDC(), digit->getTOT(), digit->getBC(), digit->getChannel() / Geo::NPADS);
328+
if (mMaskNoiseRate < 0 || mChannelCounts[digit->getChannel()] < mMaskNoiseRate)
329+
fillDigitsInStrip(strips, digit->getChannel(), digit->getTDC(), digit->getTOT(), digit->getBC(), digit->getChannel() / Geo::NPADS);
298330

299331
// int labelremoved = digit->getLabel();
300332
mFutureDigits.erase(mFutureDigits.begin() + idigit);

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class Decoder : public WindowFiller
7171

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

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); }
76+
7477
protected:
7578
static const int NCRU = 4;
7679

0 commit comments

Comments
 (0)