Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions Detectors/FIT/FDD/simulation/src/digit2raw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)<<o2::utils::Str::concat_string(outDirName, wr.getOrigin().str)<<"\n";
Expand Down
10 changes: 2 additions & 8 deletions Detectors/FIT/FT0/simulation/src/digi2raw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,12 @@ void digi2raw(const std::string& inpName, const std::string& outDir, int verbosi
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"));
Expand Down
10 changes: 2 additions & 8 deletions Detectors/FIT/FV0/simulation/src/digit2raw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,12 @@ void digit2raw(const std::string& inpName, const std::string& outDir, int verbos
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.convertDigitsToRaw(outDirName, inpName);
wr.writeConfFile(wr.getOrigin().str, "RAWDATA", o2::utils::Str::concat_string(outDirName, wr.getOrigin().str, "raw.cfg"));
Expand Down
46 changes: 26 additions & 20 deletions Detectors/Raw/include/DetectorsRaw/RawFileWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ class RawFileWriter
/// Single GBT link helper
struct LinkData {
static constexpr int MarginToFlush = 10 * sizeof(RDHAny); // flush superpage if free space left <= this margin
RDHAny rdhCopy; // RDH with the running info of the last RDH seen
IR updateIR; // IR at which new HBF needs to be created
int lastRDHoffset = -1; // position of last RDH in the link buffer
bool startOfRun = true; // to signal if this is the 1st HBF of the run or not
uint8_t packetCounter = 0; // running counter
uint16_t pageCnt = 0; // running counter
LinkSubSpec_t subspec = 0; // subspec according to DataDistribution
bool discardData = false; // discard data if true (e.g. desired max IR reached)
RDHAny rdhCopy; // RDH with the running info of the last RDH seen
IR updateIR; // IR at which new HBF needs to be created
int lastRDHoffset = -1; // position of last RDH in the link buffer
bool startOfRun = true; // to signal if this is the 1st HBF of the run or not
uint8_t packetCounter = 0; // running counter
uint16_t pageCnt = 0; // running counter
LinkSubSpec_t subspec = 0; // subspec according to DataDistribution
bool discardData = false; // discard data if true (e.g. desired max IR reached)
//
size_t nTFWritten = 0; // number of TFs written
size_t nRDHWritten = 0; // number of RDHs written
size_t nBytesWritten = 0; // number of bytes written
//
std::string fileName{}; // file name associated with this link
std::vector<char> 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<char> 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<TTree> cacheTree; // tree to store the cache
Expand Down Expand Up @@ -141,7 +141,6 @@ class RawFileWriter
nRDHWritten++;
return pushBack(reinterpret_cast<const char*>(&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
Expand Down Expand Up @@ -402,13 +401,13 @@ class RawFileWriter
int mVerbosity = 0;
o2::header::DataOrigin mOrigin = o2::header::gDataOriginInvalid;
int mUseRDHVersion = RDHUtils::getVersion<o2::header::RAWDataHeader>(); // 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
Expand All @@ -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
Expand Down
31 changes: 26 additions & 5 deletions Detectors/Raw/src/RawFileWriter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "DetectorsRaw/HBFUtils.h"
#include "CommonConstants/Triggers.h"
#include "Framework/Logger.h"
#include <filesystem>

using namespace o2::raw;
using IR = o2::InteractionRecord;
Expand Down Expand Up @@ -451,7 +452,7 @@ void RawFileWriter::LinkData::addPreformattedCRUPage(const gsl::span<char> 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());
}
Expand Down Expand Up @@ -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<RDHAny>(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
}
}

Expand Down Expand Up @@ -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
}
}
6 changes: 1 addition & 5 deletions Detectors/TPC/workflow/src/convertDigitsToRawZS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions Detectors/TRD/simulation/src/trap2raw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%;";
Expand Down
10 changes: 2 additions & 8 deletions Detectors/ZDC/simulation/src/digi2raw.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down