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
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- isValidIndex(Int_t index) \f$ \rightarrow \f$ hasIndex()
44- isValid(const RooCatType&) \f$ \rightarrow \f$ hasIndex() / hasLabel()
45**/
46
47#include "RooAbsCategory.h"
48
49#include "RooArgSet.h"
50#include "Roo1DTable.h"
51#include "RooCategory.h"
52#include "RooMsgService.h"
53#include "RooVectorDataStore.h"
55#include "TreeReadBuffer.h"
56
57#include "Compression.h"
58#include "TString.h"
59#include "TTree.h"
60#include "TLeaf.h"
61#include "TBranch.h"
62
63#include <functional>
64#include <memory>
65
66using namespace std;
67
69
70/// A category state to signify an invalid category. The category name is empty,
71/// the index is the minimal int.
73 static const decltype(RooAbsCategory::_stateNames)::value_type invalid{"", std::numeric_limits<value_type>::min()};
74 return invalid;
75}
76
77
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Constructor
83
84RooAbsCategory::RooAbsCategory(const char *name, const char *title) :
85 RooAbsArg(name,title), _currentIndex(0)
86{
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Copy constructor, copies the registered category states from the original.
95
97 RooAbsArg(other,name), _currentIndex(other._currentIndex),
98 _stateNames(other._stateNames),
99 _insertionOrder(other._insertionOrder)
100{
101 setValueDirty() ;
102 setShapeDirty() ;
103}
104
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// Destructor
109
111{
112
113}
114
115
116
117////////////////////////////////////////////////////////////////////////////////
118/// Return index number of current state
119
121{
122 if (isValueDirty() || isShapeDirty()) {
124
126 }
127
128 return _currentIndex;
129}
130
131
132
133////////////////////////////////////////////////////////////////////////////////
134/// Return label string of current state.
135
137{
138 const auto index = getCurrentIndex();
139 for (const auto& item : stateNames()) {
140 if (item.second == index)
141 return item.first.c_str();
142 }
143
144 return "";
145}
146
147
148////////////////////////////////////////////////////////////////////////////////
149/// Equality operator with a integer (compares with state index number)
150
152{
153 return (index==getCurrentIndex()) ;
154}
155
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// Equality operator with a string (compares with state label string)
160
161bool RooAbsCategory::operator==(const char* label) const
162{
163 return strcmp(label, getCurrentLabel()) == 0;
164}
165
166
167
168////////////////////////////////////////////////////////////////////////////////
169/// Equality operator with another RooAbsArg. Only functional
170/// is also a RooAbsCategory, will return true if index is the same
171
172bool RooAbsCategory::operator==(const RooAbsArg& other) const
173{
174 const RooAbsCategory* otherCat = dynamic_cast<const RooAbsCategory*>(&other) ;
175 return otherCat ? operator==(otherCat->getCurrentIndex()) : false ;
176}
177
178
179////////////////////////////////////////////////////////////////////////////////
180
181bool RooAbsCategory::isIdentical(const RooAbsArg& other, bool assumeSameType) const
182{
183 if (!assumeSameType) {
184 const RooAbsCategory* otherCat = dynamic_cast<const RooAbsCategory*>(&other) ;
185 return otherCat ? operator==(otherCat->getCurrentIndex()) : false ;
186 } else {
187 return getCurrentIndex() == static_cast<const RooAbsCategory&>(other).getCurrentIndex();
188 }
189}
190
191
192////////////////////////////////////////////////////////////////////////////////
193/// Check if a state with index `index` exists.
195{
196 for (const auto& item : stateNames()) {
197 if (item.second == index)
198 return true;
199 }
200
201 return false;
202}
203
204
205////////////////////////////////////////////////////////////////////////////////
206/// Look up the name corresponding to the given index.
207const std::string& RooAbsCategory::lookupName(value_type index) const {
208 for (const auto& item : stateNames()) {
209 if (item.second == index)
210 return item.first;
211 }
212
213 return invalidCategory().first;
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Define a new state with given label. The next available
218/// integer is assigned as index value.
219const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::defineState(const std::string& label)
220{
221 return defineState(label, nextAvailableStateIndex());
222}
223
224
225////////////////////////////////////////////////////////////////////////////////
226/// Internal version of defineState() that does not check if type
227/// already exists
229{
230 _stateNames.emplace(label, index);
231 _insertionOrder.push_back(label);
232
233 if (_stateNames.size() == 1)
235
237}
238
239
240
241////////////////////////////////////////////////////////////////////////////////
242/// Define new state with given name and index number.
243
244const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::defineState(const std::string& label, RooAbsCategory::value_type index)
245{
246 auto& theStateNames = stateNames();
247
248 if (hasIndex(index)) {
249 coutE(InputArguments) << "RooAbsCategory::" << __func__ << "(" << GetName() << "): index "
250 << index << " already assigned" << endl ;
251 return invalidCategory();
252 }
253
254 if (hasLabel(label)) {
255 coutE(InputArguments) << "RooAbsCategory::" << __func__ << "(" << GetName() << "): label "
256 << label << " already assigned or not allowed" << endl ;
257 return invalidCategory();
258 }
259
260 const auto result = theStateNames.emplace(label, index);
261 _insertionOrder.push_back(label);
262
263 if (theStateNames.size() == 1)
265
267
268 return *(result.first);
269}
270
271
272
273////////////////////////////////////////////////////////////////////////////////
274/// Delete all currently defined states
275
277{
278 _stateNames.clear();
279 _insertionOrder.clear();
281 setShapeDirty() ;
282}
283
284
285////////////////////////////////////////////////////////////////////////////////
286/// Find the index number corresponding to the state name.
287/// \see hasLabel() for checking if a given label has been defined.
288/// \return Index of the category or std::numeric_limits<int>::min() on failure.
289RooAbsCategory::value_type RooAbsCategory::lookupIndex(const std::string& stateName) const {
290 const auto item = stateNames().find(stateName);
291 if (item != stateNames().end()) {
292 return item->second;
293 }
294
295 return invalidCategory().second;
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Find our type that matches the specified type, or return 0 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.
302const RooCatType* RooAbsCategory::lookupType(const RooCatType &other, bool printError) const
303{
304 return lookupType(other.getVal(), printError);
305}
306
307
308
309////////////////////////////////////////////////////////////////////////////////
310/// Find our type corresponding to the specified index, or return nullptr for no match.
311/// \deprecated RooCatType is not used, any more. This function will create one and let it leak.
312/// Use lookupIndex() (preferred) or lookupName() instead.
314{
315 for (const auto& item : stateNames())
316 if (item.second == index) {
318 }
319
320 if (printError) {
321 coutE(InputArguments) << ClassName() << "::" << GetName() << ":lookupType: no match for index "
322 << index << endl;
323 }
324
325 return nullptr;
326}
327
328
329
330////////////////////////////////////////////////////////////////////////////////
331/// Find our type corresponding to the specified label, or return 0 for no match.
332/// \deprecated RooCatType is not used, any more. This function will create one and let it leak.
333/// Use lookupIndex() (preferred) or lookupName() instead.
334const RooCatType* RooAbsCategory::lookupType(const char* label, bool printError) const
335{
336 for (const auto& type : stateNames()) {
337 if(type.first == label)
338 return retrieveLegacyState(type.second);
339 }
340
341 // Try if label represents integer number
342 char* endptr ;
343 RooAbsCategory::value_type idx=strtol(label,&endptr,10) ;
344 if (endptr==label+strlen(label)) {
345 return lookupType(idx);
346 }
347
348 if (printError) {
349 coutE(InputArguments) << ClassName() << "::" << GetName() << ":lookupType: no match for label "
350 << label << endl;
351 }
352 return nullptr;
353}
354
355
356////////////////////////////////////////////////////////////////////////////////
357/// Check if given state is defined for this object
358
360{
361 return hasIndex(value.getVal()) ;
362}
363
364
365
366////////////////////////////////////////////////////////////////////////////////
367/// Create a table matching the shape of this category
368
370{
371 return new Roo1DTable(GetName(),label,*this) ;
372}
373
374
375
376////////////////////////////////////////////////////////////////////////////////
377/// Read object contents from stream (dummy for now)
378
379bool RooAbsCategory::readFromStream(istream&, bool, bool)
380{
381 return false ;
382}
383
384
385
386////////////////////////////////////////////////////////////////////////////////
387/// Write object contents to ostream
388
389void RooAbsCategory::writeToStream(ostream& os, bool /* compact */) const
390{
391 os << getCurrentLabel() ;
392}
393
394
395
396////////////////////////////////////////////////////////////////////////////////
397/// Print value (label name)
398
399void RooAbsCategory::printValue(ostream& os) const
400{
401 os << getCurrentLabel() << "(idx = " << getCurrentIndex() << ")" << endl ;
402}
403
404
405
406////////////////////////////////////////////////////////////////////////////////
407/// Print info about this object to the specified stream. In addition to the info
408/// from RooAbsArg::printStream() we add:
409///
410/// Shape : label, index, defined types
411
412void RooAbsCategory::printMultiline(ostream& os, Int_t contents, bool verbose, TString indent) const
413{
415
416 os << indent << "--- RooAbsCategory ---" << endl;
417 if (stateNames().empty()) {
418 os << indent << " ** No values defined **" << endl;
419 return;
420 }
421 os << indent << " Value = " << getCurrentIndex() << " \"" << getCurrentLabel() << ')' << endl;
422 os << indent << " Possible states:" << endl;
423 indent.Append(" ");
424 for (const auto& type : stateNames()) {
425 os << indent << type.first << '\t' << type.second << "\n";
426 }
427}
428
429
430
431////////////////////////////////////////////////////////////////////////////////
432/// Attach the category index and label to as branches to the given vector store
433
435{
436 RooVectorDataStore::CatVector* cv = vstore.addCategory(this) ;
438}
439
440
441
442
443////////////////////////////////////////////////////////////////////////////////
444/// Attach the category index and label as branches to the given
445/// TTree. The index field will be attached as integer with name
446/// `<name>_idx`. If a branch `<name>` exists, it attaches to this branch.
448{
449 // First check if there is an integer branch matching the category name
450 TString cleanName(cleanBranchName()) ;
451 TBranch* branch = tree.GetBranch(cleanName) ;
452 if (!branch) {
453 cleanName += "_idx";
454 branch = tree.GetBranch(cleanName);
455 }
456
457 if (branch) {
458 TLeaf* leaf = (TLeaf*)branch->GetListOfLeaves()->At(0) ;
459
460 // Check that leaf is _not_ an array
461 Int_t dummy ;
462 TLeaf* counterLeaf = leaf->GetLeafCounter(dummy) ;
463 if (counterLeaf) {
464 coutE(Eval) << "RooAbsCategory::attachToTree(" << GetName() << ") ERROR: TTree branch " << GetName()
465 << " is an array and cannot be attached to a RooAbsCategory" << endl ;
466 return ;
467 }
468
469 TString typeName(leaf->GetTypeName()) ;
470
471
472 // For different type names, store a function to attach
473 std::map<std::string, std::function<std::unique_ptr<TreeReadBuffer>()>> typeMap {
474 {"Float_t", [&](){ return createTreeReadBuffer<Float_t >(cleanName, tree); }},
475 {"Double_t", [&](){ return createTreeReadBuffer<Double_t >(cleanName, tree); }},
476 {"UChar_t", [&](){ return createTreeReadBuffer<UChar_t >(cleanName, tree); }},
477 {"Boolt_", [&](){ return createTreeReadBuffer<Bool_t >(cleanName, tree); }},
478 {"Char_t", [&](){ return createTreeReadBuffer<Char_t >(cleanName, tree); }},
479 {"UInt_t", [&](){ return createTreeReadBuffer<UInt_t >(cleanName, tree); }},
480 {"Long64_t", [&](){ return createTreeReadBuffer<Long64_t >(cleanName, tree); }},
481 {"ULong64_t", [&](){ return createTreeReadBuffer<ULong64_t>(cleanName, tree); }},
482 {"Short_t", [&](){ return createTreeReadBuffer<Short_t >(cleanName, tree); }},
483 {"UShort_t", [&](){ return createTreeReadBuffer<UShort_t >(cleanName, tree); }},
484 };
485
486 auto typeDetails = typeMap.find(typeName.Data());
487 if (typeDetails != typeMap.end()) {
488 coutI(DataHandling) << "RooAbsCategory::attachToTree(" << GetName() << ") TTree " << typeName << " branch \"" << cleanName
489 << "\" will be converted to int." << endl ;
490 _treeReadBuffer = typeDetails->second();
491 } else {
492 _treeReadBuffer = nullptr;
493
494 if (!typeName.CompareTo("Int_t")) {
495 tree.SetBranchAddress(cleanName, &_currentIndex);
496 }
497 else {
498 coutE(InputArguments) << "RooAbsCategory::attachToTree(" << GetName() << ") data type " << typeName << " is not supported." << endl ;
499 }
500 }
501 } else {
502 TString format(cleanName);
503 format.Append("/I");
504 void* ptr = &_currentIndex;
505 tree.Branch(cleanName, ptr, (const Text_t*)format, bufSize);
506 }
507}
508
509
510
511////////////////////////////////////////////////////////////////////////////////
512/// Fill tree branches associated with current object with current value
513
515{
516 TString idxName(GetName()) ;
517 idxName.Append("_idx") ;
518
519 // First determine if branch is taken
520 TBranch* idxBranch = t.GetBranch(idxName) ;
521 if (!idxBranch) {
522 coutF(DataHandling) << "RooAbsCategory::fillTreeBranch(" << GetName() << ") ERROR: not attached to tree" << endl ;
523 throw std::runtime_error("RooAbsCategory::fillTreeBranch(): Category is not attached to a tree.");
524 }
525
526 idxBranch->Fill() ;
527}
528
529
530
531////////////////////////////////////////////////////////////////////////////////
532/// (De)activate associate tree branch
533
535{
536 TBranch* branch = t.GetBranch(Form("%s_idx",GetName())) ;
537 if (branch) {
538 t.SetBranchStatus(Form("%s_idx",GetName()),active?1:0) ;
539 }
540}
541
542
543
544////////////////////////////////////////////////////////////////////////////////
545/// Explicitly synchronize RooAbsCategory internal cache
546
548{
550}
551
552
553
554////////////////////////////////////////////////////////////////////////////////
555/// Copy the cached value from given source and raise dirty flag.
556/// It is the callers responsibility to ensure that the sources
557/// cache is clean(valid) before this function is called, e.g. by
558/// calling syncCache() on the source.
559
560void RooAbsCategory::copyCache(const RooAbsArg *source, bool /*valueOnly*/, bool setValDirty)
561{
562 auto other = static_cast<const RooAbsCategory*>(source);
563 assert(dynamic_cast<const RooAbsCategory*>(source));
564
565 _currentIndex = other->_treeReadBuffer ? *other->_treeReadBuffer : other->_currentIndex;
566
567 if (setValDirty) {
569 }
570}
571
572
573////////////////////////////////////////////////////////////////////////////////
574/// Overwrite the value stored in this object's cache.
575/// This can be used to fake a computation that resulted in `value`.
576/// \param[in] value Value to write. The argument is reinterpreted as a category state.
577/// If such a state does not exist, this will create undefined behaviour.
578/// \param[in] notifyClients If true, notify users of this object that its value changed.
579/// This is the default.
580void RooAbsCategory::setCachedValue(double value, bool notifyClients) {
581 _currentIndex = static_cast<value_type>(value);
582
583 if (notifyClients) {
585 _valueDirty = false;
586 }
587}
588
589
590////////////////////////////////////////////////////////////////////////////////
591/// Return name and index of the `n`th defined state. When states are defined using
592/// defineType() or operator[], the order of insertion is tracked, to mimic the behaviour
593/// before modernising the category classes.
594/// When directly manipulating the map with state names using states(), the order of insertion
595/// is not known, so alphabetical ordering as usual for std::map is used. The latter is faster.
596/// \param[in] n Number of state to be retrieved.
597/// \return A pair with name and index.
598const std::map<std::string, RooAbsCategory::value_type>::value_type& RooAbsCategory::getOrdinal(unsigned int n) const {
599 // Retrieve state names, trigger possible recomputation
600 auto& theStateNames = stateNames();
601
602 if (n >= theStateNames.size())
603 return invalidCategory();
604
605 if (theStateNames.size() != _insertionOrder.size())
606 return *std::next(theStateNames.begin(), n);
607
608 const auto item = theStateNames.find(_insertionOrder[n]);
609 if (item != theStateNames.end())
610 return *item;
611
612 return invalidCategory();
613}
614
615
616////////////////////////////////////////////////////////////////////////////////
617/// Return ordinal number of the current state.
619 // Retrieve state names, trigger possible recomputation
620 auto& theStateNames = stateNames();
621
622 // If we don't have the full history of inserted state names, have to go by map ordering:
623 if (theStateNames.size() != _insertionOrder.size()) {
624 const auto currentIndex = getCurrentIndex();
625 for (auto it = theStateNames.begin(); it != theStateNames.end(); ++it) {
626 if (it->second == currentIndex)
627 return std::distance(theStateNames.begin(), it);
628 }
629 }
630
631 // With full insertion history, find index of current label:
632 auto item = std::find(_insertionOrder.begin(), _insertionOrder.end(), getCurrentLabel());
633 assert(item != _insertionOrder.end());
634
635 return item - _insertionOrder.begin();
636}
637
638
639////////////////////////////////////////////////////////////////////////////////
640/// Create a RooCategory fundamental object with our properties.
641
643{
644 // Add and precalculate new category column
645 RooCategory *fund= new RooCategory(newname?newname:GetName(),GetTitle()) ;
646
647 // Copy states
648 for (const auto& type : stateNames()) {
649 fund->defineStateUnchecked(type.first, type.second);
650 }
651
652 return fund;
653}
654
655
656
657////////////////////////////////////////////////////////////////////////////////
658/// Determine if category has 2 or 3 states with index values -1,0,1
659
660bool RooAbsCategory::isSignType(bool mustHaveZero) const
661{
662 const auto& theStateNames = stateNames();
663
664 if (theStateNames.size() > 3 || theStateNames.size() < 2) return false;
665 if (mustHaveZero && theStateNames.size() != 3) return false;
666
667 for (const auto& type : theStateNames) {
668 if (abs(type.second)>1)
669 return false;
670 }
671
672 return true;
673}
674
675/// \deprecated Use begin() and end() instead.
676/// \note Using this iterator creates useless RooCatType instances, which will leak
677/// unless deleted by the user.
680}
681
682const RooCatType* RooAbsCategory::defineType(const char* label) {
683 defineState(label);
684 return retrieveLegacyState(stateNames()[label]);
685}
686
687const RooCatType* RooAbsCategory::defineType(const char* label, int index) {
688 defineState(label, index);
690}
691
695}
696
697/// Return the legacy RooCatType corresponding to `index`. If it doesn't exist, create one.
699 auto result = _legacyStates.find(index);
700 if (result == _legacyStates.end()) {
701 result = _legacyStates.emplace(index,
702 std::unique_ptr<RooCatType>(new RooCatType(lookupName(index).c_str(), index))).first;
703 }
704
705 return result->second.get();
706}
707
708
710 const auto& theStateNames = stateNames();
711
712 if (theStateNames.empty())
713 return 0;
714
715 return 1 + std::max_element(theStateNames.begin(), theStateNames.end(),
716 [](const std::map<std::string, value_type>::value_type& left,
717 const std::map<std::string, value_type>::value_type& right) {
718 return left.second < right.second; })->second;
719}
#define coutI(a)
Definition: RooMsgService.h:34
#define coutF(a)
Definition: RooMsgService.h:38
#define coutE(a)
Definition: RooMsgService.h:37
char Text_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:375
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition: TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition: TString.cxx:2456
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:71
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition: RooAbsArg.h:495
bool isShapeDirty() const
Definition: RooAbsArg.h:416
void clearValueDirty() const
Definition: RooAbsArg.h:601
bool _valueDirty
Definition: RooAbsArg.h:710
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:490
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Implement multi-line detailed printing.
Definition: RooAbsArg.cxx:1493
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:1978
bool isValueDirty() const
Definition: RooAbsArg.h:421
A space to attach TBranches.
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.
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
bool operator==(value_type index) const
Equality operator with a integer (compares with state index number)
RooCatType * retrieveLegacyState(value_type index) const
Return the legacy RooCatType corresponding to index. If it doesn't exist, create one.
void copyCache(const RooAbsArg *source, bool valueOnly=false, bool setValueDirty=true) override
Copy the cached value from given source and raise dirty flag.
value_type _currentIndex
Current category state.
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.
const RooCatType * defineTypeUnchecked(const char *label, value_type index)
void setTreeBranchStatus(TTree &t, bool active) override
(De)activate associate tree branch
const RooCatType * lookupType(value_type index, bool printError=false) const
Find our type corresponding to the specified index, or return nullptr for no match.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to ostream.
value_type nextAvailableStateIndex() const
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from stream (dummy for now)
bool isSignType(bool mustHaveZero=false) const
Determine if category has 2 or 3 states with index values -1,0,1.
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.
virtual value_type evaluate() const =0
Evaluate the category state and return.
void syncCache(const RooArgSet *set=nullptr) override
Explicitly synchronize RooAbsCategory internal cache.
const std::map< std::string, value_type >::value_type & getOrdinal(unsigned int n) const
Return name and index of the nth defined state.
RooAbsArg * createFundamental(const char *newname=nullptr) const override
Create a RooCategory fundamental object with our properties.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
std::map< value_type, std::unique_ptr< RooCatType, std::function< void(RooCatType *)> > > _legacyStates
! Map holding pointers to RooCatType instances. Only for legacy interface. Don't use if possible.
bool isIdentical(const RooAbsArg &other, bool assumeSameType=false) const override
~RooAbsCategory() override
Destructor.
std::vector< std::string > _insertionOrder
Keeps track in which order state numbers have been inserted. Make sure this is updated in recomputeSh...
std::map< std::string, value_type > _stateNames
Map state names to index numbers. Make sure state names are updated in recomputeShape().
bool isValid() const override
WVE (08/21/01) Probably obsolete now.
const RooCatType * defineType(const char *label)
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.
void attachToVStore(RooVectorDataStore &vstore) override
Attach the category index and label to as branches to the given vector store.
static const decltype(_stateNames) ::value_type & invalidCategory()
A category state to signify an invalid category.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
std::unique_ptr< TreeReadBuffer > _treeReadBuffer
void attachToTree(TTree &t, Int_t bufSize=32000) override
Attach the category index and label as branches to the given TTree.
void fillTreeBranch(TTree &t) override
Fill tree branches associated with current object with current value.
bool empty() const
If there are no states defined.
void clearTypes()
Delete all currently defined states.
void printValue(std::ostream &os) const override
Print value (label name)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
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:28
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 * GetTypeName() const
Definition: TLeaf.h:139
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf (if any) or store the number of elements that the leaf c...
Definition: TLeaf.cxx:249
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition: TNamed.h:48
TObject * At(Int_t idx) const override
Definition: TObjArray.h:164
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:207
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:451
const char * Data() const
Definition: TString.h:369
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:5262
virtual void SetBranchStatus(const char *bname, Bool_t status=1, UInt_t *found=nullptr)
Set branch status to Process or DoNotProcess.
Definition: TTree.cxx:8503
RVec< PromoteType< T > > abs(const RVec< T > &v)
Definition: RVec.hxx:1778
const Int_t n
Definition: legend1.C:16
@ DataHandling
Definition: RooGlobalFunc.h:63
@ InputArguments
Definition: RooGlobalFunc.h:62
Definition: tree.py:1