CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
dqm::DQMFileSaverOnline Class Reference

#include <DQMFileSaverOnline.h>

Inheritance diagram for dqm::DQMFileSaverOnline:
dqm::DQMFileSaverBase edm::global::EDAnalyzer< edm::RunCache< NoCache >, edm::LuminosityBlockCache< NoCache > > edm::global::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  SnapshotFiles
 

Public Member Functions

 DQMFileSaverOnline (const edm::ParameterSet &ps)
 
 ~DQMFileSaverOnline () override
 
- Public Member Functions inherited from dqm::DQMFileSaverBase
 DQMFileSaverBase (const edm::ParameterSet &ps)
 
 ~DQMFileSaverBase () override
 
- Public Member Functions inherited from edm::global::EDAnalyzer< edm::RunCache< NoCache >, edm::LuminosityBlockCache< NoCache > >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static const std::string fillOrigin (const std::string &filename, const std::string &final_filename)
 
- Static Public Member Functions inherited from dqm::DQMFileSaverBase
static void fillDescription (edm::ParameterSetDescription &d)
 
- Static Public Member Functions inherited from edm::global::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Protected Member Functions

void appendSnapshot (SnapshotFiles new_snap) const
 
void checkError (const char *msg, const std::string &file, int status) const
 
void makeSnapshot (const FileParameters &fp, bool final) const
 
void saveLumi (const FileParameters &fp) const override
 
void saveRun (const FileParameters &fp) const override
 
- Protected Member Functions inherited from dqm::DQMFileSaverBase
void analyze (edm::StreamID, const edm::Event &e, const edm::EventSetup &) const final
 
std::shared_ptr< NoCacheglobalBeginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) const final
 
std::shared_ptr< NoCacheglobalBeginRun (const edm::Run &, const edm::EventSetup &) const final
 
void globalEndLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) const final
 
void globalEndRun (const edm::Run &, const edm::EventSetup &) const final
 
virtual void initRun () const
 
void logFileAction (const std::string &msg, const std::string &fileName) const
 
void saveJobReport (const std::string &filename) const
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Protected Attributes

int backupLumiCount_
 
bool keepBackupLumi_
 
std::list< SnapshotFilessnapshots_
 
std::mutex snapshots_lock_
 
- Protected Attributes inherited from dqm::DQMFileSaverBase
FileParameters initial_fp_
 
std::mutex initial_fp_lock_
 
edm::GetterOfProducts< DQMTokenlumigetter_
 
edm::GetterOfProducts< DQMTokenrungetter_
 
int runNumber_
 

Additional Inherited Members

- Public Types inherited from dqm::DQMFileSaverBase
typedef dqm::legacy::DQMStore DQMStore
 
typedef dqm::legacy::MonitorElement MonitorElement
 
- Public Types inherited from edm::global::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Protected Member Functions inherited from dqm::DQMFileSaverBase
static const std::string filename (const FileParameters &fp, bool useLumi=false)
 

Detailed Description

Definition at line 15 of file DQMFileSaverOnline.h.

Constructor & Destructor Documentation

◆ DQMFileSaverOnline()

DQMFileSaverOnline::DQMFileSaverOnline ( const edm::ParameterSet ps)

Definition at line 30 of file DQMFileSaverOnline.cc.

References backupLumiCount_, edm::ParameterSet::getUntrackedParameter(), and keepBackupLumi_.

30  : DQMFileSaverBase(ps) {
31  backupLumiCount_ = ps.getUntrackedParameter<int>("backupLumiCount", 1);
32  keepBackupLumi_ = ps.getUntrackedParameter<bool>("keepBackupLumi", false);
33 }
DQMFileSaverBase(const edm::ParameterSet &ps)
T getUntrackedParameter(std::string const &, T const &) const

◆ ~DQMFileSaverOnline()

DQMFileSaverOnline::~DQMFileSaverOnline ( )
overridedefault

Member Function Documentation

◆ appendSnapshot()

void DQMFileSaverOnline::appendSnapshot ( SnapshotFiles  new_snap) const
protected

Definition at line 113 of file DQMFileSaverOnline.cc.

References checkError(), f, keepBackupLumi_, CommonMethods::lock(), dqm::DQMFileSaverBase::logFileAction(), snapshots_, snapshots_lock_, and x.

Referenced by makeSnapshot().

113  {
114  std::lock_guard<std::mutex> lock(snapshots_lock_);
115 
116  if (!keepBackupLumi_) {
117  while (!snapshots_.empty()) {
118  SnapshotFiles& x = snapshots_.front();
119 
120  // logFileAction("Deleting old snapshot (origin): ", x.meta);
121  checkError("Unlink failed: ", x.meta, ::unlink(x.meta.c_str()));
122 
123  logFileAction("Deleting old snapshot (root): ", x.data);
124  checkError("Unlink failed: ", x.data, ::unlink(x.data.c_str()));
125 
126  snapshots_.pop_front();
127  }
128  }
129 
130  if (!f.data.empty()) {
131  snapshots_.push_back(f);
132  }
133 }
void logFileAction(const std::string &msg, const std::string &fileName) const
void checkError(const char *msg, const std::string &file, int status) const
double f[11][100]
std::list< SnapshotFiles > snapshots_

