Skip to content

Commit fb37861

Browse files
committed
Implement TH2Poly support in DQMServices
- Add TH2Poly support in DQMServices/Core - Implement TH2Poly in DQMServices/Components - Add TH2Poly support in MEtoEDMFormat.h
1 parent 5284c46 commit fb37861

File tree

9 files changed

+116
-1
lines changed

9 files changed

+116
-1
lines changed

DQMServices/Components/plugins/DQMStoreStats.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,15 @@ int DQMStoreStats::calcstats(int mode = DQMStoreStats::considerAllME) {
668668
getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
669669
it->getNbinsX() * it->getNbinsY() * sizeof(int));
670670
break;
671+
// TH2Poly does not have GetArray() method
672+
//case MonitorElement::Kind::TH2Poly:
673+
// currentSubfolder.AddBinsD(
674+
// it->getNbinsX() * it->getNbinsY(),
675+
// getEmptyMetric(it->getTH2Poly()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0));
676+
// curr->update(it->getNbinsX() * it->getNbinsY(),
677+
// getEmptyMetric(it->getTH2Poly()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
678+
// it->getNbinsX() * it->getNbinsY() * sizeof(int));
679+
// break;
671680
case MonitorElement::Kind::TPROFILE2D:
672681
currentSubfolder.AddBinsD(
673682
it->getNbinsX() * it->getNbinsY(),

DQMServices/Components/plugins/EDMtoMEConverter.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class EDMtoMEConverter : public edm::one::EDProducer<edm::one::WatchRuns,
107107
Tokens<TH2S>,
108108
Tokens<TH2D>,
109109
Tokens<TH2I>,
110+
Tokens<TH2Poly>,
110111
Tokens<TH3F>,
111112
Tokens<TProfile>,
112113
Tokens<TProfile2D>,
@@ -235,6 +236,14 @@ namespace {
235236
}
236237
};
237238
template <>
239+
struct HistoTraits<TH2Poly> {
240+
static TH2Poly *get(MonitorElement *me) { return me->getTH2Poly(); }
241+
template <typename... Args>
242+
static MonitorElement *book(DQMStore::IBooker &iBooker, Args &&...args) {
243+
return iBooker.book2DPoly(std::forward<Args>(args)...);
244+
}
245+
};
246+
template <>
238247
struct HistoTraits<TH3F> {
239248
static TH3F *get(MonitorElement *me) { return me->getTH3F(); }
240249
template <typename... Args>

DQMServices/Components/plugins/MEtoEDMConverter.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "TH2S.h"
5151
#include "TH2D.h"
5252
#include "TH2I.h"
53+
#include "TH2Poly.h"
5354
#include "TH3F.h"
5455
#include "TProfile.h"
5556
#include "TProfile2D.h"
@@ -139,6 +140,7 @@ MEtoEDMConverter::MEtoEDMConverter(const edm::ParameterSet& iPSet) : fName(""),
139140
produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
140141
produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
141142
produces<MEtoEDM<TH2I>, edm::Transition::EndRun>(sName);
143+
produces<MEtoEDM<TH2Poly>, edm::Transition::EndRun>(sName);
142144
produces<MEtoEDM<TH3F>, edm::Transition::EndRun>(sName);
143145
produces<MEtoEDM<TProfile>, edm::Transition::EndRun>(sName);
144146
produces<MEtoEDM<TProfile2D>, edm::Transition::EndRun>(sName);
@@ -155,6 +157,7 @@ MEtoEDMConverter::MEtoEDMConverter(const edm::ParameterSet& iPSet) : fName(""),
155157
produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
156158
produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
157159
produces<MEtoEDM<TH2I>, edm::Transition::EndLuminosityBlock>(sName);
160+
produces<MEtoEDM<TH2Poly>, edm::Transition::EndLuminosityBlock>(sName);
158161
produces<MEtoEDM<TH3F>, edm::Transition::EndLuminosityBlock>(sName);
159162
produces<MEtoEDM<TProfile>, edm::Transition::EndLuminosityBlock>(sName);
160163
produces<MEtoEDM<TProfile2D>, edm::Transition::EndLuminosityBlock>(sName);
@@ -220,6 +223,7 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
220223
unsigned int n2S = 0;
221224
unsigned int n2D = 0;
222225
unsigned int n2I = 0;
226+
unsigned int n2P = 0;
223227
unsigned int n3F = 0;
224228
unsigned int nProf = 0;
225229
unsigned int nProf2 = 0;
@@ -282,6 +286,10 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
282286
++n2I;
283287
break;
284288

289+
case MonitorElement::Kind::TH2Poly:
290+
++n2P;
291+
break;
292+
285293
case MonitorElement::Kind::TH3F:
286294
++n3F;
287295
break;
@@ -313,6 +321,7 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
313321
std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
314322
std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
315323
std::unique_ptr<MEtoEDM<TH2I> > pOut2i(new MEtoEDM<TH2I>(n2I));
324+
std::unique_ptr<MEtoEDM<TH2Poly> > pOut2p(new MEtoEDM<TH2Poly>(n2P));
316325
std::unique_ptr<MEtoEDM<TH3F> > pOut3(new MEtoEDM<TH3F>(n3F));
317326
std::unique_ptr<MEtoEDM<TProfile> > pOutProf(new MEtoEDM<TProfile>(nProf));
318327
std::unique_ptr<MEtoEDM<TProfile2D> > pOutProf2(new MEtoEDM<TProfile2D>(nProf2));
@@ -371,6 +380,10 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
371380
pOut2i->putMEtoEdmObject(me->getFullname(), *me->getTH2I());
372381
break;
373382

383+
case MonitorElement::Kind::TH2Poly:
384+
pOut2p->putMEtoEdmObject(me->getFullname(), *me->getTH2Poly());
385+
break;
386+
374387
case MonitorElement::Kind::TH3F:
375388
pOut3->putMEtoEdmObject(me->getFullname(), *me->getTH3F());
376389
break;
@@ -411,6 +424,7 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
411424
iPutTo.put(std::move(pOut2s), sName);
412425
iPutTo.put(std::move(pOut2d), sName);
413426
iPutTo.put(std::move(pOut2i), sName);
427+
iPutTo.put(std::move(pOut2p), sName);
414428
iPutTo.put(std::move(pOut3), sName);
415429
iPutTo.put(std::move(pOutProf), sName);
416430
iPutTo.put(std::move(pOutProf2), sName);

DQMServices/Components/scripts/dqmiolistmes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"TProfiles",
4949
"TProfile2Ds",
5050
"TH1Is",
51-
"TH2Is"
51+
"TH2Is",
52+
"TH2Polys"
5253
]
5354
trees = [f[name]["FullName"].array() for name in treenames]
5455

