92 _stateNames(other._stateNames),
93 _insertionOrder(other._insertionOrder),
94 _treeVar(other._treeVar)
135 if (item.second == index)
136 return item.first.c_str();
178 if (!assumeSameType) {
192 if (item.second == index)
204 if (item.second == index)
244 coutE(InputArguments) <<
"RooAbsCategory::" << __func__ <<
"(" <<
GetName() <<
"): index "
245 << index <<
" already assigned" << endl ;
250 coutE(InputArguments) <<
"RooAbsCategory::" << __func__ <<
"(" <<
GetName() <<
"): label "
251 << label <<
" already assigned or not allowed" << endl ;
255 const auto result = theStateNames.emplace(label, index);
258 if (theStateNames.size() == 1)
263 return *(result.first);
285 const auto item =
stateNames().find(stateName);
311 if (item.second == index) {
332 if(
type.first == label)
339 if (endptr==label+strlen(label)) {
411 os <<
indent <<
"--- RooAbsCategory ---" << endl;
413 os <<
indent <<
" ** No values defined **" << endl;
417 os <<
indent <<
" Possible states:" << endl;
457 coutI(DataHandling) <<
"RooAbsCategory::attachToTree(" <<
GetName() <<
") TTree branch " <<
GetName()
458 <<
" will be interpreted as category index" << endl ;
464 }
else if (!typeName.
CompareTo(
"UChar_t")) {
465 coutI(DataHandling) <<
"RooAbsReal::attachToTree(" <<
GetName() <<
") TTree UChar_t branch " <<
GetName()
466 <<
" will be interpreted as category index" << endl ;
476 t.
Branch(cleanName, ptr, (
const Text_t*)format, bufSize);
493 coutF(DataHandling) <<
"RooAbsCategory::fillTreeBranch(" <<
GetName() <<
") ERROR: not attached to tree" << endl ;
494 throw std::runtime_error(
"RooAbsCategory::fillTreeBranch(): Category is not attached to a tree.");
547 if (
hasIndex(other->_currentIndex)) {
550 coutE(DataHandling) <<
"RooAbsCategory::copyCache(" <<
GetName() <<
") ERROR: index of source arg "
551 << source->
GetName() <<
" is invalid (" << other->_currentIndex
552 <<
"), value not updated" << endl;
554 }
else if (source->
getAttribute(
"UCHARIDXONLY_TREE_BRANCH")) {
556 Int_t tmp =
static_cast<int>(other->_byteValue);
560 coutE(DataHandling) <<
"RooAbsCategory::copyCache(" <<
GetName() <<
") ERROR: index of source arg "
561 << source->
GetName() <<
" is invalid (" << tmp <<
"), value not updated" << endl;
596 if (
n >= theStateNames.size())
600 return *std::next(theStateNames.begin(),
n);
603 if (item != theStateNames.end())
619 for (
auto it = theStateNames.begin(); it != theStateNames.end(); ++it) {
620 if (it->second == currentIndex)
621 return std::distance(theStateNames.begin(), it);
658 if (theStateNames.size() > 3 || theStateNames.size() < 2)
return false;
659 if (mustHaveZero && theStateNames.size() != 3)
return false;
661 for (
const auto&
type : theStateNames) {
662 if (abs(
type.second)>1)
699 return result->second.get();
706 if (theStateNames.empty())
709 return 1 + std::max_element(theStateNames.begin(), theStateNames.end(),
710 [](
const std::map<std::string, value_type>::value_type& left,
711 const std::map<std::string, value_type>::value_type& right) {
712 return left.second < right.second; })->second;
static void indent(ostringstream &buf, int indent_level)
char * Form(const char *fmt,...)
Roo1DTable implements a one-dimensional table.
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multi-line detailed printing.
Bool_t isShapeDirty() const
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Bool_t isValueDirty() const
void clearValueDirty() const
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
RooAbsCategory is the base class for objects that represent a discrete value with a finite number of ...
virtual value_type getCurrentIndex() const
Return index number of current state.
void setCachedValue(double value, bool notifyClients=true) final
Overwrite the value stored in this object's cache.
virtual void copyCache(const RooAbsArg *source, Bool_t valueOnly=kFALSE, Bool_t setValueDirty=kTRUE)
Copy the cached value from given source and raise dirty flag.
virtual bool isValid() const
WVE (08/21/01) Probably obsolete now.
unsigned int getCurrentOrdinalNumber() const
Return ordinal number of the current state.
bool hasLabel(const std::string &label) const
Check if a state with name label exists.
virtual const char * getCurrentLabel() const
Return label string of current state.
const std::string & lookupName(value_type index) const
Get the name corresponding to the given index.
TIterator * typeIterator() const
virtual void fillTreeBranch(TTree &t)
Fill tree branches associated with current object with current value.
RooCatType * retrieveLegacyState(value_type index) const
Return the legacy RooCatType corresponding to index. If it doesn't exist, create one.
Bool_t operator==(value_type index) const
Equality operator with a integer (compares with state index number)
virtual void attachToVStore(RooVectorDataStore &vstore)
Attach the category index and label to as branches to the given vector store.
Roo1DTable * createTable(const char *label) const
Create a table matching the shape of this category.
void defineStateUnchecked(const std::string &label, value_type index)
Internal version of defineState() that does not check if type already exists.
virtual ~RooAbsCategory()
Destructor.
const RooCatType * defineTypeUnchecked(const char *label, value_type index)
virtual void attachToTree(TTree &t, Int_t bufSize=32000)
Attach the category index and label as branches to the given TTree.
value_type nextAvailableStateIndex() const
virtual Bool_t isIdentical(const RooAbsArg &other, Bool_t assumeSameType=kFALSE) const
RooAbsArg * createFundamental(const char *newname=0) const
Create a RooCategory fundamental object with our properties.
std::map< std::string, value_type >::const_iterator end() const
Iterator for category state names. Points to pairs of index and name.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to ostream.
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
virtual void setTreeBranchStatus(TTree &t, Bool_t active)
(De)activate associate tree branch
virtual value_type evaluate() const =0
Evaluate the category state and return.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
const std::map< std::string, value_type >::value_type & getOrdinal(unsigned int n) const
Return name and index of the nth defined state.
const RooCatType * lookupType(value_type index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return nullptr for no match.
UChar_t _byteValue
Keeps track in which order state numbers have been inserted. Make sure this is updated in recomputeSh...
std::map< value_type, std::unique_ptr< RooCatType, std::function< void(RooCatType *)> > > _legacyStates
Transient cache for byte values from tree branches.
bool hasIndex(value_type index) const
Check if a state with index index exists.
virtual void syncCache(const RooArgSet *set=0)
Explicitly synchronize RooAbsCategory internal cache.
std::vector< std::string > _insertionOrder
Map state names to index numbers. Make sure state names are updated in recomputeShape().
std::map< std::string, value_type > _stateNames
Current category state.
const RooCatType * defineType(const char *label)
Bool_t isSignType(Bool_t mustHaveZero=kFALSE) const
Determine if category has 2 or 3 states with index values -1,0,1.
const std::map< std::string, value_type > & stateNames() const
Access the map of state names to index numbers.
virtual void printValue(std::ostream &os) const
Print value (label name)
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.
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from stream (dummy for now)
bool _treeVar
Map holding pointers to RooCatType instances. Only for legacy interface. Don't use if possible.
void clearTypes()
Delete all currently defined states.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
RooCategory is an object to represent discrete states.
void setBuffer(RooAbsCategory::value_type *newBuf)
RooVectorDataStore uses std::vectors to store data columns.
CatVector * addCategory(RooAbsCategory *cat)
A TTree is a list of TBranches.
TObjArray * GetListOfLeaves()
Iterator abstract base class.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTitle() const
Returns title of object.
virtual const char * GetName() const
Returns name of object.
TObject * At(Int_t idx) const
virtual const char * ClassName() const
Returns name of class to which the object belongs.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
TString & Append(const char *cs)
A TTree represents a columnar dataset.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
TBranch * Branch(const char *name, T *obj, Int_t bufsize=32000, Int_t splitlevel=99)
Add a new branch, and infer the data type from the type of obj being passed.
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=0)
Set branch status to Process or DoNotProcess.