Skip to content

Commit

Permalink
implemented support for TH1I in DQM
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Apr 29, 2022
1 parent 0fcca5b commit 9b600e7
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 36 deletions.
6 changes: 6 additions & 0 deletions DQMServices/Components/plugins/DQMStoreStats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ int DQMStoreStats::calcstats(int mode = DQMStoreStats::considerAllME) {
getEmptyMetric(it->getTH1D()->GetArray(), it->getTH1D()->fN, 0, 0),
it->getNbinsX() * sizeof(double));
break;
case MonitorElement::Kind::TH1I:
currentSubfolder.AddBinsI(it->getNbinsX(), getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0));
curr->update(it->getNbinsX(),
getEmptyMetric(it->getTH1I()->GetArray(), it->getTH1I()->fN, 0, 0),
it->getNbinsX() * sizeof(int));
break;
case MonitorElement::Kind::TPROFILE:
currentSubfolder.AddBinsD(it->getNbinsX(),
getEmptyMetric(it->getTProfile()->GetArray(), it->getTProfile()->fN, 0, 0));
Expand Down
8 changes: 8 additions & 0 deletions DQMServices/Components/plugins/EDMtoMEConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ namespace {
}
};
template <>
struct HistoTraits<TH1I> {
static TH1I *get(MonitorElement *me) { return me->getTH1I(); }
template <typename... Args>
static MonitorElement *book(DQMStore::IBooker &iBooker, Args &&...args) {
return iBooker.book1I(std::forward<Args>(args)...);
}
};
template <>
struct HistoTraits<TH2F> {
static TH2F *get(MonitorElement *me) { return me->getTH2F(); }
template <typename... Args>
Expand Down
1 change: 1 addition & 0 deletions DQMServices/Components/plugins/EDMtoMEConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class EDMtoMEConverter : public edm::one::EDProducer<edm::one::WatchRuns,
std::tuple<Tokens<TH1F>,
Tokens<TH1S>,
Tokens<TH1D>,
Tokens<TH1I>,
Tokens<TH2F>,
Tokens<TH2S>,
Tokens<TH2D>,
Expand Down
12 changes: 12 additions & 0 deletions DQMServices/Components/plugins/MEtoEDMConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ MEtoEDMConverter::MEtoEDMConverter(const edm::ParameterSet& iPSet) : fName(""),
produces<MEtoEDM<TH1F>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH1S>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH1D>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH1I>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH2F>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH2S>, edm::Transition::EndRun>(sName);
produces<MEtoEDM<TH2D>, edm::Transition::EndRun>(sName);
Expand All @@ -63,6 +64,7 @@ MEtoEDMConverter::MEtoEDMConverter(const edm::ParameterSet& iPSet) : fName(""),
produces<MEtoEDM<TH1F>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH1S>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH1D>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH1I>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH2F>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH2S>, edm::Transition::EndLuminosityBlock>(sName);
produces<MEtoEDM<TH2D>, edm::Transition::EndLuminosityBlock>(sName);
Expand Down Expand Up @@ -123,6 +125,7 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
unsigned int n1F = 0;
unsigned int n1S = 0;
unsigned int n1D = 0;
unsigned int n1I = 0;
unsigned int n2F = 0;
unsigned int n2S = 0;
unsigned int n2D = 0;
Expand Down Expand Up @@ -169,6 +172,10 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
++n1D;
break;

case MonitorElement::Kind::TH1I:
++n1I;
break;

case MonitorElement::Kind::TH2F:
++n2F;
break;
Expand Down Expand Up @@ -211,6 +218,7 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
std::unique_ptr<MEtoEDM<TH1F> > pOut1(new MEtoEDM<TH1F>(n1F));
std::unique_ptr<MEtoEDM<TH1S> > pOut1s(new MEtoEDM<TH1S>(n1S));
std::unique_ptr<MEtoEDM<TH1D> > pOut1d(new MEtoEDM<TH1D>(n1D));
std::unique_ptr<MEtoEDM<TH1I> > pOut1i(new MEtoEDM<TH1I>(n1I));
std::unique_ptr<MEtoEDM<TH2F> > pOut2(new MEtoEDM<TH2F>(n2F));
std::unique_ptr<MEtoEDM<TH2S> > pOut2s(new MEtoEDM<TH2S>(n2S));
std::unique_ptr<MEtoEDM<TH2D> > pOut2d(new MEtoEDM<TH2D>(n2D));
Expand Down Expand Up @@ -253,6 +261,10 @@ void MEtoEDMConverter::putData(DQMStore::IGetter& iGetter, T& iPutTo, bool iLumi
pOut1d->putMEtoEdmObject(me->getFullname(), *me->getTH1D());
break;

case MonitorElement::Kind::TH1I:
pOut1i->putMEtoEdmObject(me->getFullname(), *me->getTH1I());
break;

case MonitorElement::Kind::TH2F:
pOut2->putMEtoEdmObject(me->getFullname(), *me->getTH2F());
break;
Expand Down
1 change: 1 addition & 0 deletions DQMServices/Components/plugins/MEtoEDMConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "TH1F.h"
#include "TH1S.h"
#include "TH1D.h"
#include "TH1I.h"
#include "TH2F.h"
#include "TH2S.h"
#include "TH2D.h"
Expand Down
1 change: 1 addition & 0 deletions DQMServices/Components/scripts/dqmiolistmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"TH3Fs",
"TProfiles",
"TProfile2Ds",
"TH1Is",
"TH2Is"
]
trees = [f[name]["FullName"].array() for name in treenames]
Expand Down
2 changes: 1 addition & 1 deletion DQMServices/Components/test/test_reharvest_from_dqmio.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ DATASET=/SingleElectron/Run2017D-09Aug2019_UL2017-v1/DQMIO
WORKFLOW=136.834

# run cmsDriver to generate baseline harvesting config
$(runTheMatrix.py -l 136.834 -ne | fgrep 'HARVESTING:' | grep -o 'cmsDriver.*') --no_exec
$(runTheMatrix.py -l $WORKFLOW -ne | fgrep 'HARVESTING:' | grep -o 'cmsDriver.*') --no_exec
pythonname=$(echo step*_HARVESTING.py)

# copy data to local folder and add it to config
Expand Down
1 change: 1 addition & 0 deletions DQMServices/Core/interface/DQMNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DQMNet {
static const uint32_t DQM_PROP_TYPE_TH1F = 0x00000010;
static const uint32_t DQM_PROP_TYPE_TH1S = 0x00000011;
static const uint32_t DQM_PROP_TYPE_TH1D = 0x00000012;
static const uint32_t DQM_PROP_TYPE_TH1I = 0x00000013;
static const uint32_t DQM_PROP_TYPE_TH2F = 0x00000020;
static const uint32_t DQM_PROP_TYPE_TH2S = 0x00000021;
static const uint32_t DQM_PROP_TYPE_TH2D = 0x00000022;
Expand Down
39 changes: 35 additions & 4 deletions DQMServices/Core/interface/DQMStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,41 @@ namespace dqm {
/* forceReplace */ true);
}

template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book1I(TString const& name,
TString const& title,
int const nchX,
double const lowX,
double const highX,
FUNC onbooking = NOOP()) {
return bookME(name, MonitorElementData::Kind::TH1I, [=]() {
auto th1 = new TH1I(name, title, nchX, lowX, highX);
onbooking(th1);
return th1;
});
}
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book1I(
TString const& name, TString const& title, int nchX, float const* xbinsize, FUNC onbooking = NOOP()) {
return bookME(name, MonitorElementData::Kind::TH1I, [=]() {
auto th1 = new TH1I(name, title, nchX, xbinsize);
onbooking(th1);
return th1;
});
}
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book1I(TString const& name, TH1I* object, FUNC onbooking = NOOP()) {
return bookME(
name,
MonitorElementData::Kind::TH1I,
[=]() {
auto th1 = static_cast<TH1I*>(object->Clone(name));
onbooking(th1);
return th1;
},
/* forceReplace */ true);
}

template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book2D(TString const& name,
TString const& title,
Expand Down Expand Up @@ -257,8 +292,6 @@ namespace dqm {
},
/* forceReplace */ true);
}

