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 
37  void dqmEndJob(DQMStore::IBooker & booker, DQMStore::IGetter & getter);
38 
39 private:
40  void fillSummaryPlots( DQMStore::IBooker & booker, DQMStore::IGetter & getter);
42  void fillPathSummaryPlots( DQMStore::IBooker & booker, DQMStore::IGetter & getter, double events, std::string const & path);
43 };
44 
45 
47  m_dqm_path( config.getUntrackedParameter<std::string>( "dqmPath" ) )
48 {
49 }
50 
52 {
53 }
54 
55 void
57 {
58  fillSummaryPlots(booker, getter);
59 }
60 
61 void
63 {
64  // fillSummaryPlots(getter);
65 }
66 
67 void
69 {
70  if (getter.get(m_dqm_path + "/event")) {
71  // the plots are directly in the configured folder
72  fillProcessSummaryPlots(booker, getter, m_dqm_path);
73  } else {
74  static const boost::regex running_n_processes(".*/Running [0-9]+ processes");
76  std::vector<std::string> subdirs = getter.getSubdirs();
77  for (auto const & subdir: subdirs) {
78  if (boost::regex_match(subdir, running_n_processes)) {
79  // the plots are in a per-number-of-processes folder
80  if (getter.get(subdir + "/event"))
81  fillProcessSummaryPlots(booker, getter, subdir);
82  }
83  }
84  }
85 }
86 
87 
88 
89 void
91  MonitorElement * me = getter.get(current_path + "/event");
92  if (me == 0)
93  // no FastTimerService DQM information
94  return;
95 
96  double events = me->getTH1F()->GetEntries();
97 
98  // look for per-process directories
99  static const boost::regex process_name(".*/process .*");
100  booker.setCurrentFolder(current_path);
101  std::vector<std::string> subdirs = getter.getSubdirs();
102  for (auto const & subdir: subdirs) {
103  if (boost::regex_match(subdir, process_name)) {
104  // look for per-path plots inside each per-process directory
105  if (getter.dirExists(subdir + "/Paths"))
106  fillPathSummaryPlots(booker, getter, events, subdir);
107  }
108  }
109 
110  // look for per-path plots inside the current directory
111  if (getter.dirExists(current_path + "/Paths"))
112  fillPathSummaryPlots(booker, getter, events, current_path);
113 }
114 
115 void
117  // note: the following checks need to be kept separate, as any of these histograms might be missing
118  // 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
119  MonitorElement * me;
120  TProfile const * paths = nullptr;
121  uint32_t size = 0;
122 
123  // extract the list of Paths and EndPaths from the summary plots
124  if (( me = getter.get(current_path + "/paths_active_time") )) {
125  paths = me->getTProfile();
126  size = paths->GetXaxis()->GetNbins();
127  } else
128  if (( me = getter.get(current_path + "/paths_total_time") )) {
129  paths = me->getTProfile();
130  size = paths->GetXaxis()->GetNbins();
131  } else
132  if (( me = getter.get(current_path + "/paths_exclusive_time") )) {
133  paths = me->getTProfile();
134  size = paths->GetXaxis()->GetNbins();
135  }
136 
137  if (paths == nullptr)
138  return;
139 
140  // for each path, fill histograms with
141  // - the average time spent in each module (total time spent in that module, averaged over all events)
142  // - the running time spent in each module (total time spent in that module, averaged over the events where that module actually ran)
143  // - the "efficiency" of each module (number of time a module succeded divided by the number of times the has run)
144  booker.setCurrentFolder(current_path + "/Paths");
145  for (uint32_t p = 1; p <= size; ++p) {
146  // extract the list of Paths and EndPaths from the bin labels of one of the summary plots
147  std::string label = paths->GetXaxis()->GetBinLabel(p);
148  MonitorElement * me_counter = getter.get( current_path + "/Paths/" + label + "_module_counter" );
149  MonitorElement * me_total = getter.get( current_path + "/Paths/" + label + "_module_total" );
150  if (me_counter == 0 or me_total == 0)
151  continue;
152  TH1F * counter = me_counter->getTH1F();
153  TH1F * total = me_total ->getTH1F();
154  uint32_t bins = counter->GetXaxis()->GetNbins();
155  double min = counter->GetXaxis()->GetXmin();
156  double max = counter->GetXaxis()->GetXmax();
157  TH1F * average = booker.book1D(label + "_module_average", label + " module average", bins, min, max)->getTH1F();
158  average ->SetYTitle("processing time [ms]");
159  TH1F * running = booker.book1D(label + "_module_running", label + " module running", bins, min, max)->getTH1F();
160  running ->SetYTitle("processing time [ms]");
161  TH1F * efficiency = booker.book1D(label + "_module_efficiency", label + " module efficiency", bins, min, max)->getTH1F();
162  efficiency->SetYTitle("filter efficiency");
163  efficiency->SetMaximum(1.05);
164  for (uint32_t i = 1; i <= bins; ++i) {
165  const char * module = counter->GetXaxis()->GetBinLabel(i);
166  average ->GetXaxis()->SetBinLabel(i, module);
167  running ->GetXaxis()->SetBinLabel(i, module);
168  efficiency->GetXaxis()->SetBinLabel(i, module);
169  double t = total ->GetBinContent(i);
170  double n = counter->GetBinContent(i);
171  double p = counter->GetBinContent(i+1);
172  average ->SetBinContent(i, t / events);
173  if (n) {
174  running ->SetBinContent(i, t / n);
175  efficiency->SetBinContent(i, p / n);
176  }
177  }
178  }
179 
180 }
181 
182 void
184  // The following says we do not know what parameters are allowed so do no validation
185  // Please change this to state exactly what you do use, even if it is no parameters
187  desc.addUntracked<std::string>( "dqmPath", "HLT/TimerService");
188  descriptions.add("fastTimerServiceClient", desc);
189 }
190 
191 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
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:291
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
tuple lumi
Definition: fjr2json.py:35
void fillProcessSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter, std::string const &path)
void fillPathSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter, double events, std::string const &path)
const T & max(const T &a, const T &b)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:112
void dqmEndLuminosityBlock(DQMStore::IGetter &getter, edm::LuminosityBlock const &lumi, edm::EventSetup const &setup)
FastTimerServiceClient(edm::ParameterSet const &)
void fillSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter)
bool dirExists(const std::string &path)
Definition: DQMStore.cc:307
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
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:295
tuple events
Definition: patZpeak.py:19
static std::atomic< unsigned int > counter
TProfile * getTProfile(void) const
Definition: vlib.h:208
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter)