Skip to content
Merged
Prev Previous commit
[RF] Reduce uses of RooAbsCategory::lookupType().
The deprecated RooAbsCategory::lookupType() is sometimes used to check
if a string label refers to a valid category state.
It returns a pointer to the deprecated RooCatType, but often, the
pointer was only checked if it's nullptr. These instances have been
replaced with RooAbsCategory::hasLabel().
  • Loading branch information
hageboeck committed May 5, 2020
commit 6c66dd6538913c31508790b6188af4f3a45970c8
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooAbsCategory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void RooAbsCategory::clearTypes()

////////////////////////////////////////////////////////////////////////////////
/// Find the index number corresponding to the state name.
/// \see isValidLabel() for checking if a given label has been defined.
/// \see hasLabel() for checking if a given label has been defined.
/// \return Index of the category or std::numeric_limits<int>::min() on failure.
RooAbsCategory::value_type RooAbsCategory::lookupIndex(const std::string& stateName) const {
const auto item = stateNames().find(stateName);
Expand Down
16 changes: 8 additions & 8 deletions roofit/roofitcore/src/RooDataSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var
}
for (map<string,RooAbsData*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
// Define state labels in index category (both in provided indexCat and in internal copy in dataset)
if (indexCat && !indexCat->lookupType(hiter->first.c_str())) {
if (indexCat && !indexCat->hasLabel(hiter->first)) {
indexCat->defineType(hiter->first) ;
coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
}
if (icat && !icat->lookupType(hiter->first.c_str())) {
if (icat && !icat->hasLabel(hiter->first)) {
icat->defineType(hiter->first) ;
}
icat->setLabel(hiter->first.c_str()) ;
Expand Down Expand Up @@ -431,11 +431,11 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var
RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
// Define state labels in index category (both in provided indexCat and in internal copy in dataset)
if (!indexCat->lookupType(hiter->first.c_str())) {
if (!indexCat->hasLabel(hiter->first)) {
indexCat->defineType(hiter->first) ;
coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
}
if (!icat->lookupType(hiter->first.c_str())) {
if (!icat->hasLabel(hiter->first)) {
icat->defineType(hiter->first) ;
}
icat->setLabel(hiter->first.c_str()) ;
Expand Down Expand Up @@ -495,11 +495,11 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var
RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
// Define state labels in index category (both in provided indexCat and in internal copy in dataset)
if (!indexCat->lookupType(hiter->first.c_str())) {
if (!indexCat->hasLabel(hiter->first)) {
indexCat->defineType(hiter->first) ;
coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
}
if (!icat->lookupType(hiter->first.c_str())) {
if (!icat->hasLabel(hiter->first)) {
icat->defineType(hiter->first) ;
}
icat->setLabel(hiter->first.c_str()) ;
Expand Down Expand Up @@ -550,11 +550,11 @@ RooDataSet::RooDataSet(const char* name, const char* title, const RooArgSet& var
RooCategory* icat = (RooCategory*) _vars.find(indexCat->GetName()) ;
for (map<string,RooDataSet*>::iterator hiter = hmap.begin() ; hiter!=hmap.end() ; ++hiter) {
// Define state labels in index category (both in provided indexCat and in internal copy in dataset)
if (!indexCat->lookupType(hiter->first.c_str())) {
if (!indexCat->hasLabel(hiter->first)) {
indexCat->defineType(hiter->first) ;
coutI(InputArguments) << "RooDataSet::ctor(" << GetName() << ") defining state \"" << hiter->first << "\" in index category " << indexCat->GetName() << endl ;
}
if (!icat->lookupType(hiter->first.c_str())) {
if (!icat->hasLabel(hiter->first)) {
icat->defineType(hiter->first) ;
}
icat->setLabel(hiter->first.c_str()) ;
Expand Down
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooSimPdfBuilder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ RooSimultaneous* RooSimPdfBuilder::buildPdf(const RooArgSet& buildConfig, const

// If fractional split is specified, check that remainder state is a valid state of this split cat
if (remainderState) {
if (!splitCat->lookupType(remainderState)) {
if (!splitCat->hasLabel(remainderState)) {
coutE(InputArguments) << "RooSimPdfBuilder::buildPdf: ERROR fraction split of parameter "
<< paramName << " has invalid remainder state name: " << remainderState << endl ;
delete paramList ;
Expand Down
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooSimWSTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ RooSimultaneous* RooSimWSTool::executeBuild(const char* simPdfName, ObjBuildConf
if(splitIter->second.second.size()>0) {

// Check that specified split name is in fact valid
if (!splitCat->lookupType(splitIter->second.second.c_str())) {
if (!splitCat->hasLabel(splitIter->second.second)) {
coutE(InputArguments) << "RooSimWSTool::executeBuild(" << GetName() << ") ERROR: name of remainder state for constrained split, '"
<< splitIter->second.second << "' , does not match any state name of (composite) split category " << splitCat->GetName() << endl ;
return 0 ;
Expand Down