Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:51

0001 #include "DQMServices/Core/interface/DQMStore.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/Run.h"
0004 #include "FWCore/Framework/interface/LuminosityBlock.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Version/interface/GetReleaseVersion.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/MessageLogger/interface/JobReport.h"
0010 #include "FWCore/Utilities/interface/TimeOfDay.h"
0011 #include "DataFormats/Histograms/interface/DQMToken.h"
0012 
0013 #include "DQMFileSaverBase.h"
0014 
0015 #include <sys/stat.h>
0016 #include <sys/types.h>
0017 #include <unistd.h>
0018 #include <iostream>
0019 #include <vector>
0020 #include <string>
0021 #include <fstream>
0022 #include <utility>
0023 #include <filesystem>
0024 #include <TString.h>
0025 #include <TSystem.h>
0026 
0027 using namespace dqm;
0028 
0029 DQMFileSaverBase::DQMFileSaverBase(const edm::ParameterSet &ps) {
0030   FileParameters fp;
0031 
0032   fp.path_ = ps.getUntrackedParameter<std::string>("path");
0033   fp.producer_ = ps.getUntrackedParameter<std::string>("producer");
0034   fp.run_ = 0;
0035   fp.tag_ = ps.getUntrackedParameter<std::string>("tag");
0036   fp.lumi_ = 0;
0037   fp.version_ = 1;
0038   fp.child_ = "";
0039 
0040   std::unique_lock<std::mutex> lck(initial_fp_lock_);
0041   initial_fp_ = fp;
0042 
0043   runNumber_ = ps.getUntrackedParameter<int>("runNumber", 111);
0044 
0045   // This makes sure a file saver runs in a very end
0046   consumesMany<DQMToken, edm::InLumi>();
0047   consumesMany<DQMToken, edm::InRun>();
0048 }
0049 
0050 DQMFileSaverBase::~DQMFileSaverBase() = default;
0051 
0052 std::shared_ptr<NoCache> DQMFileSaverBase::globalBeginRun(const edm::Run &r, const edm::EventSetup &) const {
0053   this->initRun();
0054 
0055   return nullptr;
0056 }
0057 
0058 std::shared_ptr<NoCache> DQMFileSaverBase::globalBeginLuminosityBlock(const edm::LuminosityBlock &l,
0059                                                                       const edm::EventSetup &) const {
0060   return nullptr;
0061 }
0062 
0063 void DQMFileSaverBase::analyze(edm::StreamID, const edm::Event &e, const edm::EventSetup &) const {
0064   // not supported
0065 }
0066 
0067 void DQMFileSaverBase::globalEndLuminosityBlock(const edm::LuminosityBlock &iLS, const edm::EventSetup &) const {
0068   int ilumi = iLS.id().luminosityBlock();
0069   int irun = iLS.id().run();
0070 
0071   std::unique_lock<std::mutex> lck(initial_fp_lock_);
0072   FileParameters fp = initial_fp_;
0073   lck.unlock();
0074 
0075   fp.lumi_ = ilumi;
0076   fp.run_ = runNumber_ == 111 ? irun : runNumber_;
0077 
0078   this->saveLumi(fp);
0079 }
0080 
0081 void DQMFileSaverBase::globalEndRun(const edm::Run &iRun, const edm::EventSetup &) const {
0082   std::unique_lock<std::mutex> lck(initial_fp_lock_);
0083   FileParameters fp = initial_fp_;
0084   lck.unlock();
0085 
0086   fp.run_ = runNumber_ == 111 ? iRun.id().run() : runNumber_;
0087 
0088   // empty
0089   this->saveRun(fp);
0090 }
0091 
0092 const std::string DQMFileSaverBase::filename(const FileParameters &fp, bool useLumi) {
0093   char buf[256];
0094   if (useLumi) {
0095     snprintf(buf,
0096              256,
0097              "%s_V%04d_%s_R%09ld_L%09ld%s",
0098              fp.producer_.c_str(),
0099              fp.version_,
0100              fp.tag_.c_str(),
0101              fp.run_,
0102              fp.lumi_,
0103              fp.child_.c_str());
0104   } else {
0105     snprintf(buf,
0106              256,
0107              "%s_V%04d_%s_R%09ld%s",
0108              fp.producer_.c_str(),
0109              fp.version_,
0110              fp.tag_.c_str(),
0111              fp.run_,
0112              fp.child_.c_str());
0113   }
0114   buf[255] = 0;
0115 
0116   namespace fs = std::filesystem;
0117   fs::path path(fp.path_);
0118   fs::path file(buf);
0119 
0120   return (path / file).string();
0121 }
0122 
0123 void DQMFileSaverBase::saveJobReport(const std::string &filename) const {
0124   // Report the file to job report service.
0125   edm::Service<edm::JobReport> jr;
0126   if (jr.isAvailable()) {
0127     std::map<std::string, std::string> info;
0128     info["Source"] = "DQMStore";
0129     info["FileClass"] = "DQM";
0130     jr->reportAnalysisFile(filename, info);
0131   }
0132 }
0133 
0134 void DQMFileSaverBase::logFileAction(const std::string &msg, const std::string &fileName) const {
0135   edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << "  " << msg << fileName;
0136   edm::FlushMessageLog();
0137 }
0138 
0139 void DQMFileSaverBase::fillDescription(edm::ParameterSetDescription &desc) {
0140   desc.addUntracked<std::string>("tag", "UNKNOWN")->setComment("File tag, DQM_V000_<TAG>*, usually a subsytem name.");
0141 
0142   desc.addUntracked<std::string>("producer", "DQM")
0143       ->setComment("Base prefix for files, <BASE>_V000_**, either 'DQM' or 'Playback'.");
0144 
0145   desc.addUntracked<std::string>("referenceHandling", "all")->setComment("saveReference_, passed to the DQMStore");
0146 
0147   desc.addUntracked<int>("referenceRequireStatus", dqm::qstatus::STATUS_OK)
0148       ->setComment("saveReference_, passed to the DQMStore");
0149 
0150   desc.addUntracked<std::string>("path", "./")->setComment("Output path prefix.");
0151 
0152   desc.addUntracked<int>("runNumber", 111)
0153       ->setComment("Run number passed in the configuration. Will appear in output file names.");
0154 }