CMS 3D CMS Logo

DQMFileSaver.cc
Go to the documentation of this file.
3 
16 
18 
19 #include <sys/stat.h>
20 
21 namespace saverDetails {
22  struct NoCache {};
23 } // namespace saverDetails
24 
25 // NOTE: This module is only save to use in a very restricted set of circumstances:
26 // - In offline HARVESTING jobs, running single-threaded. RUN and JOB histograms are saved at end of JOB.
27 // - In multi-run harvesting. JOB histograms are save at end of job.
28 // - This includes ALCAHARVEST. TODO: check if the data written there is needed for the PCL.
29 // This module is not used in online. This module is (hopefully?) not used at HLT.
30 // Online and HLT use modules in DQMServices/FileIO.
31 class DQMFileSaver : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::WatchProcessBlock> {
32 public:
36 
37 protected:
38  void beginRun(edm::Run const &, edm::EventSetup const &) override {}
39  void analyze(const edm::Event &e, const edm::EventSetup &) override;
40  void endRun(const edm::Run &, const edm::EventSetup &) override;
41  void endProcessBlock(const edm::ProcessBlock &) override;
42 
43 private:
44  void saveForOffline(const std::string &workflow, int run, int lumi);
45  void saveJobReport(const std::string &filename);
46 
52  int version_;
54 
58 
60 
62  int nrun_;
63 
64  // needed only for the harvesting step when saving in the endJob
65  int irun_;
66 
69 };
70 
71 //--------------------------------------------------------
72 static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name) {
74  if (value < 1 && value != -1)
75  throw cms::Exception("DQMFileSaver") << "Invalid '" << name << "' parameter '" << value
76  << "'. Must be -1 or >= 1.";
77 }
78 
79 static std::string onlineOfflineFileName(const std::string &fileBaseName,
80  const std::string &suffix,
81  const std::string &workflow,
82  const std::string &child) {
83  size_t pos = 0;
84  std::string wflow;
85  wflow.reserve(workflow.size() + 3);
86  wflow = workflow;
87  while ((pos = wflow.find('/', pos)) != std::string::npos)
88  wflow.replace(pos++, 1, "__");
89 
90  std::string filename = fileBaseName + suffix + wflow + child + ".root";
91  return filename;
92 }
93 
95  char suffix[64];
96  sprintf(suffix, "R%09d", run);
97 
99  assert(lumi == 0);
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)
108  me = dbe_->bookString("CMSSW", edm::getReleaseVersion().c_str());
109 
110  me = dbe_->get("Info/ProvInfo/runIsComplete");
111  if (!me)
112  me = dbe_->bookFloat("runIsComplete");
113 
114  if (me) {
115  if (runIsComplete_)
116  me->Fill(1.);
117  else
118  me->Fill(0.);
119  }
120 
122  h.save(filename, "", run, /* saveall */ true, "RECREATE");
123 
124  // save the JobReport
126 }
127 
129  // Report the file to job report service.
131  if (jr.isAvailable()) {
132  std::map<std::string, std::string> info;
133  info["Source"] = "DQMStore";
134  info["FileClass"] = "DQM";
136  }
137 }
138 
139 //--------------------------------------------------------
141  :
142 
143  workflow_(""),
144  producer_("DQM"),
145  dirName_("."),
146  child_(""),
147  version_(1),
148  runIsComplete_(false),
149  saveByRun_(-1),
150  saveAtJobEnd_(false),
151  forceRunNumber_(-1),
152  fileBaseName_(""),
153  dbe_(&*edm::Service<DQMStore>()),
154  nrun_(0),
155  irun_(0),
156  // Abuse ProcessMatch as a "match all".
157  jobmegetter_(edm::GetterOfProducts<DQMToken>(edm::ProcessMatch("*"), this, edm::InProcess)),
158  runmegetter_(edm::GetterOfProducts<DQMToken>(edm::ProcessMatch("*"), this, edm::InRun)) {
160  this->jobmegetter_(bd);
161  this->runmegetter_(bd);
162  });
163 
165  if (workflow_.empty() || workflow_[0] != '/' || *workflow_.rbegin() == '/' ||
166  std::count(workflow_.begin(), workflow_.end(), '/') != 3 ||
167  workflow_.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
168  "abcdefghijklmnopqrstuvwxyz"
169  "0123456789"
170  "-_/") != std::string::npos)
171  throw cms::Exception("DQMFileSaver") << "Invalid 'workflow' parameter '" << workflow_ << "'. Expected '/A/B/C'.";
172 
173  // version number to be used in filename
174  // Note that version *must* always be 1 vor DQMGUI upload.
175  version_ = ps.getUntrackedParameter<int>("version", version_);
176  // flag to signal that file contains data from complete run
177  runIsComplete_ = ps.getUntrackedParameter<bool>("runIsComplete", runIsComplete_);
178 
179  // Get and check the output directory.
180  struct stat s;
182  if (dirName_.empty() || stat(dirName_.c_str(), &s) == -1)
183  throw cms::Exception("DQMFileSaver") << "Invalid 'dirName' parameter '" << dirName_ << "'.";
184 
185  // Find out when and how to save files. The following contraints apply:
186  // - For offline allow files to be saved per run, at job end, and run number to be overridden (for mc data).
187 
188  getAnInt(ps, saveByRun_, "saveByRun");
189  getAnInt(ps, forceRunNumber_, "forceRunNumber");
190  saveAtJobEnd_ = ps.getUntrackedParameter<bool>("saveAtJobEnd", saveAtJobEnd_);
191 
192  // Set up base file name:
193  // - for online and offline, follow the convention <dirName>/<producer>_V<4digits>_
194  char version[8];
195  sprintf(version, "_V%04d_", int(version_));
196  version[7] = '\0';
198 
199  // Log some information what we will do.
200  edm::LogInfo("DQMFileSaver") << "DQM file saving settings:\n"
201  << " using base file name '" << fileBaseName_ << "'\n"
202  << " forcing run number " << forceRunNumber_ << "\n"
203  << " saving every " << saveByRun_ << " run(s)\n"
204  << " saving at job end: " << (saveAtJobEnd_ ? "yes" : "no") << "\n";
205 }
206 
208  //save by event and save by time are not supported
209  //anymore in the threaded framework. please use
210  //savebyLumiSection instead.
211 }
212 
213 void DQMFileSaver::endRun(const edm::Run &iRun, const edm::EventSetup &) {
214  int irun = iRun.id().run();
215  irun_ = irun;
216  if (irun > 0 && saveByRun_ > 0 && (nrun_ % saveByRun_) == 0) {
217  saveForOffline(workflow_, irun, 0);
218  }
219 }
220 
222  if (saveAtJobEnd_) {
223  if (forceRunNumber_ > 0)
225  else
227  }
228 }
229 
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: DQMFileSaver.cc:38
DQMFileSaver(const edm::ParameterSet &ps)
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
static const TGPicture * info(bool iBackgroundIsBlack)
void analyze(const edm::Event &e, const edm::EventSetup &) override
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:656
DQMStore * dbe_
Definition: DQMFileSaver.cc:61
assert(be >=bs)
std::string dirName_
Definition: DQMFileSaver.cc:50
void saveJobReport(const std::string &filename)
std::string fileBaseName_
Definition: DQMFileSaver.cc:59
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
void endRun(const edm::Run &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
Definition: DQMFileSaver.cc:72
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
bool runIsComplete_
Definition: DQMFileSaver.cc:53
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::MonitorElement MonitorElement
Definition: DQMFileSaver.cc:34
Definition: value.py:1
std::string stream_label_
Definition: DQMFileSaver.cc:49
dqm::legacy::DQMStore DQMStore
Definition: DQMFileSaver.cc:33
std::string workflow_
Definition: DQMFileSaver.cc:47
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
std::string getReleaseVersion()
std::string producer_
Definition: DQMFileSaver.cc:48
std::string child_
Definition: DQMFileSaver.cc:51
void endProcessBlock(const edm::ProcessBlock &) override
static std::string onlineOfflineFileName(const std::string &fileBaseName, const std::string &suffix, const std::string &workflow, const std::string &child)
Definition: DQMFileSaver.cc:79
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
edm::GetterOfProducts< DQMToken > runmegetter_
Definition: DQMFileSaver.cc:68
bool saveAtJobEnd_
Definition: DQMFileSaver.cc:56
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:509
void saveForOffline(const std::string &workflow, int run, int lumi)
Definition: DQMFileSaver.cc:94
bool isAvailable() const
Definition: Service.h:40
edm::GetterOfProducts< DQMToken > jobmegetter_
Definition: DQMFileSaver.cc:67
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
RunNumber_t run() const
Definition: RunID.h:26
Definition: Run.h:45