Skip to content

Commit 726f6fc

Browse files
committed
Extra options for CTF flushing/compression
1 parent e33e75a commit 726f6fc

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Detectors/CTF/workflow/src/CTFWriterSpec.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ class CTFWriterSpec : public o2::framework::Task
138138
size_t mNCTF = 0; // total number of CTFs written
139139
size_t mNCTFPrevDict = 0; // total number of CTFs used for previous dictionary version
140140
size_t mNAccCTF = 0; // total number of CTFs accumulated in the current file
141-
size_t mCTFAutoSave = 0; // if > 0, autosave after so many TFs
141+
long mCTFAutoSave = 0; // if > 0, autosave after so many TFs
142142
size_t mNCTFFiles = 0; // total number of CTF files written
143143
int mMaxCTFPerFile = 0; // max CTFs per files to store
144144
int mRejRate = 0; // CTF rejection rule (>0: percentage to reject randomly, <0: reject if timeslice%|value|!=0)
145+
int mCTFFileCompression = 0; // CTF file compression level (if >= 0)
145146
std::vector<uint32_t> mTFOrbits{}; // 1st orbits of TF accumulated in current file
146147
o2::framework::DataTakingContext mDataTakingContext{};
147148
o2::framework::TimingInfo mTimingInfo{};
@@ -210,7 +211,8 @@ void CTFWriterSpec::init(InitContext& ic)
210211
}
211212

212213
mSaveDictAfter = ic.options().get<int>("save-dict-after");
213-
mCTFAutoSave = ic.options().get<int>("save-ctf-after");
214+
mCTFAutoSave = ic.options().get<long>("save-ctf-after");
215+
mCTFFileCompression = ic.options().get<int>("ctf-file-compression");
214216
mCTFMetaFileDir = ic.options().get<std::string>("meta-output-dir");
215217
if (mCTFMetaFileDir != "/dev/null") {
216218
mCTFMetaFileDir = o2::utils::Str::rectifyDirectory(mCTFMetaFileDir);
@@ -445,6 +447,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
445447

446448
if (mWriteCTF && !mRejectCurrentTF) {
447449
szCTF += appendToTree(*mCTFTreeOut.get(), "CTFHeader", header);
450+
size_t prevSizeMB = mAccCTFSize / (1 << 20);
448451
mAccCTFSize += szCTF;
449452
mCTFTreeOut->SetEntries(++mNAccCTF);
450453
mTFOrbits.push_back(mTimingInfo.firstTForbit);
@@ -462,7 +465,7 @@ void CTFWriterSpec::run(ProcessingContext& pc)
462465

463466
if (mAccCTFSize >= mMinSize || (mMaxCTFPerFile > 0 && mNAccCTF >= mMaxCTFPerFile)) {
464467
closeTFTreeAndFile();
465-
} else if (mCTFAutoSave > 0 && mNAccCTF % mCTFAutoSave == 0) {
468+
} else if ((mCTFAutoSave > 0 && mNAccCTF % mCTFAutoSave == 0) || (mCTFAutoSave < 0 && int(prevSizeMB / (-mCTFAutoSave)) != size_t(mAccCTFSize / (1 << 20)) / (-mCTFAutoSave))) {
466469
mCTFTreeOut->AutoSave("override");
467470
}
468471
} else {
@@ -535,6 +538,9 @@ void CTFWriterSpec::prepareTFTreeAndFile()
535538
mCurrentCTFFileName = o2::base::NameConf::getCTFFileName(mTimingInfo.runNumber, mTimingInfo.firstTForbit, mTimingInfo.tfCounter, mHostName);
536539
mCurrentCTFFileNameFull = fmt::format("{}{}", ctfDir, mCurrentCTFFileName);
537540
mCTFFileOut.reset(TFile::Open(fmt::format("{}{}", mCurrentCTFFileNameFull, TMPFileEnding).c_str(), "recreate")); // to prevent premature external usage, use temporary name
541+
if (mCTFFileCompression >= 0) {
542+
mCTFFileOut->SetCompressionLevel(mCTFFileCompression);
543+
}
538544
mCTFTreeOut = std::make_unique<TTree>(std::string(o2::base::NameConf::CTFTREENAME).c_str(), "O2 CTF tree");
539545

540546
mNCTFFiles++;
@@ -733,7 +739,7 @@ DataProcessorSpec getCTFWriterSpec(DetID::mask_t dets, const std::string& outTyp
733739
Outputs{},
734740
AlgorithmSpec{adaptFromTask<CTFWriterSpec>(dets, outType, verbosity, reportInterval)}, // RS FIXME once global/local options clash is solved, --output-type will become device option
735741
Options{ //{"output-type", VariantType::String, "ctf", {"output types: ctf (per TF) or dict (create dictionaries) or both or none"}},
736-
{"save-ctf-after", VariantType::Int, 0, {"if > 0, autosave CTF tree with multiple CTFs after every N CTFs"}},
742+
{"save-ctf-after", VariantType::Int64, 0ll, {"autosave CTF tree with multiple CTFs after every N CTFs if >0 or every -N MBytes if < 0"}},
737743
{"save-dict-after", VariantType::Int, 0, {"if > 0, in dictionary generation mode save it dictionary after certain number of TFs processed"}},
738744
{"ctf-dict-dir", VariantType::String, "none", {"CTF dictionary directory, must exist"}},
739745
{"output-dir", VariantType::String, "none", {"CTF output directory, must exist"}},
@@ -743,6 +749,7 @@ DataProcessorSpec getCTFWriterSpec(DetID::mask_t dets, const std::string& outTyp
743749
{"max-file-size", VariantType::Int64, 0l, {"if > 0, try to avoid exceeding given file size, also used for space check"}},
744750
{"max-ctf-per-file", VariantType::Int, 0, {"if > 0, avoid storing more than requested CTFs per file"}},
745751
{"ctf-rejection", VariantType::Int, 0, {">0: percentage to reject randomly, <0: reject if timeslice%|value|!=0"}},
752+
{"ctf-file-compression", VariantType::Int, 0, {"if >= 0: impose CTF file compression level"}},
746753
{"ignore-partition-run-dir", VariantType::Bool, false, {"Do not creare partition-run directory in output-dir"}}}};
747754
}
748755

0 commit comments

Comments
 (0)