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.size() > 0){
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/)?([^/]+)",
397 else if (fileFormat ==
PB)
408 <<
"Internal error, can save files"
409 <<
" only in ROOT or ProtocolBuffer format.";
412 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
417 write_json(openJsonFilePathName, pt);
418 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
429 std::map<std::string, std::string>
info;
430 info[
"Source"] =
"DQMStore";
431 info[
"FileClass"] =
"DQM";
439 : convention_ (Offline),
448 runIsComplete_ (
false),
449 enableMultiThread_ (
false),
450 saveByLumiSection_ (-1),
452 saveAtJobEnd_ (
false),
453 saveReference_ (
DQMStore::SaveWithReference),
454 saveReferenceQMin_ (dqm::qstatus::
STATUS_OK),
455 forceRunNumber_ (-1),
468 if (convention ==
"Offline")
470 else if (convention ==
"Online")
472 else if (convention ==
"FilterUnit")
476 <<
"Invalid 'convention' parameter '" << convention <<
"'."
477 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
488 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
489 "abcdefghijklmnopqrstuvwxyz"
491 "-_/") != std::string::npos)
493 <<
"Invalid 'workflow' parameter '" <<
workflow_
494 <<
"'. Expected '/A/B/C'.";
498 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
506 if (fileFormat ==
"ROOT")
508 else if (fileFormat ==
"PB")
512 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'."
513 <<
" Expected one of 'ROOT' or 'PB'.";
526 <<
"Invalid 'producer' parameter '" <<
producer_
527 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
534 <<
"Invalid 'producer' parameter '" <<
producer_
535 <<
"'. Expected 'DQM'.";
547 if (refsave ==
"default")
549 else if (refsave ==
"skip")
554 else if (refsave ==
"all")
559 else if (refsave ==
"qtests")
566 <<
"Invalid 'referenceHandling' parameter '" << refsave
567 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
575 if (dirName_.empty() || stat(dirName_.c_str(), &
s) == -1)
577 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
608 sprintf(version,
"_V%04d_",
int(
version_));
612 else if (fakeFilterUnitMode_)
615 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
621 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n"
622 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
627 if (!(
fms_ && daqDirector))
629 <<
"Internal error, cannot initialize DAQ services.";
634 <<
"DQM file saving settings:\n"
638 <<
" saving every " <<
saveByRun_ <<
" run(s)\n"
639 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
658 std::shared_ptr<saverDetails::NoCache>
671 std::ofstream
file(initFileName);
678 std::shared_ptr<saverDetails::NoCache>
696 int irun = iLS.
id().
run();
701 <<
"Internal error, can save files at end of lumi block"
702 <<
" only in Online, FilterUnit or Offline mode.";
708 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
709 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
716 <<
"Internal error, can save files"
717 <<
" only in ROOT or ProtocolBuffer format.";
731 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
742 <<
"Internal error, can save files"
743 <<
" only in ROOT format.";
754 int irun = iRun.
id().
run();
761 sprintf(suffix,
"_R%09d", irun);
763 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
770 <<
"Internal error, can save files"
771 <<
" only in ROOT or ProtocolBuffer format.";
779 <<
"Internal error. Can only save files in endRun()"
780 <<
" in Online and Offline modes.";
786 <<
"Producing fake EoR file.\n";
790 std::string openJsonFilePathName = jsonFilePathName +
".open";
792 boost::filesystem::create_directories(runDir);
794 using namespace boost::property_tree;
798 ptree child1, child2, child3;
804 data.push_back(std::make_pair(
"", child1));
805 data.push_back(std::make_pair(
"", child2));
806 data.push_back(std::make_pair(
"", child3));
808 pt.add_child(
"data",
data);
809 pt.put(
"definition",
"/non-existant/");
810 pt.put(
"source",
"--hostname--");
812 std::ofstream
file(jsonFilePathName);
813 write_json(file,
pt,
true);
816 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
831 <<
"Internal error. Can only save files at the end of the"
832 <<
" job in Offline mode.";
840 unsigned int digits = 0;
841 while (numberOfChildren != 0) {
843 numberOfChildren /= 10;
850 char buffer[digits + 2];
851 snprintf(buffer, digits + 2,
"_%0*d", digits, childIndex);
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)
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 saveForOffline(const std::string &workflow, int run, int lumi) const
std::vector< std::string > getSubdirs(void) const
static std::string dataFileExtension(DQMFileSaver::FileFormat fileFormat)
virtual void globalEndRun(const edm::Run &, const edm::EventSetup &) const
void cd(void)
go to top directory (ie. root)
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
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
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.
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
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
std::string stream_label_
static const std::string streamPrefix_
void savePB(const std::string &filename, const std::string &path="", const uint32_t run=0, const uint32_t lumi=0, const bool resetMEsAfterWriting=false)
virtual std::shared_ptr< saverDetails::NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const
std::string getReleaseVersion()
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
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
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", const bool resetMEsAfterWriting=false)
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)
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