CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMFileSaver.cc
Go to the documentation of this file.
12 
15 
16 #include <sys/stat.h>
17 #include <sys/types.h>
18 #include <unistd.h>
19 #include <iostream>
20 #include <vector>
21 #include <string>
22 #include <fstream>
23 #include <utility>
24 #include <TString.h>
25 #include <TSystem.h>
26 
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>
31 
32 //--------------------------------------------------------
34 const std::string DQMFileSaver::streamSuffix_("Histograms");
35 
36 //--------------------------------------------------------
37 static void
39 {
40  value = ps.getUntrackedParameter<int>(name, value);
41  if (value < 1 && value != -1)
42  throw cms::Exception("DQMFileSaver")
43  << "Invalid '" << name << "' parameter '" << value
44  << "'. Must be -1 or >= 1.";
45 }
46 
47 static std::string
49 {
50  std::string extension;
51  if (fileFormat == DQMFileSaver::ROOT)
52  extension = ".root";
53  else if (fileFormat == DQMFileSaver::PB)
54  extension = ".pb";
55  return extension;
56 }
57 
58 static std::string
59 onlineOfflineFileName(const std::string &fileBaseName,
60  const std::string &suffix,
61  const std::string &workflow,
62  const std::string &child,
63  DQMFileSaver::FileFormat fileFormat)
64 {
65  size_t pos = 0;
66  std::string wflow;
67  wflow.reserve(workflow.size() + 3);
68  wflow = workflow;
69  while ((pos = wflow.find('/', pos)) != std::string::npos)
70  wflow.replace(pos++, 1, "__");
71 
72  std::string filename = fileBaseName + suffix + wflow + child + dataFileExtension(fileFormat);
73  return filename;
74 }
75 
76 void
78 {
79  char suffix[64];
80  sprintf(suffix, "R%09d", run);
82  dbe_->savePB(filename, filterName_);
83 }
84 
85 void
87 {
88  char suffix[64];
89  sprintf(suffix, "R%09d", run);
90 
91  char rewrite[128];
92  if (lumi == 0) // save for run
93  sprintf(rewrite, "\\1Run %d/\\2/Run summary", run);
94  else
95  sprintf(rewrite, "\\1Run %d/\\2/By Lumi Section %d-%d", run, lumi, lumi);
96 
98 
99  if (lumi == 0) // save for run
100  {
101  // set run end flag
102  dbe_->cd();
103  dbe_->setCurrentFolder("Info/ProvInfo");
104 
105  // do this, because ProvInfo is not yet run in offline DQM
106  MonitorElement* me = dbe_->get("Info/ProvInfo/CMSSW");
107  if (!me) me = dbe_->bookString("CMSSW", edm::getReleaseVersion().c_str() );
108 
109  me = dbe_->get("Info/ProvInfo/runIsComplete");
110  if (!me) me = dbe_->bookFloat("runIsComplete");
111 
112  if (me)
113  {
114  if (runIsComplete_)
115  me->Fill(1.);
116  else
117  me->Fill(0.);
118  }
119 
120  dbe_->save(filename,
121  "",
122  "^(Reference/)?([^/]+)",
123  rewrite,
124  enableMultiThread_ ? run : 0,
125  lumi,
128  fileUpdate_ ? "UPDATE" : "RECREATE");
129  }
130  else // save EventInfo folders for luminosity sections
131  {
132  std::vector<std::string> systems = (dbe_->cd(), dbe_->getSubdirs());
133 
134  edm::LogAbsolute msg("fileAction");
135  msg << "DQMFileSaver: storing EventInfo folders for Run: "
136  << run << ", Lumi Section: " << lumi << ", Subsystems: " ;
137 
138  for (size_t i = 0, e = systems.size(); i != e; ++i) {
139  if (systems[i] != "Reference") {
140  dbe_->cd();
141  msg << systems[i] << " " ;
142 
143  dbe_->save(filename,
144  systems[i]+"/EventInfo", "^(Reference/)?([^/]+)",
145  rewrite,
146  enableMultiThread_ ? run : 0,
147  lumi,
150  fileUpdate_ ? "UPDATE" : "RECREATE");
151 
152  // from now on update newly created file
153  if (fileUpdate_.load() == 0) fileUpdate_ = 1;
154  }
155  }
156  }
157 }
158 
159 static void
161  int run,
162  bool enableMultiThread,
163  const std::string &filename,
164  const std::string &directory,
165  const std::string &rxpat,
166  const std::string &rewrite,
168  int saveRefQMin,
169  const std::string &filterName,
170  DQMFileSaver::FileFormat fileFormat)
171 {
172  // TODO(rovere): fix the online case. so far we simply rely on the
173  // fact that we assume we will not run multithreaded in online.
174  if (fileFormat == DQMFileSaver::ROOT)
175  store->save(filename,
176  directory,
177  rxpat,
178  rewrite,
179  enableMultiThread ? run : 0,
180  0,
181  saveref,
182  saveRefQMin);
183  else if (fileFormat == DQMFileSaver::PB)
184  store->savePB(filename,
185  filterName,
186  enableMultiThread ? run : 0);
187 }
188 
189 void
191 {
192  // The file name contains the Online workflow name,
193  // as we do not want to look inside the DQMStore,
194  // and the @a suffix, defined in the run/lumi transitions.
195  // TODO(diguida): add the possibility to change the dir structure with rewrite.
198  filename,
199  "", "^(Reference/)?([^/]+)", "\\1\\2",
202  filterName_,
203  PB);
204 }
205 
206 void
208 {
209  std::vector<std::string> systems = (dbe_->cd(), dbe_->getSubdirs());
210 
211  for (size_t i = 0, e = systems.size(); i != e; ++i)
212  {
213  if (systems[i] != "Reference")
214  {
215  dbe_->cd();
216  if (MonitorElement* me = dbe_->get(systems[i] + "/EventInfo/processName"))
217  {
219  fileBaseName_ + me->getStringValue() + suffix + child_ + ".root",
220  "", "^(Reference/)?([^/]+)", rewrite,
223  "", ROOT);
224  return;
225  }
226  }
227  }
228 
229  // look for EventInfo folder in an unorthodox location
230  for (size_t i = 0, e = systems.size(); i != e; ++i)
231  if (systems[i] != "Reference")
232  {
233  dbe_->cd();
234  std::vector<MonitorElement*> pNamesVector = dbe_->getMatchingContents("^" + systems[i] + "/.*/EventInfo/processName",lat::Regexp::Perl);
235  if (pNamesVector.size() > 0){
237  fileBaseName_ + systems[i] + suffix + child_ + ".root",
238  "", "^(Reference/)?([^/]+)", rewrite,
241  "", ROOT);
242  pNamesVector.clear();
243  return;
244  }
245  }
246 
247  // if no EventInfo Folder is found, then store subsystem wise
248  for (size_t i = 0, e = systems.size(); i != e; ++i)
249  if (systems[i] != "Reference")
251  fileBaseName_ + systems[i] + suffix + child_ + ".root",
252  systems[i], "^(Reference/)?([^/]+)", rewrite,
255  "", ROOT);
256 }
257 
258 
259 boost::property_tree::ptree
260 DQMFileSaver::fillJson(int run, int lumi, const std::string& dataFilePathName, evf::FastMonitoringService *fms)
261 {
262  namespace bpt = boost::property_tree;
263  namespace bfs = boost::filesystem;
264 
265  bpt::ptree pt;
266 
267  int hostnameReturn;
268  char host[32];
269  hostnameReturn = gethostname(host ,sizeof(host));
270  if (hostnameReturn == -1)
271  throw cms::Exception("fillJson")
272  << "Internal error, cannot get host name";
273 
274  int pid = getpid();
275  std::ostringstream oss_pid;
276  oss_pid << pid;
277 
278  // Stat the data file: if not there, throw
279  struct stat dataFileStat;
280  if (stat(dataFilePathName.c_str(), &dataFileStat) != 0)
281  throw cms::Exception("fillJson")
282  << "Internal error, cannot get data file: "
283  << dataFilePathName;
284  // Extract only the data file name from the full path
285  std::string dataFileName = bfs::path(dataFilePathName).filename().string();
286  // The availability test of the FastMonitoringService was done in the ctor.
287  bpt::ptree data;
288  bpt::ptree processedEvents, acceptedEvents, errorEvents, bitmask, fileList, fileSize, inputFiles, fileAdler32;
289 
290  processedEvents.put("", fms ? (fms->getEventsProcessedForLumi(lumi)) : -1); // Processed events
291  acceptedEvents.put("", fms ? (fms->getEventsProcessedForLumi(lumi)) : -1); // Accepted events, same as processed for our purposes
292 
293  errorEvents.put("", 0); // Error events
294  bitmask.put("", 0); // Bitmask of abs of CMSSW return code
295  fileList.put("", dataFileName); // Data file the information refers to
296  fileSize.put("", dataFileStat.st_size); // Size in bytes of the data file
297  inputFiles.put("", ""); // We do not care about input files!
298  fileAdler32.put("", -1); // placeholder to match output json definition
299 
300  data.push_back(std::make_pair("", processedEvents));
301  data.push_back(std::make_pair("", acceptedEvents));
302  data.push_back(std::make_pair("", errorEvents));
303  data.push_back(std::make_pair("", bitmask));
304  data.push_back(std::make_pair("", fileList));
305  data.push_back(std::make_pair("", fileSize));
306  data.push_back(std::make_pair("", inputFiles));
307  data.push_back(std::make_pair("", fileAdler32));
308 
309  pt.add_child("data", data);
310 
311  if (fms == nullptr) {
312  pt.put("definition", "/fakeDefinition.jsn");
313  } else {
314  // The availability test of the EvFDaqDirector Service was done in the ctor.
315  bfs::path outJsonDefName(edm::Service<evf::EvFDaqDirector>()->baseRunDir()); //we assume this file is written bu the EvF Output module
316  outJsonDefName /= (std::string("output_") + oss_pid.str() + std::string(".jsd"));
317  pt.put("definition", outJsonDefName.string());
318  }
319 
320  char sourceInfo[64]; //host and pid information
321  sprintf(sourceInfo, "%s_%d", host, pid);
322  pt.put("source", sourceInfo);
323 
324  return pt;
325 }
326 
327 void
328 DQMFileSaver::saveForFilterUnit(const std::string& rewrite, int run, int lumi, const DQMFileSaver::FileFormat fileFormat) const
329 {
330  // get from DAQ2 services where to store the files according to their format
331  namespace bpt = boost::property_tree;
332 
333  std::string openJsonFilePathName;
334  std::string jsonFilePathName;
335  std::string openHistoFilePathName;
336  std::string histoFilePathName;
337 
338  // create the files names
339  if (fakeFilterUnitMode_) {
340  std::string runDir = str(boost::format("%s/run%06d") % dirName_ % run);
341  std::string baseName = str(boost::format("%s/run%06d_ls%04d_%s") % runDir % run % lumi % stream_label_ );
342 
343  boost::filesystem::create_directories(runDir);
344 
345  jsonFilePathName = baseName + ".jsn";
346  openJsonFilePathName = jsonFilePathName + ".open";
347 
348  histoFilePathName = baseName + dataFileExtension(fileFormat);
349  openHistoFilePathName = histoFilePathName + ".open";
350  } else {
351  openJsonFilePathName = edm::Service<evf::EvFDaqDirector>()->getOpenOutputJsonFilePath(lumi, stream_label_);
352  jsonFilePathName = edm::Service<evf::EvFDaqDirector>()->getOutputJsonFilePath(lumi, stream_label_);
353 
354  if (fileFormat == ROOT) {
355  openHistoFilePathName = edm::Service<evf::EvFDaqDirector>()->getOpenRootHistogramFilePath(lumi, stream_label_);
356  histoFilePathName = edm::Service<evf::EvFDaqDirector>()->getRootHistogramFilePath(lumi, stream_label_);
357  } else if (fileFormat == PB) {
358  openHistoFilePathName = edm::Service<evf::EvFDaqDirector>()->getOpenProtocolBufferHistogramFilePath(lumi, stream_label_);
359  histoFilePathName = edm::Service<evf::EvFDaqDirector>()->getProtocolBufferHistogramFilePath(lumi, stream_label_);
360  }
361  }
362 
363  if (fileFormat == ROOT)
364  {
365  // Save the file with the full directory tree,
366  // modifying it according to @a rewrite,
367  // but not looking for MEs inside the DQMStore, as in the online case,
368  // nor filling new MEs, as in the offline case.
369  dbe_->save(openHistoFilePathName,
370  "",
371  "^(Reference/)?([^/]+)",
372  rewrite,
373  enableMultiThread_ ? run : 0,
374  lumi,
377  fileUpdate_ ? "UPDATE" : "RECREATE",
378  true);
379  }
380  else if (fileFormat == PB)
381  {
382  // Save the file in the open directory.
383  dbe_->savePB(openHistoFilePathName,
384  filterName_,
385  enableMultiThread_ ? run : 0,
386  lumi,
387  true);
388  }
389  else
390  throw cms::Exception("DQMFileSaver")
391  << "Internal error, can save files"
392  << " only in ROOT or ProtocolBuffer format.";
393 
394  // Now move the the data and json files into the output directory.
395  rename(openHistoFilePathName.c_str(), histoFilePathName.c_str());
396 
397  // Write the json file in the open directory.
398  bpt::ptree pt = fillJson(run, lumi, histoFilePathName, fms_);
399  write_json(openJsonFilePathName, pt);
400  rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
401 }
402 
403 void
405 {
406 
407  // Report the file to job report service.
409  if (jr.isAvailable())
410  {
411  std::map<std::string, std::string> info;
412  info["Source"] = "DQMStore";
413  info["FileClass"] = "DQM";
414  jr->reportAnalysisFile(filename, info);
415  }
416 
417 }
418 
419 //--------------------------------------------------------
421  : convention_ (Offline),
422  fileFormat_(ROOT),
423  workflow_ (""),
424  producer_ ("DQM"),
425  stream_label_ (""),
426  dirName_ ("."),
427  child_ (""),
428  filterName_(""),
429  version_ (1),
430  runIsComplete_ (false),
431  enableMultiThread_ (false),
432  saveByLumiSection_ (-1),
433  saveByRun_ (-1),
434  saveAtJobEnd_ (false),
435  saveReference_ (DQMStore::SaveWithReference),
436  saveReferenceQMin_ (dqm::qstatus::STATUS_OK),
437  forceRunNumber_ (-1),
438  fileBaseName_ (""),
439  fileUpdate_ (0),
440  dbe_ (&*edm::Service<DQMStore>()),
441  nrun_ (0),
442  nlumi_ (0),
443  irun_ (0),
444  fms_(nullptr)
445 {
446  // Determine the file saving convention, and adjust defaults accordingly.
447  std::string convention = ps.getUntrackedParameter<std::string>("convention", "Offline");
448  fakeFilterUnitMode_ = ps.getUntrackedParameter<bool>("fakeFilterUnitMode", false);
449 
450  if (convention == "Offline")
452  else if (convention == "Online")
454  else if (convention == "FilterUnit")
456  else
457  throw cms::Exception("DQMFileSaver")
458  << "Invalid 'convention' parameter '" << convention << "'."
459  << " Expected one of 'Online' or 'Offline' or 'FilterUnit'.";
460 
461  // If this is neither online nor FU convention, check workflow.
462  // In this way, FU is treated as online, so we cannot specify a workflow. TBC
464  {
466  if (workflow_.empty()
467  || workflow_[0] != '/'
468  || *workflow_.rbegin() == '/'
469  || std::count(workflow_.begin(), workflow_.end(), '/') != 3
470  || workflow_.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
471  "abcdefghijklmnopqrstuvwxyz"
472  "0123456789"
473  "-_/") != std::string::npos)
474  throw cms::Exception("DQMFileSaver")
475  << "Invalid 'workflow' parameter '" << workflow_
476  << "'. Expected '/A/B/C'.";
477  }
478  else if (! ps.getUntrackedParameter<std::string>("workflow", "").empty())
479  throw cms::Exception("DQMFileSaver")
480  << "The 'workflow' parameter must be empty in 'Online' and 'FilterUnit' conventions.";
481  else // for online set parameters
482  {
483  workflow_="/Global/Online/P5";
484  }
485 
486  // Determine the file format, and adjust defaults accordingly.
487  std::string fileFormat = ps.getUntrackedParameter<std::string>("fileFormat", "ROOT");
488  if (fileFormat == "ROOT")
489  fileFormat_ = ROOT;
490  else if (fileFormat == "PB")
491  fileFormat_ = PB;
492  else
493  throw cms::Exception("DQMFileSaver")
494  << "Invalid 'fileFormat' parameter '" << fileFormat << "'."
495  << " Expected one of 'ROOT' or 'PB'.";
496 
497  // Allow file producer to be set to specific values in certain conditions.
499  // Setting the same constraints on file producer both for online and FilterUnit conventions
500  // TODO(diguida): limit the producer for FilterUnit to be 'DQM' or 'HLTDQM'?
501  // TODO(diguida): how to handle histograms produced in the playback for the FU case?
503  && producer_ != "DQM"
504  && producer_ != "HLTDQM"
505  && producer_ != "Playback")
506  {
507  throw cms::Exception("DQMFileSaver")
508  << "Invalid 'producer' parameter '" << producer_
509  << "'. Expected 'DQM', 'HLTDQM' or 'Playback'.";
510  }
511  else if (convention_ != Online
512  && convention != FilterUnit
513  && producer_ != "DQM")
514  {
515  throw cms::Exception("DQMFileSaver")
516  << "Invalid 'producer' parameter '" << producer_
517  << "'. Expected 'DQM'.";
518  }
519 
521 
522  // version number to be used in filename
523  version_ = ps.getUntrackedParameter<int>("version", version_);
524  // flag to signal that file contains data from complete run
525  runIsComplete_ = ps.getUntrackedParameter<bool>("runIsComplete", runIsComplete_);
526 
527  // Check how we should save the references.
528  std::string refsave = ps.getUntrackedParameter<std::string>("referenceHandling", "default");
529  if (refsave == "default")
530  ;
531  else if (refsave == "skip")
532  {
534  // std::cout << "skip saving all references" << std::endl;
535  }
536  else if (refsave == "all")
537  {
539  // std::cout << "saving all references" << std::endl;
540  }
541  else if (refsave == "qtests")
542  {
544  // std::cout << "saving qtest references" << std::endl;
545  }
546  else
547  throw cms::Exception("DQMFileSaver")
548  << "Invalid 'referenceHandling' parameter '" << refsave
549  << "'. Expected 'default', 'skip', 'all' or 'qtests'.";
550 
551  // Check minimum required quality test result for which reference is saved.
552  saveReferenceQMin_ = ps.getUntrackedParameter<int>("referenceRequireStatus", saveReferenceQMin_);
553 
554  // Get and check the output directory.
555  struct stat s;
557  if (dirName_.empty() || stat(dirName_.c_str(), &s) == -1)
558  throw cms::Exception("DQMFileSaver")
559  << "Invalid 'dirName' parameter '" << dirName_ << "'.";
560 
562  // Find out when and how to save files. The following contraints apply:
563  // - For online, filter unit, and offline, allow files to be saved per lumi
564  // - For online, allow files to be saved per run, at event and time intervals.
565  // - For offline allow files to be saved per run, at job end, and run number to be overridden (for mc data).
567  {
568  getAnInt(ps, saveByLumiSection_, "saveByLumiSection");
569  }
570 
571  if (convention_ == Online)
572  {
573  getAnInt(ps, saveByRun_, "saveByRun");
574  }
575 
576  if (convention_ == Offline)
577  {
578  getAnInt(ps, saveByRun_, "saveByRun");
579  getAnInt(ps, forceRunNumber_, "forceRunNumber");
580  saveAtJobEnd_ = ps.getUntrackedParameter<bool>("saveAtJobEnd", saveAtJobEnd_);
581  }
582 
583  // Set up base file name:
584  // - for online and offline, follow the convention <dirName>/<producer>_V<4digits>_
585  // - for FilterUnit, we need to follow the DAQ2 convention, so we need the run and lumisection:
586  // the path is provided by the DAQ director service.
587  if (convention_ != FilterUnit)
588  {
589  char version[8];
590  sprintf(version, "_V%04d_", int(version_));
591  version[7]='\0';
592  fileBaseName_ = dirName_ + "/" + producer_ + version;
593  }
594  else if (fakeFilterUnitMode_)
595  {
596  edm::LogInfo("DQMFileSaver")
597  << "Fake FU mode, files are saved under <dirname>/runXXXXXX/runXXXXXX_lsXXXX_<stream_Label>.pb.\n";
598  }
599  else
600  {
601  // For FU, dirName_ will not be considered at all
602  edm::LogInfo("DQMFileSaver")
603  << "The base dir provided in the configuration '" << dirName_ << "'\n"
604  << " will not be considered: for FU, the DAQ2 services will handle directories\n";
605  //check that DAQ2 services are available: throw if not
608 
609  if (!(fms_ && daqDirector))
610  throw cms::Exception("DQMFileSaver")
611  << "Internal error, cannot initialize DAQ services.";
612  }
613 
614  // Log some information what we will do.
615  edm::LogInfo("DQMFileSaver")
616  << "DQM file saving settings:\n"
617  << " using base file name '" << fileBaseName_ << "'\n"
618  << " forcing run number " << forceRunNumber_ << "\n"
619  << " saving every " << saveByLumiSection_ << " lumi section(s)\n"
620  << " saving every " << saveByRun_ << " run(s)\n"
621  << " saving at job end: " << (saveAtJobEnd_ ? "yes" : "no") << "\n";
622 }
623 
624 //--------------------------------------------------------
625 void
627 {
628  nrun_ = nlumi_ = irun_ = 0;
629 
630  // Determine if we are running multithreading asking to the DQMStore. Not to be moved in the ctor
631  enableMultiThread_ = dbe_->enableMultiThread_;
632 }
633 
634 std::shared_ptr<saverDetails::NoCache>
636 {
637  ++nrun_;
638 
639  // For Filter Unit, create an empty ini file:
640  // it is needed by the HLT deamon in order to start merging
641  // The run number is established in the service
642  // TODO(diguida): check that they are the same?
644  {
646  const std::string initFileName = daqDirector->getInitFilePath(stream_label_);
647  std::ofstream file(initFileName);
648  file.close();
649  }
650 
651  return nullptr;
652 }
653 
654 std::shared_ptr<saverDetails::NoCache>
656 {
657  ++nlumi_;
658  return nullptr;
659 }
660 
662 {
663  //save by event and save by time are not supported
664  //anymore in the threaded framework. please use
665  //savebyLumiSection instead.
666 }
667 
668 void
670 {
671  int ilumi = iLS.id().luminosityBlock();
672  int irun = iLS.id().run();
673  if (ilumi > 0 && saveByLumiSection_ > 0 )
674  {
676  throw cms::Exception("DQMFileSaver")
677  << "Internal error, can save files at end of lumi block"
678  << " only in Online, FilterUnit or Offline mode.";
679 
680  if (convention_ == Online && (nlumi_ % saveByLumiSection_) == 0) // insist on lumi section ordering
681  {
682  char suffix[64];
683  char rewrite[128];
684  sprintf(suffix, "_R%09d_L%06d", irun, ilumi);
685  sprintf(rewrite, "\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi-nlumi_, ilumi);
686  if (fileFormat_ == ROOT)
687  saveForOnline(irun, suffix, rewrite);
688  else if (fileFormat_ == PB)
689  saveForOnlinePB(irun, suffix);
690  else
691  throw cms::Exception("DQMFileSaver")
692  << "Internal error, can save files"
693  << " only in ROOT or ProtocolBuffer format.";
694  }
695 
696  // Store at every lumi section end only if some events have been processed.
697  // Caveat: if faking FilterUnit, i.e. not accessing DAQ2 services,
698  // we cannot ask FastMonitoringService the processed events, so we are forced
699  // to save the file at every lumisection, even with no statistics.
700  // Here, we protect the call to get the processed events in a lumi section
701  // by testing the pointer to FastMonitoringService: if not null, i.e. in real FU mode,
702  // we check that the events are not 0; otherwise, we skip the test, so we store at every lumi transition.
703  // TODO(diguida): allow fake FU mode to skip file creation at empty lumi sections.
704  if (convention_ == FilterUnit && (fms_ ? (fms_->getEventsProcessedForLumi(ilumi) > 0) : !fms_))
705  {
706  char rewrite[128];
707  sprintf(rewrite, "\\1Run %d/\\2/By Lumi Section %d-%d", irun, ilumi, ilumi);
708  saveForFilterUnit(rewrite, irun, ilumi, fileFormat_);
709  }
710  if (convention_ == Offline)
711  {
712  if (fileFormat_ == ROOT)
713  saveForOffline(workflow_, irun, ilumi);
714  else
715  // TODO(diguida): do we need to support lumisection saving in Offline for PB?
716  // In this case, for ROOT, we only save EventInfo folders: we can filter them...
717  throw cms::Exception("DQMFileSaver")
718  << "Internal error, can save files"
719  << " only in ROOT format.";
720  }
721 
722  // after saving per LS, delete the old LS global histograms.
723  dbe_->markForDeletion(enableMultiThread_ ? irun : 0, ilumi);
724  }
725 }
726 
727 void
729 {
730  int irun = iRun.id().run();
731  irun_ = irun;
732  if (irun > 0 && saveByRun_ > 0 && (nrun_ % saveByRun_) == 0)
733  {
734  if (convention_ == Online)
735  {
736  char suffix[64];
737  sprintf(suffix, "_R%09d", irun);
738  char rewrite[64];
739  sprintf(rewrite, "\\1Run %d/\\2/Run summary", irun);
740  if (fileFormat_ == ROOT)
741  saveForOnline(irun, suffix, rewrite);
742  else if (fileFormat_ == PB)
743  saveForOnlinePB(irun, suffix);
744  else
745  throw cms::Exception("DQMFileSaver")
746  << "Internal error, can save files"
747  << " only in ROOT or ProtocolBuffer format.";
748  }
749  else if (convention_ == Offline && fileFormat_ == ROOT)
750  saveForOffline(workflow_, irun, 0);
751  else if (convention_ == Offline && fileFormat_ == PB)
753  else
754  throw cms::Exception("DQMFileSaver")
755  << "Internal error. Can only save files in endRun()"
756  << " in Online and Offline modes.";
757  }
758 
759  // create a fake EoR file for testing purposes.
760  if (fakeFilterUnitMode_) {
761  edm::LogInfo("DQMFileSaver")
762  << "Producing fake EoR file.\n";
763 
764  std::string runDir = str(boost::format("%s/run%06d") % dirName_ % irun);
765  std::string jsonFilePathName = str(boost::format("%s/run%06d_ls0000_EoR.jsn") % runDir % irun);
766  std::string openJsonFilePathName = jsonFilePathName + ".open";
767 
768  boost::filesystem::create_directories(runDir);
769 
770  using namespace boost::property_tree;
771  ptree pt;
772  ptree data;
773 
774  ptree child1, child2, child3;
775 
776  child1.put("", -1); // Processed
777  child2.put("", -1); // Accepted
778  child3.put("", nlumi_); // number of lumi
779 
780  data.push_back(std::make_pair("", child1));
781  data.push_back(std::make_pair("", child2));
782  data.push_back(std::make_pair("", child3));
783 
784  pt.add_child("data", data);
785  pt.put("definition", "/non-existant/");
786  pt.put("source", "--hostname--");
787 
788  std::ofstream file(jsonFilePathName);
789  write_json(file, pt, true);
790  file.close();
791 
792  rename(openJsonFilePathName.c_str(), jsonFilePathName.c_str());
793  }
794 }
795 
796 void
798 {
799  if (saveAtJobEnd_)
800  {
801  if (convention_ == Offline && forceRunNumber_ > 0)
803  else if (convention_ == Offline)
805  else
806  throw cms::Exception("DQMFileSaver")
807  << "Internal error. Can only save files at the end of the"
808  << " job in Offline mode.";
809  }
810 
811  // save JobReport once per job
812  char suffix[64];
813  sprintf(suffix, "R%09d", irun_.load());
815  saveJobReport(filename);
816 }
817 
818 void
819 DQMFileSaver::postForkReacquireResources(unsigned int childIndex, unsigned int numberOfChildren)
820 {
821  // this is copied from IOPool/Output/src/PoolOutputModule.cc, for consistency
822  unsigned int digits = 0;
823  while (numberOfChildren != 0) {
824  ++digits;
825  numberOfChildren /= 10;
826  }
827  // protect against zero numberOfChildren
828  if (digits == 0) {
829  digits = 3;
830  }
831 
832  char buffer[digits + 2];
833  snprintf(buffer, digits + 2, "_%0*d", digits, childIndex);
834  child_ = std::string(buffer);
835 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
DQMFileSaver(const edm::ParameterSet &ps)
int forceRunNumber_
Definition: DQMFileSaver.h:80
int saveReferenceQMin_
Definition: DQMFileSaver.h:79
static const TGPicture * info(bool iBackgroundIsBlack)
RunID const & id() const
Definition: RunBase.h:41
void saveForOffline(const std::string &workflow, int run, int lumi) const
Definition: DQMFileSaver.cc:86
RunNumber_t run() const
Definition: RunID.h:39
static std::string dataFileExtension(DQMFileSaver::FileFormat fileFormat)
Definition: DQMFileSaver.cc:48
virtual void globalEndRun(const edm::Run &, const edm::EventSetup &) const
Convention convention_
Definition: DQMFileSaver.h:62
std::string getInitFilePath(std::string const &stream) const
tuple lumi
Definition: fjr2json.py:35
evf::FastMonitoringService * fms_
Definition: DQMFileSaver.h:93
DQMStore * dbe_
Definition: DQMFileSaver.h:85
string format
Some error handling for the usage.
std::atomic< int > nlumi_
Definition: DQMFileSaver.h:87
#define nullptr
std::string dirName_
Definition: DQMFileSaver.h:67
std::string fileBaseName_
Definition: DQMFileSaver.h:82
virtual void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const
SaveReferenceTag
Definition: DQMStore.h:78
void Fill(long long x)
unsigned int getEventsProcessedForLumi(unsigned int lumi)
int saveByLumiSection_
Definition: DQMFileSaver.h:75
bool enableMultiThread_
Definition: DQMFileSaver.h:72
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)
Definition: DQMFileSaver.cc:38
static boost::property_tree::ptree fillJson(int run, int lumi, const std::string &dataFilePathName, evf::FastMonitoringService *fms)
bool isAvailable() const
Definition: Service.h:46
RunNumber_t run() const
static std::string onlineOfflineFileName(const std::string &fileBaseName, const std::string &suffix, const std::string &workflow, const std::string &child, DQMFileSaver::FileFormat fileFormat)
Definition: DQMFileSaver.cc:59
void saveForOnline(int run, const std::string &suffix, const std::string &rewrite) const
bool fakeFilterUnitMode_
Definition: DQMFileSaver.h:73
bool runIsComplete_
Definition: DQMFileSaver.h:71
std::string stream_label_
Definition: DQMFileSaver.h:66
static const std::string streamPrefix_
Definition: DQMFileSaver.h:95
DQMStore * dbe_
std::string workflow_
Definition: DQMFileSaver.h:64
virtual std::shared_ptr< saverDetails::NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const
std::string getReleaseVersion()
string host
Definition: query.py:114
std::string producer_
Definition: DQMFileSaver.h:65
std::string child_
Definition: DQMFileSaver.h:68
int saveReference_
Definition: DQMFileSaver.h:78
void saveForOnlinePB(int run, const std::string &suffix) const
std::string filterName_
Definition: DQMFileSaver.h:69
std::atomic< int > fileUpdate_
Definition: DQMFileSaver.h:83
tuple pid
Definition: sysUtil.py:22
FileFormat fileFormat_
Definition: DQMFileSaver.h:63
LuminosityBlockNumber_t luminosityBlock() const
virtual void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const
std::atomic< int > irun_
Definition: DQMFileSaver.h:90
virtual std::shared_ptr< saverDetails::NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const
void saveForOfflinePB(const std::string &workflow, int run) const
Definition: DQMFileSaver.cc:77
bool saveAtJobEnd_
Definition: DQMFileSaver.h:77
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:559
std::atomic< int > nrun_
Definition: DQMFileSaver.h:86
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)
tuple filename
Definition: lut2db_cfg.py:20
static const int STATUS_OK
tuple inputFiles
Definition: merge.py:5
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_
Definition: DQMFileSaver.h:96
Definition: Run.h:41
void saveForFilterUnit(const std::string &rewrite, int run, int lumi, const FileFormat fileFormat) const