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 
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) {
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
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";
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';
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 
LegacyIOHelper
Definition: LegacyIOHelper.h:14
getAnInt
static void getAnInt(const edm::ParameterSet &ps, int &value, const std::string &name)
Definition: DQMFileSaver.cc:74
DQMFileSaver::runIsComplete_
bool runIsComplete_
Definition: DQMFileSaver.cc:53
DQMFileSaver::saveForOffline
void saveForOffline(const std::string &workflow, int run, int lumi)
Definition: DQMFileSaver.cc:96
DQMFileSaver::version_
int version_
Definition: DQMFileSaver.cc:52
EDAnalyzer.h
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
dqm::implementation::IBooker::bookFloat
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
DQMFileSaver::endProcessBlock
void endProcessBlock(const edm::ProcessBlock &) override
Definition: DQMFileSaver.cc:223
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:56
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
deep_tau::DeepTauBase::BasicDiscriminator
BasicDiscriminator
Definition: DeepTauBase.h:115
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
GetterOfProducts.h
cms::cuda::assert
assert(be >=bs)
DQMStore.h
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DQMFileSaver::producer_
std::string producer_
Definition: DQMFileSaver.cc:48
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::one::EDAnalyzerBase::callWhenNewProductsRegistered
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: EDAnalyzerBase.cc:50
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::InRun
Definition: BranchType.h:11
createPayload.suffix
suffix
Definition: createPayload.py:281
DQMFileSaver::jobmegetter_
edm::GetterOfProducts< DQMToken > jobmegetter_
Definition: DQMFileSaver.cc:69
LegacyIOHelper.h
edm::InProcess
Definition: BranchType.h:11
DQMFileSaver::analyze
void analyze(const edm::Event &e, const edm::EventSetup &) override
Definition: DQMFileSaver.cc:209
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DQMFileSaver::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: DQMFileSaver.cc:33
DQMFileSaver::stream_label_
std::string stream_label_
Definition: DQMFileSaver.cc:49
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
DQMFileSaver::DQMFileSaver
DQMFileSaver(const edm::ParameterSet &ps)
Definition: DQMFileSaver.cc:142
DQMToken.h
Service.h
saverDetails::NoCache
Definition: DQMFileSaver.cc:22
DQMToken
Definition: DQMToken.h:21
ProcessMatch.h
Run.h
DQMFileSaver::saveByRun_
int saveByRun_
Definition: DQMFileSaver.cc:55
Service
DQMFileSaver::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: DQMFileSaver.cc:38
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
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:61
edm::ParameterSet
Definition: ParameterSet.h:47
GetReleaseVersion.h
dqm::implementation::IBooker::bookString
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
Event.h
saverDetails
Definition: DQMFileSaver.cc:21
edm::Service
Definition: Service.h:30
edm::GetterOfProducts< DQMToken >
value
Definition: value.py:1
edm::EventSetup
Definition: EventSetup.h:58
DQMFileSaver::saveJobReport
void saveJobReport(const std::string &filename)
Definition: DQMFileSaver.cc:130
onlineOfflineFileName
static std::string onlineOfflineFileName(const std::string &fileBaseName, const std::string &suffix, const std::string &workflow, const std::string &child)
Definition: DQMFileSaver.cc:81
AlCaHarvesting_cff.workflow
workflow
Definition: AlCaHarvesting_cff.py:30
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DQMFileSaver::workflow_
std::string workflow_
Definition: DQMFileSaver.cc:47
DQMFileSaver::nrun_
int nrun_
Definition: DQMFileSaver.cc:62
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::getReleaseVersion
std::string getReleaseVersion()
Definition: GetReleaseVersion.cc:7
Exception
Definition: hltDiff.cc:245
DQMFileSaver::fileBaseName_
std::string fileBaseName_
Definition: DQMFileSaver.cc:59
DQMFileSaver::dirName_
std::string dirName_
Definition: DQMFileSaver.cc:50
DQMFileSaver::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: DQMFileSaver.cc:34
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:215
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::BranchDescription
Definition: BranchDescription.h:32
DQMFileSaver::child_
std::string child_
Definition: DQMFileSaver.cc:51
cms::Exception
Definition: Exception.h:70
JobReport.h
DQMFileSaver::irun_
int irun_
Definition: DQMFileSaver.cc:65
ParameterSet.h
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
edm::Event
Definition: Event.h:73
child
Definition: simpleInheritance.h:11
DQMFileSaver
Definition: DQMFileSaver.cc:31
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
edm::ProcessBlock
Definition: ProcessBlock.h:36
DQMFileSaver::forceRunNumber_
int forceRunNumber_
Definition: DQMFileSaver.cc:57
dqm::implementation::DQMStore::cd
void cd() override
Definition: DQMStore.h:564
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DQMFileSaver::runmegetter_
edm::GetterOfProducts< DQMToken > runmegetter_
Definition: DQMFileSaver.cc:70