17 #include <sys/types.h>
27 #include <boost/property_tree/json_parser.hpp>
28 #include <boost/property_tree/ptree.hpp>
29 #include <boost/filesystem.hpp>
30 #include <boost/format.hpp>
41 if (value < 1 && value != -1)
43 <<
"Invalid '" << name <<
"' parameter '" << value
44 <<
"'. Must be -1 or >= 1.";
67 wflow.reserve(workflow.size() + 3);
69 while ((pos = wflow.find(
'/', pos)) != std::string::npos)
70 wflow.replace(pos++, 1,
"__");
80 sprintf(suffix,
"R%09d", run);
89 sprintf(suffix,
"R%09d", run);
93 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", run);
95 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", run, lumi, lumi);
103 "^(Reference/)?([^/]+)",
113 std::vector<std::string> systems = (
dbe_->cd(),
dbe_->getSubdirs());
116 msg <<
"DQMFileSaver: storing EventInfo folders for Run: "
117 << run <<
", Lumi Section: " << lumi <<
", Subsystems: " ;
119 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i) {
120 if (systems[
i] !=
"Reference") {
122 msg << systems[
i] <<
" " ;
125 systems[
i]+
"/EventInfo",
"^(Reference/)?([^/]+)",
143 bool enableMultiThread,
156 store->save(filename,
160 enableMultiThread ? run : 0,
165 store->savePB(filename,
167 enableMultiThread ? run : 0);
180 "",
"^(Reference/)?([^/]+)",
"\\1\\2",
190 std::vector<std::string> systems = (
dbe_->cd(),
dbe_->getSubdirs());
192 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
194 if (systems[
i] !=
"Reference")
201 "",
"^(Reference/)?([^/]+)", rewrite,
211 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
212 if (systems[
i] !=
"Reference")
215 std::vector<MonitorElement*> pNamesVector =
dbe_->getMatchingContents(
"^" + systems[
i] +
"/.*/EventInfo/processName",lat::Regexp::Perl);
216 if (pNamesVector.size() > 0){
219 "",
"^(Reference/)?([^/]+)", rewrite,
223 pNamesVector.clear();
229 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
230 if (systems[
i] !=
"Reference")
233 systems[
i],
"^(Reference/)?([^/]+)", rewrite,
240 boost::property_tree::ptree
243 namespace bpt = boost::property_tree;
244 namespace bfs = boost::filesystem;
250 hostnameReturn = gethostname(host ,
sizeof(host));
251 if (hostnameReturn == -1)
253 <<
"Internal error, cannot get host name";
256 std::ostringstream oss_pid;
260 struct stat dataFileStat;
261 if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
263 <<
"Internal error, cannot get data file: "
269 bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize,
inputFiles, fileAdler32;
274 errorEvents.put(
"", 0);
276 fileList.put(
"", dataFileName);
277 fileSize.put(
"", dataFileStat.st_size);
278 inputFiles.put(
"",
"");
279 fileAdler32.put(
"", -1);
281 data.push_back(std::make_pair(
"", processedEvents));
282 data.push_back(std::make_pair(
"", acceptedEvents));
283 data.push_back(std::make_pair(
"", errorEvents));
284 data.push_back(std::make_pair(
"", bitmask));
285 data.push_back(std::make_pair(
"", fileList));
286 data.push_back(std::make_pair(
"", fileSize));
287 data.push_back(std::make_pair(
"", inputFiles));
288 data.push_back(std::make_pair(
"", fileAdler32));
290 pt.add_child(
"data", data);
292 if (fms ==
nullptr) {
293 pt.put(
"definition",
"/fakeDefinition.jsn");
298 pt.put(
"definition", outJsonDefName.string());
302 sprintf(sourceInfo,
"%s_%d", host, pid);
303 pt.put(
"source", sourceInfo);
312 namespace bpt = boost::property_tree;
324 boost::filesystem::create_directories(runDir);
326 jsonFilePathName = baseName +
".jsn";
327 openJsonFilePathName = jsonFilePathName +
".open";
330 openHistoFilePathName = histoFilePathName +
".open";
335 if (fileFormat ==
ROOT) {
338 }
else if (fileFormat ==
PB) {
344 if (fileFormat ==
ROOT)
350 dbe_->save(openHistoFilePathName,
352 "^(Reference/)?([^/]+)",
361 else if (fileFormat ==
PB)
364 dbe_->savePB(openHistoFilePathName,
372 <<
"Internal error, can save files"
373 <<
" only in ROOT or ProtocolBuffer format.";
376 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
380 write_json(openJsonFilePathName, pt);
381 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
392 std::map<std::string, std::string>
info;
393 info[
"Source"] =
"DQMStore";
394 info[
"FileClass"] =
"DQM";
402 : convention_ (Offline),
411 runIsComplete_ (
false),
412 enableMultiThread_ (
false),
413 saveByLumiSection_ (-1),
415 saveAtJobEnd_ (
false),
416 saveReference_ (
DQMStore::SaveWithReference),
417 saveReferenceQMin_ (dqm::qstatus::
STATUS_OK),
418 forceRunNumber_ (-1),
431 if (convention ==
"Offline")
433 else if (convention ==
"Online")
435 else if (convention ==
"FilterUnit")
439 <<
"Invalid 'convention' parameter '" << convention <<
"'."
440 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
451 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
452 "abcdefghijklmnopqrstuvwxyz"
454 "-_/") != std::string::npos)
456 <<
"Invalid 'workflow' parameter '" <<
workflow_
457 <<
"'. Expected '/A/B/C'.";
461 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
469 if (fileFormat ==
"ROOT")
471 else if (fileFormat ==
"PB")
475 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'."
476 <<
" Expected one of 'ROOT' or 'PB'.";
489 <<
"Invalid 'producer' parameter '" <<
producer_
490 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
497 <<
"Invalid 'producer' parameter '" <<
producer_
498 <<
"'. Expected 'DQM'.";
510 if (refsave ==
"default")
512 else if (refsave ==
"skip")
517 else if (refsave ==
"all")
522 else if (refsave ==
"qtests")
529 <<
"Invalid 'referenceHandling' parameter '" << refsave
530 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
538 if (dirName_.empty() || stat(dirName_.c_str(), &
s) == -1)
540 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
571 sprintf(version,
"_V%04d_",
int(
version_));
575 else if (fakeFilterUnitMode_)
578 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
584 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n"
585 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
590 if (!(
fms_ && daqDirector))
592 <<
"Internal error, cannot initialize DAQ services.";
597 <<
"DQM file saving settings:\n"
601 <<
" saving every " <<
saveByRun_ <<
" run(s)\n"
602 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
615 std::shared_ptr<saverDetails::NoCache>
628 std::ofstream
file(initFileName);
635 std::shared_ptr<saverDetails::NoCache>
653 int irun = iLS.
id().
run();
658 <<
"Internal error, can save files at end of lumi block"
659 <<
" only in Online, FilterUnit or Offline mode.";
665 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
666 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
673 <<
"Internal error, can save files"
674 <<
" only in ROOT or ProtocolBuffer format.";
688 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
699 <<
"Internal error, can save files"
700 <<
" only in ROOT format.";
711 int irun = iRun.
id().
run();
718 sprintf(suffix,
"_R%09d", irun);
720 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
727 <<
"Internal error, can save files"
728 <<
" only in ROOT or ProtocolBuffer format.";
736 <<
"Internal error. Can only save files in endRun()"
737 <<
" in Online and Offline modes.";
743 <<
"Producing fake EoR file.\n";
747 std::string openJsonFilePathName = jsonFilePathName +
".open";
749 boost::filesystem::create_directories(runDir);
751 using namespace boost::property_tree;
755 ptree child1, child2, child3;
761 data.push_back(std::make_pair(
"", child1));
762 data.push_back(std::make_pair(
"", child2));
763 data.push_back(std::make_pair(
"", child3));
765 pt.add_child(
"data",
data);
766 pt.put(
"definition",
"/non-existant/");
767 pt.put(
"source",
"--hostname--");
769 std::ofstream
file(jsonFilePathName);
770 write_json(file,
pt,
true);
773 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
788 <<
"Internal error. Can only save files at the end of the"
789 <<
" job in Offline mode.";
794 sprintf(suffix,
"R%09d",
irun_.load());
803 unsigned int digits = 0;
804 while (numberOfChildren != 0) {
806 numberOfChildren /= 10;
813 char buffer[digits + 2];
814 snprintf(buffer, digits + 2,
"_%0*d", digits, childIndex);
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
DQMFileSaver(const edm::ParameterSet &ps)
void saveForOffline(const std::string &workflow, int run, int lumi) const
static std::string dataFileExtension(DQMFileSaver::FileFormat fileFormat)
virtual void globalEndRun(const edm::Run &, const edm::EventSetup &) const
std::string getInitFilePath(std::string const &stream) const
evf::FastMonitoringService * fms_
string format
Some error handling for the usage.
std::atomic< int > nlumi_
std::string fileBaseName_
virtual void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const
unsigned int getEventsProcessedForLumi(unsigned int lumi)
tuple path
else: Piece not in the list, fine.
void saveJobReport(const std::string &filename) const
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
static boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, evf::FastMonitoringService *fms)
static std::string onlineOfflineFileName(const std::string &fileBaseName, const std::string &suffix, const std::string &workflow, const std::string &child, DQMFileSaver::FileFormat fileFormat)
void saveForOnline(int run, const std::string &suffix, const std::string &rewrite) const
std::string stream_label_
static const std::string streamPrefix_
virtual std::shared_ptr< saverDetails::NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const
void saveForOnlinePB(int run, const std::string &suffix) const
std::atomic< int > fileUpdate_
LuminosityBlockNumber_t luminosityBlock() const
virtual void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const
virtual std::shared_ptr< saverDetails::NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const
void saveForOfflinePB(const std::string &workflow, int run) const
char data[epos_bytes_allocation]
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
static void doSaveForOnline(DQMStore *store, int run, bool enableMultiThread, const std::string &filename, const std::string &directory, const std::string &rxpat, const std::string &rewrite, DQMStore::SaveReferenceTag saveref, int saveRefQMin, const std::string &filterName, DQMFileSaver::FileFormat fileFormat)
static const int STATUS_OK
virtual void postForkReacquireResources(unsigned int childIndex, unsigned int numberOfChildren)
volatile std::atomic< bool > shutdown_flag false
virtual void beginJob(void)
virtual void endJob(void)
static const std::string streamSuffix_
void saveForFilterUnit(const std::string &rewrite, int run, int lumi, const FileFormat fileFormat) const