Skip to content

Commit edcfb9c

Browse files
authored
Merge pull request #48859 from smorovic/151x-rawwriter-one-ls-v3
[DAQ] HLT test-stand conversion job patches
2 parents 727b6d9 + cc804fa commit edcfb9c

File tree

6 files changed

+71
-49
lines changed

6 files changed

+71
-49
lines changed

EventFilter/Utilities/interface/EvFDaqDirector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ namespace evf {
6868
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
6969
void preallocate(edm::service::SystemBounds const& bounds);
7070
void preBeginRun(edm::GlobalContext const& globalContext);
71-
void postEndRun(edm::GlobalContext const& globalContext);
7271
void preGlobalEndLumi(edm::GlobalContext const& globalContext);
7372
void updateRunParams();
7473
void overrideRunNumber(unsigned int run) {

EventFilter/Utilities/plugins/RawEventFileWriterForBU.cc

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ using namespace edm::streamer;
2424

2525
RawEventFileWriterForBU::RawEventFileWriterForBU(edm::ParameterSet const& ps)
2626
: microSleep_(ps.getParameter<int>("microSleep")),
27-
frdFileVersion_(ps.getParameter<unsigned int>("frdFileVersion")) {
27+
frdFileVersion_(ps.getParameter<unsigned int>("frdFileVersion")),
28+
writeEoR_(ps.getUntrackedParameter<bool>("writeEoR")),
29+
writeToOpen_(ps.getUntrackedParameter<bool>("writeToOpen")) {
2830
if (edm::Service<evf::FastMonitoringService>().isAvailable())
2931
fms_ = static_cast<evf::FastMonitoringService*>(edm::Service<evf::FastMonitoringService>().operator->());
3032

@@ -185,7 +187,6 @@ void RawEventFileWriterForBU::initialize(std::string const& destinationDir,
185187
void RawEventFileWriterForBU::writeJsds() {
186188
std::stringstream ss;
187189
ss << destinationDir_ << "/jsd";
188-
mkdir(ss.str().c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
189190

190191
std::string rawJSDName = ss.str() + "/rawData.jsd";
191192
std::string eolJSDName = ss.str() + "/EoLS.jsd";
@@ -196,6 +197,21 @@ void RawEventFileWriterForBU::writeJsds() {
196197
runMon_->setDefPath(eorJSDName);
197198

198199
struct stat fstat;
200+
201+
//only crete JSD definitions from process that created directory
202+
std::string outdirpath = ss.str();
203+
if (stat(outdirpath.c_str(), &fstat) == 0)
204+
return;
205+
206+
auto retval = mkdir(outdirpath.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
207+
if (retval) {
208+
if (errno == EEXIST)
209+
return;
210+
else
211+
throw cms::Exception("RawEventFileWriterForBU", "writeJsds")
212+
<< "Error creating directory " << outdirpath << " : " << strerror(errno);
213+
}
214+
199215
if (stat(rawJSDName.c_str(), &fstat) != 0) {
200216
std::string content;
201217
JSONSerializer::serialize(&rawJsonDef_, content);
@@ -223,7 +239,8 @@ void RawEventFileWriterForBU::finishFileWrite(unsigned int ls) {
223239
write(outfd_, (char*)&frdFileHeader, sizeof(FRDFileHeader_v1));
224240
closefd();
225241
//move raw file from open to run directory
226-
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
242+
if (!writeToOpen_)
243+
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
227244

228245
edm::LogInfo("RawEventFileWriterForBU")
229246
<< "Wrote RAW input file: " << fileName_ << " with perFileEventCount = " << perFileEventCount_.value()
@@ -234,14 +251,16 @@ void RawEventFileWriterForBU::finishFileWrite(unsigned int ls) {
234251
write(outfd_, (char*)&frdFileHeader, sizeof(FRDFileHeader_v2));
235252
closefd();
236253
//move raw file from open to run directory
237-
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
254+
if (!writeToOpen_)
255+
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
238256
edm::LogInfo("RawEventFileWriterForBU")
239257
<< "Wrote RAW input file: " << fileName_ << " with perFileEventCount = " << perFileEventCount_.value()
240258
<< " and size " << perFileSize_.value();
241259
} else {
242260
closefd();
243261
//move raw file from open to run directory
244-
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
262+
if (!writeToOpen_)
263+
rename(fileName_.c_str(), (destinationDir_ + fileName_.substr(fileName_.rfind('/'))).c_str());
245264
//create equivalent JSON file
246265
//TODO:fix this to use DaqDirector convention and better extension replace
247266
std::filesystem::path source(fileName_);
@@ -252,7 +271,8 @@ void RawEventFileWriterForBU::finishFileWrite(unsigned int ls) {
252271
fileMon_->discardCollected(ls);
253272

254273
//move the json file from open
255-
rename(path.c_str(), (destinationDir_ + path.substr(path.rfind('/'))).c_str());
274+
if (!writeToOpen_)
275+
rename(path.c_str(), (destinationDir_ + path.substr(path.rfind('/'))).c_str());
256276

257277
edm::LogInfo("RawEventFileWriterForBU")
258278
<< "Wrote JSON input file: " << path << " with perFileEventCount = " << perFileEventCount_.value()
@@ -274,17 +294,23 @@ void RawEventFileWriterForBU::endOfLS(unsigned int ls) {
274294
}
275295
lumiMon_->snap(ls);
276296

297+
std::ostringstream ostrOpen;
277298
std::ostringstream ostr;
278299

300+
ostrOpen << destinationDir_ << "/open/" << runPrefix_ << "_ls" << std::setfill('0') << std::setw(4) << ls << "_EoLS"
301+
<< ".jsn";
279302
ostr << destinationDir_ << "/" << runPrefix_ << "_ls" << std::setfill('0') << std::setw(4) << ls << "_EoLS"
280303
<< ".jsn";
281304
//outfd_ = open(ostr.str().c_str(), O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
282305
//closefd();
283306

284-
std::string path = ostr.str();
285-
lumiMon_->outputFullJSON(path, ls);
307+
std::string pathOpen = ostrOpen.str();
308+
lumiMon_->outputFullJSON(pathOpen, ls);
286309
lumiMon_->discardCollected(ls);
287310

311+
if (!writeToOpen_)
312+
rename(pathOpen.c_str(), ostr.str().c_str());
313+
288314
perRunEventCount_.value() += perLumiEventCount_.value();
289315
perRunTotalEventCount_.value() = perRunEventCount_.value();
290316
perRunFileCount_.value() += perLumiFileCount_.value();
@@ -301,16 +327,20 @@ void RawEventFileWriterForBU::endOfLS(unsigned int ls) {
301327
void RawEventFileWriterForBU::stop() {
302328
if (lumiOpen_ > lumiClosed_)
303329
endOfLS(lumiOpen_);
304-
edm::LogInfo("RawEventFileWriterForBU") << "Writing EOR file!";
305-
if (!destinationDir_.empty()) {
330+
if (writeEoR_ && !destinationDir_.empty()) {
331+
edm::LogInfo("RawEventFileWriterForBU") << "Writing EOR file!";
306332
// create EoR file
333+
std::string pathOpen = destinationDir_ + "/open/" + runPrefix_ + "_ls0000_EoR.jsn";
307334
std::string path = destinationDir_ + "/" + runPrefix_ + "_ls0000_EoR.jsn";
308335
runMon_->snap(0);
309-
runMon_->outputFullJSON(path, 0);
336+
runMon_->outputFullJSON(pathOpen, 0);
337+
if (!writeToOpen_)
338+
rename(pathOpen.c_str(), path.c_str());
310339
}
311340
}
312341

313342
void RawEventFileWriterForBU::extendDescription(edm::ParameterSetDescription& desc) {
314343
desc.add<int>("microSleep", 0);
315344
desc.add<unsigned int>("frdFileVersion", 0);
345+
desc.addUntracked<bool>("writeEoR", true);
316346
}

EventFilter/Utilities/plugins/RawEventFileWriterForBU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class RawEventFileWriterForBU {
8888

8989
int microSleep_;
9090
unsigned int frdFileVersion_;
91+
bool writeEoR_;
92+
bool writeToOpen_;
9193

9294
edm::streamer::uint32 adlera_;
9395
edm::streamer::uint32 adlerb_;

EventFilter/Utilities/plugins/RawEventOutputModuleForBU.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ void RawEventOutputModuleForBU<Consumer>::fillDescriptions(edm::ConfigurationDes
255255
desc.addUntracked<std::string>("rawProductName", "FEDRawDataCollection")
256256
->setComment("FEDRawDataCollection or RawDataBuffer");
257257
desc.addUntracked<std::vector<unsigned int>>("sourceIdList", std::vector<unsigned int>());
258+
desc.addUntracked<bool>("writeToOpen", false);
258259
Consumer::extendDescription(desc);
259260

260261
descriptions.addWithDefaultLabel(desc);

EventFilter/Utilities/src/EvFDaqDirector.cc

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ namespace evf {
5757
hltSourceDirectory_(pset.getUntrackedParameter<std::string>("hltSourceDirectory", "")),
5858
hostname_(""),
5959
bu_readlock_fd_(-1),
60-
bu_writelock_fd_(-1),
6160
fu_readwritelock_fd_(-1),
6261
fulocal_rwlock_fd_(-1),
6362
fulocal_rwlock_fd2_(-1),
64-
bu_w_lock_stream(nullptr),
65-
bu_r_lock_stream(nullptr),
6663
fu_rw_lock_stream(nullptr),
6764
dirManager_(base_dir_),
6865
previousFileSize_(0),
@@ -74,7 +71,6 @@ namespace evf {
7471
fu_rw_fulk(make_flock(F_UNLCK, SEEK_SET, 0, 0, getpid())) {
7572
reg.watchPreallocate(this, &EvFDaqDirector::preallocate);
7673
reg.watchPreGlobalBeginRun(this, &EvFDaqDirector::preBeginRun);
77-
reg.watchPostGlobalEndRun(this, &EvFDaqDirector::postEndRun);
7874
reg.watchPreGlobalEndLumi(this, &EvFDaqDirector::preGlobalEndLumi);
7975

8076
//save hostname for later
@@ -216,7 +212,6 @@ namespace evf {
216212
//for BU, it is created at this point
217213
if (directorBU_) {
218214
bu_run_dir_ = base_dir_ + "/" + run_string_;
219-
std::string bulockfile = bu_run_dir_ + "/bu.lock";
220215
fulockfile_ = bu_run_dir_ + "/fu.lock";
221216

222217
//make or find bu run dir
@@ -232,30 +227,23 @@ namespace evf {
232227
<< " Error creating bu run open dir -: " << bu_run_open_dir_ << " mkdir error:" << strerror(errno);
233228
}
234229

235-
// the BU director does not need to know about the fu lock
236-
bu_writelock_fd_ = open(bulockfile.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
237-
if (bu_writelock_fd_ == -1)
238-
edm::LogWarning("EvFDaqDirector") << "problem with creating filedesc for buwritelock -: " << strerror(errno);
239-
else
240-
edm::LogInfo("EvFDaqDirector") << "creating filedesc for buwritelock -: " << bu_writelock_fd_;
241-
bu_w_lock_stream = fdopen(bu_writelock_fd_, "w");
242-
if (bu_w_lock_stream == nullptr)
243-
edm::LogWarning("EvFDaqDirector") << "Error creating write lock stream -: " << strerror(errno);
244-
245-
// BU INITIALIZES LOCK FILE
246-
// FU LOCK FILE OPEN
247-
openFULockfileStream(true);
248-
tryInitializeFuLockFile();
249-
fflush(fu_rw_lock_stream);
250-
close(fu_readwritelock_fd_);
251-
252230
if (!hltSourceDirectory_.empty()) {
253231
struct stat buf;
254232
if (stat(hltSourceDirectory_.c_str(), &buf) == 0) {
255233
std::string hltdir = bu_run_dir_ + "/hlt";
256-
std::string tmphltdir = bu_run_open_dir_ + "/hlt";
234+
if (!stat(hltdir.c_str(), &buf)) {
235+
edm::LogInfo("EvFDaqDirector") << "hlt directory already exists";
236+
return;
237+
}
238+
239+
timeval ts_temp;
240+
gettimeofday(&ts_temp, nullptr);
241+
std::stringstream ss;
242+
ss << bu_run_open_dir_ << "/hlt" << getpid() << "_" << ts_temp.tv_sec << "_" << ts_temp.tv_usec;
243+
std::string tmphltdir = ss.str();
244+
//this directory should be unique
257245
retval = mkdir(tmphltdir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
258-
if (retval != 0 && errno != EEXIST)
246+
if (retval)
259247
throw cms::Exception("DaqDirector")
260248
<< " Error creating bu run dir -: " << hltdir << " mkdir error:" << strerror(errno);
261249

@@ -274,8 +262,12 @@ namespace evf {
274262
} catch (...) {
275263
}
276264
}
277-
278-
std::filesystem::rename(tmphltdir, hltdir);
265+
try {
266+
std::filesystem::rename(tmphltdir, hltdir);
267+
} catch (std::filesystem::filesystem_error& e) {
268+
if (e.code() != std::errc::file_exists)
269+
throw e;
270+
}
279271
} else
280272
throw cms::Exception("DaqDirector") << " Error looking for HLT configuration -: " << hltSourceDirectory_;
281273
}
@@ -431,15 +423,6 @@ namespace evf {
431423
}
432424
}
433425

434-
void EvFDaqDirector::postEndRun(edm::GlobalContext const& globalContext) {
435-
close(bu_readlock_fd_);
436-
close(bu_writelock_fd_);
437-
if (directorBU_) {
438-
std::string filename = bu_run_dir_ + "/bu.lock";
439-
removeFile(filename);
440-
}
441-
}
442-
443426
void EvFDaqDirector::preGlobalEndLumi(edm::GlobalContext const& globalContext) {
444427
lsWithFilesMap_.erase(globalContext.luminosityBlockID().luminosityBlock());
445428
}

EventFilter/Utilities/test/startBU.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
options = VarParsing.VarParsing ('analysis')
1212

1313
options.register ('runNumber',
14-
100, # default value
14+
100101, # default value
1515
VarParsing.VarParsing.multiplicity.singleton,
1616
VarParsing.VarParsing.varType.int, # string, int, or float
1717
"Run Number")
@@ -70,13 +70,19 @@
7070
VarParsing.VarParsing.varType.string, # string, int, or float
7171
"List of generated subsystem FEDs. Empty means all.")
7272

73-
7473
options.register ('conversionTest',
7574
False,
7675
VarParsing.VarParsing.multiplicity.singleton,
7776
VarParsing.VarParsing.varType.bool,
7877
"Test conversion between new and old format")
7978

79+
options.register ('writeToOpen',
80+
0,
81+
VarParsing.VarParsing.multiplicity.singleton,
82+
VarParsing.VarParsing.varType.int, # string, int, or float
83+
"Write only to open directory")
84+
85+
8086

8187
options.parseArguments()
8288

@@ -155,6 +161,7 @@
155161
numEventsPerFile = cms.uint32(options.eventsPerFile),
156162
frdVersion = cms.uint32(6),
157163
frdFileVersion = cms.uint32(options.frdFileVersion),
164+
writeToOpen = cms.untracked.bool(True if options.writeToOpen else False)
158165
)
159166

160167
elif options.dataType == "DTH":

0 commit comments

Comments
 (0)