Skip to content

Commit

Permalink
[RF] Fix invalid static_cast in RooTreeDataStore::loadValues
Browse files Browse the repository at this point in the history
In the logging for out-of-range values in `RooTreeDataStore::loadValues`,
there was `static_cast<RooAbsReal*>(arg)->getVal()` called also for
categories, which is invalid.

This led to garbage numbers as here in the tutorial outputs:
https://root.cern/doc/v624/rf401__importttreethx_8C.html
(see the lines with `Skipping event #2 because i cannot accommodate the value`)
  • Loading branch information
guitargeek committed Oct 11, 2022
1 parent dfdbe42 commit 0985e6f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions roofit/roofitcore/src/RooTreeDataStore.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,15 @@ void RooTreeDataStore::loadValues(const TTree *t, const RooFormulaVar* select, c
numInvalid++ ;
allOK=kFALSE ;
if (numInvalid < 5) {
coutI(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping event #" << i << " because " << destArg->GetName()
<< " cannot accommodate the value " << static_cast<RooAbsReal*>(sourceArg)->getVal() << std::endl;
auto& log = coutI(DataHandling);
log << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping event #" << i << " because " << destArg->GetName()
<< " cannot accommodate the value ";
if(sourceArg->isCategory()) {
log << static_cast<RooAbsCategory*>(sourceArg)->getCurrentIndex();
} else {
log << static_cast<RooAbsReal*>(sourceArg)->getVal();
}
log << std::endl;
} else if (numInvalid == 5) {
coutI(DataHandling) << "RooTreeDataStore::loadValues(" << GetName() << ") Skipping ..." << std::endl;
}
Expand Down

0 comments on commit 0985e6f

Please sign in to comment.