Skip to content

Commit 84ee8e1

Browse files
nicolovallenvalle
andauthored
ITS - (and MFT), better TF sampling in the deadmap builder (#13349)
* ITS - (and MFT), better TF sampling in the deadmap builder * improved sampling algorithm --------- Co-authored-by: nvalle <nicolo@pcvalle.homenet.telecomitalia.it>
1 parent 8cd5556 commit 84ee8e1

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

Detectors/ITSMFT/common/workflow/include/ITSMFTWorkflow/DeadMapBuilderSpec.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ class ITSMFTDeadMapBuilder : public Task
108108
std::string mDataSource = "chipsstatus";
109109

110110
int mTFSampling = 350;
111-
std::string mSamplingMode = "first-orbit-run"; // Use this default to ensure process of first TF. At the moment, use any other option to sample on absolute orbit value.
111+
112+
// utils for an improved sampling algorithm
113+
std::unordered_set<long> mSampledTFs{};
114+
std::deque<long> mSampledHistory{};
115+
int mTFSamplingTolerance = 20;
116+
int mSampledSlidingWindowSize = 1000; // units: mTFSampling
112117

113118
o2::itsmft::TimeDeadMap mMapObject;
114119

@@ -118,6 +123,7 @@ class ITSMFTDeadMapBuilder : public Task
118123
// Utils
119124

120125
std::vector<uint16_t> getChipIDsOnSameCable(uint16_t);
126+
bool acceptTF(long);
121127

122128
o2::framework::DataTakingContext mDataTakingContext{};
123129
o2::framework::TimingInfo mTimingInfo{};

Detectors/ITSMFT/common/workflow/src/DeadMapBuilderSpec.cxx

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ void ITSMFTDeadMapBuilder::init(InitContext& ic)
4747
LOG(info) << "ITSMFTDeadMapBuilder init... " << mSelfName;
4848

4949
mTFSampling = ic.options().get<int>("tf-sampling");
50-
mSamplingMode = ic.options().get<std::string>("sampling-mode");
50+
mTFSamplingTolerance = ic.options().get<int>("tf-sampling-tolerance");
51+
if (mTFSamplingTolerance > mTFSampling) {
52+
LOG(warning) << "Invalid request tf-sampling-tolerance larger or equal than tf-sampling. Setting tolerance to " << mTFSampling - 1;
53+
mTFSamplingTolerance = mTFSampling - 1;
54+
}
55+
mSampledSlidingWindowSize = ic.options().get<int>("tf-sampling-history-size");
5156
mTFLength = ic.options().get<int>("tf-length");
5257
mDoLocalOutput = ic.options().get<bool>("local-output");
5358
mObjectName = ic.options().get<std::string>("outfile");
@@ -67,6 +72,8 @@ void ITSMFTDeadMapBuilder::init(InitContext& ic)
6772
N_CHIPS = o2::itsmft::ChipMappingITS::getNChips();
6873
}
6974

75+
mSampledTFs.clear();
76+
mSampledHistory.clear();
7077
mDeadMapTF.clear();
7178
mStaticChipStatus.clear();
7279
mMapObject.clear();
@@ -76,7 +83,7 @@ void ITSMFTDeadMapBuilder::init(InitContext& ic)
7683
mStaticChipStatus.resize(N_CHIPS, false);
7784
}
7885

79-
LOG(info) << "Sampling one TF every " << mTFSampling;
86+
LOG(info) << "Sampling one TF every " << mTFSampling << " with " << mTFSamplingTolerance << " TF tolerance";
8087

8188
return;
8289
}
@@ -95,6 +102,39 @@ std::vector<uint16_t> ITSMFTDeadMapBuilder::getChipIDsOnSameCable(uint16_t chip)
95102
}
96103
}
97104

