CMS 3D CMS Logo

DQMFileSaverBase.cc
Go to the documentation of this file.
14 
15 #include "DQMFileSaverBase.h"
16 
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20 #include <iostream>
21 #include <vector>
22 #include <string>
23 #include <fstream>
24 #include <utility>
25 #include <filesystem>
26 #include <TString.h>
27 #include <TSystem.h>
28 
29 using namespace dqm;
30 
33 
34  fp.path_ = ps.getUntrackedParameter<std::string>("path");
35  fp.producer_ = ps.getUntrackedParameter<std::string>("producer");
36  fp.run_ = 0;
37  fp.tag_ = ps.getUntrackedParameter<std::string>("tag");
38  fp.lumi_ = 0;
39  fp.version_ = 1;
40  fp.child_ = "";
41 
42  std::unique_lock<std::mutex> lck(initial_fp_lock_);
43  initial_fp_ = fp;
44 
45  runNumber_ = ps.getUntrackedParameter<int>("runNumber", 111);
46 
47  // This makes sure a file saver runs in a very end
51  this->lumigetter_(bd);
52  this->rungetter_(bd);
53  });
54 }
55 
57 
58 std::shared_ptr<NoCache> DQMFileSaverBase::globalBeginRun(const edm::Run &r, const edm::EventSetup &) const {
59  this->initRun();
60 
61  return nullptr;
62 }
63 
65  const edm::EventSetup &) const {
66  return nullptr;
67 }
68 
70  // not supported
71 }
72 
74  int ilumi = iLS.id().luminosityBlock();
75  int irun = iLS.id().run();
76 
77  std::unique_lock<std::mutex> lck(initial_fp_lock_);
79  lck.unlock();
80 
81  fp.lumi_ = ilumi;
82  fp.run_ = runNumber_ == 111 ? irun : runNumber_;
83 
84  this->saveLumi(fp);
85 }
86 
87 void DQMFileSaverBase::globalEndRun(const edm::Run &iRun, const edm::EventSetup &) const {
88  std::unique_lock<std::mutex> lck(initial_fp_lock_);
90  lck.unlock();
91 
92  fp.run_ = runNumber_ == 111 ? iRun.id().run() : runNumber_;
93 
94  // empty
95  this->saveRun(fp);
96 }
97 
99  char buf[256];
100  if (useLumi) {
101  snprintf(buf,
102  256,
103  "%s_V%04d_%s_R%09ld_L%09ld%s",
104  fp.producer_.c_str(),
105  fp.version_,
106  fp.tag_.c_str(),
107  fp.run_,
108  fp.lumi_,
109  fp.child_.c_str());
110  } else {
111  snprintf(buf,
112  256,
113  "%s_V%04d_%s_R%09ld%s",
114  fp.producer_.c_str(),
115  fp.version_,
116  fp.tag_.c_str(),
117  fp.run_,
118  fp.child_.c_str());
119  }
120  buf[255] = 0;
121 
122  namespace fs = std::filesystem;
123  fs::path path(fp.path_);
124  fs::path file(buf);
125 
126  return (path / file).string();
127 }
128 
130  // Report the file to job report service.
132  if (jr.isAvailable()) {
133  std::map<std::string, std::string> info;
134  info["Source"] = "DQMStore";
135  info["FileClass"] = "DQM";
137  }
138 }
139 
141  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << " " << msg << fileName;
143 }
144 
146  desc.addUntracked<std::string>("tag", "UNKNOWN")->setComment("File tag, DQM_V000_<TAG>*, usually a subsytem name.");
147 
148  desc.addUntracked<std::string>("producer", "DQM")
149  ->setComment("Base prefix for files, <BASE>_V000_**, either 'DQM' or 'Playback'.");
150 
151  desc.addUntracked<std::string>("referenceHandling", "all")->setComment("saveReference_, passed to the DQMStore");
152 
153  desc.addUntracked<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK)
154  ->setComment("saveReference_, passed to the DQMStore");
155 
156  desc.addUntracked<std::string>("path", "./")->setComment("Output path prefix.");
157 
158  desc.addUntracked<int>("runNumber", 111)
159  ->setComment("Run number passed in the configuration. Will appear in output file names.");
160 }
DQMFileSaverBase(const edm::ParameterSet &ps)
LuminosityBlockNumber_t luminosityBlock() const
void logFileAction(const std::string &msg, const std::string &fileName) const
static const TGPicture * info(bool iBackgroundIsBlack)
void FlushMessageLog()
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
~DQMFileSaverBase() override
virtual void saveLumi(const FileParameters &fp) const
void analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const final
static const std::string filename(const FileParameters &fp, bool useLumi=false)
edm::GetterOfProducts< DQMToken > rungetter_
void saveJobReport(const std::string &filename) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void initRun() const
virtual void saveRun(const FileParameters &fp) const
RunNumber_t run() const
RunID const & id() const
Definition: RunBase.h:39
std::shared_ptr< NoCache > globalBeginRun(const edm::Run &, const edm::EventSetup &) const final
std::shared_ptr< NoCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const final
LuminosityBlockID id() const
void globalEndRun(const edm::Run &, const edm::EventSetup &) const final
tuple msg
Definition: mps_check.py:286
FileParameters initial_fp_
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:509
static const int STATUS_OK
edm::GetterOfProducts< DQMToken > lumigetter_
static void fillDescription(edm::ParameterSetDescription &d)
Log< level::System, true > LogAbsolute
bool isAvailable() const
Definition: Service.h:40
Definition: DQMStore.h:18
void globalEndLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) const final
RunNumber_t run() const
Definition: RunID.h:26
Definition: Run.h:45