CMS 3D CMS Logo

DQMFileSaver.cc
Go to the documentation of this file.
3 
13 
15 
16 #include <sys/stat.h>
17 
18 namespace saverDetails {
19  struct NoCache {};
20 } // namespace saverDetails
21 
22 // NOTE: This module is only save to use in a very restricted set of circumstances:
23 // - In offline HARVESTING jobs, running single-threaded. RUN and JOB histograms are saved at end of JOB.
24 // - In multi-run harvesting. JOB histograms are save at end of job.
25 // - This includes ALCAHARVEST. TODO: check if the data written there is needed for the PCL.
26 // This module is not used in online. This module is (hopefully?) not used at HLT.
27 // Online and HLT use modules in DQMServices/FileIO.
28 class DQMFileSaver : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
29 public:
33 
34 protected:
35  void beginRun(edm::Run const &, edm::EventSetup const &) override{};
36  void analyze(const edm::Event &e, const edm::EventSetup &) override;
37  void endRun(const edm::Run &, const edm::EventSetup &) override;
38  void endJob() override;
39 
40 private:
41  void saveForOffline(const std::string &workflow, int run, int lumi);
42  void saveJobReport(const std::string &filename);
43 
49  int version_;
51 
55 
57 
59  int nrun_;
60 
61  // needed only for the harvesting step when saving in the endJob
62  int irun_;
63 };
64 
65 //--------------------------------------------------------
66 static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name) {
68  if (value < 1 && value != -1)
69  throw cms::Exception("DQMFileSaver") << "Invalid '" << name << "' parameter '" << value
70  << "'. Must be -1 or >= 1.";
71 }
72 
73 static std::string onlineOfflineFileName(const std::string &fileBaseName,
74  const std::string &suffix,
75  const std::string &workflow,
76  const std::string &child) {
77  size_t pos = 0;
78  std::string wflow;
79  wflow.reserve(workflow.size() + 3);
80  wflow = workflow;
81  while ((pos = wflow.find('/', pos)) != std::string::npos)
82  wflow.replace(pos++, 1, "__");
83 
84  std::string filename = fileBaseName + suffix + wflow + child + ".root";
85  return filename;
86 }
87 
89  char suffix[64];
90  sprintf(suffix, "R%09d", run);
91 
93  assert(lumi == 0);
94 
95  // set run end flag
96  dbe_->cd();
97  dbe_->setCurrentFolder("Info/ProvInfo");
98 
99  // do this, because ProvInfo is not yet run in offline DQM
100  MonitorElement *me = dbe_->get("Info/ProvInfo/CMSSW");
101  if (!me)
102  me = dbe_->bookString("CMSSW", edm::getReleaseVersion().c_str());
103 
104  me = dbe_->get("Info/ProvInfo/runIsComplete");
105  if (!me)
106  me = dbe_->bookFloat("runIsComplete");
107 
108  if (me) {
109  if (runIsComplete_)
110  me->Fill(1.);
111  else
112  me->Fill(0.);
113  }
114 
116  h.save(filename, "", run, /* saveall */ true, "RECREATE");
117 
118  // save the JobReport
120 }
121 
123  // Report the file to job report service.
125  if (jr.isAvailable()) {
126  std::map<std::string, std::string> info;
127  info["Source"] = "DQMStore";
128  info["FileClass"] = "DQM";
130  }
131 }
132 
133 //--------------------------------------------------------
135  :
136 
137  workflow_(""),
138  producer_("DQM"),
139  dirName_("."),
140  child_(""),
141  version_(1),
142  runIsComplete_(false),
143  saveByRun_(-1),
144  saveAtJobEnd_(false),
145  forceRunNumber_(-1),
146  fileBaseName_(""),
147  dbe_(&*edm::Service<DQMStore>()),
148  nrun_(0),
149  irun_(0) {
150  // Note: this is insufficient, we also need to enforce running *after* all
151  // DQMEDAnalyzers (a.k.a. EDProducers) in endJob.
152  // This is not supported in edm currently.
153  consumesMany<DQMToken, edm::InRun>();
155  if (workflow_.empty() || workflow_[0] != '/' || *workflow_.rbegin() == '/' ||
156  std::count(workflow_.begin(), workflow_.end(), '/') != 3 ||
157  workflow_.find_first_not_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
158  "abcdefghijklmnopqrstuvwxyz"
159  "0123456789"
160  "-_/") != std::string::npos)
161  throw cms::Exception("DQMFileSaver") << "Invalid 'workflow' parameter '" << workflow_ << "'. Expected '/A/B/C'.";
162 
163  // version number to be used in filename
164  // Note that version *must* always be 1 vor DQMGUI upload.
165  version_ = ps.getUntrackedParameter<int>("version", version_);
166  // flag to signal that file contains data from complete run
167  runIsComplete_ = ps.getUntrackedParameter<bool>("runIsComplete", runIsComplete_);
168 
169  // Get and check the output directory.
170  struct stat s;
172  if (dirName_.empty() || stat(dirName_.c_str(), &s) == -1)
173  throw cms::Exception("DQMFileSaver") << "Invalid 'dirName' parameter '" << dirName_ << "'.";
174 
175  // Find out when and how to save files. The following contraints apply:
176  // - For offline allow files to be saved per run, at job end, and run number to be overridden (for mc data).
177 
178  getAnInt(ps, saveByRun_, "saveByRun");
179  getAnInt(ps, forceRunNumber_, "forceRunNumber");
180  saveAtJobEnd_ = ps.getUntrackedParameter<bool>("saveAtJobEnd", saveAtJobEnd_);
181 
182  // Set up base file name:
183  // - for online and offline, follow the convention <dirName>/<producer>_V<4digits>_
184  char version[8];
185  sprintf(version, "_V%04d_", int(version_));
186  version[7] = '\0';
188 
189  // Log some information what we will do.
190  edm::LogInfo("DQMFileSaver") << "DQM file saving settings:\n"
191  << " using base file name '" << fileBaseName_ << "'\n"
192  << " forcing run number " << forceRunNumber_ << "\n"
193  << " saving every " << saveByRun_ << " run(s)\n"
194  << " saving at job end: " << (saveAtJobEnd_ ? "yes" : "no") << "\n";
195 }
196 
198  //save by event and save by time are not supported
199  //anymore in the threaded framework. please use
200  //savebyLumiSection instead.
201 }
202 
203 void DQMFileSaver::endRun(const edm::Run &iRun, const edm::EventSetup &) {
204  int irun = iRun.id().run();
205  irun_ = irun;
206  if (irun > 0 && saveByRun_ > 0 && (nrun_ % saveByRun_) == 0) {
207  saveForOffline(workflow_, irun, 0);
208  }
209 }
210 
212  if (saveAtJobEnd_) {
213  if (forceRunNumber_ > 0)
215  else
217  }
218 }
219 
LegacyIOHelper
Definition: LegacyIOHelper.h:14
getAnInt
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
Definition: DQMFileSaver.cc:66
DQMFileSaver::runIsComplete_
bool runIsComplete_
Definition: DQMFileSaver.cc:50
DQMFileSaver::saveForOffline
void saveForOffline(const std::string &workflow, int run, int lumi)
Definition: DQMFileSaver.cc:88
DQMFileSaver::version_
int version_
Definition: DQMFileSaver.cc:49
EDAnalyzer.h
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
dqm::implementation::IBooker::bookFloat
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
edm::RunID::run
RunNumber_t run() const
Definition: RunID.h:36
edm::Run
Definition: Run.h:45
LuminosityBlock.h
DQMFileSaver::saveAtJobEnd_
bool saveAtJobEnd_
Definition: DQMFileSaver.cc:53
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
pos
Definition: PixelAliasList.h:18
edm::JobReport::reportAnalysisFile
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
edm::LogInfo
Definition: MessageLogger.h:254
cms::cuda::assert
assert(be >=bs)
DQMStore.h
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DQMFileSaver::producer_
std::string producer_
Definition: DQMFileSaver.cc:45
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
createPayload.suffix
suffix
Definition: createPayload.py:281
LegacyIOHelper.h
DQMFileSaver::analyze
void analyze(const edm::Event &e, const edm::EventSetup &) override
Definition: DQMFileSaver.cc:197
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DQMFileSaver::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: DQMFileSaver.cc:30
DQMFileSaver::stream_label_
std::string stream_label_
Definition: DQMFileSaver.cc:46
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
hgcalPlots.stat
stat
Definition: hgcalPlots.py:1111
DQMFileSaver::DQMFileSaver
DQMFileSaver(const edm::ParameterSet &ps)
Definition: DQMFileSaver.cc:134
DQMToken.h
Service.h
saverDetails::NoCache
Definition: DQMFileSaver.cc:19
Run.h
DQMFileSaver::saveByRun_
int saveByRun_
Definition: DQMFileSaver.cc:52
Service
DQMFileSaver::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: DQMFileSaver.cc:35
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
dqm::implementation::DQMStore::setCurrentFolder
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:569
dbe_
dqm::legacy::DQMStore * dbe_
Definition: PFJetBenchmarkAnalyzer.cc:77
h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DQMFileSaver::dbe_
DQMStore * dbe_
Definition: DQMFileSaver.cc:58
edm::ParameterSet
Definition: ParameterSet.h:36
GetReleaseVersion.h
dqm::implementation::IBooker::bookString
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
Event.h
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
saverDetails
Definition: DQMFileSaver.cc:18
edm::Service
Definition: Service.h:30
value
Definition: value.py:1
edm::EventSetup
Definition: EventSetup.h:57
DQMFileSaver::saveJobReport
void saveJobReport(const std::string &filename)
Definition: DQMFileSaver.cc:122
onlineOfflineFileName
static std::string onlineOfflineFileName(const std::string &fileBaseName, const std::string &suffix, const std::string &workflow, const std::string &child)
Definition: DQMFileSaver.cc:73
AlCaHarvesting_cff.workflow
workflow
Definition: AlCaHarvesting_cff.py:30
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DQMFileSaver::workflow_
std::string workflow_
Definition: DQMFileSaver.cc:44
DQMFileSaver::nrun_
int nrun_
Definition: DQMFileSaver.cc:59
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::getReleaseVersion
std::string getReleaseVersion()
Definition: GetReleaseVersion.cc:7
Exception
Definition: hltDiff.cc:246
DQMFileSaver::fileBaseName_
std::string fileBaseName_
Definition: DQMFileSaver.cc:56
DQMFileSaver::dirName_
std::string dirName_
Definition: DQMFileSaver.cc:47
DQMFileSaver::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: DQMFileSaver.cc:31
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
DQMFileSaver::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: DQMFileSaver.cc:203
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DQMFileSaver::child_
std::string child_
Definition: DQMFileSaver.cc:48
cms::Exception
Definition: Exception.h:70
JobReport.h
DQMFileSaver::irun_
int irun_
Definition: DQMFileSaver.cc:62
ParameterSet.h
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:56
edm::Event
Definition: Event.h:73
child
Definition: simpleInheritance.h:11
DQMFileSaver
Definition: DQMFileSaver.cc:28
lumi
Definition: LumiSectionData.h:20
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
edm::RunBase::id
RunID const & id() const
Definition: RunBase.h:39
DQMFileSaver::forceRunNumber_
int forceRunNumber_
Definition: DQMFileSaver.cc:54
dqm::implementation::DQMStore::cd
void cd() override
Definition: DQMStore.h:564
DQMFileSaver::endJob
void endJob() override
Definition: DQMFileSaver.cc:211
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37