diff --git a/Detectors/FIT/FDD/simulation/src/digit2raw.cxx b/Detectors/FIT/FDD/simulation/src/digit2raw.cxx index 94e45a9a48051..4437237c9c98a 100644 --- a/Detectors/FIT/FDD/simulation/src/digit2raw.cxx +++ b/Detectors/FIT/FDD/simulation/src/digit2raw.cxx @@ -104,20 +104,13 @@ void digi2raw(const std::string& inpName, const std::string& outDir, bool filePe wr.useRDHVersion(rdhV); wr.setDontFillEmptyHBF(noEmptyHBF); + o2::raw::assertOutputDirectory(outDir); + std::string outDirName(outDir); if (outDirName.back() != '/') { outDirName += '/'; } - // if needed, create output directory - if (!std::filesystem::exists(outDirName)) { - if (!std::filesystem::create_directories(outDirName)) { - LOG(FATAL) << "could not create output directory " << outDirName; - } else { - LOG(INFO) << "created output directory " << outDirName; - } - } - m2r.readDigits(outDirName, inpName); wr.writeConfFile(wr.getOrigin().str, "RAWDATA", o2::utils::Str::concat_string(outDirName, wr.getOrigin().str, "raw.cfg")); //LOG(INFO)< buffer; // buffer to accumulate superpage data - RawFileWriter* writer = nullptr; // pointer on the parent writer + std::string fileName{}; // file name associated with this link + std::vector buffer; // buffer to accumulate superpage data + RawFileWriter* writer = nullptr; // pointer on the parent writer PayloadCache cacheBuffer; // used for caching in case of async. data input std::unique_ptr cacheTree; // tree to store the cache @@ -141,7 +141,6 @@ class RawFileWriter nRDHWritten++; return pushBack(reinterpret_cast(&rdh), sizeof(RDHAny), false); } - }; //===================================================================================== // If addData was called with given IR for at least 1 link, then it should be called for all links, even it with empty payload @@ -402,13 +401,13 @@ class RawFileWriter int mVerbosity = 0; o2::header::DataOrigin mOrigin = o2::header::gDataOriginInvalid; int mUseRDHVersion = RDHUtils::getVersion(); // by default, use default version - int mSuperPageSize = 1024 * 1024; // super page size - bool mStartTFOnNewSPage = true; // every TF must start on a new SPage - bool mDontFillEmptyHBF = false; // skipp adding empty HBFs (uness it must have TF flag) - bool mAddSeparateHBFStopPage = true; // HBF stop is added on a separate CRU page - bool mUseRDHStop = true; // detector uses STOP in RDH - bool mCRUDetector = true; // Detector readout via CRU ( RORC if false) - bool mApplyCarryOverToLastPage = false; // call CarryOver method also for last chunk and overwrite modified trailer + int mSuperPageSize = 1024 * 1024; // super page size + bool mStartTFOnNewSPage = true; // every TF must start on a new SPage + bool mDontFillEmptyHBF = false; // skipp adding empty HBFs (uness it must have TF flag) + bool mAddSeparateHBFStopPage = true; // HBF stop is added on a separate CRU page + bool mUseRDHStop = true; // detector uses STOP in RDH + bool mCRUDetector = true; // Detector readout via CRU ( RORC if false) + bool mApplyCarryOverToLastPage = false; // call CarryOver method also for last chunk and overwrite modified trailer //>> caching -------------- bool mCachingStage = false; // signal that current data should be cached @@ -425,7 +424,14 @@ class RawFileWriter bool mDoLazinessCheck = true; ClassDefNV(RawFileWriter, 1); -}; // namespace raw +}; + +/** Ensure (i.e. create if needed) directory + * @param outDirName : output path to be asserted + * + * Log a FATAL if the directory does not exist and can not be created + */ +void assertOutputDirectory(std::string_view outDirName); } // namespace raw } // namespace o2 diff --git a/Detectors/Raw/src/RawFileWriter.cxx b/Detectors/Raw/src/RawFileWriter.cxx index 425aa2dba2dc9..c8182cc740da2 100644 --- a/Detectors/Raw/src/RawFileWriter.cxx +++ b/Detectors/Raw/src/RawFileWriter.cxx @@ -22,6 +22,7 @@ #include "DetectorsRaw/HBFUtils.h" #include "CommonConstants/Triggers.h" #include "Framework/Logger.h" +#include using namespace o2::raw; using IR = o2::InteractionRecord; @@ -451,7 +452,7 @@ void RawFileWriter::LinkData::addPreformattedCRUPage(const gsl::span data) throw std::runtime_error("preformatted payload exceeds max size"); } if (int(buffer.size()) - lastRDHoffset > sizeof(RDHAny)) { // we must start from empty page - addHBFPage(); // start new CRU page + addHBFPage(); // start new CRU page } pushBack(&data[0], data.size()); } @@ -646,11 +647,11 @@ void RawFileWriter::LinkData::fillEmptyHBHs(const IR& ir, bool dataAdded) if (writer->mVerbosity > 2) { LOG(INFO) << "Adding HBF " << ir << " for " << describe(); } - closeHBFPage(); // close current HBF: add RDH with stop and update counters - RDHUtils::setTriggerType(rdhCopy, 0); // reset to avoid any detector specific flags in the dummy HBFs + closeHBFPage(); // close current HBF: add RDH with stop and update counters + RDHUtils::setTriggerType(rdhCopy, 0); // reset to avoid any detector specific flags in the dummy HBFs writer->mHBFUtils.updateRDH(rdhCopy, ir, false); // update HBF orbit/bc and trigger flags - openHBFPage(rdhCopy); // open new HBF - updateIR = ir + 1; // new Trigger in RORC detector will be generated at >= this IR + openHBFPage(rdhCopy); // open new HBF + updateIR = ir + 1; // new Trigger in RORC detector will be generated at >= this IR } } @@ -726,3 +727,23 @@ void RawFileWriter::DetLazinessCheck::completeLinks(RawFileWriter* wr, const IR& } clear(); } + +void o2::raw::assertOutputDirectory(std::string_view outDirName) +{ + if (!std::filesystem::exists(outDirName)) { +#if defined(__clang__) + // clang `create_directories` implementation is misbehaving and can + // return false even if the directory is actually successfully created + // so we work around that "feature" by not checking the + // return value at all but using a second call to `exists` + std::filesystem::create_directories(outDirName); + if (!std::filesystem::exists(outDirName)) { + LOG(FATAL) << "could not create output directory " << outDirName; + } +#else + if (!std::filesystem::create_directories(outDirName)) { + LOG(FATAL) << "could not create output directory " << outDirName; + } +#endif + } +} diff --git a/Detectors/TPC/workflow/src/convertDigitsToRawZS.cxx b/Detectors/TPC/workflow/src/convertDigitsToRawZS.cxx index 30a4cb7cb13fc..0d0764bcf1f39 100644 --- a/Detectors/TPC/workflow/src/convertDigitsToRawZS.cxx +++ b/Detectors/TPC/workflow/src/convertDigitsToRawZS.cxx @@ -97,11 +97,7 @@ void convertDigitsToZSfinal(std::string_view digitsFile, std::string_view output // if needed, create output directory if (!std::filesystem::exists(outDir)) { if (createParentDir) { - if (!std::filesystem::create_directories(outDir)) { - LOG(FATAL) << "could not create output directory " << outDir; - } else { - LOG(INFO) << "created output directory " << outDir; - } + o2::raw::assertOutputDirectory(outDir); } else { LOGP(error, "Requested output directory '{}' does not exists, consider removing '-n'", outDir); exit(1); diff --git a/Detectors/TRD/simulation/src/trap2raw.cxx b/Detectors/TRD/simulation/src/trap2raw.cxx index 910321fe41ed7..7948a362de602 100644 --- a/Detectors/TRD/simulation/src/trap2raw.cxx +++ b/Detectors/TRD/simulation/src/trap2raw.cxx @@ -129,18 +129,12 @@ void trap2raw(const std::string& inpDigitsName, const std::string& inpTrackletsN wr.useRDHVersion(rdhV); wr.setDontFillEmptyHBF(noEmptyHBF); + o2::raw::assertOutputDirectory(outDir); + std::string outDirName(outDir); if (outDirName.back() != '/') { outDirName += '/'; } - // if needed, create output directory - if (!std::filesystem::exists(outDirName)) { - if (!std::filesystem::create_directories(outDirName)) { - LOG(FATAL) << "could not create output directory " << outDirName; - } else { - LOG(INFO) << "created output directory " << outDirName; - } - } mc2raw.setTrackletHCHeader(trackletHCHeader); LOG(info) << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;"; diff --git a/Detectors/ZDC/simulation/src/digi2raw.cxx b/Detectors/ZDC/simulation/src/digi2raw.cxx index e3b3557510bbe..c205d0cdf1673 100644 --- a/Detectors/ZDC/simulation/src/digi2raw.cxx +++ b/Detectors/ZDC/simulation/src/digi2raw.cxx @@ -153,18 +153,12 @@ void digi2raw(const std::string& inpName, const std::string& outDir, int verbosi wr.setSuperPageSize(superPageSizeInB); wr.useRDHVersion(rdhV); + o2::raw::assertOutputDirectory(outDir); + std::string outDirName(outDir); if (outDirName.back() != '/') { outDirName += '/'; } - // if needed, create output directory - if (!std::filesystem::exists(outDirName)) { - if (!std::filesystem::create_directories(outDirName)) { - LOG(FATAL) << "could not create output directory " << outDirName; - } else { - LOG(INFO) << "created output directory " << outDirName; - } - } d2r.setModuleConfig(moduleConfig); d2r.setSimCondition(simCondition);