Skip to content

Commit 7755770

Browse files
committed
Fix MonitorElement::getNcells() dimension handling
- Add proper dimension checks based on histogram type (TH1/TH2/TH3) - Match dimension handling pattern used in MonitorElement::Reset() method - Fix FastTimerService fatal error related to incorrect dimension access
1 parent c0af007 commit 7755770

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

DQMServices/Core/src/MonitorElement.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,34 @@ namespace dqm::impl {
673673
// Returns number of cells (9 indicates empty TH2Poly without user-defined bins)
674674
int MonitorElement::getNcells() const {
675675
auto access = this->access();
676-
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
676+
if (kind() == Kind::TH1F)
677+
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
678+
else if (kind() == Kind::TH1S)
679+
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
680+
else if (kind() == Kind::TH1D)
681+
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
682+
else if (kind() == Kind::TH1I)
683+
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
684+
else if (kind() == Kind::TPROFILE)
685+
return accessRootObject(access, __PRETTY_FUNCTION__, 1)->GetNcells();
686+
else if (kind() == Kind::TH2F)
687+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
688+
else if (kind() == Kind::TH2S)
689+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
690+
else if (kind() == Kind::TH2D)
691+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
692+
else if (kind() == Kind::TH2I)
693+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
694+
else if (kind() == Kind::TH2Poly)
695+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
696+
else if (kind() == Kind::TPROFILE2D)
697+
return accessRootObject(access, __PRETTY_FUNCTION__, 2)->GetNcells();
698+
else if (kind() == Kind::TH3F)
699+
return accessRootObject(access, __PRETTY_FUNCTION__, 3)->GetNcells();
700+
else {
701+
incompatible(__PRETTY_FUNCTION__);
702+
return 0;
703+
}
677704
}
678705

679706
/// get # of bin entries (for profiles)

0 commit comments

Comments
 (0)