CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IgProfModule.cc
Go to the documentation of this file.
9 
11 #include <string>
12 #include <dlfcn.h>
13 #include <cstdio>
14 #include <cstring>
15 
17 {
18 public:
20  : dump_(0),
21  prescale_(0),
22  nrecord_(0),
23  nevent_(0),
24  nrun_(0),
25  nlumi_(0),
26  nfile_(0)
27  {
28  // Removing the __extension__ gives a warning which
29  // is acknowledged as a language problem in the C++ Standard Core
30  // Language Defect Report
31  //
32  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#195
33  //
34  // since the suggested decision seems to be that the syntax should
35  // actually be "Conditionally-Supported Behavior" in some
36  // future C++ standard I simply silence the warning.
37  if (void *sym = dlsym(0, "igprof_dump_now"))
38  dump_ = __extension__ (void(*)(const char *)) sym;
39  else
40  edm::LogWarning("IgProfModule")
41  << "IgProfModule requested but application is not"
42  << " currently being profiled with igprof\n";
43 
44  prescale_ = ps.getUntrackedParameter<int>("reportEventInterval", prescale_);
45  atBeginJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginJob", atBeginJob_);
46  atEndJob_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndJob", atEndJob_);
47  atBeginLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtBeginLumi", atBeginLumi_);
48  atEndLumi_ = ps.getUntrackedParameter<std::string>("reportToFileAtEndLumi", atEndLumi_);
49  atInputFile_ = ps.getUntrackedParameter<std::string>("reportToFileAtInputFile", atInputFile_);
50  atEvent_ = ps.getUntrackedParameter<std::string>("reportToFileAtEvent", atEvent_);
51  }
52 
53  virtual void beginJob() override
54  { makeDump(atBeginJob_); }
55 
56  virtual void endJob(void) override
57  { makeDump(atEndJob_); }
58 
59  virtual void analyze(const edm::Event &e, const edm::EventSetup &) override
60  {
61  nevent_ = e.id().event();
62  if (prescale_ > 0 && (++nrecord_ % prescale_) == 1)
64  }
65 
66  virtual void beginRun(const edm::Run &r, const edm::EventSetup &) override
67  { nrun_ = r.run(); makeDump(atBeginRun_); }
68 
69  virtual void endRun(const edm::Run &, const edm::EventSetup &) override
70  { makeDump(atEndRun_); }
71 
72  virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
74 
75  virtual void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
76  { makeDump(atEndLumi_); }
77 
78  virtual void respondToOpenInputFile(const edm::FileBlock &) override
80 
81 private:
83  {
84  if (! dump_ || format.empty())
85  return;
86 
87  std::string final(format);
88  final = replace(final, "%I", nrecord_);
89  final = replace(final, "%E", nevent_);
90  final = replace(final, "%R", nrun_);
91  final = replace(final, "%L", nlumi_);
92  final = replace(final, "%F", nfile_);
93  dump_(final.c_str());
94  }
95 
96  static std::string replace(const std::string &s, const char *pat, int val)
97  {
98  size_t pos = 0;
99  size_t patlen = strlen(pat);
100  std::string result = s;
101  while ((pos = result.find(pat, pos)) != std::string::npos)
102  {
103  char buf[64];
104  int n = sprintf(buf, "%d", val);
105  result.replace(pos, patlen, buf);
106  pos = pos - patlen + n;
107  }
108 
109  return result;
110  }
111 
112  void (*dump_)(const char *);
122  int nrecord_;
123  int nevent_;
124  int nrun_;
125  int nlumi_;
126  int nfile_;
127 };
128 
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
RunNumber_t run() const
Definition: RunBase.h:42
std::string atBeginRun_
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: IgProfModule.cc:69
std::string atInputFile_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &e, const edm::EventSetup &) override
Definition: IgProfModule.cc:59
string format
Some error handling for the usage.
std::string atEndLumi_
void(* dump_)(const char *)
static std::string replace(const std::string &s, const char *pat, int val)
Definition: IgProfModule.cc:96
void makeDump(const std::string &format)
Definition: IgProfModule.cc:82
std::string atEndRun_
LuminosityBlockNumber_t luminosityBlock() const
tuple result
Definition: query.py:137
std::string atEndJob_
virtual void endJob(void) override
Definition: IgProfModule.cc:56
virtual void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
Definition: IgProfModule.cc:75
virtual void beginRun(const edm::Run &r, const edm::EventSetup &) override
Definition: IgProfModule.cc:66
virtual void respondToOpenInputFile(const edm::FileBlock &) override
Definition: IgProfModule.cc:78
edm::EventID id() const
Definition: EventBase.h:56
std::string atEvent_
std::string atBeginJob_
std::string atBeginLumi_
IgProfModule(const edm::ParameterSet &ps)
Definition: IgProfModule.cc:19
virtual void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &) override
Definition: IgProfModule.cc:72
virtual void beginJob() override
Definition: IgProfModule.cc:53
Definition: Run.h:41