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