43 ClassImp(RooCategory);
46 RooSharedPropertiesList RooCategory::_sharedPropList ;
47 RooCategorySharedProperties RooCategory::_nullProp(
"00000000-0000-0000-0000-000000000000") ;
51 RooCategory::RooCategory() : _sharedProp(0)
61 RooCategory::RooCategory(
const char *name,
const char *title) :
62 RooAbsCategoryLValue(name,title)
64 _sharedProp = (RooCategorySharedProperties*) _sharedPropList.registerProperties(
new RooCategorySharedProperties()) ;
76 RooCategory::RooCategory(
const RooCategory& other,
const char* name) :
77 RooAbsCategoryLValue(other, name)
79 _sharedProp = (RooCategorySharedProperties*) _sharedPropList.registerProperties(other._sharedProp) ;
88 RooCategory::~RooCategory()
90 _sharedPropList.unregisterProperties(_sharedProp) ;
102 Bool_t RooCategory::setIndex(Int_t index, Bool_t printError)
104 const RooCatType* type = lookupType(index,printError) ;
105 if (!type)
return kTRUE ;
118 Bool_t RooCategory::setLabel(
const char* label, Bool_t printError)
120 const RooCatType* type = lookupType(label,printError) ;
121 if (!type)
return kTRUE ;
136 Bool_t RooCategory::defineType(
const char* label)
138 if (TString(label).Contains(
";")) {
139 coutE(InputArguments) <<
"RooCategory::defineType(" << GetName()
140 <<
"): semicolons not allowed in label name" << endl ;
144 return RooAbsCategory::defineType(label)?kFALSE:kTRUE ;
154 Bool_t RooCategory::defineType(
const char* label, Int_t index)
156 if (TString(label).Contains(
";")) {
157 coutE(InputArguments) <<
"RooCategory::defineType(" << GetName()
158 <<
"): semicolons not allowed in label name" << endl ;
162 return RooAbsCategory::defineType(label,index)?kFALSE:kTRUE ;
169 Bool_t RooCategory::readFromStream(istream& is, Bool_t , Bool_t verbose)
172 RooStreamParser parser(is) ;
173 TString token = parser.readToken() ;
175 return setLabel(token,verbose) ;
183 void RooCategory::writeToStream(ostream& os, Bool_t compact)
const
196 void RooCategory::clearRange(
const char* name, Bool_t silent)
199 coutE(InputArguments) <<
"RooCategory::clearRange(" << GetName() <<
") ERROR: must specificy valid range name" << endl ;
204 TList* rangeNameList =
static_cast<TList*
>(_sharedProp->_altRanges.FindObject(name)) ;
208 rangeNameList->Clear() ;
209 }
else if (!silent) {
210 coutE(InputArguments) <<
"RooCategory::clearRange(" << GetName() <<
") ERROR: range '" << name <<
"' does not exist" << endl ;
217 void RooCategory::setRange(
const char* name,
const char* stateNameList)
219 clearRange(name,kTRUE) ;
220 addToRange(name,stateNameList) ;
228 void RooCategory::addToRange(
const char* name,
const char* stateNameList)
230 if (!name || !stateNameList) {
231 coutE(InputArguments) <<
"RooCategory::setRange(" << GetName() <<
") ERROR: must specificy valid name and state name list" << endl ;
236 TList* rangeNameList =
static_cast<TList*
>(_sharedProp->_altRanges.FindObject(name)) ;
239 if (!rangeNameList) {
240 coutI(Contents) <<
"RooCategory::setRange(" << GetName()
241 <<
") new range named '" << name <<
"' created with state list " << stateNameList << endl ;
243 rangeNameList =
new TList ;
244 rangeNameList->SetOwner(kTRUE) ;
245 rangeNameList->SetName(name) ;
246 _sharedProp->_altRanges.Add(rangeNameList) ;
250 const size_t bufSize = strlen(stateNameList)+1;
251 char* buf =
new char[bufSize] ;
252 strlcpy(buf,stateNameList,bufSize) ;
253 char* token = strtok(buf,
",") ;
255 const RooCatType* state = lookupType(token,kFALSE) ;
256 if (state && !rangeNameList->FindObject(token)) {
257 rangeNameList->Add(
new RooCatType(*state)) ;
259 coutW(InputArguments) <<
"RooCategory::setRange(" << GetName() <<
") WARNING: Ignoring invalid state name '"
260 << token <<
"' in state name list" << endl ;
262 token = strtok(0,
",") ;
273 Bool_t RooCategory::isStateInRange(
const char* rangeName,
const char* stateName)
const
281 coutE(InputArguments) <<
"RooCategory::isStateInRange(" << GetName() <<
") ERROR: must specificy valid state name" << endl ;
287 TList* rangeNameList =
static_cast<TList*
>(_sharedProp->_altRanges.FindObject(rangeName)) ;
291 return rangeNameList->FindObject(stateName) ? kTRUE : kFALSE ;
302 void RooCategory::Streamer(TBuffer &R__b)
305 if (R__b.IsReading()) {
307 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v) { }
308 RooAbsCategoryLValue::Streamer(R__b);
313 RooCategorySharedProperties* tmpSharedProp =
new RooCategorySharedProperties() ;
314 tmpSharedProp->Streamer(R__b) ;
315 if (!(_nullProp==*tmpSharedProp)) {
316 _sharedProp = (RooCategorySharedProperties*) _sharedPropList.registerProperties(tmpSharedProp,kFALSE) ;
318 delete tmpSharedProp ;
323 R__b.CheckByteCount(R__s, R__c, RooCategory::IsA());
327 R__c = R__b.WriteVersion(RooCategory::IsA(), kTRUE);
328 RooAbsCategoryLValue::Streamer(R__b);
330 _sharedProp->Streamer(R__b) ;
332 _nullProp.Streamer(R__b) ;
334 R__b.SetByteCount(R__c, kTRUE);