142 _ranges(other._ranges)
168 coutE(InputArguments) <<
"RooCategory: Trying to set invalid state " <<
index <<
" for category " <<
GetName() << std::endl;
196 coutE(InputArguments) <<
"Trying to set invalid state label '" << label <<
"' for category " <<
GetName() << std::endl;
211 if (label.find(
';') != std::string::npos) {
212 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
213 <<
"): semicolons not allowed in label name" << endl ;
227 if (label.find(
';') != std::string::npos) {
228 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
229 <<
"): semicolons not allowed in label name" << endl ;
245 for (
const auto& nameAndIdx : allowedStates) {
246 defineType(nameAndIdx.first, nameAndIdx.second);
323 std::map<std::string, std::vector<value_type>>::iterator item =
_ranges->find(
name);
326 coutE(InputArguments) <<
"RooCategory::clearRange(" <<
GetName() <<
") ERROR: must specify valid range name" << endl ;
352 coutE(Contents) <<
"RooCategory::addToRange(" <<
GetName()
353 <<
"): Need valid range name." << std::endl;
357 item =
_ranges->emplace(
name, std::vector<value_type>()).first;
358 coutI(Contents) <<
"RooCategory::setRange(" <<
GetName()
359 <<
") new range named '" <<
name <<
"' created for state " << stateIndex << endl ;
362 item->second.push_back(stateIndex);
374 if (!stateNameList) {
375 coutE(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") ERROR: must specify valid name and state name list" << endl ;
380 for (
const auto& token :
ROOT::Split(stateNameList,
",")) {
385 coutW(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") WARNING: Ignoring invalid state name '"
386 << token <<
"' in state name list" << endl ;
397 if (rangeName ==
nullptr ||
_ranges->empty())
400 const auto item =
_ranges->find(rangeName);
404 const std::vector<value_type>&
vec = item->second;
405 return std::find(
vec.begin(),
vec.end(), stateIndex) !=
vec.end();
422 coutE(InputArguments) <<
"RooCategory::isStateInRange(" <<
GetName() <<
") ERROR: must specify valid state name" << endl ;
448 }
else if (R__v == 2) {
452 auto props = std::make_unique<RooCategorySharedProperties>();
453 props->Streamer(R__b);
485 if (
auto existingObject = weakPtr.lock()) {
487 _ranges = std::move(existingObject);
490 _ranges = std::make_unique<std::map<std::string, std::vector<value_type>>>();
494 for (
auto * olist : static_range_cast<TList*>(props->
_altRanges)) {
495 std::vector<value_type>&
vec = rangesMap[olist->GetName()];
498 for(
auto * ctype : static_range_cast<RooCatType*>(*olist)) {
499 vec.push_back(ctype->getVal());
514 if (rangeMap ==
nullptr)
521 if (
a.size() !=
b.size())
524 for (
const auto& itemA :
a) {
525 const auto itemB =
b.find(itemA.first);
526 if (itemB ==
b.end())
529 if (itemA.second != itemB->second)
538 auto existingMap = weakPtr.lock();
539 if (existingMap && checkRangeMapsEqual(*rangeMap, *existingMap)) {
541 _ranges = std::move(existingMap);
542 if (rangeMap.get() ==
_ranges.get()) {
544 (void) rangeMap.release();
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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 _currentIndex
Current category 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.
std::vector< std::string > _insertionOrder
Keeps track in which order state numbers have been inserted. Make sure this is updated in recomputeSh...
const std::map< std::string, value_type > & stateNames() const
Access the map of state names to index numbers.
bool hasIndex(value_type index) const
Check if a state with index index exists.
static const decltype(_stateNames) ::value_type & invalidCategory()
A category state to signify an invalid category.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
RooCategorySharedProperties is the container for all properties that are shared between instance of R...
RooLinkedList _altRanges
Optional alternative ranges.
RooCategory is an object to represent discrete states.
RangeMap_t * _rangesPointerForIO
Pointer to the same object as _ranges, but not shared for I/O.
void addToRange(const char *rangeName, RooAbsCategory::value_type stateIndex)
Add the given state to the given range.
bool setIndex(Int_t index, bool printError=true) override
Set value by specifying the index code of the desired state.
void setRange(const char *rangeName, const char *stateNameList)
void defineTypes(const std::map< std::string, int > &allowedStates)
Define multiple states in a single call.
void writeToStream(std::ostream &os, bool compact) const override
compact only at the moment
static std::map< std::string, std::weak_ptr< RangeMap_t > > _sharedRangeIOHelper
Helper for restoring shared ranges from current versions of this class read from files....
TClass * IsA() const override
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.
void clearRange(const char *name, bool silent)
Clear the named range.
std::shared_ptr< RangeMap_t > _ranges
Map range names to allowed category states.
std::map< std::string, std::vector< value_type > > RangeMap_t
static std::map< RooSharedProperties::UUID, std::weak_ptr< RangeMap_t > > _uuidToSharedRangeIOHelper
Helper for restoring shared ranges from old versions of this class read from files....
value_type & operator[](const std::string &stateName)
Access a named state.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from given stream.
bool setLabel(const char *label, bool printError=true) override
Set value by specifying the name of the desired state.
std::map< std::string, RooAbsCategory::value_type > & states()
Return a reference to the map of state names to index states.
bool isStateInRange(const char *rangeName, RooAbsCategory::value_type stateIndex) const
Check if the state is in the given range.
value_type getCurrentIndex() const final
Return current index.
void installLegacySharedProp(const RooCategorySharedProperties *sp)
When reading old versions of the class, we get instances of shared properties.
~RooCategory() override
Destructor.
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 Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
const char * GetName() const override
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.