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