@@ -24,7 +24,9 @@ using namespace edm::streamer;
2424
2525RawEventFileWriterForBU::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,
185187void 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) {
301327void 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
313342void 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}
0 commit comments