#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <stdlib.h>
#include <string.h>
#include "TTree.h"
#include "TString.h"
#include "TH1.h"
#include "RooCategory.h"
#include "RooArgSet.h"
#include "RooStreamParser.h"
ClassImp(RooCategory)
;
RooSharedPropertiesList RooCategory::_sharedPropList ;
RooCategory::RooCategory()
{
}
RooCategory::RooCategory(const char *name, const char *title) :
RooAbsCategoryLValue(name,title)
{
_sharedProp = (RooCategorySharedProperties*) _sharedPropList.registerProperties(new RooCategorySharedProperties()) ;
setValueDirty() ;
setShapeDirty() ;
}
RooCategory::RooCategory(const RooCategory& other, const char* name) :
RooAbsCategoryLValue(other, name)
{
_sharedProp = (RooCategorySharedProperties*) _sharedPropList.registerProperties(other._sharedProp) ;
}
RooCategory::~RooCategory()
{
_sharedPropList.unregisterProperties(_sharedProp) ;
}
Bool_t RooCategory::setIndex(Int_t index, Bool_t printError)
{
const RooCatType* type = lookupType(index,printError) ;
if (!type) return kTRUE ;
_value = *type ;
setValueDirty() ;
return kFALSE ;
}
Bool_t RooCategory::setLabel(const char* label, Bool_t printError)
{
const RooCatType* type = lookupType(label,printError) ;
if (!type) return kTRUE ;
_value = *type ;
setValueDirty() ;
return kFALSE ;
}
Bool_t RooCategory::defineType(const char* label)
{
if (TString(label).Contains(";")) {
cout << "RooCategory::defineType(" << GetName()
<< "): semicolons not allowed in label name" << endl ;
return kTRUE ;
}
return RooAbsCategory::defineType(label)?kFALSE:kTRUE ;
}
Bool_t RooCategory::defineType(const char* label, Int_t index)
{
if (TString(label).Contains(";")) {
cout << "RooCategory::defineType(" << GetName()
<< "): semicolons not allowed in label name" << endl ;
return kTRUE ;
}
return RooAbsCategory::defineType(label,index)?kFALSE:kTRUE ;
}
Bool_t RooCategory::readFromStream(istream& is, Bool_t , Bool_t verbose)
{
RooStreamParser parser(is) ;
TString token = parser.readToken() ;
return setLabel(token,verbose) ;
}
void RooCategory::writeToStream(ostream& os, Bool_t compact) const
{
if (compact) {
os << getIndex() ;
} else {
os << getLabel() ;
}
}
void RooCategory::clearRange(const char* name, Bool_t silent)
{
if (!name) {
cout << "RooCategory::clearRange(" << GetName() << ") ERROR: must specificy valid range name" << endl ;
return ;
}
TList* rangeNameList = static_cast<TList*>(_sharedProp->_altRanges.FindObject(name)) ;
if (rangeNameList) {
rangeNameList->Clear() ;
} else if (!silent) {
cout << "RooCategory::clearRange(" << GetName() << ") ERROR: range '" << name << "' does not exist" << endl ;
}
}
void RooCategory::setRange(const char* name, const char* stateNameList)
{
clearRange(name,kTRUE) ;
addToRange(name,stateNameList) ;
}
void RooCategory::addToRange(const char* name, const char* stateNameList)
{
if (!name || !stateNameList) {
cout << "RooCategory::setRange(" << GetName() << ") ERROR: must specificy valid name and state name list" << endl ;
return ;
}
TList* rangeNameList = static_cast<TList*>(_sharedProp->_altRanges.FindObject(name)) ;
if (!rangeNameList) {
cout << "RooCategory::setRange(" << GetName()
<< ") new range named '" << name << "' created with state list " << stateNameList << endl ;
rangeNameList = new TList ;
rangeNameList->SetName(name) ;
_sharedProp->_altRanges.Add(rangeNameList) ;
}
char* buf = new char[strlen(stateNameList)+1] ;
strcpy(buf,stateNameList) ;
char* token = strtok(buf,",") ;
while(token) {
const RooCatType* state = lookupType(token,kFALSE) ;
if (state && !rangeNameList->FindObject(token)) {
rangeNameList->Add(const_cast<RooCatType*>(state)) ;
} else {
cout << "RooCategory::setRange(" << GetName() << ") WARNING: Ignoring invalid state name '"
<< token << "' in state name list" << endl ;
}
token = strtok(0,",") ;
}
delete[] buf ;
}
Bool_t RooCategory::isStateInRange(const char* rangeName, const char* stateName) const
{
if (!rangeName||!stateName) {
cout << "RooCategory::isStateInRange(" << GetName() << ") ERROR: must specificy valid range name and state name" << endl ;
return kFALSE ;
}
TList* rangeNameList = static_cast<TList*>(_sharedProp->_altRanges.FindObject(rangeName)) ;
if (rangeNameList) {
return rangeNameList->FindObject(stateName) ? kTRUE : kFALSE ;
}
return kTRUE ;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.