// MM 23.04.22 add TH2I histograms
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book2I(TString const& name,
TString const& title,
Expand Down Expand Up @@ -301,8 +334,6 @@ namespace dqm {
},
/* forceReplace */ true);
}

// MM 23.04.2022 add TH2I histograms
template <typename FUNC = NOOP, std::enable_if_t<not std::is_arithmetic<FUNC>::value, int> = 0>
MonitorElement* book2DD(TString const& name,
TString const& title,
Expand Down
6 changes: 6 additions & 0 deletions DQMServices/Core/interface/MonitorElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "TH1F.h"
#include "TH1S.h"
#include "TH1D.h"
#include "TH1I.h"
#include "TH2F.h"
#include "TH2S.h"
#include "TH2I.h"
Expand Down Expand Up @@ -437,6 +438,7 @@ namespace dqm::impl {
virtual TH1F *getTH1F();
virtual TH1S *getTH1S();
virtual TH1D *getTH1D();
virtual TH1I *getTH1I();
virtual TH2F *getTH2F();
virtual TH2S *getTH2S();
virtual TH2I *getTH2I();
Expand Down Expand Up @@ -489,6 +491,10 @@ namespace dqm::legacy {
virtual TH1D *getTH1D() const {
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH1D();
};
using dqm::reco::MonitorElement::getTH1I;
virtual TH1I *getTH1I() const {
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH1I();
};
using dqm::reco::MonitorElement::getTH2F;
virtual TH2F *getTH2F() const {
return const_cast<dqm::legacy::MonitorElement *>(this)->dqm::reco::MonitorElement::getTH2F();
Expand Down
4 changes: 4 additions & 0 deletions DQMServices/Core/src/DQMNet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ DQMNet::reinstateObject(DQMStore *store, Object &o)
obj = store->book1DD(name, dynamic_cast<TH1D *>(o.object));
break;

case DQM_PROP_TYPE_TH1I:
obj = store->book1I(name, dynamic_cast<TH1I *>(o.object));
break;

case DQM_PROP_TYPE_TH2F:
obj = store->book2D(name, dynamic_cast<TH2F *>(o.object));
break;
Expand Down
7 changes: 7 additions & 0 deletions DQMServices/Core/src/LegacyIOHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ bool LegacyIOHelper::readdir(TDirectory *dir, const std::string &toppath) {
getMEName<TH1D>(h, toppath, meName);
data_.insert(dbe_->book1DD(meName, h));
}
} else if (cl->InheritsFrom("TH1I")) {
TH1I *h = dynamic_cast<TH1I *>(key->ReadObject<TH1I>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1I>(h, toppath, meName);
data_.insert(dbe_->book1I(meName, h));
}
} else if (cl->InheritsFrom("TH2F")) {
TH2F *h = dynamic_cast<TH2F *>(key->ReadObject<TH2F>()->Clone());
h->SetDirectory(nullptr);
Expand Down
12 changes: 11 additions & 1 deletion DQMServices/Core/src/MonitorElement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ namespace dqm::impl {
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, 1);
else if (kind() == Kind::TH1S)
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, 1);
else if (kind() == Kind::TH1I)
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, 1);
else if (kind() == Kind::TH1D)
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, 1);
else
Expand Down Expand Up @@ -229,6 +231,8 @@ namespace dqm::impl {
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, yw);
else if (kind() == Kind::TH1D)
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, yw);
else if (kind() == Kind::TH1I)
accessRootObject(access, __PRETTY_FUNCTION__, 1)->Fill(x, yw);
else if (kind() == Kind::TH2F)
static_cast<TH2F *>(accessRootObject(access, __PRETTY_FUNCTION__, 2))->Fill(x, yw, 1);
else if (kind() == Kind::TH2S)
Expand All @@ -250,7 +254,7 @@ namespace dqm::impl {
// TODO: this should take the lock only once to be actually safe.
// But since it is not const, we don't even claim it is thread-safe.
update();
if (kind() == Kind::TH1F || kind() == Kind::TH1S || kind() == Kind::TH1D) {
if (kind() == Kind::TH1F || kind() == Kind::TH1S || kind() == Kind::TH1D || kind() == Kind::TH1I) {
int nbins = getNbinsX();
auto entries = (int)getEntries();
// first fill bins from left to right
Expand Down Expand Up @@ -988,6 +992,12 @@ namespace dqm::impl {
return static_cast<TH1S *>(accessRootObject(access, __PRETTY_FUNCTION__, 1));
}

TH1I *MonitorElement::getTH1I() {
auto access = this->accessMut();
assert(kind() == Kind::TH1I);
return static_cast<TH1I *>(accessRootObject(access, __PRETTY_FUNCTION__, 1));
}

TH1D *MonitorElement::getTH1D() {
auto access = this->accessMut();
assert(kind() == Kind::TH1D);
Expand Down
6 changes: 4 additions & 2 deletions DQMServices/Demo/test/TestDQMEDAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ class BookerFiller {
mes_1D.push_back(ibooker.bookInt("int" + num));
mes_1D.push_back(ibooker.book1D("th1f" + num, "1D Float Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1S("th1s" + num, "1D Short Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1I("th1i" + num, "1D Integer Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1DD("th1d" + num, "1D Double Histogram " + num, 101, -0.5, 100.5));

mes_2D.push_back(ibooker.book2D("th2f" + num, "2D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2S("th2s" + num, "2D Short Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2DD("th2d" + num, "2D Double Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Int Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Integer Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(
ibooker.bookProfile("tprofile" + num, "1D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));

Expand All @@ -50,12 +51,13 @@ class BookerFiller {
mes_1D.push_back(ibooker.bookInt("int" + num));
mes_1D.push_back(ibooker.book1D("th1f" + num, "1D Float Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1S("th1s" + num, "1D Short Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1I("th1i" + num, "1D Integer Histogram " + num, 101, -0.5, 100.5));
mes_1D.push_back(ibooker.book1DD("th1d" + num, "1D Double Histogram " + num, 101, -0.5, 100.5));

mes_2D.push_back(ibooker.book2D("th2f" + num, "2D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2S("th2s" + num, "2D Short Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2DD("th2d" + num, "2D Double Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Int Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Integer Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
mes_2D.push_back(
ibooker.bookProfile("tprofile" + num, "1D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));

Expand Down
3 changes: 2 additions & 1 deletion DQMServices/Demo/test/dqmiodumpentries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
9: "TH3Fs",
10: "TProfiles",
11: "TProfile2Ds",
12: "TH2Is",
12: "TH1Is",
13: "TH2Is"
}

f = ROOT.TFile.Open(args.inputfile)
Expand Down
Loading

0 comments on commit 9b600e7

Please sign in to comment.