CMS 3D CMS Logo

HistogramManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1Common
4 // Class : HistogramManager
5 //
7 
8 #include <sstream>
9 #include <boost/algorithm/string.hpp>
10 
11 // Geometry stuff
14 
15 // Logger
17 
19  : iConfig(iconfig),
20  geometryInterface(geo),
21  enabled(iconfig.getParameter<bool>("enabled")),
22  perLumiHarvesting(iconfig.getParameter<bool>("perLumiHarvesting")),
23  bookUndefined(iconfig.getParameter<bool>("bookUndefined")),
24  top_folder_name(iconfig.getParameter<std::string>("topFolderName")),
25  name(iconfig.getParameter<std::string>("name")),
26  title(iconfig.getParameter<std::string>("title")),
27  xlabel(iconfig.getParameter<std::string>("xlabel")),
28  ylabel(iconfig.getParameter<std::string>("ylabel")),
29  dimensions(iconfig.getParameter<int>("dimensions")),
30  range_x_nbins(iconfig.getParameter<int>("range_nbins")),
31  range_x_min(iconfig.getParameter<double>("range_min")),
32  range_x_max(iconfig.getParameter<double>("range_max")),
33  range_y_nbins(iconfig.getParameter<int>("range_y_nbins")),
34  range_y_min(iconfig.getParameter<double>("range_y_min")),
35  range_y_max(iconfig.getParameter<double>("range_y_max")),
36  statsOverflows(iconfig.getParameter<bool>("statsOverflows")) {
37  auto spec_configs = iconfig.getParameter<edm::VParameterSet>("specs");
38  for (const auto& spec : spec_configs) {
39  // this would fit better in SummationSpecification(...), but it has to
40  // happen here.
41  auto conf = spec.getParameter<edm::ParameterSet>("conf");
42  if (!conf.getParameter<bool>("enabled"))
43  continue;
45  }
46 }
47 
49  specs.push_back(spec);
50  tables.push_back(Table());
51  counters.push_back(Table());
53  fastpath.push_back(nullptr);
54 }
55 
56 // This is the hottest function in the HistogramManager. Make sure it does not
57 // allocate memory or other expensive things.
58 // Currently the GeometryInterface::extract (some virtual calls) and the map
59 // lookups should be the most expensive things, but they should only happen if
60 // the module changed from the last call; an optimization that fails when row/
61 // col are used.
62 // fillInternal (called from here) does more lookups on the geometry, if EXTEND
63 // is used; we do not attempt the optimization there since in most cases row/
64 // col are involved.
65 void HistogramManager::fill(double x, double y, DetId sourceModule, const edm::Event* sourceEvent, int col, int row) {
66  if (!enabled)
67  return;
68 
69  // We only need to check the module here, since the fastpath is only used to
70  // determine which plot is filled (not which bin inside) and fillInternal
71  // re-extracts whatever it needs for the axis.
72  // Since do not support booking based on ROC or time, the plot can only depend
73  // on the module.
74  // The sourceEvent check is not really effective (pointer is always the same)
75  // but needed for initialisation.
76  // NOTE that this might change if we want to support per-ROC booking
77  // NOTE that we could even cache the bin to fill if iq and spec are identical,
78  // also across HistogramManagers.
79  bool cached = false;
80  if (sourceModule == this->iq.sourceModule && sourceEvent == this->iq.sourceEvent) {
81  cached = true;
82  }
83  iq = GeometryInterface::InterestingQuantities{sourceEvent, sourceModule, int16_t(col), int16_t(row)};
84  for (unsigned int i = 0; i < specs.size(); i++) {
85  auto& s = specs[i];
86  auto& t = s.steps[0].type == SummationStep::COUNT ? counters[i] : tables[i];
87  if (!cached) { // recompute ME to fill (aka fastpath)
88  significantvalues[i].clear();
90  auto histo = t.find(significantvalues[i]);
91  if (histo == t.end()) {
92  if (bookUndefined) {
93  edm::LogError("HistogramManager") << "Missing Histogram!\n"
94  << "name " << tables[i].begin()->second.th1->GetName() << "\n";
95  assert(!"Histogram not booked! Probably inconsistent geometry description.");
96  }
97  fastpath[i] = nullptr;
98  } else {
99  fastpath[i] = &(histo->second);
100  }
101  }
102  // A fastpath of nullptr means there is no ME for this iq, which can be
103  // a valid cached result.
104  if (fastpath[i]) {
105  if (s.steps[0].type == SummationStep::COUNT) {
106  fastpath[i]->count++;
107  } else {
108  fillInternal(x, y, this->dimensions, iq, s.steps.begin() + 1, s.steps.end(), *(fastpath[i]));
109  }
110  }
111  }
112 }
113 void HistogramManager::fill(double x, DetId sourceModule, const edm::Event* sourceEvent, int col, int row) {
114  assert(this->dimensions == 1);
115  fill(x, 0.0, sourceModule, sourceEvent, col, row);
116 }
117 void HistogramManager::fill(DetId sourceModule, const edm::Event* sourceEvent, int col, int row) {
118  assert(this->dimensions == 0);
119  fill(0.0, 0.0, sourceModule, sourceEvent, col, row);
120 }
121 
123  double y,
124  int n_parameters,
126  std::vector<SummationStep>::iterator first,
127  std::vector<SummationStep>::iterator last,
129  double fx = 0, fy = 0, fz = 0;
130  int tot_parameters = n_parameters;
131  for (auto it = first; it != last; ++it) {
132  if (it->stage != SummationStep::STAGE1)
133  break;
134  // The specification builder precomputes where x and y go, this loop will
135  // always do 3 iterations to set x, y, z. The builder does not know how
136  // many parameters we have, so we have to check that and count the total.
137  switch (it->type) {
139  if (it->arg[0] == '1' && n_parameters >= 1)
140  fx = x;
141  if (it->arg[0] == '2' && n_parameters >= 2)
142  fx = y;
143  break;
145  if (it->arg[0] == '1' && n_parameters >= 1)
146  fy = x;
147  if (it->arg[0] == '2' && n_parameters >= 2)
148  fy = y;
149  break;
151  if (it->arg[0] == '1' && n_parameters >= 1)
152  fz = x;
153  if (it->arg[0] == '2' && n_parameters >= 2)
154  fz = y;
155  break;
157  fx = geometryInterface.extract(it->columns[0], iq).second;
158  tot_parameters++;
159  break;
161  fy = geometryInterface.extract(it->columns[0], iq).second;
162  tot_parameters++;
163  break;
165  break; // profile does not make a difference here, only in booking
166  default:
167  assert(!"illegal step in STAGE1!");
168  }
169  }
170 
171  switch (tot_parameters) {
172  case 1:
173  dest.me->Fill(fx);
174  break;
175  case 2:
176  dest.me->Fill(fx, fy);
177  break;
178  case 3:
179  dest.me->Fill(fx, fy, fz);
180  break;
181  default:
182  edm::LogError("HistogramManager") << "got " << tot_parameters << " dimensions\n"
183  << "name " << dest.th1->GetName() << "\n";
184  assert(!"More than 3 dimensions should never occur.");
185  }
186 }
187 
188 // This is only used for ndigis-like counting. It could be more optimized, but
189 // is probably fine for a per-event thing.
191  if (!enabled)
192  return;
193  for (unsigned int i = 0; i < specs.size(); i++) {
194  auto& s = specs[i];
195  auto& t = tables[i];
196  auto& c = counters[i];
197  if (s.steps[0].type != SummationStep::COUNT)
198  continue; // no counting, done
199  assert((s.steps.size() >= 2 && s.steps[1].type == SummationStep::GROUPBY) ||
200  !"Incomplete spec (but this cannot be caught in Python)");
201  for (auto& e : c) {
202  // the iq on the counter can only be a _sample_, since many modules
203  // could be grouped on one counter. Even worse, the sourceEvent ptr
204  // could be dangling if the counter was not touched in this event, so
205  // we replace it. row/col are most likely useless as well.
206  auto iq = e.second.iq_sample;
207  iq.sourceEvent = sourceEvent;
208 
209  significantvalues[i].clear();
211  auto histo = t.find(significantvalues[i]);
212  if (histo == t.end()) {
213  if (!bookUndefined)
214  continue;
215  edm::LogError("HistogramManager") << "Histogram Missing!\n"
216  << "name " << t.begin()->second.th1->GetName() << "\n"
217  << "ctr "
218  << " detid " << iq.sourceModule << "\n";
219  assert(!"Histogram not booked! (per-event) Probably inconsistent geometry description.");
220  }
221  fillInternal(e.second.count, 0, 1, iq, s.steps.begin() + 2, s.steps.end(), histo->second);
222  e.second.count = 0;
223  }
224  }
225 }
226 
227 std::pair<std::string, std::string> HistogramManager::makePathName(SummationSpecification const& s,
228  GeometryInterface::Values const& significantvalues,
229  SummationStep const* upto) {
230  std::ostringstream dir("");
231  std::string suffix = "";
232 
233  // we omit the last value here, to get all disks next to each other etc.
234  if (!significantvalues.empty()) {
235  for (auto it = significantvalues.begin(); it != (significantvalues.end() - 1); ++it) {
236  auto name = geometryInterface.formatValue(it->first, it->second);
237  if (name.empty())
238  continue;
239  dir << name << "/";
240  }
241  auto e = significantvalues[significantvalues.size() - 1];
242  suffix = "_" + geometryInterface.formatValue(e.first, e.second);
243  }
244 
245  // PERF: this is actually independent of significantvalues and iq
246  std::string name = this->name;
247  for (SummationStep const& step : s.steps) {
248  if (&step == upto)
249  break;
250  switch (step.type) {
252  name = "num_" + name;
253  break;
256  if (step.stage != SummationStep::STAGE1)
257  break;
258  GeometryInterface::Column col0 = step.columns[0];
259  std::string colname = geometryInterface.pretty(col0);
260  name = name + "_per_" + colname;
261  break;
262  }
263  case SummationStep::REDUCE: {
264  auto red = step.arg;
266  name = red + "_" + name;
267  break;
268  }
269  default:
270  // Maybe PROFILE is worth showing.
271  break; // not visible in name
272  }
273  }
274  return std::make_pair(top_folder_name + "/" + dir.str(), name + suffix);
275 }
276 
278  if (!geometryInterface.loaded()) {
279  geometryInterface.load(iSetup);
280  }
281  if (!enabled)
282  return;
283 
284  struct MEInfo {
285  int dimensions = 1;
286  double range_x_min = 1e12;
287  double range_x_max = -1e12;
288  double range_y_min = 1e12;
289  double range_y_max = -1e12;
290  double range_z_min = 1e12; // z range carried around but unused
291  double range_z_max = -1e12;
292  int range_x_nbins = 0;
293  int range_y_nbins = 0;
294  int range_z_nbins = 0;
295  GeometryInterface::Value binwidth_x = 0; // override nbins for geom-things
296  GeometryInterface::Value binwidth_y = 0;
297  std::string title, xlabel, ylabel, zlabel;
298  bool do_profile = false;
299  bool statsOverflows = true;
300  ;
301  };
302  std::map<GeometryInterface::Values, MEInfo> toBeBooked;
303 
304  for (unsigned int i = 0; i < specs.size(); i++) {
305  auto& s = specs[i];
306  auto& t = tables[i];
307  auto& c = counters[i];
308  toBeBooked.clear();
309  bool bookCounters = false;
310 
311  auto firststep = s.steps.begin();
312  int n_parameters = this->dimensions;
313 
314  if (firststep->type != SummationStep::GROUPBY) {
315  ++firststep;
316  n_parameters = 1;
317  bookCounters = true;
318  }
319 
320  auto laststep = std::find_if(
321  s.steps.begin(), s.steps.end(), [](SummationStep const& step) { return step.stage == SummationStep::STAGE2; });
322 
324 
325  for (auto iq : geometryInterface.allModules()) {
326  if (bookCounters) {
327  // add an entry for the counting step if present
329  c[significantvalues].iq_sample = iq;
330  }
331 
333  if (!bookUndefined) {
334  // skip if any column is UNDEFINED
335  bool ok = true;
336  for (auto e : significantvalues)
337  if (e.second == GeometryInterface::UNDEFINED)
338  ok = false;
339  if (!ok)
340  continue;
341  }
342 
343  auto histo = toBeBooked.find(significantvalues);
344  if (histo == toBeBooked.end()) {
345  // create new histo
346  MEInfo& mei = toBeBooked[significantvalues];
347  mei.title = this->title;
348  mei.statsOverflows = this->statsOverflows;
349  if (bookCounters)
350  mei.title =
351  "Number of " + mei.title + " per Event and " + geometryInterface.pretty(*(s.steps[0].columns.end() - 1));
352  std::string xlabel = bookCounters ? "#" + this->xlabel : this->xlabel;
353 
354  // refer to fillInternal() for the actual execution
355  // compute labels, title, type, user-set ranges here
356  int tot_parameters = n_parameters;
357 
358 #define SET_AXIS(to, from) \
359  mei.to##label = from##label; \
360  mei.range_##to##_min = ((it->nbins == -1) ? this->range_##from##_min : it->xmin); \
361  mei.range_##to##_max = ((it->nbins == -1) ? this->range_##from##_max : it->xmax); \
362  mei.range_##to##_nbins = ((it->nbins == -1) ? this->range_##from##_nbins : it->nbins)
363 
364  for (auto it = firststep + 1; it != laststep; ++it) {
365  switch (it->type) {
367  if (it->arg[0] == '1' && n_parameters >= 1) {
368  SET_AXIS(x, x);
369  } // TODO: make use of current nbins, xmin, xmax if set
370  if (it->arg[0] == '2' && n_parameters >= 2) {
371  SET_AXIS(x, y);
372  }
373  break;
375  if (it->arg[0] == '1' && n_parameters >= 1) {
376  SET_AXIS(y, x);
377  }
378  if (it->arg[0] == '2' && n_parameters >= 2) {
379  SET_AXIS(y, y);
380  }
381  break;
383  if (it->arg[0] == '1' && n_parameters >= 1) {
384  SET_AXIS(z, x);
385  }
386  if (it->arg[0] == '2' && n_parameters >= 2) {
387  SET_AXIS(z, y);
388  }
389  break;
391  assert(mei.range_x_nbins == 0);
392  auto col = it->columns[0];
393  mei.xlabel = geometryInterface.pretty(col);
394  mei.title = mei.title + " by " + mei.xlabel;
396  mei.range_x_min = geometryInterface.minValue(col);
398  mei.range_x_max = geometryInterface.maxValue(col);
399  mei.binwidth_x = geometryInterface.binWidth(col);
400  tot_parameters++;
401  } break;
403  auto col = it->columns[0];
404  mei.ylabel = geometryInterface.pretty(col);
405  mei.title = mei.title + " by " + mei.ylabel;
407  mei.range_y_min = geometryInterface.minValue(col);
409  mei.range_y_max = geometryInterface.maxValue(col);
410  mei.binwidth_y = geometryInterface.binWidth(col);
411  tot_parameters++;
412  } break;
414  mei.do_profile = true;
415  break;
416  default:
417  assert(!"illegal step in STAGE1! (booking)");
418  }
419  }
420  mei.dimensions = tot_parameters;
421  if (mei.do_profile)
422  mei.title = "Profile of " + mei.title;
423  if (!mei.zlabel.empty())
424  mei.title = mei.title + " (Z: " + mei.zlabel + ")";
425  }
426  // only update range
427  MEInfo& mei = toBeBooked[significantvalues];
428  double val;
429 
430  for (auto it = firststep + 1; it != laststep; ++it) {
431  switch (it->type) {
433  val = geometryInterface.extract(it->columns[0], iq).second;
435  break;
436  mei.range_x_min = std::min(mei.range_x_min, val);
437  mei.range_x_max = std::max(mei.range_x_max, val);
438  break;
440  val = geometryInterface.extract(it->columns[0], iq).second;
442  break;
443  mei.range_y_min = std::min(mei.range_y_min, val);
444  mei.range_y_max = std::max(mei.range_y_max, val);
445  break;
446  default: // ignore the rest, code above will catch bugs
447  break;
448  }
449  }
450  }
451 
452  // Now do the actual booking.
453  for (auto& e : toBeBooked) {
454  AbstractHistogram& h = t[e.first];
455  MEInfo& mei = e.second;
456  auto name = makePathName(s, e.first, &(*laststep));
457  iBooker.setCurrentFolder(name.first);
458 
459  // determine nbins for geometry derived quantities
460  // due to how we counted above, we need to include lower and upper bound
461  // For Coord-values, which are not precisely aligned with the bins, we force
462  // alignment.
463  if (mei.binwidth_x != 0) {
464  double range = (mei.range_x_max - mei.range_x_min) / mei.binwidth_x;
465  if ((range - int(range)) == 0.0) {
466  mei.range_x_min -= mei.binwidth_x / 2;
467  mei.range_x_max += mei.binwidth_x / 2;
468  } else {
469  mei.range_x_min = std::floor(mei.range_x_min / mei.binwidth_x) * mei.binwidth_x;
470  mei.range_x_max = std::ceil(mei.range_x_max / mei.binwidth_x) * mei.binwidth_x;
471  }
472  mei.range_x_nbins = int((mei.range_x_max - mei.range_x_min) / mei.binwidth_x);
473  }
474  if (mei.binwidth_y != 0) {
475  double range = (mei.range_y_max - mei.range_y_min) / mei.binwidth_y;
476  if ((range - int(range)) == 0.0) {
477  mei.range_y_min -= mei.binwidth_y / 2;
478  mei.range_y_max += mei.binwidth_y / 2;
479  } else {
480  mei.range_y_min = std::floor(mei.range_y_min / mei.binwidth_y) * mei.binwidth_y;
481  mei.range_y_max = std::ceil(mei.range_y_max / mei.binwidth_y) * mei.binwidth_y;
482  }
483  mei.range_y_nbins = int((mei.range_y_max - mei.range_y_min) / mei.binwidth_y);
484  }
485 
486  if (mei.dimensions == 1) {
487  h.me = iBooker.book1D(
488  name.second, (mei.title + ";" + mei.xlabel).c_str(), mei.range_x_nbins, mei.range_x_min, mei.range_x_max);
489  } else if (mei.dimensions == 2 && !mei.do_profile) {
490  h.me = iBooker.book2D(name.second,
491  (mei.title + ";" + mei.xlabel + ";" + mei.ylabel).c_str(),
492  mei.range_x_nbins,
493  mei.range_x_min,
494  mei.range_x_max,
495  mei.range_y_nbins,
496  mei.range_y_min,
497  mei.range_y_max);
498  } else if (mei.dimensions == 2 && mei.do_profile) {
499  h.me = iBooker.bookProfile(name.second,
500  (mei.title + ";" + mei.xlabel + ";" + mei.ylabel).c_str(),
501  mei.range_x_nbins,
502  mei.range_x_min,
503  mei.range_x_max,
504  0.0,
505  0.0,
506  "");
507  } else if (mei.dimensions == 3 && mei.do_profile) {
508  h.me = iBooker.bookProfile2D(name.second,
509  (mei.title + ";" + mei.xlabel + ";" + mei.ylabel).c_str(),
510  mei.range_x_nbins,
511  mei.range_x_min,
512  mei.range_x_max,
513  mei.range_y_nbins,
514  mei.range_y_min,
515  mei.range_y_max,
516  0.0,
517  0.0); // Z range is ignored if min==max
518  } else {
519  edm::LogError("HistogramManager") << "Illegal Histogram!\n"
520  << "name " << name.second << "\n"
521  << "dim " << mei.dimensions << " profile " << mei.do_profile << "\n";
522  assert(!"Illegal Histogram kind.");
523  }
524  h.th1 = h.me->getTH1();
525  h.me->setStatOverflows(mei.statsOverflows);
526  }
527  }
528 }
529 
531  DQMStore::IGetter& iGetter,
532  edm::LuminosityBlock const& lumiBlock,
533  edm::EventSetup const& iSetup) {
534  if (!enabled)
535  return;
536  // this should also give us the GeometryInterface for offline, though it is a
537  // bit dirty and might explode.
538  if (!geometryInterface.loaded()) {
539  geometryInterface.load(iSetup);
540  }
541  if (perLumiHarvesting) {
542  this->lumisection = &lumiBlock; // "custom" steps can use this
543  executeHarvesting(iBooker, iGetter);
544  this->lumisection = nullptr;
545  }
546 }
547 
549  t.clear();
551  auto firststep = s.steps.begin();
552  if (firststep->type != SummationStep::GROUPBY)
553  ++firststep;
554  auto laststep = std::find_if(
555  s.steps.begin(), s.steps.end(), [](SummationStep const& step) { return step.stage == SummationStep::STAGE2; });
556 
557  for (auto iq : geometryInterface.allModules()) {
559 
560  auto histo = t.find(significantvalues);
561  if (histo == t.end()) {
562  auto name = makePathName(s, significantvalues, &(*laststep));
563  std::string path = name.first + name.second;
564  MonitorElement* me = iGetter.get(path);
565  if (!me) {
566  if (bookUndefined)
567  edm::LogError("HistogramManager") << "ME " << path << " not found\n";
568  // else this will happen quite often
569  } else {
571  histo.me = me;
572  histo.th1 = histo.me->getTH1();
573  histo.iq_sample = iq;
574  }
575  }
576  }
577 }
578 
580  Table& t,
581  DQMStore::IBooker& iBooker,
582  SummationSpecification const& s) {
583  // Simple regrouping, sum histos if they end up in the same place.
584  Table out;
586  for (auto& e : t) {
587  TH1* th1 = e.second.th1;
588  geometryInterface.extractColumns(step.columns, e.second.iq_sample, significantvalues);
590  if (!new_histo.me) {
592  iBooker.setCurrentFolder(name.first);
593  if (dynamic_cast<TH1F*>(th1))
594  new_histo.me = iBooker.book1D(name.second, (TH1F*)th1);
595  else if (dynamic_cast<TH2F*>(th1))
596  new_histo.me = iBooker.book2D(name.second, (TH2F*)th1);
597  else if (dynamic_cast<TProfile*>(th1))
598  new_histo.me = iBooker.bookProfile(name.second, (TProfile*)th1);
599  else if (dynamic_cast<TProfile2D*>(th1))
600  new_histo.me = iBooker.bookProfile2D(name.second, (TProfile2D*)th1);
601  else
602  assert(!"No idea how to book this.");
603  new_histo.th1 = new_histo.me->getTH1();
604  new_histo.iq_sample = e.second.iq_sample;
605  } else {
606  new_histo.th1->Add(th1);
607  }
608  new_histo.me->setStatOverflows(e.second.me->getStatOverflows());
609  }
610  t.swap(out);
611 }
612 
614  Table& t,
615  std::string const& reduce_type,
616  DQMStore::IBooker& iBooker,
617  SummationSpecification const& s) {
618  // For the moment only X.
619  // first pass determines the range.
620  std::map<GeometryInterface::Values, int> nbins;
621  // separators collects meta info for the render plugin about the boundaries.
622  // for each EXTEND, this is added to the axis label. In total this is not
623  // fully correct since we have to assume the the substructure of each sub-
624  // histogram is the same, which is e.g. not true for layers. It still works
625  // since layers only contain leaves (ladders).
626  std::map<GeometryInterface::Values, std::string> separators;
627 
629 
630  for (auto& e : t) {
631  geometryInterface.extractColumns(step.columns, e.second.iq_sample, significantvalues);
632  int& n = nbins[significantvalues];
633  assert(e.second.th1 || !"invalid histogram");
634  // if we reduce, every histogram only needs one bin
635  int bins = !reduce_type.empty() ? 1 : e.second.th1->GetXaxis()->GetNbins();
636  if (bins > 1)
637  separators[significantvalues] += std::to_string(n) + ",";
638  n += bins;
639  }
640  for (auto& e : separators)
641  e.second = "(" + e.second + ")/";
642 
643  Table out;
644  for (auto& e : t) {
645  geometryInterface.extractColumns(step.columns, e.second.iq_sample, significantvalues);
646  TH1* th1 = e.second.th1;
647  assert(th1);
648 
650  if (!new_histo.me) {
651  // we put the name of the actual, last column of a input histo there.
652  std::string colname = geometryInterface.pretty((e.first.end() - 1)->first);
653 
654  auto separator = separators[significantvalues];
655 
657  auto title =
658  std::string("") + th1->GetTitle() + " per " + colname + ";" + colname + separator +
659  (!reduce_type.empty() ? th1->GetYaxis()->GetTitle() : th1->GetXaxis()->GetTitle()) + ";" +
660  (!reduce_type.empty() ? reduce_type + " of " + th1->GetXaxis()->GetTitle() : th1->GetYaxis()->GetTitle());
661  iBooker.setCurrentFolder(name.first);
662 
663  if (th1->GetDimension() == 1) {
664  new_histo.me =
665  iBooker.book1D(name.second, title, nbins[significantvalues], 0.5, nbins[significantvalues] + 0.5);
666  } else {
667  assert(!"2D extend not implemented in harvesting.");
668  }
669  new_histo.th1 = new_histo.me->getTH1();
670  new_histo.iq_sample = e.second.iq_sample;
671  new_histo.count = 1; // used as a fill pointer. Assumes histograms are
672  // ordered correctly (map should provide that)
673  }
674 
675  // now add data.
676  if (new_histo.th1->GetDimension() == 1) {
677  if (reduce_type.empty()) { // no reduction, concatenate
678  for (int i = 1; i <= th1->GetXaxis()->GetNbins(); i++) {
679  new_histo.th1->SetBinContent(new_histo.count, th1->GetBinContent(i));
680  new_histo.th1->SetBinError(new_histo.count, th1->GetBinError(i));
681  new_histo.count += 1;
682  }
683  } else if (reduce_type == "MEAN") {
684  new_histo.th1->SetBinContent(new_histo.count, th1->GetMean());
685  new_histo.th1->SetBinError(new_histo.count, th1->GetMeanError());
686  new_histo.count += 1;
687  } else {
688  assert(!"Reduction type not supported");
689  }
690  new_histo.me->setStatOverflows(e.second.me->getStatOverflows());
691  } else {
692  assert(!"2D extend not implemented in harvesting.");
693  }
694  }
695  t.swap(out);
696 }
697 
699  if (!enabled)
700  return;
701  // Debug output
702  for (auto& s : specs) {
703  edm::LogInfo log("HistogramManager");
704  log << "Specs for " << name << " ";
705  s.dump(log, geometryInterface);
706  }
707 
708  for (unsigned int i = 0; i < specs.size(); i++) {
709  auto& s = specs[i];
710  auto& t = tables[i];
711  loadFromDQMStore(s, t, iGetter);
712 
713  std::string reduce_type = "";
714 
715  // now execute step2.
716  for (SummationStep const& step : s.steps) {
717  if (step.stage == SummationStep::STAGE2) {
718  switch (step.type) {
719  case SummationStep::SAVE:
720  // no explicit implementation atm.
721  break;
723  executeGroupBy(step, t, iBooker, s);
724  break;
726  // reduction is done in the following EXTEND
727  reduce_type = step.arg;
728  break;
730  executeExtend(step, t, reduce_type, iBooker, s);
731  reduce_type = "";
732  break;
734  assert(!"EXTEND_Y currently not supported in harvesting.");
735  break;
736  default:
737  assert(!"Operation not supported in harvesting.");
738  }
739  }
740  }
741  }
742 }
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
DDAxes::y
HistogramManager::tables
std::vector< Table > tables
Definition: HistogramManager.h:66
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
electrons_cff.bool
bool
Definition: electrons_cff.py:366
HistogramManager::significantvalues
std::vector< GeometryInterface::Values > significantvalues
Definition: HistogramManager.h:119
mps_fire.i
i
Definition: mps_fire.py:428
HistogramManager::executeExtend
void executeExtend(SummationStep const &step, Table &t, std::string const &reduction, DQMStore::IBooker &iBooker, SummationSpecification const &s)
Definition: HistogramManager.cc:613
MessageLogger.h
HistogramManager::perLumiHarvesting
bool perLumiHarvesting
Definition: HistogramManager.h:91
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TrackerGeometry.h
GeometryInterface::InterestingQuantities::sourceModule
DetId sourceModule
Definition: GeometryInterface.h:60
HistogramManager::range_x_nbins
int range_x_nbins
Definition: HistogramManager.h:100
HistogramManager::addSpec
void addSpec(SummationSpecification spec)
Definition: HistogramManager.cc:48
step
step
Definition: StallMonitor.cc:94
HistogramManager_cfi.range_y_min
range_y_min
Definition: HistogramManager_cfi.py:78
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
HistogramManager_cfi.range_y_max
range_y_max
Definition: HistogramManager_cfi.py:79
HistogramManager::executePerLumiHarvesting
void executePerLumiHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &iSetup)
Definition: HistogramManager.cc:530
GeometryInterface::loaded
bool loaded()
Definition: GeometryInterface.h:52
min
T min(T a, T b)
Definition: MathUtil.h:58
multPhiCorr_741_25nsDY_cfi.fx
fx
Definition: multPhiCorr_741_25nsDY_cfi.py:9
SummationStep::STAGE2
Definition: SummationSpecification.h:43
HistogramManager::lumisection
edm::LuminosityBlock const * lumisection
Definition: HistogramManager.h:109
dqm::implementation::IBooker::bookProfile2D
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
cuy.col
col
Definition: cuy.py:1009
AbstractHistogram::iq_sample
GeometryInterface::InterestingQuantities iq_sample
Definition: AbstractHistogram.h:27
HistogramManager::bookUndefined
bool bookUndefined
Definition: HistogramManager.h:92
HistogramManager::iq
GeometryInterface::InterestingQuantities iq
Definition: HistogramManager.h:117
HistogramManager::executeGroupBy
void executeGroupBy(SummationStep const &step, Table &t, DQMStore::IBooker &iBooker, SummationSpecification const &s)
Definition: HistogramManager.cc:579
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
HistogramManager::counters
std::vector< Table > counters
Definition: HistogramManager.h:67
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:278
cms::cuda::assert
assert(be >=bs)
edm::VParameterSet
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
HistogramManager::range_y_nbins
int range_y_nbins
Definition: HistogramManager.h:103
DDAxes::x
GeometryInterface::pretty
std::string pretty(Column col)
Definition: GeometryInterface.h:125
HistogramManager::fillInternal
void fillInternal(double x, double y, int n_parameters, GeometryInterface::InterestingQuantities const &iq, std::vector< SummationStep >::iterator first, std::vector< SummationStep >::iterator last, AbstractHistogram &dest)
Definition: HistogramManager.cc:122
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
SummationStep::USE_X
Definition: SummationSpecification.h:33
SET_AXIS
#define SET_AXIS(to, from)
GeometryInterface::binWidth
Value binWidth(ID id)
Definition: GeometryInterface.h:103
HistogramManager_cfi.dimensions
dimensions
Definition: HistogramManager_cfi.py:74
GeometryInterface::load
void load(edm::EventSetup const &iSetup)
Definition: GeometryInterface.cc:62
DivergingColor.red
list red
Definition: DivergingColor.py:172
HistogramManager_cfi.perLumiHarvesting
perLumiHarvesting
Definition: HistogramManager_cfi.py:57
GeometryInterface::Value
double Value
Definition: GeometryInterface.h:41
createPayload.suffix
suffix
Definition: createPayload.py:281
HistogramManager::fastpath
std::vector< AbstractHistogram * > fastpath
Definition: HistogramManager.h:121
mps_merge.separator
string separator
Definition: mps_merge.py:79
AbstractHistogram::count
int count
Definition: AbstractHistogram.h:22
AbstractHistogram
Definition: AbstractHistogram.h:21
DetId
Definition: DetId.h:17
SummationStep::STAGE1
Definition: SummationSpecification.h:43
Table
alignCSCRings.s
s
Definition: alignCSCRings.py:92
dqmdumpme.last
last
Definition: dqmdumpme.py:56
GeometryInterface::formatValue
std::string formatValue(Column, Value)
Definition: GeometryInterface.cc:485
HistogramManager::executeHarvesting
void executeHarvesting(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter)
Definition: HistogramManager.cc:698
reco::ceil
constexpr int32_t ceil(float num)
Definition: constexpr_cmath.h:7
DDAxes::z
dqm::implementation::IBooker::bookProfile
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
HistogramManager_cfi.statsOverflows
statsOverflows
Definition: HistogramManager_cfi.py:53
h
GeometryInterface::maxValue
Value maxValue(ID id)
Definition: GeometryInterface.h:101
HistogramManager_cfi.xlabel
xlabel
Definition: HistogramManager_cfi.py:72
SummationStep::REDUCE
Definition: SummationSpecification.h:31
GeometryInterface::InterestingQuantities::sourceEvent
const edm::Event * sourceEvent
Definition: GeometryInterface.h:59
SummationStep::EXTEND_X
Definition: SummationSpecification.h:28
dqm::legacy::MonitorElement::getTH1
virtual TH1 * getTH1() const
Definition: MonitorElement.h:475
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
multPhiCorr_741_25nsDY_cfi.fy
fy
Definition: multPhiCorr_741_25nsDY_cfi.py:11
HistogramManager::dimensions
int dimensions
Definition: HistogramManager.h:99
GeometryInterface::extractColumns
void extractColumns(std::vector< Column > const &names, InterestingQuantities const &iq, Values &out)
Definition: GeometryInterface.h:66
HistogramManager::range_x_max
double range_x_max
Definition: HistogramManager.h:102
AbstractHistogram::me
dqm::legacy::MonitorElement * me
Definition: AbstractHistogram.h:23
HistogramManager::executePerEventHarvesting
void executePerEventHarvesting(edm::Event const *ev)
Definition: HistogramManager.cc:190
SummationStep::SAVE
Definition: SummationSpecification.h:32
HistogramManager_cfi.bookUndefined
bookUndefined
Definition: HistogramManager_cfi.py:64
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
HistogramManager.h
HistogramManager::loadFromDQMStore
void loadFromDQMStore(SummationSpecification &s, Table &t, DQMStore::IGetter &iGetter)
Definition: HistogramManager.cc:548
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
to_lower
std::string to_lower(const std::string &s)
Definition: CredentialStore.h:23
HistogramManager::specs
std::vector< SummationSpecification > specs
Definition: HistogramManager.h:65
GeometryInterface::UNDEFINED
static const Value UNDEFINED
Definition: GeometryInterface.h:42
createfilelist.int
int
Definition: createfilelist.py:10
HistogramManager::name
std::string name
Definition: HistogramManager.h:95
HistogramManager::xlabel
std::string xlabel
Definition: HistogramManager.h:97
SummationStep::USE_Z
Definition: SummationSpecification.h:35
HistogramManager::range_y_max
double range_y_max
Definition: HistogramManager.h:105
edm::EventSetup
Definition: EventSetup.h:58
GeometryInterface::Values
std::vector< std::pair< Column, Value > > Values
Definition: GeometryInterface.h:46
SummationStep::USE_Y
Definition: SummationSpecification.h:34
HistogramManager::enabled
bool enabled
Definition: HistogramManager.h:90
HistogramManager::range_x_min
double range_x_min
Definition: HistogramManager.h:101
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GeometryInterface::Column
ID Column
Definition: GeometryInterface.h:40
SummationStep::PROFILE
Definition: SummationSpecification.h:36
dqm::impl::MonitorElement::setStatOverflows
virtual DQM_DEPRECATED void setStatOverflows(bool value)
Definition: MonitorElement.cc:898
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HistogramManager::fill
void fill(DetId sourceModule, const edm::Event *sourceEvent=nullptr, int col=0, int row=0)
Definition: HistogramManager.cc:117
SummationStep::EXTEND_Y
Definition: SummationSpecification.h:29
HistogramManager_cfi.ylabel
ylabel
Definition: HistogramManager_cfi.py:73
GeometryInterface::minValue
Value minValue(ID id)
Definition: GeometryInterface.h:102
AbstractHistogram::th1
TH1 * th1
Definition: AbstractHistogram.h:24
HistogramManager::HistogramManager
HistogramManager(const edm::ParameterSet &iConfig, GeometryInterface &geo)
Definition: HistogramManager.cc:18
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
GeometryInterface::extract
std::pair< Column, Value > extract(Column const &col, InterestingQuantities const &iq)
Definition: GeometryInterface.h:76
HistogramManager::title
std::string title
Definition: HistogramManager.h:96
dqm::implementation::IGetter
Definition: DQMStore.h:484
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
genVertex_cff.x
x
Definition: genVertex_cff.py:13
SummationSpecification
Definition: SummationSpecification.h:56
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
SummationStep
Definition: SummationSpecification.h:20
SummationStep::COUNT
Definition: SummationSpecification.h:30
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HistogramManager_cfi.range_y_nbins
range_y_nbins
Definition: HistogramManager_cfi.py:80
HistogramManager::geometryInterface
GeometryInterface & geometryInterface
Definition: HistogramManager.h:63
HistogramManager::Table
std::map< GeometryInterface::Values, AbstractHistogram > Table
Definition: HistogramManager.h:59
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
dqm::implementation::IBooker
Definition: DQMStore.h:43
HistogramManager::book
void book(DQMStore::IBooker &iBooker, edm::EventSetup const &iSetup)
Definition: HistogramManager.cc:277
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
HistogramManager::ylabel
std::string ylabel
Definition: HistogramManager.h:98
GeometryInterface::InterestingQuantities
Definition: GeometryInterface.h:57
HistogramManager::makePathName
std::pair< std::string, std::string > makePathName(SummationSpecification const &s, GeometryInterface::Values const &, SummationStep const *upto)
Definition: HistogramManager.cc:227
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
GeometryInterface
Definition: GeometryInterface.h:34
HistogramManager::range_y_min
double range_y_min
Definition: HistogramManager.h:104
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
hlt_dqm_clientPB-live_cfg.me
me
Definition: hlt_dqm_clientPB-live_cfg.py:61
edm::Event
Definition: Event.h:73
SummationStep::GROUPBY
Definition: SummationSpecification.h:27
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::Log
Definition: MessageLogger.h:70
HistogramManager::top_folder_name
std::string top_folder_name
Definition: HistogramManager.h:93
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
mps_fire.dest
dest
Definition: mps_fire.py:179
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
pixel_dqm_sourceclient-live_cfg.enabled
enabled
Definition: pixel_dqm_sourceclient-live_cfg.py:139
HistogramManager::statsOverflows
bool statsOverflows
Definition: HistogramManager.h:106
GeometryInterface::allModules
std::vector< InterestingQuantities > const & allModules()
Definition: GeometryInterface.h:99