◆ checkError()

void DQMFileSaverOnline::checkError ( const char *  msg,
const std::string &  file,
int  status 
) const
protected

Definition at line 135 of file DQMFileSaverOnline.cc.

References geometryDiff::file, dqm::DQMFileSaverBase::logFileAction(), mps_check::msg, mps_update::status, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by appendSnapshot(), and makeSnapshot().

135  {
136  if (status != 0) {
137  std::string actual_msg = msg;
138  actual_msg += std::strerror(status);
139  logFileAction(actual_msg, file);
140  }
141 }
void logFileAction(const std::string &msg, const std::string &fileName) const
tuple msg
Definition: mps_check.py:286

◆ fillDescriptions()

void DQMFileSaverOnline::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 170 of file DQMFileSaverOnline.cc.

References edm::ConfigurationDescriptions::addDefault(), submitPVResolutionJobs::desc, and dqm::DQMFileSaverBase::fillDescription().

170  {
172  desc.setComment("Saves histograms from DQM store, online workflow.");
173 
174  desc.addUntracked<int>("backupLumiCount", 10)
175  ->setComment(
176  "How often the backup file will be generated, in lumisections (-1 "
177  "disables).");
178 
179  desc.addUntracked<bool>("keepBackupLumi", false)
180  ->setComment(
181  "Usually the backup old backup is deleted once the new file is "
182  "available. Setting this to true ensures that no backup files are "
183  "ever deleted. Useful for ML applications, which use backups as a "
184  "'history' of what happened during the run.");
185 
187 
188  // Changed to use addDefault instead of add here because previously
189  // DQMFileSaverOnline and DQMFileSaverPB both used the module label
190  // "saver" which caused conflicting cfi filenames to be generated.
191  // add could be used if unique module labels were given.
192  descriptions.addDefault(desc);
193 }
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescription(edm::ParameterSetDescription &d)

◆ fillOrigin()

const std::string DQMFileSaverOnline::fillOrigin ( const std::string &  filename,
const std::string &  final_filename 
)
static

Definition at line 143 of file DQMFileSaverOnline.cc.

References EVP_MD_CTX_free, EVP_MD_CTX_new, dqm::DQMFileSaverBase::filename(), personalPlayback::fp, cond::hash, mps_fire::i, createfilelist::int, cms::openssl_init(), and MillePedeFileConverter_cfg::out.

Referenced by makeSnapshot().

143  {
144  // format.origin (one line):
145  // md5:d566a34b27f48d507150a332b189398b 294835 final_filename.root
146 
148  EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
149  const EVP_MD* md = EVP_get_digestbyname("MD5");
150  unsigned int md_len = 0;
151  unsigned char md5[EVP_MAX_MD_SIZE];
152 
153  boost::iostreams::mapped_file_source fp(filename);
154 
155  EVP_DigestInit_ex(mdctx, md, nullptr);
156  EVP_DigestUpdate(mdctx, (unsigned char*)fp.data(), fp.size());
157  EVP_DigestFinal_ex(mdctx, md5, &md_len);
158  EVP_MD_CTX_free(mdctx);
159 
160  std::ostringstream hash;
161  for (unsigned int i = 0; i < md_len; i++) {
162  hash << std::hex << std::setfill('0') << std::setw(2) << (int)md5[i];
163  }
164 
165  std::ostringstream out;
166  out << "md5:" << hash.str() << " " << fp.size() << " " << final_filename;
167  return out.str();
168 }
void openssl_init()
Definition: openssl_init.cc:5
static const std::string filename(const FileParameters &fp, bool useLumi=false)
#define EVP_MD_CTX_free
Definition: openssl_init.h:7
#define EVP_MD_CTX_new
Definition: openssl_init.h:6

◆ makeSnapshot()

void DQMFileSaverOnline::makeSnapshot ( const FileParameters fp,
bool  final 
) const
protected

Definition at line 48 of file DQMFileSaverOnline.cc.

References appendSnapshot(), checkError(), dqm::DQMFileSaverBase::filename(), submitPVResolutionJobs::files, fillOrigin(), personalPlayback::fp, h, dqm::DQMFileSaverBase::logFileAction(), hcallasereventfilter2012_cfi::prefix, dqm::DQMFileSaverBase::saveJobReport(), AlCaHLTBitMon_QueryRunRegistry::string, and makePlotsFromDump::suffix.

Referenced by saveLumi(), and saveRun().

