CMS 3D CMS Logo

ThroughputServiceClient.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:
29  ~ThroughputServiceClient() override = default;
30 
31  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
32 
33 private:
35  const bool m_dqm_merge;
36 
37  void dqmEndLuminosityBlock(DQMStore::IBooker & booker, DQMStore::IGetter & getter, edm::LuminosityBlock const &, edm::EventSetup const&) override;
38  void dqmEndJob(DQMStore::IBooker & booker, DQMStore::IGetter & getter) override;
39 
40 private:
41  void fillSummaryPlots(DQMStore::IBooker & booker, DQMStore::IGetter & getter);
42 };
43 
44 
46  m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
47  m_dqm_merge(config.getUntrackedParameter<bool>("createSummary"))
48 {
49 }
50 
51 void
53 {
54  fillSummaryPlots(booker, getter);
55 }
56 
57 void
59 {
60  fillSummaryPlots(booker, getter);
61 }
62 
63 void
65 {
66  // find whether the plots are in the main folder, or in per-number-of-processess subfolders
67  std::vector<std::string> folders;
68  if (getter.get(m_dqm_path + "/throughput_sourced")) {
69  // the plots are in the main folder
70  folders.push_back(m_dqm_path);
71  } else {
72  static const boost::regex running_n_processes(".*/Running .*");
74  std::vector<std::string> subdirs = getter.getSubdirs();
75  for (auto const & subdir: subdirs) {
76  if (boost::regex_match(subdir, running_n_processes)) {
77  if (getter.get(subdir + "/throughput_sourced"))
78  // the plots are in a per-number-of-processes subfolder
79  folders.push_back(subdir);
80  }
81  }
82  }
83  // create a summary folder if there are more than one
84  if (m_dqm_merge and folders.size() > 1) {
85  std::string summary_folder = m_dqm_path + "/Summary";
86  booker.setCurrentFolder(summary_folder);
87  // drop the summary histograms, if they exist
88  if (getter.get(summary_folder + "/throughput_sourced"))
89  getter.removeElement(summary_folder, "throughput_sourced", true);
90  if (getter.get(summary_folder + "/throughput_retired"))
91  getter.removeElement(summary_folder, "throughput_retired", true);
92  // clone the first set of histograms
93  auto folder = folders.begin();
94  TH1F * sourced = booker.book1D("throughput_sourced", getter.get(*folder + "/throughput_sourced")->getTH1F())->getTH1F();
95  TH1F * retired = booker.book1D("throughput_retired", getter.get(*folder + "/throughput_retired")->getTH1F())->getTH1F();
96  // add the other sets of histograms
97  for (++folder; folder != folders.end(); ++folder) {
98  sourced->Add(getter.get(*folder + "/throughput_sourced")->getTH1F());
99  retired->Add(getter.get(*folder + "/throughput_retired")->getTH1F());
100  }
101  // move the summary folder to the list
102  folders.push_back(std::move(summary_folder));
103  }
104  for (auto const & folder: folders) {
105  TH1F * sourced = getter.get(folder + "/throughput_sourced")->getTH1F();
106  TH1F * retired = getter.get(folder + "/throughput_retired")->getTH1F();
107  booker.setCurrentFolder(folder);
108  unsigned int nbins = sourced->GetXaxis()->GetNbins();
109  double range = sourced->GetXaxis()->GetXmax();
110 
111  // drop .../concurrent, if it exists
112  if (getter.get(folder + "/concurrent"))
113  getter.removeElement(folder, "concurrent", true);
114  // (re)book and fill .../concurrent
115  TH1F* concurrent = booker.book1D("concurrent", "Concurrent events being processed", nbins, 0., range)->getTH1F();
116  double sum = 0;
117  // from bin=0 (underflow) to bin=nbins+1 (overflow)
118  for (unsigned int i = 0; i <= nbins+1; ++i) {
119  sum += sourced->GetBinContent(i) - retired->GetBinContent(i);
120  concurrent->Fill(concurrent->GetXaxis()->GetBinCenter(i), sum);
121  }
122 
123  TH1F* average = nullptr;
124  double avg_min = std::min(sourced->GetMinimum(0.), retired->GetMinimum(0.));
125  double avg_max = std::max(sourced->GetMaximum(), retired->GetMaximum());
126  double width = avg_max - avg_min;
127  avg_min = std::floor(avg_min - width * 0.2);
128  if (avg_min < 0.) avg_min = 0.;
129  avg_max = std::ceil(avg_max + width * 0.2);
130  width = avg_max - avg_min;
131 
132  // drop .../average_sourced, if it exists
133  if (getter.get(folder + "/average_sourced"))
134  getter.removeElement(folder, "average_sourced", true);
135  // define the range for .../average_sourced
136  uint64_t first = sourced->FindFirstBinAbove(0.);
137  uint64_t last = sourced->FindLastBinAbove(0.);
138  booker.setCurrentFolder(folder);
139  // (re)book and fill .../average_sourced
140  average = booker.book1D("average_sourced", "Throughput (sourced events)", (int) width, avg_min, avg_max)->getTH1F();
141  for (unsigned int i = first; i <= last; ++i)
142  average->Fill(sourced->GetBinContent(i));
143 
144  // drop .../average_retired, if it exists
145  if (getter.get(folder + "/average_retired"))
146  getter.removeElement(folder, "average_retired", true);
147  // define the range for .../average_retired
148  first = retired->FindFirstBinAbove(0.);
149  last = retired->FindLastBinAbove(0.);
150  booker.setCurrentFolder(folder);
151  // (re)book and fill .../average_retired
152  average = booker.book1D("average_retired", "Throughput (retired events)", (int) width, avg_min, avg_max)->getTH1F();
153  for (unsigned int i = first; i <= last; ++i)
154  average->Fill(retired->GetBinContent(i));
155  }
156 }
157 
158 void
161  desc.addUntracked<std::string>("dqmPath", "HLT/Throughput");
162  desc.addUntracked<bool>("createSummary", true);
163  descriptions.add("throughputServiceClient", desc);
164 }
165 
166 // declare this class as a framework plugin
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
TH1F * getTH1F() const
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: config.py:1
void fillSummaryPlots(DQMStore::IBooker &booker, DQMStore::IGetter &getter)
ThroughputServiceClient(edm::ParameterSet const &)
void dqmEndLuminosityBlock(DQMStore::IBooker &booker, DQMStore::IGetter &getter, edm::LuminosityBlock const &, edm::EventSetup const &) override
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle otherwise a larger ***bin number will have no effects or even make the ***precision lower than before *********************************************************************************************************it lies in three folders
Definition: invegas.h:5
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter) override
T min(T a, T b)
Definition: MathUtil.h:58
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
unsigned long long uint64_t
Definition: Time.h:15
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~ThroughputServiceClient() override=default
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:320
void removeElement(Args &&...args)
Definition: DQMStore.h:310
def move(src, dest)
Definition: eostools.py:510