Skip to content

Commit 05ed86d

Browse files
authored
Merge pull request #48704 from smorovic/151x-phase2-req
[DAQ] DAQSource read-only mode and processing specific lumis in file discovery mode (Phase-2)
2 parents df56735 + 78bae1a commit 05ed86d

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

EventFilter/Utilities/doc/README-DTH.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Example file name for this mode is `run123456_ls000_index000000_source01234.raw`
4444

4545
It is possible that another DAQ-specific header will be added to both file and per-orbit to better encapsulate data (similar is done for Run2/3 FRD files), to provide additional metadata to improve integrity and completeness checks after aggregation of data in DAQ. At present, only RAW DTH is supported by the "DTH" module.
4646

47+
Additional parameters were added **for file discovery mode only** to allow only specific lumisection range to be processed, `overrideRangeLS = cms.untracked.vuint32($N,$M)`, and to keep input read only, `keepRawFiles = cms.untracked.bool(True)`
48+
4749
# DAQ file formats
4850
Documentation:
4951
https://twiki.cern.ch/twiki/bin/view/CMS/FFFMetafileFormats

EventFilter/Utilities/interface/DAQSource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class DAQSource : public edm::RawInputSource {
126126
const bool fileListLoopMode_;
127127
unsigned int loopModeIterationInc_ = 0;
128128

129+
std::vector<unsigned int> overrideRangeLS_;
130+
bool keepRawFiles_;
131+
129132
edm::RunNumber_t runNumber_;
130133
std::string fuOutputDir_;
131134

EventFilter/Utilities/interface/EvFDaqDirector.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ namespace evf {
187187
bool fileListMode() const { return fileListMode_; }
188188
unsigned int lsWithFilesOpen(unsigned int ls) const;
189189

190+
void setDiscoveryRange(int minDiscoveryLS, bool readOnly) {
191+
minDiscoveryLS_ = minDiscoveryLS;
192+
discoveryReadOnly_ = readOnly;
193+
}
194+
190195
private:
191196
void createLumiSectionFiles(const uint32_t lumiSection,
192197
const uint32_t currentLumiSection,
@@ -314,6 +319,9 @@ namespace evf {
314319
std::string discard_ls_filestem_;
315320
bool fileListMode_ = false;
316321
std::pair<unsigned, int> lastFileIdx_ = std::make_pair<unsigned, int>(0, -1);
322+
323+
int minDiscoveryLS_ = -1;
324+
bool discoveryReadOnly_ = false;
317325
};
318326
} // namespace evf
319327

EventFilter/Utilities/src/DAQSource.cc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ DAQSource::DAQSource(edm::ParameterSet const& pset, edm::InputSourceDescription
5050
fileListMode_(pset.getUntrackedParameter<bool>("fileListMode")),
5151
fileDiscoveryMode_(pset.getUntrackedParameter<bool>("fileDiscoveryMode", false)),
5252
fileListLoopMode_(pset.getUntrackedParameter<bool>("fileListLoopMode", false)),
53+
overrideRangeLS_(
54+
pset.getUntrackedParameter<std::vector<unsigned int>>("overrideRangeLS", std::vector<unsigned int>())),
55+
keepRawFiles_(pset.getUntrackedParameter<bool>("keepRawFiles", false)),
5356
runNumber_(edm::Service<evf::EvFDaqDirector>()->getRunNumber()),
5457
processHistoryID_(),
5558
currentLumiSection_(0),
@@ -719,6 +722,8 @@ void DAQSource::readSupervisor() {
719722
uint64_t sumLockWaitTimeUs = 0.;
720723

721724
bool requireHeader = dataMode_->requireHeader();
725+
int minDiscoveryLS = !overrideRangeLS_.empty() ? overrideRangeLS_.at(0) : -1;
726+
daqDirector_->setDiscoveryRange(minDiscoveryLS, keepRawFiles_);
722727

723728
while (!stop) {
724729
//wait for at least one free thread and chunk
@@ -855,6 +860,7 @@ void DAQSource::readSupervisor() {
855860
[&](std::string const& name, int& fd, int64_t& fsize, uint32_t sLS, bool& found) -> unsigned int {
856861
return dataMode_->eventCounterCallback(name, fd, fsize, sLS, found);
857862
};
863+
nextFile = std::string();
858864

859865
status = daqDirector_->getNextFromFileBroker(currentLumiSection,
860866
ls,
@@ -904,16 +910,39 @@ void DAQSource::readSupervisor() {
904910
if (ls > currentLumiSection) {
905911
//new file service
906912
if (currentLumiSection == 0 && !alwaysStartFromFirstLS_) {
907-
if (daqDirector_->getStartLumisectionFromEnv() > 1) {
913+
auto lsFromEnv = daqDirector_->getStartLumisectionFromEnv();
914+
unsigned int lsFromEnvMax = 0;
915+
//override if parameter is specified
916+
if (!overrideRangeLS_.empty()) {
917+
lsFromEnv = overrideRangeLS_.at(0);
918+
if (overrideRangeLS_.size() > 1) {
919+
lsFromEnvMax = overrideRangeLS_.at(1);
920+
}
921+
if (overrideRangeLS_.size() > 2)
922+
edm::LogError("DAQSource") << "More than two parameters in overrideRangeLS, they will be ignored.";
923+
}
924+
if (lsFromEnv > 1) {
908925
//start transitions from LS specified by env, continue if not reached
909-
if (ls < daqDirector_->getStartLumisectionFromEnv()) {
926+
//not currently compatible with fileListMode
927+
//note that this should not be higher LS than daqDirector has already handled (if daqDirector is used)
928+
if (ls < lsFromEnv) {
910929
//skip file if from earlier LS than specified by env
911930
if (rawFd != -1) {
912931
close(rawFd);
913932
rawFd = -1;
914933
}
915934
status = evf::EvFDaqDirector::noFile;
916935
continue;
936+
} else if (lsFromEnvMax && lsFromEnvMax < ls) {
937+
//finished specified LS window
938+
if (rawFd != -1) {
939+
close(rawFd);
940+
rawFd = -1;
941+
}
942+
status = evf::EvFDaqDirector::runEnded;
943+
fileQueue_.push(std::make_unique<RawInputFile>(evf::EvFDaqDirector::runEnded));
944+
stop = true;
945+
break;
917946
} else {
918947
fileQueue_.push(std::make_unique<RawInputFile>(evf::EvFDaqDirector::newLumi, ls));
919948
}
@@ -930,6 +959,16 @@ void DAQSource::readSupervisor() {
930959
}
931960
} else {
932961
//queue all lumisections after last one seen to avoid gaps
962+
unsigned lsFromEnvMax = overrideRangeLS_.size() > 1 ? overrideRangeLS_[1] : 0;
963+
if (lsFromEnvMax && lsFromEnvMax < ls) {
964+
for (unsigned int nextLS = currentLumiSection + 1; nextLS <= lsFromEnvMax; nextLS++)
965+
fileQueue_.push(std::make_unique<RawInputFile>(evf::EvFDaqDirector::newLumi, nextLS));
966+
status = evf::EvFDaqDirector::runEnded;
967+
fileQueue_.push(std::make_unique<RawInputFile>(evf::EvFDaqDirector::runEnded));
968+
stop = true;
969+
break;
970+
}
971+
933972
for (unsigned int nextLS = currentLumiSection + 1; nextLS <= ls; nextLS++) {
934973
fileQueue_.push(std::make_unique<RawInputFile>(evf::EvFDaqDirector::newLumi, nextLS));
935974
}
@@ -1024,6 +1063,10 @@ void DAQSource::readSupervisor() {
10241063
0,
10251064
eventsInNewFile,
10261065
this));
1066+
if (keepRawFiles_) {
1067+
edm::LogWarning("DAQSource") << "Disabling raw file deletion for " << rawFile;
1068+
newInputFile->unsetDeleteFile();
1069+
}
10271070

10281071
uint64_t neededSize = fileSize;
10291072
for (const auto& addFile : additionalFiles.second) {

EventFilter/Utilities/src/DAQSourceModelsDTH.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ int DataModeDTH::eventCounterCallback(
476476
if ((rawFd = ::open(name.c_str(), O_RDONLY)) < 0) {
477477
assert(rawFd == -1);
478478
found = false;
479-
edm::LogError("EvFDaqDirector") << "parseFRDFileHeader - failed to open input file -: " << name << " : "
480-
<< strerror(errno);
479+
edm::LogError("EvFDaqDirector") << "rawCounter - failed to open input file -: " << name << " : " << strerror(errno);
481480
return -1;
482481
}
483482
found = true;

EventFilter/Utilities/src/EvFDaqDirector.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ namespace evf {
11381138
if (rawFd == -1) {
11391139
if ((rawFd = ::open(rawPath.c_str(), O_RDONLY)) < 0) {
11401140
edm::LogWarning("EvFDaqDirector")
1141-
<< "parseFRDFileHeader - failed to open input file -: " << rawPath << " : " << strerror(errno);
1141+
<< "hasFRDFileHeader - failed to open input file -: " << rawPath << " : " << strerror(errno);
11421142
return retErr();
11431143
}
11441144
}
@@ -1930,6 +1930,8 @@ namespace evf {
19301930
continue;
19311931
}
19321932
auto lumi = extractLumiSectionNumber(fname);
1933+
if (lumi > 0 && lumi < minDiscoveryLS_)
1934+
continue;
19331935
if (fname.find("_EoLS.jsn") != std::string::npos) {
19341936
if (lumi > (int)maxClosedLS)
19351937
maxClosedLS = lumi;
@@ -1957,7 +1959,7 @@ namespace evf {
19571959
if (fname.size() < 4 || fname.substr(fname.size() - 4) != std::string(".raw"))
19581960
continue;
19591961
if (lumi >= (int)lastFileIdx_.first) {
1960-
if (extractIndexNumber(fname) >= lastFileIdx_.second) {
1962+
if (extractIndexNumber(fname) > lastFileIdx_.second) {
19611963
filenames.push_back(entry.path().filename().string());
19621964
}
19631965
}
@@ -2037,9 +2039,14 @@ namespace evf {
20372039
fmt::format("{}{}{}{}", bu_run_dir_, fileprefix, p.stem().string(), p.extension().string());
20382040
try {
20392041
//grab file if possible
2040-
std::filesystem::rename(rawpath, nextFileRawTmp);
2041-
//apply changes
2042-
nextFileRaw = nextFileRawTmp;
2042+
if (!discoveryReadOnly_) {
2043+
//read-only mode allows only one client in file discovery option
2044+
std::filesystem::rename(rawpath, nextFileRawTmp);
2045+
//apply changes
2046+
nextFileRaw = nextFileRawTmp;
2047+
} else
2048+
nextFileRaw = rawpath;
2049+
20432050
serverLS = nextLS; //if changed
20442051
closedServerLS = nextLS - 1;
20452052

0 commit comments

Comments
 (0)