105+
bool ITSMFTDeadMapBuilder::acceptTF(long orbit)
106+
{
107+
108+
// Description of the algorithm:
109+
// Return true if the TF index (calculated as orbit/TF_length) falls within any interval [k * tf_sampling, k * tf_sampling + tolerance) for some integer k, provided no other TFs have been found in the same interval.
110+
111+
if (mTFSamplingTolerance < 1) {
112+
return ((orbit / mTFLength) % mTFSampling == 0);
113+
}
114+
115+
if ((orbit / mTFLength) % mTFSampling > mTFSamplingTolerance) {
116+
return false;
117+
}
118+
119+
long sampling_index = orbit / mTFLength / mTFSampling;
120+
121+
if (mSampledTFs.find(sampling_index) == mSampledTFs.end()) {
122+
123+
mSampledTFs.insert(sampling_index);
124+
mSampledHistory.push_back(sampling_index);
125+
126+
if (mSampledHistory.size() > mSampledSlidingWindowSize) {
127+
long oldIndex = mSampledHistory.front();
128+
mSampledHistory.pop_front();
129+
mSampledTFs.erase(oldIndex);
130+
}
131+
132+
return true;
133+
}
134+
135+
return false;
136+
}
137+
98138
//////////////////////////////////////////////////////////////////////////////
99139

100140
void ITSMFTDeadMapBuilder::finalizeOutput()
@@ -151,12 +191,9 @@ void ITSMFTDeadMapBuilder::run(ProcessingContext& pc)
151191
mFirstOrbitRun = mFirstOrbitTF;
152192
}
153193

154-
long sampled_orbit = mFirstOrbitTF;
155-
if (mSamplingMode == "first-orbit-run") {
156-
sampled_orbit = sampled_orbit - mFirstOrbitRun;
157-
}
194+
long sampled_orbit = mFirstOrbitTF - mFirstOrbitRun;
158195

159-
if ((sampled_orbit / mTFLength) % mTFSampling != 0) {
196+
if (!acceptTF(sampled_orbit)) {
160197
return;
161198
}
162199

@@ -270,7 +307,7 @@ void ITSMFTDeadMapBuilder::PrepareOutputCcdb(EndOfStreamContext* ec, std::string
270307
if (ec != nullptr) {
271308

272309
LOG(important) << "Sending object " << info.getPath() << "/" << info.getFileName()
273-
<< "to ccdb-populator, of size " << image->size() << " bytes, valid for "
310+
<< " to ccdb-populator, of size " << image->size() << " bytes, valid for "
274311
<< info.getStartValidityTimestamp() << " : " << info.getEndValidityTimestamp();
275312

276313
if (mRunMFT) {
@@ -332,7 +369,7 @@ void ITSMFTDeadMapBuilder::stop()
332369
finalizeOutput();
333370
if (!mCCDBUrl.empty()) {
334371
std::string detname = mRunMFT ? "MFT" : "ITS";
335-
LOG(warning) << "endOfStream not processed. Sending output to ccdb from the " << detname << "deadmap builder workflow.";
372+
LOG(warning) << "endOfStream not processed. Sending output to ccdb from the " << detname << " deadmap builder workflow.";
336373
PrepareOutputCcdb(nullptr, mCCDBUrl);
337374
} else {
338375
LOG(alarm) << "endOfStream not processed. Nothing forwarded as output.";
@@ -379,7 +416,8 @@ DataProcessorSpec getITSMFTDeadMapBuilderSpec(std::string datasource, bool doMFT
379416
outputs,
380417
AlgorithmSpec{adaptFromTask<ITSMFTDeadMapBuilder>(datasource, doMFT)},
381418
Options{{"tf-sampling", VariantType::Int, 350, {"Process every Nth TF. Selection according to first TF orbit."}},
382-
{"sampling-mode", VariantType::String, "first-orbit-run", {"Use absolute orbit value or offset from first processed orbit."}},
419+
{"tf-sampling-tolerance", VariantType::Int, 20, {"Tolerance on the tf-sampling value (sliding window size)."}},
420+
{"tf-sampling-history-size", VariantType::Int, 1000, {"Do not check if new TF is contained in a window that is older than N steps."}},
383421
{"tf-length", VariantType::Int, 32, {"Orbits per TF."}},
384422
{"skip-static-map", VariantType::Bool, false, {"Do not fill static part of the map."}},
385423
{"ccdb-url", VariantType::String, "", {"CCDB url. Ignored if endOfStream is processed."}},

0 commit comments

Comments
 (0)