DQMServices/Core/interface/DQMNet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class DQMNet {
3838
static const uint32_t DQM_PROP_TYPE_TH2S = 0x00000021;
3939
static const uint32_t DQM_PROP_TYPE_TH2D = 0x00000022;
4040
static const uint32_t DQM_PROP_TYPE_TH2I = 0x00000023;
41+
static const uint32_t DQM_PROP_TYPE_TH2Poly = 0x00000024;
4142
static const uint32_t DQM_PROP_TYPE_TH3F = 0x00000030;
4243
static const uint32_t DQM_PROP_TYPE_TH3S = 0x00000031;
4344
static const uint32_t DQM_PROP_TYPE_TH3D = 0x00000032;

DQMServices/Core/interface/DQMStore.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ namespace dqm {
274274
});
275275
}
276276
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
277+
MonitorElement* book2DPoly(TString const& name, TH2Poly* object, FUNC onbooking = NOOP()) {
278+
return bookME(
279+
name,
280+
MonitorElementData::Kind::TH2Poly,
281+
[=]() {
282+
auto th2 = static_cast<TH2Poly*>(object->Clone(name));
283+
onbooking(th2);
284+
return th2;
285+
},
286+
/* forceReplace */ true);
287+
}
288+
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
277289
MonitorElement* book2S(TString const& name,
278290
TString const& title,
279291
int nchX,

DQMServices/Core/src/DQMNet.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ DQMNet::reinstateObject(DQMStore *store, Object &o)
327327
obj = store->book2I(name, dynamic_cast<TH2I *>(o.object));
328328
break;
329329

330+
case DQM_PROP_TYPE_TH2Poly:
331+
obj = store->book2DPoly(name, dynamic_cast<TH2Poly *>(o.object));
332+
break;
333+
330334
case DQM_PROP_TYPE_TH3F:
331335
obj = store->book3D(name, dynamic_cast<TH3F *>(o.object));
332336
break;

DQMServices/Core/src/LegacyIOHelper.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ bool LegacyIOHelper::readdir(TDirectory *dir, const std::string &toppath) {
253253
getMEName<TH2I>(h, toppath, meName);
254254
data_.insert(dbe_->book2I(meName, h));
255255
}
256+
} else if (cl->InheritsFrom("TH2Poly")) {
257+
TH2Poly *h = dynamic_cast<TH2Poly *>(key->ReadObject<TH2Poly>()->Clone());
258+
h->SetDirectory(nullptr);
259+
if (h) {
260+
getMEName<TH2Poly>(h, toppath, meName);
261+
data_.insert(dbe_->book2DPoly(meName, h));
262+
}
256263
} else if (cl->InheritsFrom("TH3F")) {
257264
TH3F *h = dynamic_cast<TH3F *>(key->ReadObject<TH3F>()->Clone());
258265
h->SetDirectory(nullptr);

DataFormats/Histograms/interface/MEtoEDMFormat.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* \author M. Strang SUNY-Buffalo
1010
*/
1111

12+
#include <TClass.h>
1213
#include <TObject.h>
1314
#include <TH1F.h>
1415
#include <TH1S.h>
@@ -121,6 +122,15 @@ class MEtoEDM {
121122
if (MEtoEdmObject[j].object.Merge(&list) == -1) {
122123
std::cout << "ERROR MEtoEDM::mergeProducts(): merge failed for '" << name << "'" << std::endl;
123124
}
125+
// } else if (MEtoEdmObject[j].object.IsA()->InheritsFrom("TH2Poly")) {
126+
// // ad-hoc addition because no matching function for call to 'TH2Poly::Add(const TH2Poly*)'
127+
// int nbins = MEtoEdmObject[j].object.GetNcells() - 9;
128+
// for(int ibin=1; ibin<nbins+1; ++ibin) {
129+
// double value1 = MEtoEdmObject[j].object.GetBinContent(ibin);
130+
// double value2 = newMEtoEDMObject[i].object.GetBinContent(ibin);
131+
// double total = value1 + value2;
132+
// MEtoEdmObject[j].object.SetBinContent(ibin, total);
133+
// }
124134
} else {
125135
// this value is also in the new container: add the two
126136
if (MEtoEdmObject[j].object.GetNbinsX() == newMEtoEDMObject[i].object.GetNbinsX() &&
@@ -347,4 +357,52 @@ inline bool MEtoEDM<TString>::mergeProduct(const MEtoEDM<TString> &newMEtoEDM) {
347357
return true;
348358
}
349359

360+
template <>
361+
inline bool MEtoEDM<TH2Poly>::mergeProduct(const MEtoEDM<TH2Poly> &newMEtoEDM) {
362+
const MEtoEdmObjectVector &newMEtoEDMObject = newMEtoEDM.getMEtoEdmObject();
363+
const size_t nObjects = newMEtoEDMObject.size();
364+
// NOTE: we remember the present size since we will only add content
365+
// from newMEtoEDMObject after this point
366+
const size_t nOldObjects = MEtoEdmObject.size();
367+
368+
// if the old and new are not the same size, we want to report a problem
369+
if (nObjects != nOldObjects) {
370+
std::cout << "WARNING MEtoEDM::mergeProducts(): the lists of histograms to be merged have different sizes: new="
371+
<< nObjects << ", old=" << nOldObjects << std::endl;
372+
}
373+
374+
for (unsigned int i = 0; i < nObjects; ++i) {
375+
unsigned int j = 0;
376+
// see if the name is already in the old container up to the point where
377+
// we may have added new entries in the container
378+
const std::string &name = newMEtoEDMObject[i].name;
379+
if (i < nOldObjects && (MEtoEdmObject[i].name == name)) {
380+
j = i;
381+
} else {
382+
j = 0;
383+
while (j < nOldObjects && (MEtoEdmObject[j].name != name))
384+
++j;
385+
}
386+
if (j >= nOldObjects) {
387+
// this value is only in the new container, not the old one
388+
#if METOEDMFORMAT_DEBUG
389+
std::cout << "WARNING MEtoEDM::mergeProducts(): adding new histogram '" << name << "'" << std::endl;
390+
#endif
391+
MEtoEdmObject.emplace_back(std::move(newMEtoEDMObject[i]));
392+
} else if (MEtoEdmObject[j].object.IsA()->InheritsFrom("TH2Poly")) {
393+
//MEtoEdmObject[j].object.Add((TH1*)newMEtoEDMObject[i].object, 1);
394+
395+
// ad-hoc addition because no matching function for call to 'TH2Poly::Add(const TH2Poly*)'
396+
int nbins = MEtoEdmObject[j].object.GetNcells() - 9;
397+
for(int ibin=1; ibin<nbins+1; ++ibin) {
398+
double value1 = MEtoEdmObject[j].object.GetBinContent(ibin);
399+
double value2 = newMEtoEDMObject[i].object.GetBinContent(ibin);
400+
double total = value1 + value2;
401+
MEtoEdmObject[j].object.SetBinContent(ibin, total);
402+
}
403+
}
404+
}
405+
return true;
406+
}
407+
350408
#endif

0 commit comments

Comments
 (0)