141 _ranges(other._ranges)
210 if (label.find(
';') != std::string::npos) {
212 <<
"): semicolons not allowed in label name" << endl ;
226 if (label.find(
';') != std::string::npos) {
228 <<
"): semicolons not allowed in label name" << endl ;
244 for (
const auto& nameAndIdx : allowedStates) {
245 defineType(nameAndIdx.first, nameAndIdx.second);
322 std::map<std::string, std::vector<value_type>>::iterator item =
_ranges->find(
name);
352 <<
"): Need valid range name." << std::endl;
356 item =
_ranges->emplace(
name, std::vector<value_type>()).first;
358 <<
") new range named '" <<
name <<
"' created for state " << stateIndex << endl ;
361 item->second.push_back(stateIndex);
373 if (!stateNameList) {
374 coutE(
InputArguments) <<
"RooCategory::setRange(" <<
GetName() <<
") ERROR: must specify valid name and state name list" << endl ;
385 << token <<
"' in state name list" << endl ;
396 if (rangeName ==
nullptr ||
_ranges->empty())
399 const auto item =
_ranges->find(rangeName);
403 const std::vector<value_type>& vec = item->second;
404 return std::find(vec.begin(), vec.end(), stateIndex) != vec.end();
431void RooCategory::Streamer(
TBuffer &R__b)
439 RooAbsCategoryLValue::Streamer(R__b);
447 }
else if (R__v == 2) {
448 RooAbsCategoryLValue::Streamer(R__b);
451 auto props = std::make_unique<RooCategorySharedProperties>();
452 props->Streamer(R__b);
484 if (
auto existingObject = weakPtr.lock()) {
486 _ranges = std::move(existingObject);
489 _ranges = std::make_shared<std::map<std::string, std::vector<value_type>>>();
495 std::vector<value_type>& vec = rangesMap[olist->GetName()];
498 std::unique_ptr<TIterator> citer(olist->MakeIterator());
500 vec.push_back(ctype->getVal());
515 if (rangeMap ==
nullptr)
522 if (
a.size() !=
b.size())
525 auto vecsEqual = [](
const std::vector<RooAbsCategory::value_type>& aa,
const std::vector<RooAbsCategory::value_type>& bb) {
526 return aa.size() == bb.size() && std::equal(aa.begin(), aa.end(), bb.begin());
529 for (
const auto& itemA :
a) {
530 const auto itemB =
b.find(itemA.first);
531 if (itemB ==
b.end())
534 if (!vecsEqual(itemA.second, itemB->second))
543 auto existingMap = weakPtr.lock();
544 if (existingMap && checkRangeMapsEqual(*rangeMap, *existingMap)) {
546 _ranges = std::move(existingMap);
547 if (rangeMap.get() == existingMap.get()) {
549 (
void) rangeMap.release();
typedef void((*Func_t)())
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
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.
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
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 > tokenise(const std::string &str, const std::string &delims, bool returnEmptyToken=true)
Tokenise the string by splitting at the characters in delims.
static constexpr double second