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
24 
26 public:
28  ~ThroughputServiceClient() override = default;
29 
30  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
31 
32 private:
34  const bool m_dqm_merge;
35 
37  DQMStore::IGetter &getter,
38  edm::LuminosityBlock const &,
39  edm::EventSetup const &) override;
40  void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter) override;
41 
42 private:
44 };
45 
47  : m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
48  m_dqm_merge(config.getUntrackedParameter<bool>("createSummary")) {}
49 
51  fillSummaryPlots(booker, getter);
52 }
53 
55  DQMStore::IGetter &getter,
56  edm::LuminosityBlock const &,
57  edm::EventSetup const &) {
58  fillSummaryPlots(booker, getter);
59 }
60 
62  // find whether the plots are in the main folder, or in per-number-of-processess subfolders
63  std::vector<std::string> folders;
64  if (getter.get(m_dqm_path + "/throughput_sourced")) {
65  // the plots are in the main folder
66  folders.push_back(m_dqm_path);
67  } else {
68  static const boost::regex running_n_processes(".*/Running .*");
70  std::vector<std::string> subdirs = getter.getSubdirs();
71  for (auto const &subdir : subdirs) {
72  if (boost::regex_match(subdir, running_n_processes)) {
73  if (getter.get(subdir + "/throughput_sourced"))
74  // the plots are in a per-number-of-processes subfolder
75  folders.push_back(subdir);
76  }
77  }
78  }
79  // create a summary folder if there are more than one
80  if (m_dqm_merge and folders.size() > 1) {
81  std::string summary_folder = m_dqm_path + "/Summary";
82  booker.setCurrentFolder(summary_folder);
83  // clone the first set of histograms
84  auto folder = folders.begin();
85  TH1F *sourced =
86  booker.book1D("throughput_sourced", getter.get(*folder + "/throughput_sourced")->getTH1F())->getTH1F();
87  TH1F *retired =
88  booker.book1D("throughput_retired", getter.get(*folder + "/throughput_retired")->getTH1F())->getTH1F();
89  // add the other sets of histograms
90  for (++folder; folder != folders.end(); ++folder) {
91  sourced->Add(getter.get(*folder + "/throughput_sourced")->getTH1F());
92  retired->Add(getter.get(*folder + "/throughput_retired")->getTH1F());
93  }
94  // move the summary folder to the list
95  folders.push_back(std::move(summary_folder));
96  }
97  for (auto const &folder : folders) {
98  TH1F *sourced = getter.get(folder + "/throughput_sourced")->getTH1F();
99  TH1F *retired = getter.get(folder + "/throughput_retired")->getTH1F();
100  booker.setCurrentFolder(folder);
101  unsigned int nbins = sourced->GetXaxis()->GetNbins();
102  double range = sourced->GetXaxis()->GetXmax();
103 
104  // (re)book and fill .../concurrent
105  TH1F *concurrent = booker.book1D("concurrent", "Concurrent events being processed", nbins, 0., range)->getTH1F();
106  double sum = 0;
107  // from bin=0 (underflow) to bin=nbins+1 (overflow)
108  for (unsigned int i = 0; i <= nbins + 1; ++i) {
109  sum += sourced->GetBinContent(i) - retired->GetBinContent(i);
110  concurrent->Fill(concurrent->GetXaxis()->GetBinCenter(i), sum);
111  }
112 
113  TH1F *average = nullptr;
114  double avg_min = std::min(sourced->GetMinimum(0.), retired->GetMinimum(0.));
115  double avg_max = std::max(sourced->GetMaximum(), retired->GetMaximum());
116  double width = avg_max - avg_min;
117  avg_min = std::floor(avg_min - width * 0.2);
118  if (avg_min < 0.)
119  avg_min = 0.;
120  avg_max = std::ceil(avg_max + width * 0.2);
121  width = avg_max - avg_min;
122 
123  // define the range for .../average_sourced
124  auto first = sourced->FindFirstBinAbove(0.);
125  auto last = sourced->FindLastBinAbove(0.);
126  booker.setCurrentFolder(folder);
127  // (re)book and fill .../average_sourced
128  average = booker.book1D("average_sourced", "Throughput (sourced events)", (int)width, avg_min, avg_max)->getTH1F();
129  if (first >= 0)
130  for (auto i = first; i <= last; ++i)
131  average->Fill(sourced->GetBinContent(i));
132 
133  // define the range for .../average_retired
134  first = retired->FindFirstBinAbove(0.);
135  last = retired->FindLastBinAbove(0.);
136  booker.setCurrentFolder(folder);
137  // (re)book and fill .../average_retired
138  average = booker.book1D("average_retired", "Throughput (retired events)", (int)width, avg_min, avg_max)->getTH1F();
139  if (first >= 0)
140  for (auto i = first; i <= last; ++i)
141  average->Fill(retired->GetBinContent(i));
142  }
143 }
144 
147  desc.addUntracked<std::string>("dqmPath", "HLT/Throughput");
148  desc.addUntracked<bool>("createSummary", true);
149  descriptions.add("throughputServiceClient", desc);
150 }
151 
152 // declare this class as a framework plugin
constexpr int32_t ceil(float num)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
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)
void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual TH1F * getTH1F() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~ThroughputServiceClient() override=default
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:690
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
def move(src, dest)
Definition: eostools.py:511
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:717