48  {
49  int pid = getpid();
50  char hostname[64];
51  gethostname(hostname, 64);
52  hostname[63] = 0;
53 
54  char suffix[128];
55  if (!final) {
56  snprintf(suffix, 127, ".ls%08ld_host%s_pid%08d", fp.lumi_, hostname, pid);
57  } else {
58  suffix[0] = 0;
59  }
60 
61  std::string prefix = filename(fp, false);
62 
63  std::string root_fp = prefix + ".root" + suffix;
64  std::string meta_fp = prefix + ".root.origin" + suffix;
65 
66  std::string tmp_root_fp = root_fp + ".tmp";
67  std::string tmp_meta_fp = meta_fp + ".tmp";
68 
69  // run_ and lumi_ are ignored if dqmstore is not in multithread mode
71 
72  logFileAction("Writing DQM Root file: ", root_fp);
73  // logFileAction("Writing DQM Origin file: ", meta_fp);
74 
75  //char rewrite[128];
76  //snprintf(rewrite, 128, "\\1Run %ld/\\2/Run summary", fp.run_);
77 
78  //store->save(tmp_root_fp, /* filename */
79  // "", /* path */
80  // "^(Reference/)?([^/]+)", /* pattern */
81  // rewrite, /* rewrite */
82  // store->mtEnabled() ? fp.run_ : 0, /* run */
83  // 0, /* lumi */
84  // fp.saveReference_, /* ref */
85  // fp.saveReferenceQMin_, /* ref minStatus */
86  // "RECREATE"); /* fileupdate */
87  // TODO: some parameters prepared here are now unused, and the code should
88  // eventually be removed.
89  LegacyIOHelper h(&*store);
90  h.save(tmp_root_fp, "", fp.run_, /* saveall */ true, "RECREATE");
91 
92  // write metadata
93  // format.origin: md5:d566a34b27f48d507150a332b189398b 294835
94  // /home/dqmprolocal/output/DQM_V0001_FED_R000194224.root
95  std::ofstream meta_fd(tmp_meta_fp);
96  meta_fd << fillOrigin(tmp_root_fp, root_fp);
97  meta_fd.close();
98 
99  checkError("Rename failed: ", root_fp, ::rename(tmp_root_fp.c_str(), root_fp.c_str()));
100  checkError("Rename failed: ", meta_fp, ::rename(tmp_meta_fp.c_str(), meta_fp.c_str()));
101 
102  SnapshotFiles files = {root_fp, meta_fp};
103  if (final) {
104  // final will never be cleared
105  appendSnapshot(SnapshotFiles{});
106 
107  saveJobReport(root_fp);
108  } else {
109  appendSnapshot(SnapshotFiles{root_fp, meta_fp});
110  }
111 }
void logFileAction(const std::string &msg, const std::string &fileName) const
Definition: rename.py:1
static const std::string fillOrigin(const std::string &filename, const std::string &final_filename)
static const std::string filename(const FileParameters &fp, bool useLumi=false)
void saveJobReport(const std::string &filename) const
void appendSnapshot(SnapshotFiles new_snap) const
void checkError(const char *msg, const std::string &file, int status) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ saveLumi()

void DQMFileSaverOnline::saveLumi ( const FileParameters fp) const
overrideprotectedvirtual

Reimplemented from dqm::DQMFileSaverBase.

Definition at line 37 of file DQMFileSaverOnline.cc.

References backupLumiCount_, personalPlayback::fp, and makeSnapshot().

37  {
38  if (backupLumiCount_ > 0) {
39  if (fp.lumi_ % backupLumiCount_ == 0) {
40  // actual saving is done here
41  makeSnapshot(fp, false);
42  }
43  }
44 }
void makeSnapshot(const FileParameters &fp, bool final) const

◆ saveRun()

void DQMFileSaverOnline::saveRun ( const FileParameters fp) const
overrideprotectedvirtual

Reimplemented from dqm::DQMFileSaverBase.

Definition at line 46 of file DQMFileSaverOnline.cc.

References personalPlayback::fp, and makeSnapshot().

46 { makeSnapshot(fp, true); }
void makeSnapshot(const FileParameters &fp, bool final) const

Member Data Documentation

◆ backupLumiCount_

int dqm::DQMFileSaverOnline::backupLumiCount_
protected

Definition at line 27 of file DQMFileSaverOnline.h.

Referenced by DQMFileSaverOnline(), and saveLumi().

◆ keepBackupLumi_

bool dqm::DQMFileSaverOnline::keepBackupLumi_
protected

Definition at line 28 of file DQMFileSaverOnline.h.

Referenced by appendSnapshot(), and DQMFileSaverOnline().

◆ snapshots_

std::list<SnapshotFiles> dqm::DQMFileSaverOnline::snapshots_
mutableprotected

Definition at line 40 of file DQMFileSaverOnline.h.

Referenced by appendSnapshot().

◆ snapshots_lock_

std::mutex dqm::DQMFileSaverOnline::snapshots_lock_
mutableprotected

Definition at line 39 of file DQMFileSaverOnline.h.

Referenced by appendSnapshot().