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 <filesystem>
24 #include <TString.h>
25 #include <TSystem.h>
26 
27 using namespace dqm;
28 
31 
32  fp.path_ = ps.getUntrackedParameter<std::string>("path");
33  fp.producer_ = ps.getUntrackedParameter<std::string>("producer");
34  fp.run_ = 0;
35  fp.tag_ = ps.getUntrackedParameter<std::string>("tag");
36  fp.lumi_ = 0;
37  fp.version_ = 1;
38  fp.child_ = "";
39 
40  std::unique_lock<std::mutex> lck(initial_fp_lock_);
41  initial_fp_ = fp;
42 
43  runNumber_ = ps.getUntrackedParameter<int>("runNumber", 111);
44 
45  // This makes sure a file saver runs in a very end
46  consumesMany<DQMToken, edm::InLumi>();
47  consumesMany<DQMToken, edm::InRun>();
48 }
49 
51 
52 std::shared_ptr<NoCache> DQMFileSaverBase::globalBeginRun(const edm::Run &r, const edm::EventSetup &) const {
53  this->initRun();
54 
55  return nullptr;
56 }
57 
59  const edm::EventSetup &) const {
60  return nullptr;
61 }
62 
64  // not supported
65 }
66 
68  int ilumi = iLS.id().luminosityBlock();
69  int irun = iLS.id().run();
70 
71  std::unique_lock<std::mutex> lck(initial_fp_lock_);
73  lck.unlock();
74 
75  fp.lumi_ = ilumi;
76  fp.run_ = runNumber_ == 111 ? irun : runNumber_;
77 
78  this->saveLumi(fp);
79 }
80 
81 void DQMFileSaverBase::globalEndRun(const edm::Run &iRun, const edm::EventSetup &) const {
82  std::unique_lock<std::mutex> lck(initial_fp_lock_);
84  lck.unlock();
85 
86  fp.run_ = runNumber_ == 111 ? iRun.id().run() : runNumber_;
87 
88  // empty
89  this->saveRun(fp);
90 }
91 
93  char buf[256];
94  if (useLumi) {
95  snprintf(buf,
96  256,
97  "%s_V%04d_%s_R%09ld_L%09ld%s",
98  fp.producer_.c_str(),
99  fp.version_,
100  fp.tag_.c_str(),
101  fp.run_,
102  fp.lumi_,
103  fp.child_.c_str());
104  } else {
105  snprintf(buf,
106  256,
107  "%s_V%04d_%s_R%09ld%s",
108  fp.producer_.c_str(),
109  fp.version_,
110  fp.tag_.c_str(),
111  fp.run_,
112  fp.child_.c_str());
113  }
114  buf[255] = 0;
115 
116  namespace fs = std::filesystem;
117  fs::path path(fp.path_);
118  fs::path file(buf);
119 
120  return (path / file).string();
121 }
122 
124  // Report the file to job report service.
126  if (jr.isAvailable()) {
127  std::map<std::string, std::string> info;
128  info["Source"] = "DQMStore";
129  info["FileClass"] = "DQM";
131  }
132 }
133 
135  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << " " << msg << fileName;
137 }
138 
140  desc.addUntracked<std::string>("tag", "UNKNOWN")->setComment("File tag, DQM_V000_<TAG>*, usually a subsytem name.");
141 
142  desc.addUntracked<std::string>("producer", "DQM")
143  ->setComment("Base prefix for files, <BASE>_V000_**, either 'DQM' or 'Playback'.");
144 
145  desc.addUntracked<std::string>("referenceHandling", "all")->setComment("saveReference_, passed to the DQMStore");
146 
147  desc.addUntracked<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK)
148  ->setComment("saveReference_, passed to the DQMStore");
149 
150  desc.addUntracked<std::string>("path", "./")->setComment("Output path prefix.");
151 
152  desc.addUntracked<int>("runNumber", 111)
153  ->setComment("Run number passed in the configuration. Will appear in output file names.");
154 }
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()
~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)
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:486
static const int STATUS_OK
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