CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
67  // We want to consume all DQMTokens for runs and jobs. But consumesMany is
68  // confused by the labels, so we sue these getters.
71 };
72 
73 //--------------------------------------------------------
74 static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name) {
75  value = ps.getUntrackedParameter<int>(name, value);
76  if (value < 1 && value != -1)
77  throw cms::Exception("DQMFileSaver") << "Invalid '" << name << "' parameter '" << value
78  << "'. Must be -1 or >= 1.";
79 }
80 
81 static std::string onlineOfflineFileName(const std::string &fileBaseName,
82  const std::string &suffix,
83  const std::string &workflow,
84  const std::string &child) {
85  size_t pos = 0;
86  std::string wflow;
87  wflow.reserve(workflow.size() + 3);
88  wflow = workflow;
89  while ((pos = wflow.find('/', pos)) != std::string::npos)
90  wflow.replace(pos++, 1, "__");
91 
92  std::string filename = fileBaseName + suffix + wflow + child + ".root";
93  return filename;
94 }
95 
97  char suffix[64];
98  sprintf(suffix, "R%09d", run);
99 
101  assert(lumi == 0);
102 
103  // set run end flag
104  dbe_->cd();
105  dbe_->setCurrentFolder("Info/ProvInfo");
106 
107  // do this, because ProvInfo is not yet run in offline DQM
108  MonitorElement *me = dbe_->get("Info/ProvInfo/CMSSW");
109  if (!me)
110  me = dbe_->bookString("CMSSW", edm::getReleaseVersion().c_str());
111 
112  me = dbe_->get("Info/ProvInfo/runIsComplete");
113  if (!me)
114  me = dbe_->bookFloat("runIsComplete");
115 
116  if (me) {
117  if (runIsComplete_)
118  me->Fill(1.);
119  else
120  me->Fill(0.);
121  }
122 
124  h.save(filename, "", run, /* saveall */ true, "RECREATE");
125 
126  // save the JobReport
127  saveJobReport(filename);
128 }
129 
131  // Report the file to job report service.
133  if (jr.isAvailable()) {
134  std::map<std::string, std::string> info;
135  info["Source"] = "DQMStore";
136  info["FileClass"] = "DQM";
137  jr->reportAnalysisFile(filename, info);
138  }
139 }
140 
141 //--------------------------------------------------------
143  :
144 
145  workflow_(""),
146  producer_("DQM"),
147  dirName_("."),
148  child_(""),
149  version_(1),
150  runIsComplete_(false),
151  saveByRun_(-1),
152  saveAtJobEnd_(false),
153  forceRunNumber_(-1),
154  fileBaseName_(""),
155  dbe_(&*edm::Service<DQMStore>()),
156  nrun_(0),
157  irun_(0),
158  // Abuse ProcessMatch as a "match all".
159  jobmegetter_(edm::GetterOfProducts<DQMToken>(edm::ProcessMatch("*"), this, edm::InProcess)),
160  runmegetter_(edm::GetterOfProducts<DQMToken>(edm::ProcessMatch("*"), this, edm::InRun)) {
162  this->jobmegetter_(bd);
163  this->runmegetter_(bd);
164  });
165 
167  if (workflow_.empty() || workflow_[0] != '/' || *workflow_.rbegin() == '/' ||
168  std::count(workflow_.begin(), workflow_.end(), '/') != 3 ||
169  workflow_.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
170  "abcdefghijklmnopqrstuvwxyz"
171  "0123456789"
172  "-_/") != std::string::npos)
173  throw cms::Exception("DQMFileSaver") << "Invalid 'workflow' parameter '" << workflow_ << "'. Expected '/A/B/C'.";
174 
175  // version number to be used in filename
176  // Note that version *must* always be 1 vor DQMGUI upload.
177  version_ = ps.getUntrackedParameter<int>("version", version_);
178  // flag to signal that file contains data from complete run
179  runIsComplete_ = ps.getUntrackedParameter<bool>("runIsComplete", runIsComplete_);
180 
181  // Get and check the output directory.
182  struct stat s;
184  if (dirName_.empty() || stat(dirName_.c_str(), &s) == -1)
185  throw cms::Exception("DQMFileSaver") << "Invalid 'dirName' parameter '" << dirName_ << "'.";
186 
187  // Find out when and how to save files. The following contraints apply:
188  // - For offline allow files to be saved per run, at job end, and run number to be overridden (for mc data).
189 
190  getAnInt(ps, saveByRun_, "saveByRun");
191  getAnInt(ps, forceRunNumber_, "forceRunNumber");
192  saveAtJobEnd_ = ps.getUntrackedParameter<bool>("saveAtJobEnd", saveAtJobEnd_);
193 
194  // Set up base file name:
195  // - for online and offline, follow the convention <dirName>/<producer>_V<4digits>_
196  char version[8];
197  sprintf(version, "_V%04d_", int(version_));
198  version[7] = '\0';
199  fileBaseName_ = dirName_ + "/" + producer_ + version;
200 
201  // Log some information what we will do.
202  edm::LogInfo("DQMFileSaver") << "DQM file saving settings:\n"
203  << " using base file name '" << fileBaseName_ << "'\n"
204  << " forcing run number " << forceRunNumber_ << "\n"
205  << " saving every " << saveByRun_ << " run(s)\n"
206  << " saving at job end: " << (saveAtJobEnd_ ? "yes" : "no") << "\n";
207 }
208 
210  //save by event and save by time are not supported
211  //anymore in the threaded framework. please use
212  //savebyLumiSection instead.
213 }
214 
215 void DQMFileSaver::endRun(const edm::Run &iRun, const edm::EventSetup &) {
216  int irun = iRun.id().run();
217  irun_ = irun;
218  if (irun > 0 && saveByRun_ > 0 && (nrun_ % saveByRun_) == 0) {
219  saveForOffline(workflow_, irun, 0);
220  }
221 }
222 
224  if (saveAtJobEnd_) {
225  if (forceRunNumber_ > 0)
227  else
229  }
230 }
231 
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: DQMFileSaver.cc:38
T getUntrackedParameter(std::string const &, T const &) const
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
RunID const & id() const
Definition: RunBase.h:39
void save(std::string const &filename, std::string const &path="", uint32_t const run=0, bool saveall=true, std::string const &fileupdate="RECREATE")
RunNumber_t run() const
Definition: RunID.h:36
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
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
void Fill(long long x)
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
Definition: DQMFileSaver.cc:74
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
bool isAvailable() const
Definition: Service.h:40
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
bool runIsComplete_
Definition: DQMFileSaver.cc:53
dqm::legacy::MonitorElement MonitorElement
Definition: DQMFileSaver.cc:34
list lumi
Definition: dqmdumpme.py:53
std::string stream_label_
Definition: DQMFileSaver.cc:49
dqm::legacy::DQMStore DQMStore
Definition: DQMFileSaver.cc:33
std::string workflow_
Definition: DQMFileSaver.cc:47
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:81
edm::GetterOfProducts< DQMToken > runmegetter_
Definition: DQMFileSaver.cc:70
bool saveAtJobEnd_
Definition: DQMFileSaver.cc:56
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
void saveForOffline(const std::string &workflow, int run, int lumi)
Definition: DQMFileSaver.cc:96
tuple filename
Definition: lut2db_cfg.py:20
edm::GetterOfProducts< DQMToken > jobmegetter_
Definition: DQMFileSaver.cc:69
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Definition: Run.h:45