CMS 3D CMS Logo

DQMFileSaverBase.cc
Go to the documentation of this file.
12 
13 #include "DQMFileSaverBase.h"
14 
15 #include <sys/stat.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <iostream>
19 #include <vector>
20 #include <string>
21 #include <fstream>
22 #include <utility>
23 #include <TString.h>
24 #include <TSystem.h>
25 
26 using namespace dqm;
27 
29  FileParameters fp;
30 
31  fp.path_ = ps.getUntrackedParameter<std::string>("path");
32  fp.producer_ = ps.getUntrackedParameter<std::string>("producer");
33  fp.run_ = 0;
34  fp.tag_ = ps.getUntrackedParameter<std::string>("tag");
35  fp.lumi_ = 0;
36  fp.version_ = 1;
37  fp.child_ = "";
38 
40  // Check how we should save the references.
41  std::string refsave = ps.getUntrackedParameter<std::string>("referenceHandling", "all");
42  if (refsave == "skip")
43  {
45  }
46  else if (refsave == "all")
47  {
49  }
50  else if (refsave == "qtests")
51  {
53  }
54  else {
55  //edm::LogInfo("DQMFileSaverBase")
56  std::cerr
57  << "Invalid 'referenceHandling' parameter '" << refsave
58  << "'. Expected 'skip', 'all' or 'qtests'.";
59 
60  }
61 
62  // Check minimum required quality test result for which reference is saved.
63  fp.saveReferenceQMin_ = ps.getUntrackedParameter<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK);
64 
65  std::unique_lock<std::mutex> lck(initial_fp_lock_);
66  initial_fp_ = fp;
67 }
68 
70 
71 std::shared_ptr<NoCache> DQMFileSaverBase::globalBeginRun(
72  const edm::Run &r, const edm::EventSetup &) const {
73 
74  this->initRun();
75 
76  return nullptr;
77 }
78 
80  const edm::LuminosityBlock &l, const edm::EventSetup &) const {
81 
82  return nullptr;
83 }
84 
86  const edm::EventSetup &) const {
87  // not supported
88 }
89 
91  const edm::EventSetup &) const {
92  int ilumi = iLS.id().luminosityBlock();
93  int irun = iLS.id().run();
94 
95  std::unique_lock<std::mutex> lck(initial_fp_lock_);
97  lck.unlock();
98 
99  fp.lumi_ = ilumi;
100  fp.run_ = irun;
101 
102  this->saveLumi(fp);
103 
105  store->deleteUnusedLumiHistograms(store->mtEnabled() ? irun : 0, ilumi);
106 }
107 
109  const edm::EventSetup &) const {
110 
111  std::unique_lock<std::mutex> lck(initial_fp_lock_);
113  lck.unlock();
114 
115  fp.run_ = iRun.id().run();
116 
117  // empty
118  this->saveRun(fp);
119 }
120 
122  unsigned int childIndex, unsigned int numberOfChildren) {
123  // this is copied from IOPool/Output/src/PoolOutputModule.cc, for consistency
124  unsigned int digits = 0;
125  while (numberOfChildren != 0) {
126  ++digits;
127  numberOfChildren /= 10;
128  }
129  // protect against zero numberOfChildren
130  if (digits == 0) {
131  digits = 3;
132  }
133 
134  char buffer[digits + 2];
135  snprintf(buffer, digits + 2, "_F%0*d", digits, childIndex);
136 
137  std::unique_lock<std::mutex> lck(initial_fp_lock_);
138  initial_fp_.child_ = std::string(buffer);
139 }
140 
141 const std::string DQMFileSaverBase::filename(const FileParameters& fp, bool useLumi) {
142  char buf[256];
143  if (useLumi) {
144  snprintf(buf, 256, "%s_V%04d_%s_R%09ld_L%09ld%s", fp.producer_.c_str(),
145  fp.version_, fp.tag_.c_str(), fp.run_, fp.lumi_,
146  fp.child_.c_str());
147  } else {
148  snprintf(buf, 256, "%s_V%04d_%s_R%09ld%s", fp.producer_.c_str(), fp.version_,
149  fp.tag_.c_str(), fp.run_, fp.child_.c_str());
150  }
151  buf[255] = 0;
152 
153  namespace fs = boost::filesystem;
154  fs::path path(fp.path_);
155  fs::path file(buf);
156 
157  return (path / file).string();
158 }
159 
161 {
162  // Report the file to job report service.
164  if (jr.isAvailable())
165  {
166  std::map<std::string, std::string> info;
167  info["Source"] = "DQMStore";
168  info["FileClass"] = "DQM";
169  jr->reportAnalysisFile(filename, info);
170  }
171 
172 }
173 
175  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay()
176  << " " << msg << fileName;
178 }
179 
181  desc.addUntracked<std::string>("tag", "UNKNOWN")
182  ->setComment("File tag, DQM_V000_<TAG>*, usually a subsytem name.");
183 
184  desc.addUntracked<std::string>("producer", "DQM")
185  ->setComment("Base prefix for files, <BASE>_V000_**, either 'DQM' or 'Playback'.");
186 
187  desc.addUntracked<std::string>("referenceHandling", "all")
188  ->setComment("saveReference_, passed to the DQMStore");
189 
190  desc.addUntracked<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK)
191  ->setComment("saveReference_, passed to the DQMStore");
192 
193  desc.addUntracked<std::string>("path", "./")->setComment(
194  "Output path prefix.");
195 }
DQMFileSaverBase(const edm::ParameterSet &ps)
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
void saveJobReport(const std::string &filename) const
RunID const & id() const
Definition: RunBase.h:39
virtual void saveRun(const FileParameters &fp) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void globalEndRun(const edm::Run &, const edm::EventSetup &) const override final
RunNumber_t run() const
Definition: RunID.h:39
void FlushMessageLog()
virtual void postForkReacquireResources(unsigned int childIndex, unsigned int numberOfChildren) override
static const std::string filename(const FileParameters &fp, bool useLumi=false)
virtual void saveLumi(const FileParameters &fp) const
virtual void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const override final
virtual void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const override final
bool isAvailable() const
Definition: Service.h:46
RunNumber_t run() const
void logFileAction(const std::string &msg, const std::string &fileName) const
virtual std::shared_ptr< NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const override final
DQMStore::SaveReferenceTag saveReference_
LuminosityBlockNumber_t luminosityBlock() const
FileParameters initial_fp_
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:563
static const int STATUS_OK
static void fillDescription(edm::ParameterSetDescription &d)
virtual std::shared_ptr< NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const override final
virtual void initRun(void) const
Definition: Run.h:42