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/)?([^/]+)",
115 std::cout <<
" DQMFileSaver: storing EventInfo folders for Run: "
116 << run <<
", Lumi Section: " << lumi <<
", Subsystems: " ;
118 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i) {
119 if (systems[
i] !=
"Reference") {
123 systems[
i]+
"/EventInfo",
"^(Reference/)?([^/]+)",
140 bool enableMultiThread,
153 store->
save(filename,
157 enableMultiThread ? run : 0,
164 enableMultiThread ? run : 0);
177 "",
"^(Reference/)?([^/]+)",
"\\1\\2",
189 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
191 if (systems[
i] !=
"Reference")
198 "",
"^(Reference/)?([^/]+)", rewrite,
208 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
209 if (systems[
i] !=
"Reference")
212 std::vector<MonitorElement*> pNamesVector =
dbe_->
getMatchingContents(
"^" + systems[
i] +
"/.*/EventInfo/processName",lat::Regexp::Perl);
213 if (pNamesVector.size() > 0){
216 "",
"^(Reference/)?([^/]+)", rewrite,
220 pNamesVector.clear();
226 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
227 if (systems[
i] !=
"Reference")
230 systems[
i],
"^(Reference/)?([^/]+)", rewrite,
240 namespace bpt = boost::property_tree;
241 namespace bfs = boost::filesystem;
244 hostnameReturn = gethostname(host ,
sizeof(host));
245 if (hostnameReturn == -1)
247 <<
"Internal error, cannot get host name";
250 std::ostringstream oss_pid;
254 struct stat dataFileStat;
255 if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
257 <<
"Internal error, cannot get data file: "
263 bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize,
inputFiles, fileAdler32;
268 errorEvents.put(
"", 0);
270 fileList.put(
"", dataFileName);
271 fileSize.put(
"", dataFileStat.st_size);
272 inputFiles.put(
"",
"");
273 fileAdler32.put(
"", -1);
275 data.push_back(std::make_pair(
"", processedEvents));
276 data.push_back(std::make_pair(
"", acceptedEvents));
277 data.push_back(std::make_pair(
"", errorEvents));
278 data.push_back(std::make_pair(
"", bitmask));
279 data.push_back(std::make_pair(
"", fileList));
280 data.push_back(std::make_pair(
"", fileSize));
281 data.push_back(std::make_pair(
"", inputFiles));
282 data.push_back(std::make_pair(
"", fileAdler32));
284 pt.add_child(
"data", data);
287 pt.put(
"definition",
"/fakeDefinition.jsn");
292 pt.put(
"definition", outJsonDefName.string());
296 sprintf(sourceInfo,
"%s_%d", host, pid);
297 pt.put(
"source", sourceInfo);
304 namespace bpt = boost::property_tree;
317 boost::filesystem::create_directories(runDir);
319 jsonFilePathName = baseName +
".jsn";
320 openJsonFilePathName = jsonFilePathName +
".open";
323 openHistoFilePathName = histoFilePathName +
".open";
328 if (fileFormat ==
ROOT) {
331 }
else if (fileFormat ==
PB) {
337 if (fileFormat ==
ROOT)
345 "^(Reference/)?([^/]+)",
354 else if (fileFormat ==
PB)
365 <<
"Internal error, can save files"
366 <<
" only in ROOT or ProtocolBuffer format.";
369 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
372 fillJson(run, lumi, histoFilePathName, pt);
373 write_json(openJsonFilePathName, pt);
374 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
385 std::map<std::string, std::string>
info;
386 info[
"Source"] =
"DQMStore";
387 info[
"FileClass"] =
"DQM";
395 : convention_ (Offline),
404 runIsComplete_ (
false),
405 enableMultiThread_ (
false),
406 saveByLumiSection_ (-1),
408 saveAtJobEnd_ (
false),
409 saveReference_ (
DQMStore::SaveWithReference),
410 saveReferenceQMin_ (dqm::qstatus::
STATUS_OK),
411 forceRunNumber_ (-1),
424 if (convention ==
"Offline")
426 else if (convention ==
"Online")
428 else if (convention ==
"FilterUnit")
432 <<
"Invalid 'convention' parameter '" << convention <<
"'."
433 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
444 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
445 "abcdefghijklmnopqrstuvwxyz"
447 "-_/") != std::string::npos)
449 <<
"Invalid 'workflow' parameter '" <<
workflow_
450 <<
"'. Expected '/A/B/C'.";
454 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
462 if (fileFormat ==
"ROOT")
464 else if (fileFormat ==
"PB")
468 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'."
469 <<
" Expected one of 'ROOT' or 'PB'.";
482 <<
"Invalid 'producer' parameter '" <<
producer_
483 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
490 <<
"Invalid 'producer' parameter '" <<
producer_
491 <<
"'. Expected 'DQM'.";
503 if (refsave ==
"default")
505 else if (refsave ==
"skip")
510 else if (refsave ==
"all")
515 else if (refsave ==
"qtests")
522 <<
"Invalid 'referenceHandling' parameter '" << refsave
523 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
531 if (dirName_.empty() || stat(dirName_.c_str(), &
s) == -1)
533 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
564 sprintf(version,
"_V%04d_",
int(
version_));
568 else if (fakeFilterUnitMode_)
571 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
577 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n"
578 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
583 if (!(
fms_ && daqDirector))
585 <<
"Internal error, cannot initialize DAQ services.";
590 <<
"DQM file saving settings:\n"
594 <<
" saving every " <<
saveByRun_ <<
" run(s)\n"
595 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
608 std::shared_ptr<saverDetails::NoCache>
621 std::ofstream
file(initFileName);
628 std::shared_ptr<saverDetails::NoCache>
646 int irun = iLS.
id().
run();
651 <<
"Internal error, can save files at end of lumi block"
652 <<
" only in Online, FilterUnit or Offline mode.";
658 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
659 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
666 <<
"Internal error, can save files"
667 <<
" only in ROOT or ProtocolBuffer format.";
681 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
692 <<
"Internal error, can save files"
693 <<
" only in ROOT format.";
701 int irun = iRun.
id().
run();
708 sprintf(suffix,
"_R%09d", irun);
710 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
717 <<
"Internal error, can save files"
718 <<
" only in ROOT or ProtocolBuffer format.";
726 <<
"Internal error. Can only save files in endRun()"
727 <<
" in Online and Offline modes.";
733 <<
"Producing fake EoR file.\n";
737 std::string openJsonFilePathName = jsonFilePathName +
".open";
739 boost::filesystem::create_directories(runDir);
741 using namespace boost::property_tree;
745 ptree child1, child2, child3;
751 data.push_back(std::make_pair(
"", child1));
752 data.push_back(std::make_pair(
"", child2));
753 data.push_back(std::make_pair(
"", child3));
755 pt.add_child(
"data",
data);
756 pt.put(
"definition",
"/non-existant/");
757 pt.put(
"source",
"--hostname--");
759 std::ofstream
file(jsonFilePathName);
760 write_json(file,
pt,
true);
763 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
778 <<
"Internal error. Can only save files at the end of the"
779 <<
" job in Offline mode.";
784 sprintf(suffix,
"R%09d",
irun_.load());
793 unsigned int digits = 0;
794 while (numberOfChildren != 0) {
796 numberOfChildren /= 10;
803 char buffer[digits + 2];
804 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
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_
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
void fillJson(int run, int lumi, const std::string &dataFilePathName, boost::property_tree::ptree &pt) 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 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
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)
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)
static const std::string streamSuffix_
void saveForFilterUnit(const std::string &rewrite, int run, int lumi, const FileFormat fileFormat) const