18 #include <sys/types.h> 28 #include <boost/property_tree/json_parser.hpp> 29 #include <boost/property_tree/ptree.hpp> 30 #include <boost/filesystem.hpp> 31 #include <boost/format.hpp> 42 if (value < 1 && value != -1)
44 <<
"Invalid '" << name <<
"' parameter '" << value
45 <<
"'. Must be -1 or >= 1.";
68 wflow.reserve(workflow.size() + 3);
70 while ((pos = wflow.find(
'/', pos)) != std::string::npos)
71 wflow.replace(pos++, 1,
"__");
81 sprintf(suffix,
"R%09d", run);
90 sprintf(suffix,
"R%09d", run);
94 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", run);
96 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", run, lumi, lumi);
110 me =
dbe_->
get(
"Info/ProvInfo/runIsComplete");
123 "^(Reference/)?([^/]+)",
139 msg <<
"DQMFileSaver: storing EventInfo folders for Run: " 140 << run <<
", Lumi Section: " << lumi <<
", Subsystems: " ;
142 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i) {
143 if (systems[
i] !=
"Reference") {
145 msg << systems[
i] <<
" " ;
148 systems[
i]+
"/EventInfo",
"^(Reference/)?([^/]+)",
167 bool enableMultiThread,
180 store->
save(filename,
184 enableMultiThread ? run : 0,
191 enableMultiThread ? run : 0);
204 "",
"^(Reference/)?([^/]+)",
"\\1\\2",
216 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
218 if (systems[
i] !=
"Reference")
225 "",
"^(Reference/)?([^/]+)", rewrite,
235 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
236 if (systems[
i] !=
"Reference")
239 std::vector<MonitorElement*> pNamesVector =
dbe_->
getMatchingContents(
"^" + systems[
i] +
"/.*/EventInfo/processName",lat::Regexp::Perl);
240 if (!pNamesVector.empty()){
243 "",
"^(Reference/)?([^/]+)", rewrite,
247 pNamesVector.clear();
253 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
254 if (systems[
i] !=
"Reference")
257 systems[
i],
"^(Reference/)?([^/]+)", rewrite,
264 boost::property_tree::ptree
274 namespace bpt = boost::property_tree;
286 boost::filesystem::create_directories(runDir);
288 jsonFilePathName = baseName +
".jsn";
289 openJsonFilePathName = jsonFilePathName +
".open";
292 openHistoFilePathName = histoFilePathName +
".open";
297 if (fileFormat ==
ROOT) {
300 }
else if (fileFormat ==
PB) {
307 if (fileFormat ==
ROOT)
315 "^(Reference/)?([^/]+)",
323 else if (fileFormat ==
PB)
333 <<
"Internal error, can save files" 334 <<
" only in ROOT or ProtocolBuffer format.";
337 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
342 write_json(openJsonFilePathName, pt);
343 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
354 std::map<std::string, std::string>
info;
355 info[
"Source"] =
"DQMStore";
356 info[
"FileClass"] =
"DQM";
393 if (convention ==
"Offline")
395 else if (convention ==
"Online")
397 else if (convention ==
"FilterUnit")
401 <<
"Invalid 'convention' parameter '" << convention <<
"'." 402 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
413 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 414 "abcdefghijklmnopqrstuvwxyz" 416 "-_/") != std::string::npos)
418 <<
"Invalid 'workflow' parameter '" <<
workflow_ 419 <<
"'. Expected '/A/B/C'.";
423 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
431 if (fileFormat ==
"ROOT")
433 else if (fileFormat ==
"PB")
437 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'." 438 <<
" Expected one of 'ROOT' or 'PB'.";
451 <<
"Invalid 'producer' parameter '" <<
producer_ 452 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
459 <<
"Invalid 'producer' parameter '" <<
producer_ 460 <<
"'. Expected 'DQM'.";
472 if (refsave ==
"default")
474 else if (refsave ==
"skip")
479 else if (refsave ==
"all")
484 else if (refsave ==
"qtests")
491 <<
"Invalid 'referenceHandling' parameter '" << refsave
492 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
500 if (dirName_.empty() ||
stat(dirName_.c_str(), &
s) == -1)
502 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
533 sprintf(version,
"_V%04d_",
int(
version_));
537 else if (fakeFilterUnitMode_)
540 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
546 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n" 547 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
552 if (!(
fms_ && daqDirector))
554 <<
"Internal error, cannot initialize DAQ services.";
559 <<
"DQM file saving settings:\n" 563 <<
" saving every " <<
saveByRun_ <<
" run(s)\n" 564 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
583 std::shared_ptr<saverDetails::NoCache>
596 std::ofstream
file(initFileName);
603 std::shared_ptr<saverDetails::NoCache>
621 int irun = iLS.
id().
run();
626 <<
"Internal error, can save files at end of lumi block" 627 <<
" only in Online, FilterUnit or Offline mode.";
633 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
634 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
641 <<
"Internal error, can save files" 642 <<
" only in ROOT or ProtocolBuffer format.";
656 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
667 <<
"Internal error, can save files" 668 <<
" only in ROOT format.";
679 int irun = iRun.
id().
run();
686 sprintf(suffix,
"_R%09d", irun);
688 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
695 <<
"Internal error, can save files" 696 <<
" only in ROOT or ProtocolBuffer format.";
704 <<
"Internal error. Can only save files in endRun()" 705 <<
" in Online and Offline modes.";
711 <<
"Producing fake EoR file.\n";
715 std::string openJsonFilePathName = jsonFilePathName +
".open";
717 boost::filesystem::create_directories(runDir);
719 using namespace boost::property_tree;
723 ptree child1, child2, child3;
729 data.push_back(std::make_pair(
"", child1));
730 data.push_back(std::make_pair(
"", child2));
731 data.push_back(std::make_pair(
"", child3));
733 pt.add_child(
"data", data);
734 pt.put(
"definition",
"/non-existant/");
735 pt.put(
"source",
"--hostname--");
737 std::ofstream
file(jsonFilePathName);
738 write_json(file, pt,
true);
741 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
756 <<
"Internal error. Can only save files at the end of the" 757 <<
" job in Offline mode.";
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
DQMFileSaver(const edm::ParameterSet &ps)
unsigned int getEventsProcessedForLumi(unsigned int lumi, bool *abortFlag=0)
std::shared_ptr< saverDetails::NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const override
void saveForOffline(const std::string &workflow, int run, int lumi) const
void savePB(std::string const &filename, std::string const &path="", uint32_t run=0, uint32_t lumi=0)
void globalEndRun(const edm::Run &, const edm::EventSetup &) const override
static std::string dataFileExtension(DQMFileSaver::FileFormat fileFormat)
std::string getInitFilePath(std::string const &stream) const
std::vector< MonitorElement * > getMatchingContents(std::string const &pattern, lat::Regexp::Syntax syntaxType=lat::Regexp::Wildcard) const
evf::FastMonitoringService * fms_
bool shouldWriteFiles(unsigned int lumi, unsigned int *proc=0)
std::atomic< int > nlumi_
std::string fileBaseName_
MonitorElement * bookFloat(char_string const &name)
Book float.
std::string transferDestination_
void saveJobReport(const std::string &filename) const
void deleteUnusedLumiHistograms(uint32_t run, uint32_t lumi)
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
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::shared_ptr< saverDetails::NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const override
format
Some error handling for the usage.
std::string stream_label_
std::vector< std::string > getSubdirs() const
MonitorElement * bookString(char_string const &name, char_string const &value)
Book string.
static const std::string streamPrefix_
std::string getReleaseVersion()
void setCurrentFolder(std::string const &fullpath)
void saveForOnlinePB(int run, const std::string &suffix) const
void cd()
go to top directory (ie. root)
std::atomic< int > fileUpdate_
LuminosityBlockNumber_t luminosityBlock() const
static boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, const std::string &transferDestinationStr, const std::string &mergeTypeStr, evf::FastMonitoringService *fms)
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const override
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
void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const override
static const std::string streamSuffix_
boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, const std::string &transferDestinationStr, const std::string &mergeTypeStr, evf::FastMonitoringService *fms)
void saveForFilterUnit(const std::string &rewrite, int run, int lumi, const FileFormat fileFormat) const