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 dbe_->setCurrentFolder(
"Info/ProvInfo");
109 me =
dbe_->get(
"Info/ProvInfo/runIsComplete");
110 if (!me) me =
dbe_->bookFloat(
"runIsComplete");
122 "^(Reference/)?([^/]+)",
132 std::vector<std::string> systems = (
dbe_->cd(),
dbe_->getSubdirs());
135 msg <<
"DQMFileSaver: storing EventInfo folders for Run: "
136 << run <<
", Lumi Section: " << lumi <<
", Subsystems: " ;
138 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i) {
139 if (systems[
i] !=
"Reference") {
141 msg << systems[
i] <<
" " ;
144 systems[
i]+
"/EventInfo",
"^(Reference/)?([^/]+)",
162 bool enableMultiThread,
175 store->save(filename,
179 enableMultiThread ? run : 0,
184 store->savePB(filename,
186 enableMultiThread ? run : 0);
199 "",
"^(Reference/)?([^/]+)",
"\\1\\2",
209 std::vector<std::string> systems = (
dbe_->cd(),
dbe_->getSubdirs());
211 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
213 if (systems[
i] !=
"Reference")
220 "",
"^(Reference/)?([^/]+)", rewrite,
230 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
231 if (systems[
i] !=
"Reference")
234 std::vector<MonitorElement*> pNamesVector =
dbe_->getMatchingContents(
"^" + systems[
i] +
"/.*/EventInfo/processName",lat::Regexp::Perl);
235 if (pNamesVector.size() > 0){
238 "",
"^(Reference/)?([^/]+)", rewrite,
242 pNamesVector.clear();
248 for (
size_t i = 0,
e = systems.size();
i !=
e; ++
i)
249 if (systems[
i] !=
"Reference")
252 systems[
i],
"^(Reference/)?([^/]+)", rewrite,
259 boost::property_tree::ptree
262 namespace bpt = boost::property_tree;
263 namespace bfs = boost::filesystem;
269 hostnameReturn = gethostname(host ,
sizeof(host));
270 if (hostnameReturn == -1)
272 <<
"Internal error, cannot get host name";
275 std::ostringstream oss_pid;
282 struct stat dataFileStat;
283 dataFileStat.st_size=0;
285 if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
287 <<
"Internal error, cannot get data file: "
290 dataFileName =
bfs::path(dataFilePathName).filename().string();
294 bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize,
inputFiles, fileAdler32, transferDestination;
296 processedEvents.put(
"", nProcessed);
297 acceptedEvents.put(
"", nProcessed);
299 errorEvents.put(
"", 0);
301 fileList.put(
"", dataFileName);
302 fileSize.put(
"", dataFileStat.st_size);
303 inputFiles.put(
"",
"");
304 fileAdler32.put(
"", -1);
305 transferDestination.put(
"", transferDestinationStr);
307 data.push_back(std::make_pair(
"", processedEvents));
308 data.push_back(std::make_pair(
"", acceptedEvents));
309 data.push_back(std::make_pair(
"", errorEvents));
310 data.push_back(std::make_pair(
"", bitmask));
311 data.push_back(std::make_pair(
"", fileList));
312 data.push_back(std::make_pair(
"", fileSize));
313 data.push_back(std::make_pair(
"", inputFiles));
314 data.push_back(std::make_pair(
"", fileAdler32));
315 data.push_back(std::make_pair(
"", transferDestination));
317 pt.add_child(
"data", data);
319 if (fms ==
nullptr) {
320 pt.put(
"definition",
"/fakeDefinition.jsn");
325 pt.put(
"definition", outJsonDefName.string());
329 sprintf(sourceInfo,
"%s_%d", host, pid);
330 pt.put(
"source", sourceInfo);
339 namespace bpt = boost::property_tree;
351 boost::filesystem::create_directories(runDir);
353 jsonFilePathName = baseName +
".jsn";
354 openJsonFilePathName = jsonFilePathName +
".open";
357 openHistoFilePathName = histoFilePathName +
".open";
362 if (fileFormat ==
ROOT) {
365 }
else if (fileFormat ==
PB) {
372 if (fileFormat ==
ROOT)
378 dbe_->save(openHistoFilePathName,
380 "^(Reference/)?([^/]+)",
389 else if (fileFormat ==
PB)
392 dbe_->savePB(openHistoFilePathName,
400 <<
"Internal error, can save files"
401 <<
" only in ROOT or ProtocolBuffer format.";
404 rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
409 write_json(openJsonFilePathName, pt);
410 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
421 std::map<std::string, std::string>
info;
422 info[
"Source"] =
"DQMStore";
423 info[
"FileClass"] =
"DQM";
431 : convention_ (Offline),
440 runIsComplete_ (
false),
441 enableMultiThread_ (
false),
442 saveByLumiSection_ (-1),
444 saveAtJobEnd_ (
false),
445 saveReference_ (
DQMStore::SaveWithReference),
446 saveReferenceQMin_ (dqm::qstatus::
STATUS_OK),
447 forceRunNumber_ (-1),
460 if (convention ==
"Offline")
462 else if (convention ==
"Online")
464 else if (convention ==
"FilterUnit")
468 <<
"Invalid 'convention' parameter '" << convention <<
"'."
469 <<
" Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
480 ||
workflow_.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
481 "abcdefghijklmnopqrstuvwxyz"
483 "-_/") != std::string::npos)
485 <<
"Invalid 'workflow' parameter '" <<
workflow_
486 <<
"'. Expected '/A/B/C'.";
490 <<
"The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
498 if (fileFormat ==
"ROOT")
500 else if (fileFormat ==
"PB")
504 <<
"Invalid 'fileFormat' parameter '" << fileFormat <<
"'."
505 <<
" Expected one of 'ROOT' or 'PB'.";
518 <<
"Invalid 'producer' parameter '" <<
producer_
519 <<
"'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
526 <<
"Invalid 'producer' parameter '" <<
producer_
527 <<
"'. Expected 'DQM'.";
539 if (refsave ==
"default")
541 else if (refsave ==
"skip")
546 else if (refsave ==
"all")
551 else if (refsave ==
"qtests")
558 <<
"Invalid 'referenceHandling' parameter '" << refsave
559 <<
"'. Expected 'default', 'skip', 'all' or 'qtests'.";
567 if (dirName_.empty() || stat(dirName_.c_str(), &
s) == -1)
569 <<
"Invalid 'dirName' parameter '" << dirName_ <<
"'.";
600 sprintf(version,
"_V%04d_",
int(
version_));
604 else if (fakeFilterUnitMode_)
607 <<
"Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
613 <<
"The base dir provided in the configuration '" << dirName_ <<
"'\n"
614 <<
" will not be considered: for FU, the DAQ2 services will handle directories\n";
619 if (!(
fms_ && daqDirector))
621 <<
"Internal error, cannot initialize DAQ services.";
626 <<
"DQM file saving settings:\n"
630 <<
" saving every " <<
saveByRun_ <<
" run(s)\n"
631 <<
" saving at job end: " << (
saveAtJobEnd_ ?
"yes" :
"no") <<
"\n";
649 std::shared_ptr<saverDetails::NoCache>
662 std::ofstream
file(initFileName);
669 std::shared_ptr<saverDetails::NoCache>
687 int irun = iLS.
id().
run();
692 <<
"Internal error, can save files at end of lumi block"
693 <<
" only in Online, FilterUnit or Offline mode.";
699 sprintf(suffix,
"_R%09d_L%06d", irun, ilumi);
700 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-
nlumi_, ilumi);
707 <<
"Internal error, can save files"
708 <<
" only in ROOT or ProtocolBuffer format.";
722 sprintf(rewrite,
"\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
733 <<
"Internal error, can save files"
734 <<
" only in ROOT format.";
745 int irun = iRun.
id().
run();
752 sprintf(suffix,
"_R%09d", irun);
754 sprintf(rewrite,
"\\1Run %d/\\2/Run summary", irun);
761 <<
"Internal error, can save files"
762 <<
" only in ROOT or ProtocolBuffer format.";
770 <<
"Internal error. Can only save files in endRun()"
771 <<
" in Online and Offline modes.";
777 <<
"Producing fake EoR file.\n";
781 std::string openJsonFilePathName = jsonFilePathName +
".open";
783 boost::filesystem::create_directories(runDir);
785 using namespace boost::property_tree;
789 ptree child1, child2, child3;
795 data.push_back(std::make_pair(
"", child1));
796 data.push_back(std::make_pair(
"", child2));
797 data.push_back(std::make_pair(
"", child3));
799 pt.add_child(
"data",
data);
800 pt.put(
"definition",
"/non-existant/");
801 pt.put(
"source",
"--hostname--");
803 std::ofstream
file(jsonFilePathName);
804 write_json(file,
pt,
true);
807 rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
822 <<
"Internal error. Can only save files at the end of the"
823 <<
" job in Offline mode.";
828 sprintf(suffix,
"R%09d",
irun_.load());
837 unsigned int digits = 0;
838 while (numberOfChildren != 0) {
840 numberOfChildren /= 10;
847 char buffer[digits + 2];
848 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)
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
static boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, const std::string transferDestinationStr, evf::FastMonitoringService *fms)
evf::FastMonitoringService * fms_
bool shouldWriteFiles(unsigned int lumi, unsigned int *proc=0)
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
std::string transferDestination_
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
std::string stream_label_
static const std::string streamPrefix_
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
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