Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsCategory.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooAbsCategory.cxx
19\class RooAbsCategory
20\ingroup Roofitcore
21
22RooAbsCategory is the base class for objects that represent a discrete value with a finite number of states.
23
24Each state is denoted by an integer and a name. Both can be used to retrieve and
25set states, but referring to states by index is more efficient. Conversion between
26index and name can be done using lookupName() or lookupIndex().
27It is possible to iterate through all defined states using begin() and end().
28
29For category classes deriving from RooAbsCategory, states can only be evaluated, *i.e.*, queried.
30Refer to RooAbsCategoryLValue and its derived classes for categories where states can also be set. The
31simplest category class whose states can be set, queried and saved in a dataset, refer to RooCategory.
32
33### Interface change in ROOT-6.22
34Category data were based in the class RooCatType, holding an index state and a category name truncated to 256
35characters. This wastes 64 bytes of storage space per entry, and prevents fast retrieval of category data.
36Since ROOT-6.22, categories are only represented by an integer. RooAbsCategory::lookupName() can be used to
37retrieve the corresponding state name. There is no limit for the length of the state name.
38
39To not break old code, the old RooCatType interfaces are still available. Whenever possible,
40the following replacements should be used:
41- lookupType() \f$ \rightarrow \f$ lookupName() / lookupIndex()
42- typeIterator() \f$ \rightarrow \f$ range-based for loop / begin() / end()
43- isValid(const RooCatType&) \f$ \rightarrow \f$ hasIndex() / hasLabel()
44**/
45
46#include "RooAbsCategory.h"
47
48#include "RooFit.h"
49#include "RooArgSet.h"
50#include "Roo1DTable.h"
51#include "RooCategory.h"
52#include "RooMsgService.h"
53#include "RooVectorDataStore.h"
55
56#include "Compression.h"
57#include "TString.h"
58#include "TTree.h"
59#include "TLeaf.h"
60#include "ROOT/RMakeUnique.hxx"
61#include "TBranch.h"
62
63using namespace std;
64
66
67/// A category state to signify an invalid category. The category name is empty,
68/// the index is the minimal int.
70 static const decltype(RooAbsCategory::_stateNames)::value_type invalid{"", std::numeric_limits<value_type>::min()};
71 return invalid;
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Constructor
76
77RooAbsCategory::RooAbsCategory(const char *name, const char *title) :
78 RooAbsArg(name,title), _currentIndex(0)
79{
82}
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Copy constructor, copies the registered category states from the original.
88
90 RooAbsArg(other,name), _currentIndex(other._currentIndex),
91 _stateNames(other._stateNames),
92 _insertionOrder(other._insertionOrder),
93 _treeVar(other._treeVar)
94{
97}
98
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Destructor
103
105{
106
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Return index number of current state
113
115{
116 if (isValueDirty() || isShapeDirty()) {
118
120 }
121
122 return _currentIndex;
123}
124
125
126
127////////////////////////////////////////////////////////////////////////////////
128/// Return label string of current state.
129
131{
132 const auto index = getCurrentIndex();
133 for (const auto& item : stateNames()) {
134 if (item.second == index)
135 return item.first.c_str();
136 }
137
138 return "";
139}
140
141
142////////////////////////////////////////////////////////////////////////////////
143/// Equality operator with a integer (compares with state index number)
144
146{
147 return (index==getCurrentIndex()) ;
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Equality operator with a string (compares with state label string)
154
155Bool_t RooAbsCategory::operator==(const char* label) const
156{
157 return strcmp(label, getCurrentLabel()) == 0;
158}
159
160
161
162////////////////////////////////////////////////////////////////////////////////
163/// Equality operator with another RooAbsArg. Only functional
164/// is also a RooAbsCategory, will return true if index is the same
165
167{
168 const RooAbsCategory* otherCat = dynamic_cast<const RooAbsCategory*>(&other) ;
169 return otherCat ? operator==(otherCat->getCurrentIndex()) : kFALSE ;
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174
175Bool_t RooAbsCategory::isIdentical(const RooAbsArg& other, Bool_t assumeSameType) const
176{
177 if (!assumeSameType) {
178 const RooAbsCategory* otherCat = dynamic_cast<const RooAbsCategory*>(&other) ;
179 return otherCat ? operator==(otherCat->getCurrentIndex()) : kFALSE ;
180 } else {
181 return getCurrentIndex() == static_cast<const RooAbsCategory&>(other).getCurrentIndex();
182 }
183}
184
185
186////////////////////////////////////////////////////////////////////////////////
187/// Check if a state with index `index` exists.
189{
190 for (const auto& item : stateNames()) {
191 if (item.second == index)
192 return true;
193 }
194
195 return false;
196}
197
198
199////////////////////////////////////////////////////////////////////////////////
200/// Look up the name corresponding to the given index.
201const std::string& RooAbsCategory::lookupName(value_type index) const {
202 for (const auto& item : stateNames()) {
203 if (item.second == index)
204 return item.first;
205 }
206
207 return invalidCategory().first;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Define a new state with given label. The next available
212/// integer is assigned as index value.
213const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::defineState(const std::string& label)
214{
215 return defineState(label, nextAvailableStateIndex());
216}
217
218
219////////////////////////////////////////////////////////////////////////////////
220/// Internal version of defineState() that does not check if type
221/// already exists
223{
224 _stateNames.emplace(label, index);
225 _insertionOrder.push_back(label);
226
227 if (_stateNames.size() == 1)
228 _currentIndex = index;
229
231}
232
233
234
235////////////////////////////////////////////////////////////////////////////////
236/// Define new state with given name and index number.
237
238const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::defineState(const std::string& label, RooAbsCategory::value_type index)
239{
240 auto& theStateNames = stateNames();
241
242 if (hasIndex(index)) {
243 coutE(InputArguments) << "RooAbsCategory::" << __func__ << "(" << GetName() << "): index "
244 << index << " already assigned" << endl ;
245 return invalidCategory();
246 }
247
248 if (hasLabel(label)) {
249 coutE(InputArguments) << "RooAbsCategory::" << __func__ << "(" << GetName() << "): label "
250 << label << " already assigned or not allowed" << endl ;
251 return invalidCategory();
252 }
253
254 const auto result = theStateNames.emplace(label, index);
255 _insertionOrder.push_back(label);
256
257 if (theStateNames.size() == 1)
258 _currentIndex = index;
259
261
262 return *(result.first);
263}
264
265
266
267////////////////////////////////////////////////////////////////////////////////
268/// Delete all currently defined states
269
271{
272 _stateNames.clear();
273 _insertionOrder.clear();
275 setShapeDirty() ;
276}
277
278
279////////////////////////////////////////////////////////////////////////////////
280/// Find the index number corresponding to the state name.
281/// \see hasLabel() for checking if a given label has been defined.
282/// \return Index of the category or std::numeric_limits<int>::min() on failure.
283RooAbsCategory::value_type RooAbsCategory::lookupIndex(const std::string& stateName) const {
284 const auto item = stateNames().find(stateName);
285 if (item != stateNames().end()) {
286 return item->second;
287 }
288
289 return invalidCategory().second;
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Find our type that matches the specified type, or return 0 for no match.
294/// \deprecated RooCatType is not used, any more. This function will create one and let it leak.
295/// Use lookupIndex() (preferred) or lookupName() instead.
296const RooCatType* RooAbsCategory::lookupType(const RooCatType &other, Bool_t printError) const
297{
298 return lookupType(other.getVal(), printError);
299}
300
301
302
303////////////////////////////////////////////////////////////////////////////////
304/// Find our type corresponding to the specified index, or return nullptr for no match.
305/// \deprecated RooCatType is not used, any more. This function will create one and let it leak.
306/// Use lookupIndex() (preferred) or lookupName() instead.
308{
309 for (const auto& item : stateNames())
310 if (item.second == index) {
311 return retrieveLegacyState(index);
312 }
313
314 if (printError) {
315 coutE(InputArguments) << ClassName() << "::" << GetName() << ":lookupType: no match for index "
316 << index << endl;
317 }
318
319 return nullptr;
320}
321
322
323
324////////////////////////////////////////////////////////////////////////////////
325/// Find our type corresponding to the specified label, or return 0 for no match.
326/// \deprecated RooCatType is not used, any more. This function will create one and let it leak.
327/// Use lookupIndex() (preferred) or lookupName() instead.
328const RooCatType* RooAbsCategory::lookupType(const char* label, Bool_t printError) const
329{
330 for (const auto& type : stateNames()) {
331 if(type.first == label)
332 return retrieveLegacyState(type.second);
333 }
334
335 // Try if label represents integer number
336 char* endptr ;
337 RooAbsCategory::value_type idx=strtol(label,&endptr,10) ;
338 if (endptr==label+strlen(label)) {
339 return lookupType(idx);
340 }
341
342 if (printError) {
343 coutE(InputArguments) << ClassName() << "::" << GetName() << ":lookupType: no match for label "
344 << label << endl;
345 }
346 return nullptr;
347}
348
349
350////////////////////////////////////////////////////////////////////////////////
351/// Check if given state is defined for this object
352
354{
355 return hasIndex(value.getVal()) ;
356}
357
358
359
360////////////////////////////////////////////////////////////////////////////////
361/// Create a table matching the shape of this category
362
364{
365 return new Roo1DTable(GetName(),label,*this) ;
366}
367
368
369
370////////////////////////////////////////////////////////////////////////////////
371/// Read object contents from stream (dummy for now)
372
374{
375 return kFALSE ;
376}
377
378
379
380////////////////////////////////////////////////////////////////////////////////
381/// Write object contents to ostream
382
383void RooAbsCategory::writeToStream(ostream& os, Bool_t /* compact */) const
384{
385 os << getCurrentLabel() ;
386}
387
388
389
390////////////////////////////////////////////////////////////////////////////////
391/// Print value (label name)
392
393void RooAbsCategory::printValue(ostream& os) const
394{
395 os << getCurrentLabel() << "(idx = " << getCurrentIndex() << ")" << endl ;
396}
397
398
399
400////////////////////////////////////////////////////////////////////////////////
401/// Print info about this object to the specified stream. In addition to the info
402/// from RooAbsArg::printStream() we add:
403///
404/// Shape : label, index, defined types
405
406void RooAbsCategory::printMultiline(ostream& os, Int_t contents, Bool_t verbose, TString indent) const
407{
408 RooAbsArg::printMultiline(os,contents,verbose,indent);
409
410 os << indent << "--- RooAbsCategory ---" << endl;
411 if (stateNames().empty()) {
412 os << indent << " ** No values defined **" << endl;
413 return;
414 }
415 os << indent << " Value = " << getCurrentIndex() << " \"" << getCurrentLabel() << ')' << endl;
416 os << indent << " Possible states:" << endl;
417 indent.Append(" ");
418 for (const auto& type : stateNames()) {
419 os << indent << type.first << '\t' << type.second << "\n";
420 }
421}
422
423
424
425////////////////////////////////////////////////////////////////////////////////
426/// Attach the category index and label to as branches to the given vector store
427
429{
430 RooVectorDataStore::CatVector* cv = vstore.addCategory(this) ;
432}
433
434
435
436
437////////////////////////////////////////////////////////////////////////////////
438/// Attach the category index and label as branches to the given
439/// TTree. The index field will be attached as integer with name
440/// `<name>_idx`. If a branch `<name>` exists, it attaches to this branch.
442{
443 // First check if there is an integer branch matching the category name
444 TString cleanName(cleanBranchName()) ;
445 TBranch* branch = t.GetBranch(cleanName) ;
446 if (!branch) {
447 cleanName += "_idx";
448 branch = t.GetBranch(cleanName);
449 }
450
451 if (branch) {
452 TString typeName(((TLeaf*)branch->GetListOfLeaves()->At(0))->GetTypeName()) ;
453 if (!typeName.CompareTo("Int_t")) {
454 // Imported TTree: attach only index field as branch
455
456 coutI(DataHandling) << "RooAbsCategory::attachToTree(" << GetName() << ") TTree branch " << GetName()
457 << " will be interpreted as category index" << endl ;
458
459 t.SetBranchAddress(cleanName, &_currentIndex) ;
460 setAttribute("INTIDXONLY_TREE_BRANCH",kTRUE) ;
461 _treeVar = true;
462 return ;
463 } else if (!typeName.CompareTo("UChar_t")) {
464 coutI(DataHandling) << "RooAbsReal::attachToTree(" << GetName() << ") TTree UChar_t branch " << GetName()
465 << " will be interpreted as category index" << endl ;
466 t.SetBranchAddress(cleanName,&_byteValue) ;
467 setAttribute("UCHARIDXONLY_TREE_BRANCH",kTRUE) ;
468 _treeVar = true;
469 return ;
470 }
471 } else {
472 TString format(cleanName);
473 format.Append("/I");
474 void* ptr = &_currentIndex;
475 t.Branch(cleanName, ptr, (const Text_t*)format, bufSize);
476 }
477}
478
479
480
481////////////////////////////////////////////////////////////////////////////////
482/// Fill tree branches associated with current object with current value
483
485{
486 TString idxName(GetName()) ;
487 idxName.Append("_idx") ;
488
489 // First determine if branch is taken
490 TBranch* idxBranch = t.GetBranch(idxName) ;
491 if (!idxBranch) {
492 coutF(DataHandling) << "RooAbsCategory::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
493 throw std::runtime_error("RooAbsCategory::fillTreeBranch(): Category is not attached to a tree.");
494 }
495
496 idxBranch->Fill() ;
497}
498
499
500
501////////////////////////////////////////////////////////////////////////////////
502/// (De)activate associate tree branch
503
505{
506 TBranch* branch = t.GetBranch(Form("%s_idx",GetName())) ;
507 if (branch) {
508 t.SetBranchStatus(Form("%s_idx",GetName()),active?1:0) ;
509 }
510}
511
512
513
514////////////////////////////////////////////////////////////////////////////////
515/// Explicitly synchronize RooAbsCategory internal cache
516
518{
520}
521
522
523
524////////////////////////////////////////////////////////////////////////////////
525/// Copy the cached value from given source and raise dirty flag.
526/// It is the callers responsibility to ensure that the sources
527/// cache is clean(valid) before this function is called, e.g. by
528/// calling syncCache() on the source.
529
530void RooAbsCategory::copyCache(const RooAbsArg *source, Bool_t /*valueOnly*/, Bool_t setValDirty)
531{
532 auto other = static_cast<const RooAbsCategory*>(source);
533 assert(dynamic_cast<const RooAbsCategory*>(source));
534
535 _currentIndex = other->_currentIndex;
536
537 if (setValDirty) {
539 }
540
541 if (!_treeVar)
542 return;
543
544 if (source->getAttribute("INTIDXONLY_TREE_BRANCH")) {
545 // Lookup cat state from other-index because label is missing
546 if (hasIndex(other->_currentIndex)) {
547 _currentIndex = other->_currentIndex;
548 } else {
549 coutE(DataHandling) << "RooAbsCategory::copyCache(" << GetName() << ") ERROR: index of source arg "
550 << source->GetName() << " is invalid (" << other->_currentIndex
551 << "), value not updated" << endl;
552 }
553 } else if (source->getAttribute("UCHARIDXONLY_TREE_BRANCH")) {
554 // Lookup cat state from other-index because label is missing
555 Int_t tmp = static_cast<int>(other->_byteValue);
556 if (hasIndex(tmp)) {
557 _currentIndex = tmp;
558 } else {
559 coutE(DataHandling) << "RooAbsCategory::copyCache(" << GetName() << ") ERROR: index of source arg "
560 << source->GetName() << " is invalid (" << tmp << "), value not updated" << endl;
561 }
562 }
563}
564
565////////////////////////////////////////////////////////////////////////////////
566/// Return name and index of the `n`th defined state. When states are defined using
567/// defineType() or operator[], the order of insertion is tracked, to mimic the behaviour
568/// before modernising the category classes.
569/// When directly manipulating the map with state names using states(), the order of insertion
570/// is not known, so alphabetical ordering as usual for std::map is used. The latter is faster.
571/// \param[in] n Number of state to be retrieved.
572/// \return A pair with name and index.
573const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::getOrdinal(unsigned int n) const {
574 // Retrieve state names, trigger possible recomputation
575 auto& theStateNames = stateNames();
576
577 if (n >= theStateNames.size())
578 return invalidCategory();
579
580 if (theStateNames.size() != _insertionOrder.size())
581 return *std::next(theStateNames.begin(), n);
582
583 const auto item = theStateNames.find(_insertionOrder[n]);
584 if (item != theStateNames.end())
585 return *item;
586
587 return invalidCategory();
588}
589
590
591////////////////////////////////////////////////////////////////////////////////
592/// Return ordinal number of the current state.
594 // Retrieve state names, trigger possible recomputation
595 auto& theStateNames = stateNames();
596
597 // If we don't have the full history of inserted state names, have to go by map ordering:
598 if (theStateNames.size() != _insertionOrder.size()) {
599 const auto currentIndex = getCurrentIndex();
600 for (auto it = theStateNames.begin(); it != theStateNames.end(); ++it) {
601 if (it->second == currentIndex)
602 return std::distance(theStateNames.begin(), it);
603 }
604 }
605
606 // With full insertion history, find index of current label:
607 auto item = std::find(_insertionOrder.begin(), _insertionOrder.end(), getCurrentLabel());
608 assert(item != _insertionOrder.end());
609
610 return item - _insertionOrder.begin();
611}
612
613
614////////////////////////////////////////////////////////////////////////////////
615/// Create a RooCategory fundamental object with our properties.
616
618{
619 // Add and precalculate new category column
620 RooCategory *fund= new RooCategory(newname?newname:GetName(),GetTitle()) ;
621
622 // Copy states
623 for (const auto& type : stateNames()) {
624 fund->defineStateUnchecked(type.first, type.second);
625 }
626
627 return fund;
628}
629
630
631
632////////////////////////////////////////////////////////////////////////////////
633/// Determine if category has 2 or 3 states with index values -1,0,1
634
636{
637 const auto& theStateNames = stateNames();
638
639 if (theStateNames.size() > 3 || theStateNames.size() < 2) return false;
640 if (mustHaveZero && theStateNames.size() != 3) return false;
641
642 for (const auto& type : theStateNames) {
643 if (abs(type.second)>1)
644 return false;
645 }
646
647 return true;
648}
649
650/// \deprecated Use begin() and end() instead.
651/// \note Using this iterator creates useless RooCatType instances, which will leak
652/// unless deleted by the user.
655}
656
657const RooCatType* RooAbsCategory::defineType(const char* label) {
658 defineState(label);
659 return retrieveLegacyState(stateNames()[label]);
660}
661
662const RooCatType* RooAbsCategory::defineType(const char* label, int index) {
663 defineState(label, index);
664 return retrieveLegacyState(index);
665}
666
668 defineStateUnchecked(label, index);
669 return retrieveLegacyState(index);
670}
671
672/// Return the legacy RooCatType corresponding to `index`. If it doesn't exist, create one.
674 auto result = _legacyStates.find(index);
675 if (result == _legacyStates.end()) {
676 result = _legacyStates.emplace(index,
677 std::unique_ptr<RooCatType>(new RooCatType(lookupName(index).c_str(), index))).first;
678 }
679
680 return result->second.get();
681}
682
683
685 const auto& theStateNames = stateNames();
686
687 if (theStateNames.empty())
688 return 0;
689
690 return 1 + std::max_element(theStateNames.begin(), theStateNames.end(),
691 [](const std::map<std::string, value_type>::value_type& left,
692 const std::map<std::string, value_type>::value_type& right) {
693 return left.second < right.second; })->second;
694}
#define coutI(a)
#define coutF(a)
#define coutE(a)
char Text_t
Definition RtypesCore.h:62
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition TGX11.cxx:110
int type
Definition TGX11.cxx:121
char * Form(const char *fmt,...)
Roo1DTable implements a one-dimensional table.
Definition Roo1DTable.h:23
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:513
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
Definition RooAbsArg.h:434
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
Definition RooAbsArg.h:439
void clearValueDirty() const
Definition RooAbsArg.h:581
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:508
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.
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.
value_type _currentIndex
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.
Definition RooArgSet.h:29
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Int_t getVal() const
RooCategory is an object to represent discrete states.
Definition RooCategory.h:27
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.
Definition TBranch.h:89
TObjArray * GetListOfLeaves()
Definition TBranch.h:243
Int_t Fill()
Definition TBranch.h:201
Iterator abstract base class.
Definition TIterator.h:30
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
TObject * At(Int_t idx) const
Definition TObjArray.h:166
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:130
Basic string class.
Definition TString.h:136
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition TString.cxx:438
TString & Append(const char *cs)
Definition TString.h:564
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
Definition TTree.cxx:5275
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition TTree.cxx:8349
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.
Definition TTree.h:350
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=0)
Set branch status to Process or DoNotProcess.
Definition TTree.cxx:8498
const Int_t n
Definition legend1.C:16