CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastTimerServiceClient.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <string>
3 #include <cstring>
4 
5 // boost headers
6 #include <boost/regex.hpp>
7 
8 // Root headers
9 #include <TH1F.h>
10 
11 // CMSSW headers
25 
27 public:
28  explicit FastTimerServiceClient(edm::ParameterSet const &);
30 
31  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
32 
33 private:
35 
36  void dqmEndLuminosityBlock(DQMStore::IBooker & booker, DQMStore::IGetter & getter, edm::LuminosityBlock const &, edm::EventSetup const&) override;
37  void dqmEndJob(DQMStore::IBooker & booker, DQMStore::IGetter & getter) override;
38 
39  void fillSummaryPlots( DQMStore::IBooker & booker, DQMStore::IGetter & getter);
41  void fillPathSummaryPlots( DQMStore::IBooker & booker, DQMStore::IGetter & getter, double events, std::string const & path);
42 };
43 
44 
46  m_dqm_path( config.getUntrackedParameter<std::string>( "dqmPath" ) )
47 {
48 }
49 
51 {
52 }
53 
54 void
56 {
57  fillSummaryPlots(booker, getter);
58 }
59 
60 void
62 {
63  fillSummaryPlots(booker, getter);
64 }
65 
66 void
68 {
69  if (getter.get(m_dqm_path + "/event")) {
70  // the plots are directly in the configured folder
71  fillProcessSummaryPlots(booker, getter, m_dqm_path);
72  } else {
73  static const boost::regex running_n_processes(".*/Running [0-9]+ processes");
75  std::vector<std::string> subdirs = getter.getSubdirs();
76  for (auto const & subdir: subdirs) {
77  if (boost::regex_match(subdir, running_n_processes)) {
78  // the plots are in a per-number-of-processes folder
79  if (getter.get(subdir + "/event"))
80  fillProcessSummaryPlots(booker, getter, subdir);
81  }
82  }
83  }
84 }
85 
86 
87 
88 void
90  MonitorElement * me = getter.get(current_path + "/event");
91  if (me == 0)
92  // no FastTimerService DQM information
93  return;
94 
95  double events = me->getTH1F()->GetEntries();
96 
97  // look for per-process directories
98  static const boost::regex process_name(".*/process .*");
99  booker.setCurrentFolder(current_path);
100  std::vector<std::string> subdirs = getter.getSubdirs();
101  for (auto const & subdir: subdirs) {
102  if (boost::regex_match(subdir, process_name)) {
103  // look for per-path plots inside each per-process directory
104  if (getter.dirExists(subdir + "/Paths"))
105  fillPathSummaryPlots(booker, getter, events, subdir);
106  }
107  }
108 
109  // look for per-path plots inside the current directory
110  if (getter.dirExists(current_path + "/Paths"))
111  fillPathSummaryPlots(booker, getter, events, current_path);
112 }
113 
114 void
116  // note: the following checks need to be kept separate, as any of these histograms might be missing
117  // if any of them is filled, size will have the total number of paths, and "paths" can be used to extract the list of labels
118  MonitorElement * me;
119  TProfile const * paths = nullptr;
120  uint32_t size = 0;
121 
122  // extract the list of Paths and EndPaths from the summary plots
123  if (( me = getter.get(current_path + "/paths_active_time") )) {
124  paths = me->getTProfile();
125  size = paths->GetXaxis()->GetNbins();
126  } else
127  if (( me = getter.get(current_path + "/paths_total_time") )) {
128  paths = me->getTProfile();
129  size = paths->GetXaxis()->GetNbins();
130  } else
131  if (( me = getter.get(current_path + "/paths_exclusive_time") )) {
132  paths = me->getTProfile();
133  size = paths->GetXaxis()->GetNbins();
134  }
135 
136  if (paths == nullptr)
137  return;
138 
139  // for each path, fill histograms with
140  // - the average time spent in each module (total time spent in that module, averaged over all events)
141  // - the running time spent in each module (total time spent in that module, averaged over the events where that module actually ran)
142  // - the "efficiency" of each module (number of time a module succeded divided by the number of times the has run)
143  booker.setCurrentFolder(current_path + "/Paths");
144  for (uint32_t p = 1; p <= size; ++p) {
145  // extract the list of Paths and EndPaths from the bin labels of one of the summary plots
146  std::string label = paths->GetXaxis()->GetBinLabel(p);
147  MonitorElement * me_counter = getter.get( current_path + "/Paths/" + label + "_module_counter" );
148  MonitorElement * me_total = getter.get( current_path + "/Paths/" + label + "_module_total" );
149  if (me_counter == 0 or me_total == 0)
150  continue;
151  TH1F * counter = me_counter->getTH1F();
152  TH1F * total = me_total ->getTH1F();
153  uint32_t bins = counter->GetXaxis()->GetNbins() - 1;
154  double min = counter->GetXaxis()->GetXmin();
155  double max = counter->GetXaxis()->GetXmax() - 1;
156  booker.setCurrentFolder(current_path + "/Paths");
157 
158  TH1F * average;
159  TH1F * running;
160  TH1F * efficiency;
161  MonitorElement * me;
162 
163  me = getter.get( current_path + "/Paths/" + label + "_module_average" );
164  if (me) {
165  average = me->getTH1F();
166  //assert( me->getTH1F()->GetXaxis()->GetNbins() == (int) bins );
167  assert( me->getTH1F()->GetXaxis()->GetXmin() == min );
168  assert( me->getTH1F()->GetXaxis()->GetXmax() == max );
169  average->Reset();
170  } else {
171  average = booker.book1D(label + "_module_average", label + " module average", bins, min, max)->getTH1F();
172  average->SetYTitle("processing time [ms]");
173  for (uint32_t i = 1; i <= bins; ++i) {
174  const char * module = counter->GetXaxis()->GetBinLabel(i);
175  average->GetXaxis()->SetBinLabel(i, module);
176  }
177  }
178 
179  me = getter.get( current_path + "/Paths/" + label + "_module_running" );
180  if (me) {
181  running = me->getTH1F();
182  //assert( me->getTH1F()->GetXaxis()->GetNbins() == (int) bins );
183  assert( me->getTH1F()->GetXaxis()->GetXmin() == min );
184  assert( me->getTH1F()->GetXaxis()->GetXmax() == max );
185  running->Reset();
186  } else {
187  running = booker.book1D(label + "_module_running", label + " module running", bins, min, max)->getTH1F();
188  running->SetYTitle("processing time [ms]");
189  for (uint32_t i = 1; i <= bins; ++i) {
190  const char * module = counter->GetXaxis()->GetBinLabel(i);
191  running->GetXaxis()->SetBinLabel(i, module);
192  }
193  }
194 
195  me = getter.get( current_path + "/Paths/" + label + "_module_efficiency" );
196  if (me) {
197  efficiency = me->getTH1F();
198  //assert( me->getTH1F()->GetXaxis()->GetNbins() == (int) bins );
199  assert( me->getTH1F()->GetXaxis()->GetXmin() == min );
200  assert( me->getTH1F()->GetXaxis()->GetXmax() == max );
201  efficiency->Reset();
202  } else {
203  efficiency = booker.book1D(label + "_module_efficiency", label + " module efficiency", bins, min, max)->getTH1F();
204  efficiency->SetYTitle("filter efficiency");
205  efficiency->SetMaximum(1.05);
206  for (uint32_t i = 1; i <= bins; ++i) {
207  const char * module = counter->GetXaxis()->GetBinLabel(i);
208  efficiency->GetXaxis()->SetBinLabel(i, module);
209  }
210  }
211 
212  for (uint32_t i = 1; i <= bins; ++i) {
213  double t = total ->GetBinContent(i);
214  double n = counter->GetBinContent(i);
215  double p = counter->GetBinContent(i+1);
216  average ->SetBinContent(i, t / events);
217  if (n) {
218  running ->SetBinContent(i, t / n);
219  efficiency->SetBinContent(i, p / n);
220  }
221  }
222  }
223 
224 }
225 
226 void
228  // The following says we do not know what parameters are allowed so do no validation
229  // Please change this to state exactly what you do use, even if it is no parameters
231  desc.addUntracked<std::string>( "dqmPath", "HLT/TimerService");
232  descriptions.add("fastTimerServiceClient", desc);
233 }
234 
235 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
void dqmEndLuminosityBlock(DQMStore::IBooker &booker, DQMStore::IGetter &getter, edm::LuminosityBlock const &, edm::EventSetup const &) override
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:304
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple lumi
Definition: fjr2json.py:35
assert(m_qm.get())
void fillProcessSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter, std::string const &path)
void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter) override
void fillPathSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter, double events, std::string const &path)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
T min(T a, T b)
Definition: MathUtil.h:58
FastTimerServiceClient(edm::ParameterSet const &)
void fillSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter)
bool dirExists(const std::string &path)
Definition: DQMStore.cc:334
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
TH1F * getTH1F(void) const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int average
Definition: PDRates.py:137
std::vector< std::string > getSubdirs(void)
Definition: DQMStore.cc:322
tuple events
Definition: patZpeak.py:19
static std::atomic< unsigned int > counter
TProfile * getTProfile(void) const
Definition: vlib.h:208
tuple size
Write out results.