Skip to content

Commit

Permalink
Merge pull request #4771 from deguio/fixBinLabelsDQMStore_72X
Browse files Browse the repository at this point in the history
DQMServices -- move checkBinLabel as a static function in MonitorElement and use it fro...
  • Loading branch information
nclopezo committed Jul 28, 2014
2 parents 49d68b6 + 3ff2524 commit 35afc75
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
3 changes: 3 additions & 0 deletions DQMServices/Core/interface/MonitorElement.h
Expand Up @@ -96,6 +96,9 @@ class MonitorElement
return DQMNet::setOrder(data_, x.data_);
}

/// Check the consistency of the axis labels
static bool CheckBinLabels(const TAxis* a1, const TAxis * a2);

/// Get the type of the monitor element.
Kind kind(void) const
{ return Kind(data_.flags & DQMNet::DQM_PROP_TYPE_MASK); }
Expand Down
5 changes: 4 additions & 1 deletion DQMServices/Core/src/DQMStore.cc
Expand Up @@ -1489,7 +1489,10 @@ DQMStore::checkBinningMatches(MonitorElement *me, TH1 *h)
|| me->getTH1()->GetZaxis()->GetXmin() != h->GetZaxis()->GetXmin()
|| me->getTH1()->GetXaxis()->GetXmax() != h->GetXaxis()->GetXmax()
|| me->getTH1()->GetYaxis()->GetXmax() != h->GetYaxis()->GetXmax()
|| me->getTH1()->GetZaxis()->GetXmax() != h->GetZaxis()->GetXmax())
|| me->getTH1()->GetZaxis()->GetXmax() != h->GetZaxis()->GetXmax()
|| !MonitorElement::CheckBinLabels((TAxis*)me->getTH1()->GetXaxis(),(TAxis*)h->GetXaxis())
|| !MonitorElement::CheckBinLabels((TAxis*)me->getTH1()->GetYaxis(),(TAxis*)h->GetYaxis())
|| !MonitorElement::CheckBinLabels((TAxis*)me->getTH1()->GetZaxis(),(TAxis*)h->GetZaxis()) )
{
// edm::LogWarning ("DQMStore")
std::cout << "*** DQMStore: WARNING:"
Expand Down
29 changes: 29 additions & 0 deletions DQMServices/Core/src/MonitorElement.cc
Expand Up @@ -6,6 +6,7 @@
#include "TClass.h"
#include "TMath.h"
#include "TList.h"
#include "THashList.h"
#include <iostream>
#include <cassert>
#include <cfloat>
Expand Down Expand Up @@ -228,6 +229,34 @@ MonitorElement::~MonitorElement(void)
delete refvalue_;
}

//utility function to check the consistency of the axis labels
//taken from TH1::CheckBinLabels which is not public
bool
MonitorElement::CheckBinLabels(const TAxis* a1, const TAxis * a2)
{
// check that axis have same labels
THashList *l1 = (const_cast<TAxis*>(a1))->GetLabels();
THashList *l2 = (const_cast<TAxis*>(a2))->GetLabels();

if (!l1 && !l2 )
return true;
if (!l1 || !l2 ) {
return false;
}
// check now labels sizes are the same
if (l1->GetSize() != l2->GetSize() ) {
return false;
}
for (int i = 1; i <= a1->GetNbins(); ++i) {
TString label1 = a1->GetBinLabel(i);
TString label2 = a2->GetBinLabel(i);
if (label1 != label2) {
return false;
}
}
return true;
}

/// "Fill" ME methods for string
void
MonitorElement::Fill(std::string &value)
Expand Down
34 changes: 3 additions & 31 deletions DQMServices/FwkIO/plugins/DQMRootSource.cc
Expand Up @@ -20,7 +20,6 @@
#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "THashList.h"
#include "TH1.h"
#include "TH2.h"
#include "TProfile.h"
Expand Down Expand Up @@ -66,33 +65,6 @@
#include "format.h"

namespace {
//utility function to check the consistency of the axis labels
//taken from TH1::CheckBinLabels
bool CheckBinLabels(const TAxis* a1, const TAxis * a2)
{
// check that axis have same labels
THashList *l1 = (const_cast<TAxis*>(a1))->GetLabels();
THashList *l2 = (const_cast<TAxis*>(a2))->GetLabels();

if (!l1 && !l2 )
return true;
if (!l1 || !l2 ) {
return false;
}
// check now labels sizes are the same
if (l1->GetSize() != l2->GetSize() ) {
return false;
}
for (int i = 1; i <= a1->GetNbins(); ++i) {
TString label1 = a1->GetBinLabel(i);
TString label2 = a2->GetBinLabel(i);
if (label1 != label2) {
return false;
}
}
return true;
}

//adapter functions
MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1F* iHist) {
//std::cout <<"create: hist size "<<iName <<" "<<iHist->GetEffectiveEntries()<<std::endl;
Expand All @@ -116,9 +88,9 @@ namespace {
iOriginal->GetNbinsZ() == iToAdd->GetNbinsZ() &&
iOriginal->GetZaxis()->GetXmin() == iToAdd->GetZaxis()->GetXmin() &&
iOriginal->GetZaxis()->GetXmax() == iToAdd->GetZaxis()->GetXmax() &&
CheckBinLabels(iOriginal->GetXaxis(),iToAdd->GetXaxis()) &&
CheckBinLabels(iOriginal->GetYaxis(),iToAdd->GetYaxis()) &&
CheckBinLabels(iOriginal->GetZaxis(),iToAdd->GetZaxis())) {
MonitorElement::CheckBinLabels(iOriginal->GetXaxis(),iToAdd->GetXaxis()) &&
MonitorElement::CheckBinLabels(iOriginal->GetYaxis(),iToAdd->GetYaxis()) &&
MonitorElement::CheckBinLabels(iOriginal->GetZaxis(),iToAdd->GetZaxis())) {
iOriginal->Add(iToAdd);
} else {
edm::LogError("MergeFailure")<<"Found histograms with different axis limits or different labels'"<<iOriginal->GetName()<<"' not merged.";
Expand Down

0 comments on commit 35afc75

Please sign in to comment.