Skip to content

Commit 5493086

Browse files
shahor02davidrohr
authored andcommitted
Add option to write only fraction of TFs to CTF
with --ctf-rejection <N> one can request only fraction of TFs written to the CTF: N>0 : percentage to reject randomly (if >99: reject all) N<-1: store only 1 out |N| TFs (with timeslice%N==0)
1 parent f9b4b83 commit 5493086

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Detectors/CTF/workflow/src/CTFWriterSpec.cxx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <vector>
5252
#include <TFile.h>
5353
#include <TTree.h>
54+
#include <TRandom.h>
5455
#include <filesystem>
5556
#include <ctime>
5657
#include <sys/stat.h>
@@ -121,6 +122,7 @@ class CTFWriterSpec : public o2::framework::Task
121122
bool mCreateDict = false;
122123
bool mCreateRunEnvDir = true;
123124
bool mStoreMetaFile = false;
125+
bool mRejectCurrentTF = false;
124126
int mReportInterval = -1;
125127
int mVerbosity = 0;
126128
int mSaveDictAfter = 0; // if positive and mWriteCTF==true, save dictionary after each mSaveDictAfter TFs processed
@@ -137,6 +139,7 @@ class CTFWriterSpec : public o2::framework::Task
137139
size_t mCTFAutoSave = 0; // if > 0, autosave after so many TFs
138140
size_t mNCTFFiles = 0; // total number of CTF files written
139141
int mMaxCTFPerFile = 0; // max CTFs per files to store
142+
int mRejRate = 0; // CTF rejection rule (>0: percentage to reject randomly, <0: reject if timeslice%|value|!=0)
140143
std::vector<uint32_t> mTFOrbits{}; // 1st orbits of TF accumulated in current file
141144
o2::framework::DataTakingContext mDataTakingContext{};
142145
o2::framework::TimingInfo mTimingInfo{};
@@ -220,6 +223,13 @@ void CTFWriterSpec::init(InitContext& ic)
220223
mMinSize = ic.options().get<int64_t>("min-file-size");
221224
mMaxSize = ic.options().get<int64_t>("max-file-size");
222225
mMaxCTFPerFile = ic.options().get<int>("max-ctf-per-file");
226+
mRejRate = ic.options().get<int>("ctf-rejection");
227+
if (mRejRate > 0) {
228+
LOGP(info, "Will reject{} {}% of TFs", mRejRate < 100 ? " randomly" : "", mRejRate < 100 ? mRejRate : 100);
229+
} else if (mRejRate < -1) {
230+
LOGP(info, "Will reject all but each {}-th TF slice", -mRejRate);
231+
}
232+
223233
if (mWriteCTF) {
224234
if (mMinSize > 0) {
225235
LOG(info) << "Multiple CTFs will be accumulated in the tree/file until its size exceeds " << mMinSize << " bytes";
@@ -269,7 +279,7 @@ size_t CTFWriterSpec::processDet(o2::framework::ProcessingContext& pc, DetID det
269279
auto ctfBuffer = pc.inputs().get<gsl::span<o2::ctf::BufferType>>(det.getName());
270280
const auto ctfImage = C::getImage(ctfBuffer.data());
271281
ctfImage.print(o2::utils::Str::concat_string(det.getName(), ": "), mVerbosity);
272-
if (mWriteCTF) {
282+
if (mWriteCTF && !mRejectCurrentTF) {
273283
sz = ctfImage.appendToTree(*tree, det.getName());
274284
header.detectors.set(det);
275285
} else {
@@ -374,12 +384,11 @@ void CTFWriterSpec::run(ProcessingContext& pc)
374384
auto cput = mTimer.CpuTime();
375385
mTimer.Start(false);
376386
updateTimeDependentParams(pc);
377-
387+
mRejectCurrentTF = (mRejRate > 0 && int(gRandom->Rndm() * 100) < mRejRate) || (mRejRate < -1 && mTimingInfo.timeslice % (-mRejRate));
378388
mCurrCTFSize = estimateCTFSize(pc);
379-
if (mWriteCTF) {
389+
if (mWriteCTF && !mRejectCurrentTF) {
380390
prepareTFTreeAndFile();
381391
}
382-
383392
// create header
384393
CTFHeader header{mTimingInfo.runNumber, mTimingInfo.creation, mTimingInfo.firstTFOrbit, mTimingInfo.tfCounter};
385394
size_t szCTF = 0;
@@ -406,7 +415,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
406415

407416
mTimer.Stop();
408417

409-
if (mWriteCTF) {
418+
if (mWriteCTF && !mRejectCurrentTF) {
410419
szCTF += appendToTree(*mCTFTreeOut.get(), "CTFHeader", header);
411420
mAccCTFSize += szCTF;
412421
mCTFTreeOut->SetEntries(++mNAccCTF);
@@ -429,7 +438,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
429438
mCTFTreeOut->AutoSave("override");
430439
}
431440
} else {
432-
LOG(info) << "TF#" << mNCTF << " CTF writing is disabled, size was " << szCTF << " bytes";
441+
LOG(info) << "TF#" << mNCTF << " {" << header << "} CTF writing is disabled, size was " << szCTF << " bytes";
433442
}
434443

435444
mNCTF++;
@@ -701,6 +710,7 @@ DataProcessorSpec getCTFWriterSpec(DetID::mask_t dets, uint64_t run, const std::
701710
{"min-file-size", VariantType::Int64, 0l, {"accumulate CTFs until given file size reached"}},
702711
{"max-file-size", VariantType::Int64, 0l, {"if > 0, try to avoid exceeding given file size, also used for space check"}},
703712
{"max-ctf-per-file", VariantType::Int, 0, {"if > 0, avoid storing more than requested CTFs per file"}},
713+
{"ctf-rejection", VariantType::Int, 0, {">0: percentage to reject randomly, <0: reject if timeslice%|value|!=0"}},
704714
{"ignore-partition-run-dir", VariantType::Bool, false, {"Do not creare partition-run directory in output-dir"}}}};
705715
}
706716

0 commit comments

Comments
 (0)