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 ()
 
- Public Member Functions inherited from dqm::DQMFileSaverBase
 DQMFileSaverBase (const edm::ParameterSet &ps)
 
 ~DQMFileSaverBase ()
 
- Public Member Functions inherited from edm::global::EDAnalyzer< edm::RunCache< NoCache >, edm::LuminosityBlockCache< NoCache > >
 EDAnalyzer ()=default
 
- Public Member Functions inherited from edm::global::EDAnalyzerBase
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDAnalyzerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
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 & itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, 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
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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
 
virtual void saveLumi (const FileParameters &fp) const override
 
virtual void saveRun (const FileParameters &fp) const override
 
- Protected Member Functions inherited from dqm::DQMFileSaverBase
virtual void analyze (edm::StreamID, const edm::Event &e, const edm::EventSetup &) const override final
 
virtual std::shared_ptr< NoCacheglobalBeginLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) const override final
 
virtual std::shared_ptr< NoCacheglobalBeginRun (const edm::Run &, const edm::EventSetup &) const override final
 
virtual void globalEndLuminosityBlock (const edm::LuminosityBlock &, const edm::EventSetup &) const override final
 
virtual void globalEndRun (const edm::Run &, const edm::EventSetup &) const override final
 
virtual void initRun (void) const
 
void logFileAction (const std::string &msg, const std::string &fileName) const
 
virtual void postForkReacquireResources (unsigned int childIndex, unsigned int numberOfChildren) override
 
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)
 
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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
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)
 

Protected Attributes

int backupLumiCount_
 
std::list< SnapshotFilessnapshots_
 
std::mutex snapshots_lock_
 
- Protected Attributes inherited from dqm::DQMFileSaverBase
FileParameters initial_fp_
 
std::mutex initial_fp_lock_
 

Additional Inherited Members

- 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 ( const edm::ParameterSet ps)

Definition at line 31 of file DQMFileSaverOnline.cc.

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

32  : DQMFileSaverBase(ps) {
33 
34  backupLumiCount_ = ps.getUntrackedParameter<int>("backupLumiCount", 1);
35 }
DQMFileSaverBase(const edm::ParameterSet &ps)
T getUntrackedParameter(std::string const &, T const &) const
DQMFileSaverOnline::~DQMFileSaverOnline ( )

Definition at line 37 of file DQMFileSaverOnline.cc.

37 {}

Member Function Documentation

void DQMFileSaverOnline::appendSnapshot ( SnapshotFiles  new_snap) const
protected

Definition at line 115 of file DQMFileSaverOnline.cc.

References checkError(), dqm::DQMFileSaverOnline::SnapshotFiles::data, CommonMethods::lock(), dqm::DQMFileSaverBase::logFileAction(), dqm::DQMFileSaverOnline::SnapshotFiles::meta, snapshots_, snapshots_lock_, and x().

Referenced by makeSnapshot().

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

Definition at line 135 of file DQMFileSaverOnline.cc.

References dqm::DQMFileSaverBase::logFileAction(), mps_alisetup::msg, 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
void DQMFileSaverOnline::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 167 of file DQMFileSaverOnline.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::addUntracked(), DEFINE_FWK_MODULE, dqm::DQMFileSaverBase::fillDescription(), and edm::ParameterSetDescription::setComment().

168  {
169 
171  desc.setComment("Saves histograms from DQM store, online workflow.");
172 
173  desc.addUntracked<int>("backupLumiCount", 10)->setComment(
174  "How often the backup file will be generated, in lumisections (-1 disables).");
175 
177 
178  descriptions.add("saver", desc);
179 }
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescription(edm::ParameterSetDescription &d)
const std::string DQMFileSaverOnline::fillOrigin ( const std::string  filename,
const std::string  final_filename 
)
static

Definition at line 143 of file DQMFileSaverOnline.cc.

References cond::hash, mps_fire::i, createfilelist::int, and MillePedeFileConverter_cfg::out.

Referenced by makeSnapshot().

144  {
145 
146  // format.origin (one line):
147  // md5:d566a34b27f48d507150a332b189398b 294835 final_filename.root
148 
149  unsigned char md5[MD5_DIGEST_LENGTH];
150 
151  boost::iostreams::mapped_file_source fp(filename);
152 
153  MD5((unsigned char *)fp.data(), fp.size(), md5);
154 
155  std::ostringstream hash;
156  for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
157  hash << std::hex << std::setfill('0') << std::setw(2) << (int)(md5[i]);
158  }
159 
160  std::ostringstream out;
161  out << "md5:" << hash.str() << " " << fp.size() << " " << final_filename;
162  return out.str();
163 }
static const std::string filename(const FileParameters &fp, bool useLumi=false)
void DQMFileSaverOnline::makeSnapshot ( const FileParameters fp,
bool  final 
) const
protected

Definition at line 53 of file DQMFileSaverOnline.cc.

