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 
121 const std::string DQMFileSaverBase::filename(const FileParameters& fp, bool useLumi) {
122  char buf[256];
123  if (useLumi) {
124  snprintf(buf, 256, "%s_V%04d_%s_R%09ld_L%09ld%s", fp.producer_.c_str(),
125  fp.version_, fp.tag_.c_str(), fp.run_, fp.lumi_,
126  fp.child_.c_str());
127  } else {
128  snprintf(buf, 256, "%s_V%04d_%s_R%09ld%s", fp.producer_.c_str(), fp.version_,
129  fp.tag_.c_str(), fp.run_, fp.child_.c_str());
130  }
131  buf[255] = 0;
132 
133  namespace fs = boost::filesystem;
134  fs::path path(fp.path_);
135  fs::path file(buf);
136 
137  return (path / file).string();
138 }
139 
141 {
142  // Report the file to job report service.
144  if (jr.isAvailable())
145  {
146  std::map<std::string, std::string> info;
147  info["Source"] = "DQMStore";
148  info["FileClass"] = "DQM";
149  jr->reportAnalysisFile(filename, info);
150  }
151 
152 }
153 
155  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay()
156  << " " << msg << fileName;
158 }
159 
161  desc.addUntracked<std::string>("tag", "UNKNOWN")
162  ->setComment("File tag, DQM_V000_<TAG>*, usually a subsytem name.");
163 
164  desc.addUntracked<std::string>("producer", "DQM")
165  ->setComment("Base prefix for files, <BASE>_V000_**, either 'DQM' or 'Playback'.");
166 
167  desc.addUntracked<std::string>("referenceHandling", "all")
168  ->setComment("saveReference_, passed to the DQMStore");
169 
170  desc.addUntracked<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK)
171  ->setComment("saveReference_, passed to the DQMStore");
172 
173  desc.addUntracked<std::string>("path", "./")->setComment(
174  "Output path prefix.");
175 }
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()
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:507
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