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);
109 me =
dbe_->
get(
"Info/ProvInfo/runIsComplete");
122 "^(Reference/)?([^/]+)",
138 msg <<
"DQMFileSaver: storing EventInfo folders for Run: " 139 << run <<
", Lumi Section: " << lumi <<
", Subsystems: " ;
141 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i) {
142 if (systems[
i] !=
"Reference") {
144 msg << systems[
i] <<
" " ;
147 systems[
i]+
"/EventInfo",
"^(Reference/)?([^/]+)",
166 bool enableMultiThread,
179 store->
save(filename,
183 enableMultiThread ? run : 0,
190 enableMultiThread ? run : 0);
203 "",
"^(Reference/)?([^/]+)",
"\\1\\2",
215 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
217 if (systems[
i] !=
"Reference")
224 "",
"^(Reference/)?([^/]+)", rewrite,
234 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
235 if (systems[
i] !=
"Reference")
238 std::vector<MonitorElement*> pNamesVector =
dbe_->
getMatchingContents(
"^" + systems[
i] +
"/.*/EventInfo/processName",lat::Regexp::Perl);
239 if (!pNamesVector.empty()){
242 "",
"^(Reference/)?([^/]+)", rewrite,
246 pNamesVector.clear();
252 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
253 if (systems[
i] !=
"Reference")
256 systems[
i],
"^(Reference/)?([^/]+)", rewrite,
263 boost::property_tree::ptree
266 namespace bpt = boost::property_tree;
267 namespace bfs = boost::filesystem;
273 hostnameReturn = gethostname(host ,
sizeof(host));
274 if (hostnameReturn == -1)
276 <<
"Internal error, cannot get host name";
279 std::ostringstream oss_pid;
286 struct stat dataFileStat;
287 dataFileStat.st_size=0;
289 if (
stat(dataFilePathName.c_str(), &dataFileStat) != 0)
291 <<
"Internal error, cannot get data file: " 294 dataFileName =
bfs::path(dataFilePathName).filename().string();
298 bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize,
inputFiles, fileAdler32, transferDestination, mergeType, hltErrorEvents;
300 processedEvents.put(
"", nProcessed);
301 acceptedEvents.put(
"", nProcessed);
303 errorEvents.put(
"", 0);
305 fileList.put(
"", dataFileName);
306 fileSize.put(
"", dataFileStat.st_size);
307 inputFiles.put(
"",
"");
308 fileAdler32.put(
"", -1);
309 transferDestination.put(
"", transferDestinationStr);
310 mergeType.put(
"", mergeTypeStr);
311 hltErrorEvents.put(
"", 0);
313 data.push_back(std::make_pair(
"", processedEvents));
314 data.push_back(std::make_pair(
"", acceptedEvents));
315 data.push_back(std::make_pair(
"", errorEvents));
316 data.push_back(std::make_pair(
"", bitmask));
317 data.push_back(std::make_pair(
"", fileList));
318 data.push_back(std::make_pair(
"", fileSize));
319 data.push_back(std::make_pair(
"", inputFiles));
320 data.push_back(std::make_pair(
"", fileAdler32));
321 data.push_back(std::make_pair(
"", transferDestination));
322 data.push_back(std::make_pair(
"", mergeType));
323 data.push_back(std::make_pair(
"", hltErrorEvents));
325 pt.add_child(
"data", data);
327 if (fms ==
nullptr) {
328 pt.put(
"definition",
"/fakeDefinition.jsn");
333 pt.put(
"definition", outJsonDefName.string());
337 sprintf(sourceInfo,
"%s_%d", host, pid);
338 pt.put(
"source", sourceInfo);
347 namespace bpt = boost::property_tree;
359 boost::filesystem::create_directories(runDir);
361 jsonFilePathName = baseName +
".jsn";
362 openJsonFilePathName = jsonFilePathName +
".open";
365 openHistoFilePathName = histoFilePathName +
".open";
370 if (fileFormat ==
ROOT) {
373 }
else if (fileFormat ==
PB) {
380 if (fileFormat ==
ROOT)
388 "^(Reference/)?([^/]+)",
396 else if (fileFormat ==
PB)
406 <<
"Internal error, can save files" 407 <<
" only in ROOT or ProtocolBuffer format.";
410 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
415 write_json(openJsonFilePathName, pt);
416 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
427 std::map<std::string, std::string>
info;
428 info[
"Source"] =
"DQMStore";
429 info[
"FileClass"] =
"DQM";
466 if (convention ==
"Offline")
468 else if (convention ==
"Online")
470 else if (convention ==
"FilterUnit")
474 <<
"Invalid 'convention' parameter '" << convention <<
"'." 475 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
486 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" 487 "abcdefghijklmnopqrstuvwxyz" 489 "-_/") != std::string::npos)
491 <<
"Invalid 'workflow' parameter '" <<
workflow_ 492 <<
"'. Expected '/A/B/C'.";
496 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
504 if (fileFormat ==
"ROOT")
506 else if (fileFormat ==
"PB")
510 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'." 511 <<
" Expected one of 'ROOT' or 'PB'.";
524 <<
"Invalid 'producer' parameter '" <<
producer_ 525 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
532 <<
"Invalid 'producer' parameter '" <<
producer_ 533 <<
"'. Expected 'DQM'.";
545 if (refsave ==
"default")
547 else if (refsave ==
"skip")
552 else if (refsave ==
"all")
557 else if (refsave ==
"qtests")
564 <<
"Invalid 'referenceHandling' parameter '" << refsave
565 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
573 if (dirName_.empty() ||
stat(dirName_.c_str(), &
s) == -1)
575 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
606 sprintf(version,
"_V%04d_",
int(
version_));
610 else if (fakeFilterUnitMode_)
613 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
619 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n" 620 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
625 if (!(
fms_ && daqDirector))
627 <<
"Internal error, cannot initialize DAQ services.";
632 <<
"DQM file saving settings:\n" 636 <<
" saving every " <<
saveByRun_ <<
" run(s)\n" 637 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
656 std::shared_ptr<saverDetails::NoCache>
669 std::ofstream
file(initFileName);
676 std::shared_ptr<saverDetails::NoCache>
694 int irun = iLS.
id().
run();
699 <<
"Internal error, can save files at end of lumi block" 700 <<
" only in Online, FilterUnit or Offline mode.";
706 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
707 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
714 <<
"Internal error, can save files" 715 <<
" only in ROOT or ProtocolBuffer format.";
729 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
740 <<
"Internal error, can save files" 741 <<
" only in ROOT format.";
752 int irun = iRun.
id().
run();
759 sprintf(suffix,
"_R%09d", irun);
761 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
768 <<
"Internal error, can save files" 769 <<
" only in ROOT or ProtocolBuffer format.";
777 <<
"Internal error. Can only save files in endRun()" 778 <<
" in Online and Offline modes.";
784 <<
"Producing fake EoR file.\n";
788 std::string openJsonFilePathName = jsonFilePathName +
".open";
790 boost::filesystem::create_directories(runDir);
792 using namespace boost::property_tree;
796 ptree child1, child2, child3;
802 data.push_back(std::make_pair(
"", child1));
803 data.push_back(std::make_pair(
"", child2));
804 data.push_back(std::make_pair(
"", child3));
806 pt.add_child(
"data", data);
807 pt.put(
"definition",
"/non-existant/");
808 pt.put(
"source",
"--hostname--");
810 std::ofstream
file(jsonFilePathName);
811 write_json(file, pt,
true);
814 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
829 <<
"Internal error. Can only save files at the end of the" 830 <<
" 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 globalEndRun(const edm::Run &, const edm::EventSetup &) const override
static std::string dataFileExtension(DQMFileSaver::FileFormat fileFormat)
std::string getInitFilePath(std::string const &stream) const
evf::FastMonitoringService * fms_
bool shouldWriteFiles(unsigned int lumi, unsigned int *proc=0)
std::vector< MonitorElement * > getMatchingContents(const std::string &pattern, lat::Regexp::Syntax syntaxType=lat::Regexp::Wildcard) const
std::atomic< int > nlumi_
std::string fileBaseName_
MonitorElement * bookFloat(const char *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 * bookString(const char *name, const char *value)
Book string.
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
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.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
std::string stream_label_
std::vector< std::string > getSubdirs() const
static const std::string streamPrefix_
std::string getReleaseVersion()
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 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 savePB(const std::string &filename, const std::string &path="", const uint32_t run=0, const uint32_t lumi=0)
void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const override
void setCurrentFolder(const std::string &fullpath)
static const std::string streamSuffix_
void saveForFilterUnit(const std::string &rewrite, int run, int lumi, const FileFormat fileFormat) const