Skip to content

Commit 4eeb0e8

Browse files
authored
Merge pull request #47478 from ywkao/th2poly-getarray-implementation
Implement TH2Poly in DQM Services and add GetArray support
2 parents cbbd269 + 63ce864 commit 4eeb0e8

File tree

21 files changed

+310
-69
lines changed

21 files changed

+310
-69
lines changed

DQMServices/Components/plugins/DQMStoreStats.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class DQMStoreStats : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one:
338338

339339
private:
340340
int calcstats(int);
341+
std::vector<double> GetTH2PolyArray(TH2Poly* poly);
341342
void calcIgProfDump(Folder&);
342343
void dumpMemoryProfile();
343344
std::pair<unsigned int, unsigned int> readMemoryEntry() const;
@@ -514,6 +515,15 @@ void DQMStoreStats::calcIgProfDump(Folder& root) {
514515
stream << sql_statement << std::endl;
515516
}
516517

518+
std::vector<double> DQMStoreStats::GetTH2PolyArray(TH2Poly* poly) {
519+
int nBins = poly->GetNumberOfBins();
520+
std::vector<double> array(nBins + 1, 0.0); // Initialize with zeros
521+
for (int i = 1; i <= nBins; i++) {
522+
array[i] = poly->GetBinContent(i);
523+
}
524+
return array;
525+
}
526+
517527
///
518528
/// do the stats here and produce output;
519529
///
@@ -668,6 +678,13 @@ int DQMStoreStats::calcstats(int mode = DQMStoreStats::considerAllME) {
668678
getEmptyMetric(it->getTH2I()->GetArray(), it->getNbinsX() + 2, it->getNbinsY() + 2, 0),
669679
it->getNbinsX() * it->getNbinsY() * sizeof(int));
670680
break;
681+
case MonitorElement::Kind::TH2Poly: {
682+
std::vector<double> polyArray = GetTH2PolyArray(it->getTH2Poly());
683+
int nBins = polyArray.size() - 1;
684+
currentSubfolder.AddBinsD(nBins, getEmptyMetric(polyArray.data(), nBins + 1, 1, 0));
685+
curr->update(nBins, getEmptyMetric(polyArray.data(), nBins + 1, 1, 0), nBins * sizeof(double));
686+
break;
687+
}
671688
case MonitorElement::Kind::TPROFILE2D:
672689
currentSubfolder.AddBinsD(
673690
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"TH2Fs",
4545
"TH2Ss",
4646
"TH2Ds",
47+
"TH2Polys",
4748
"TH3Fs",
4849
"TProfiles",
4950
"TProfile2Ds",

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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace dqm {
3636
virtual ~NavigatorBase() {}
3737

3838
protected:
39-
NavigatorBase(){};
39+
NavigatorBase() {};
4040
std::string cwd_ = "";
4141
};
4242

@@ -260,6 +260,32 @@ namespace dqm {
260260
/* forceReplace */ true);
261261
}
262262
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
263+
MonitorElement* book2DPoly(TString const& name,
264+
TString const& title,
265+
double lowX,
266+
double highX,
267+
double lowY,
268+
double highY,
269+
FUNC onbooking = NOOP()) {
270+
return bookME(name, MonitorElementData::Kind::TH2Poly, [=]() {
271+
auto th2poly = new TH2Poly(name, title, lowX, highX, lowY, highY);
272+
onbooking(th2poly);
273+
return th2poly;
274+
});
275+
}
276+
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>
263289
MonitorElement* book2S(TString const& name,
264290
TString const& title,
265291
int nchX,

DQMServices/Core/interface/MonitorElement.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
#include "TH2S.h"
2222
#include "TH2I.h"
2323
#include "TH2D.h"
24+
#include "TH2Poly.h"
2425
#include "TH3F.h"
2526
#include "TProfile.h"
2627
#include "TProfile2D.h"
2728
#include "TObjString.h"
2829
#include "TAxis.h"
30+
#include "TGraph.h"
2931

3032
#include <mutex>
3133
#include <memory>
@@ -55,7 +57,7 @@ namespace dqm {
5557
static const int STATUS_OK = 100; //< Test was succesful.
5658
static const int WARNING = 200; //< Test had some problems.
5759
static const int ERROR = 300; //< Test has failed.
58-
} // namespace qstatus
60+
} // namespace qstatus
5961

6062
namespace me_util {
6163
using Channel = DQMChannel;
@@ -374,6 +376,7 @@ namespace dqm::impl {
374376
virtual int getNbinsY() const;
375377
virtual int getNbinsZ() const;
376378
virtual int getBin(int binx, int biny) const;
379+
virtual int getNcells() const;
377380
virtual std::string getAxisTitle(int axis = 1) const;
378381
virtual std::string getTitle() const;
379382

@@ -398,6 +401,9 @@ namespace dqm::impl {
398401
virtual const std::string &getStringValue() const;
399402

400403
// non-const -- thread safety and semantical issues
404+
virtual void addBin(TGraph *graph);
405+
virtual void addBin(int n, const double *x, const double *y);
406+
virtual void addBin(double x1, double y1, double x2, double y2);
401407
virtual void setBinContent(int binx, double content);
402408
virtual void setBinContent(int binx, int biny, double content);
403409
virtual void setBinContent(int binx, int biny, int binz, double content);
@@ -443,6 +449,7 @@ namespace dqm::impl {
443449
virtual TH2S *getTH2S();
444450
virtual TH2I *getTH2I();
445451
virtual TH2D *getTH2D();
452+
virtual TH2Poly *getTH2Poly();
446453
virtual TH3F *getTH3F();
447454
virtual TProfile *getTProfile();
448455
virtual TProfile2D *getTProfile2D();
@@ -511,6 +518,10 @@ namespace dqm::legacy {
511518
virtual TH2D *getTH2D() const {
512519
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH2D();
513520
};
521+
using dqm::reco::MonitorElement::getTH2Poly;
522+
virtual TH2Poly *getTH2Poly() const {
523+
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH2Poly();
524+
};
514525
using dqm::reco::MonitorElement::getTH3F;
515526
virtual TH3F *getTH3F() const {
516527
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH3F();

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);

0 commit comments

Comments
 (0)