References appendSnapshot(), checkError(), dqm::DQMFileSaverBase::filename(), PatBasicFWLiteAnalyzer::files, fillOrigin(), dqm::DQMFileSaverBase::logFileAction(), dqm::DQMFileSaverBase::FileParameters::lumi_, sysUtil::pid, tablePrinter::prefix, dqm::DQMFileSaverBase::FileParameters::run_, dqm::DQMFileSaverBase::saveJobReport(), dqm::DQMFileSaverBase::FileParameters::saveReference_, dqm::DQMFileSaverBase::FileParameters::saveReferenceQMin_, AlCaHLTBitMon_QueryRunRegistry::string, and createPayload::suffix.

Referenced by saveLumi(), and saveRun().

53  {
54  int pid = getpid();
55  char hostname[64];
56  gethostname(hostname, 64);
57  hostname[63] = 0;
58 
59  char suffix[128];
60  if (!final) {
61  snprintf(suffix, 127, ".ls%08ld_host%s_pid%08d", fp.lumi_, hostname, pid);
62  } else {
63  suffix[0] = 0;
64  }
65 
66  std::string prefix = filename(fp, false);
67 
68  std::string root_fp = prefix + ".root" + suffix;
69  std::string meta_fp = prefix + ".root.origin" + suffix;
70 
71  std::string tmp_root_fp = root_fp + ".tmp";
72  std::string tmp_meta_fp = meta_fp + ".tmp";
73 
74  // run_ and lumi_ are ignored if dqmstore is not in multithread mode
76 
77  logFileAction("Writing DQM Root file: ", root_fp);
78  //logFileAction("Writing DQM Origin file: ", meta_fp);
79 
80  char rewrite[128];
81  snprintf(rewrite, 128, "\\1Run %ld/\\2/Run summary", fp.run_);
82 
83  store->save(tmp_root_fp, /* filename */
84  "", /* path */
85  "^(Reference/)?([^/]+)", /* pattern */
86  rewrite, /* rewrite */
87  store->mtEnabled() ? fp.run_ : 0, /* run */
88  0, /* lumi */
89  fp.saveReference_, /* ref */
90  fp.saveReferenceQMin_, /* ref minStatus */
91  "RECREATE", /* fileupdate */
92  false /* resetMEs */
93  );
94 
95  // write metadata
96  // format.origin: md5:d566a34b27f48d507150a332b189398b 294835 /home/dqmprolocal/output/DQM_V0001_FED_R000194224.root
97  std::ofstream meta_fd(tmp_meta_fp);
98  meta_fd << fillOrigin(tmp_root_fp, root_fp);
99  meta_fd.close();
100 
101  checkError("Rename failed: ", root_fp, ::rename(tmp_root_fp.c_str(), root_fp.c_str()));
102  checkError("Rename failed: ", meta_fp, ::rename(tmp_meta_fp.c_str(), meta_fp.c_str()));
103 
104  SnapshotFiles files = { root_fp, meta_fp };
105  if (final) {
106  // final will never be cleared
107  appendSnapshot(SnapshotFiles{});
108 
109  saveJobReport(root_fp);
110  } else {
111  appendSnapshot(SnapshotFiles{ root_fp, meta_fp });
112  }
113 }
static const std::string fillOrigin(const std::string filename, const std::string final_filename)
void saveJobReport(const std::string &filename) const
Definition: rename.py:1
static const std::string filename(const FileParameters &fp, bool useLumi=false)
void appendSnapshot(SnapshotFiles new_snap) const
void checkError(const char *msg, const std::string file, int status) const
void logFileAction(const std::string &msg, const std::string &fileName) const
void DQMFileSaverOnline::saveLumi ( const FileParameters fp) const
overrideprotectedvirtual

Reimplemented from dqm::DQMFileSaverBase.

Definition at line 39 of file DQMFileSaverOnline.cc.

References backupLumiCount_, dqm::DQMFileSaverBase::FileParameters::lumi_, and makeSnapshot().

39  {
40  if (backupLumiCount_ > 0) {
41  if (fp.lumi_ % backupLumiCount_ == 0) {
42 
43  // actual saving is done here
44  makeSnapshot(fp, false);
45  }
46  }
47 }
void makeSnapshot(const FileParameters &fp, bool final) const
void DQMFileSaverOnline::saveRun ( const FileParameters fp) const
overrideprotectedvirtual

Reimplemented from dqm::DQMFileSaverBase.

Definition at line 49 of file DQMFileSaverOnline.cc.

References makeSnapshot().

49  {
50  makeSnapshot(fp, true);
51 }
void makeSnapshot(const FileParameters &fp, bool final) const

Member Data Documentation

int dqm::DQMFileSaverOnline::backupLumiCount_
protected

Definition at line 28 of file DQMFileSaverOnline.h.

Referenced by DQMFileSaverOnline(), and saveLumi().

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

Definition at line 40 of file DQMFileSaverOnline.h.

Referenced by appendSnapshot().

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

Definition at line 39 of file DQMFileSaverOnline.h.

Referenced by appendSnapshot().