143 _ranges(other._ranges)
169 coutE(InputArguments) <<
"RooCategory: Trying to set invalid state " << index <<
" for category " <<
GetName() << std::endl;
197 coutE(InputArguments) <<
"Trying to set invalid state label '" << label <<
"' for category " <<
GetName() << std::endl;
212 if (label.find(
';') != std::string::npos) {
213 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
214 <<
"): semicolons not allowed in label name" << endl ;
228 if (label.find(
';') != std::string::npos) {
229 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
230 <<
"): semicolons not allowed in label name" << endl ;
246 for (
const auto& nameAndIdx : allowedStates) {
247 defineType(nameAndIdx.first, nameAndIdx.second);
324 std::map<std::string, std::vector<value_type>>::iterator item =
_ranges->find(
name);
327 coutE(InputArguments) <<
"RooCategory::clearRange(" <<
GetName() <<
") ERROR: must specify valid range name" << endl ;
353 coutE(Contents) <<
"RooCategory::addToRange(" <<
GetName()
354 <<
"): Need valid range name." << std::endl;
358 item =
_ranges->emplace(
name, std::vector<value_type>()).first;
359 coutI(Contents) <<
"RooCategory::setRange(" <<
GetName()
360 <<
") new range named '" <<
name <<
"' created for state " << stateIndex << endl ;
363 item->second.push_back(stateIndex);
375 if (!stateNameList) {
376 coutE(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") ERROR: must specify valid name and state name list" << endl ;
381 for (
const auto& token :
ROOT::Split(stateNameList,
",")) {
386 coutW(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") WARNING: Ignoring invalid state name '"
387 << token <<
"' in state name list" << endl ;
398 if (rangeName ==
nullptr ||
_ranges->empty())
401 const auto item =
_ranges->find(rangeName);
405 const std::vector<value_type>&
vec = item->second;
406 return std::find(
vec.begin(),
vec.end(), stateIndex) !=
vec.end();
423 coutE(InputArguments) <<
"RooCategory::isStateInRange(" <<
GetName() <<
") ERROR: must specify valid state name" << endl ;
449 }
else if (R__v == 2) {
453 auto props = std::make_unique<RooCategorySharedProperties>();
454 props->Streamer(R__b);
486 if (
auto existingObject = weakPtr.lock()) {
488 _ranges = std::move(existingObject);
491 _ranges = std::make_shared<std::map<std::string, std::vector<value_type>>>();
495 for (
auto * olist : static_range_cast<TList*>(props->
_altRanges)) {
496 std::vector<value_type>&
vec = rangesMap[olist->GetName()];
499 std::unique_ptr<TIterator> citer(olist->MakeIterator());
501 vec.push_back(ctype->getVal());
516 if (rangeMap ==
nullptr)
523 if (
a.size() !=
b.size())
526 auto vecsEqual = [](
const std::vector<RooAbsCategory::value_type>& aa,
const std::vector<RooAbsCategory::value_type>& bb) {
527 return aa.size() == bb.size() && std::equal(aa.begin(), aa.end(), bb.begin());
530 for (
const auto& itemA :
a) {
531 const auto itemB =
b.find(itemA.first);
532 if (itemB ==
b.end())
535 if (!vecsEqual(itemA.second, itemB->second))
544 auto existingMap = weakPtr.lock();
545 if (existingMap && checkRangeMapsEqual(*rangeMap, *existingMap)) {
547 _ranges = std::move(existingMap);
548 if (rangeMap.get() ==
_ranges.get()) {
550 (
void) rangeMap.release();
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
friend void RooRefArray::Streamer(TBuffer &)
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual const char * getCurrentLabel() const
Return label string of current state.
value_type nextAvailableStateIndex() const
std::map< std::string, value_type >::const_iterator end() const
Iterator for category state names. Points to pairs of index and name.
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
bool hasIndex(value_type index) const
Check if a state with index index exists.
std::vector< std::string > _insertionOrder
Map state names to index numbers. Make sure state names are updated in recomputeShape().
const std::map< std::string, value_type > & stateNames() const
Access the map of state names to index numbers.
static const decltype(_stateNames) ::value_type & invalidCategory()
Is this category attached to a tree?
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
RooCategorySharedProperties is the container for all properties that are shared between instance of R...
RooCategory is an object to represent discrete states.
RangeMap_t * _rangesPointerForIO
void addToRange(const char *rangeName, RooAbsCategory::value_type stateIndex)
Add the given state to the given range.
virtual void writeToStream(std::ostream &os, Bool_t compact) const override
compact only at the moment
void setRange(const char *rangeName, const char *stateNameList)
void defineTypes(const std::map< std::string, int > &allowedStates)
Define multiple states in a single call.
static std::map< std::string, std::weak_ptr< RangeMap_t > > _sharedRangeIOHelper
void installSharedRange(std::unique_ptr< RangeMap_t > &&rangeMap)
In current versions of the class, a map with ranges can be shared between instances.
bool defineType(const std::string &label)
Define a state with given name.
virtual ~RooCategory()
Destructor.
std::shared_ptr< RangeMap_t > _ranges
Map range names to allowed category states.
std::map< std::string, std::vector< value_type > > RangeMap_t
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE) override
Read object contents from given stream.
virtual Bool_t setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
virtual value_type getCurrentIndex() const override final
Return current index.
value_type & operator[](const std::string &stateName)
Access a named state.
static std::map< std::string, std::weak_ptr< RangeMap_t > > _uuidToSharedRangeIOHelper
virtual Bool_t setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
void clearRange(const char *name, Bool_t silent)
Clear the named range.
std::map< std::string, RooAbsCategory::value_type > & states()
Return a reference to the map of state names to index states.
Bool_t isStateInRange(const char *rangeName, RooAbsCategory::value_type stateIndex) const
Check if the state is in the given range.
void installLegacySharedProp(const RooCategorySharedProperties *sp)
When reading old versions of the class, we get instances of shared properties.
TString readToken()
Read one token separated by any of the know punctuation characters This function recognizes and handl...
Buffer base class used for serializing objects.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual const char * GetName() const
Returns name of object.
Bool_t IsDec() const
Returns true if all characters in string are decimal digits (0-9).
const char * Data() const
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.