93using std::endl, std::istream, std::ostream;
138 _ranges(other._ranges)
162 coutE(InputArguments) <<
"RooCategory: Trying to set invalid state " <<
index <<
" for category " <<
GetName() << std::endl;
190 coutE(InputArguments) <<
"Trying to set invalid state label '" << label <<
"' for category " <<
GetName() << std::endl;
205 if (label.find(
';') != std::string::npos) {
206 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
207 <<
"): semicolons not allowed in label name" << std::endl ;
221 if (label.find(
';') != std::string::npos) {
222 coutE(InputArguments) <<
"RooCategory::defineType(" <<
GetName()
223 <<
"): semicolons not allowed in label name" << std::endl ;
239 for (
const auto& nameAndIdx : allowedStates) {
240 defineType(nameAndIdx.first, nameAndIdx.second);
317 std::map<std::string, std::vector<value_type>>::iterator item =
_ranges->find(
name);
320 coutE(InputArguments) <<
"RooCategory::clearRange(" <<
GetName() <<
") ERROR: must specify valid range name" << std::endl ;
346 coutE(Contents) <<
"RooCategory::addToRange(" <<
GetName()
347 <<
"): Need valid range name." << std::endl;
351 item =
_ranges->emplace(
name, std::vector<value_type>()).first;
352 coutI(Contents) <<
"RooCategory::setRange(" <<
GetName()
353 <<
") new range named '" <<
name <<
"' created for state " << stateIndex << std::endl ;
356 item->second.push_back(stateIndex);
368 if (!stateNameList) {
369 coutE(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") ERROR: must specify valid name and state name list" << std::endl ;
374 for (
const auto& token :
ROOT::Split(stateNameList,
",")) {
379 coutW(InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") WARNING: Ignoring invalid state name '"
380 << token <<
"' in state name list" << std::endl ;
391 if (rangeName ==
nullptr ||
_ranges->empty())
394 const auto item =
_ranges->find(rangeName);
398 const std::vector<value_type>& vec = item->second;
399 return std::find(vec.begin(), vec.end(), stateIndex) != vec.end();
416 coutE(InputArguments) <<
"RooCategory::isStateInRange(" <<
GetName() <<
") ERROR: must specify valid state name" << std::endl ;
438 RooCategorySharedProperties* props =
nullptr;
443 }
else if (R__v == 2) {
447 auto props = std::make_unique<RooCategorySharedProperties>();
448 props->Streamer(R__b);
476 if (props ==
nullptr || (*props == RooCategorySharedProperties(
"00000000-0000-0000-0000-000000000000")))
480 if (
auto existingObject = weakPtr.lock()) {
482 _ranges = std::move(existingObject);
485 _ranges = std::make_unique<std::map<std::string, std::vector<value_type>>>();
489 for (
auto * olist : static_range_cast<TList*>(props->_altRanges)) {
490 std::vector<value_type>& vec = rangesMap[olist->GetName()];
493 for(
auto * ctype : static_range_cast<RooCatType*>(*olist)) {
494 vec.push_back(ctype->getVal());
509 if (rangeMap ==
nullptr)
516 if (
a.size() !=
b.size())
519 for (
const auto& itemA :
a) {
520 const auto itemB =
b.find(itemA.first);
521 if (itemB ==
b.end())
524 if (itemA.second != itemB->second)
533 auto existingMap = weakPtr.lock();
534 if (existingMap && checkRangeMapsEqual(*rangeMap, *existingMap)) {
536 _ranges = std::move(existingMap);
537 if (rangeMap.get() ==
_ranges.get()) {
539 (void) rangeMap.release();
short Version_t
Class version identifier (short)
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.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
virtual const char * getCurrentLabel() const
Return label string of current state.
value_type _currentIndex
Current category state.
value_type nextAvailableStateIndex() const
static const decltype(_stateNames) ::value_type & invalidCategory()
A category state to signify an invalid category.
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.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
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.
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.
std::map< std::string, std::vector< value_type > > RangeMap_t
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.