Logo ROOT   6.14/05
Reference Guide
RooAbsCategory.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooAbsCategory.h,v 1.38 2007/05/11 09:11:30 verkerke Exp $
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 #ifndef ROO_ABS_CATEGORY
17 #define ROO_ABS_CATEGORY
18 
19 #include "TObjArray.h"
20 #include "RooAbsArg.h"
21 #include "RooCatType.h"
22 
23 class TTree ;
24 class RooArgSet ;
25 class RooDataSet ;
26 class Roo1DTable ;
27 class RooVectorDataStore ;
28 
29 class RooAbsCategory : public RooAbsArg {
30 public:
31  // Constructors, assignment etc.
33  // Default constructor
34  _treeVar = kFALSE ;
36  } ;
37  RooAbsCategory(const char *name, const char *title);
38  RooAbsCategory(const RooAbsCategory& other, const char* name=0) ;
39  virtual ~RooAbsCategory();
40 
41  // Value accessors
42  virtual Int_t getIndex() const ;
43  virtual const char* getLabel() const ;
44  Bool_t operator==(Int_t index) const ;
45  Bool_t operator!=(Int_t index) { return !operator==(index);}
46  Bool_t operator==(const char* label) const ;
47  Bool_t operator!=(const char* label) { return !operator==(label);}
48  virtual Bool_t operator==(const RooAbsArg& other) ;
49  Bool_t operator!=(const RooAbsArg& other) { return !operator==(other);}
50  virtual Bool_t isIdentical(const RooAbsArg& other, Bool_t assumeSameType=kFALSE) ;
51 
52  Bool_t isValidIndex(Int_t index) const ;
53  Bool_t isValidLabel(const char* label) const ;
54  const RooCatType* lookupType(Int_t index, Bool_t printError=kFALSE) const ;
55  const RooCatType* lookupType(const char* label, Bool_t printError=kFALSE) const ;
56  const RooCatType* lookupType(const RooCatType& type, Bool_t printError=kFALSE) const ;
57  TIterator* typeIterator() const ;
58  Int_t numTypes(const char* /*rangeName*/=0) const {
59  // Return number of types defined (in range named rangeName if rangeName!=0)
60  return _types.GetEntries() ;
61  }
62  Bool_t isSignType(Bool_t mustHaveZero=kFALSE) const ;
63 
64  Roo1DTable *createTable(const char *label) const ;
65 
66  // I/O streaming interface
67  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
68  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
69 
70  virtual void printValue(std::ostream& os) const ;
71  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
72 
73  virtual Bool_t isIntegrationSafeLValue(const RooArgSet* /*set*/) const {
74  // Is this l-value object safe for use as integration observable
75  return kTRUE ;
76  }
77 
78  RooAbsArg *createFundamental(const char* newname=0) const;
79 
80 protected:
81 
82  // Function evaluation and error tracing
83  RooCatType traceEval() const ;
84  // coverity[PASS_BY_VALUE]
85  virtual Bool_t traceEvalHook(RooCatType /*value*/) const {
86  // Hook function for trace evaluation (dummy)
87  return kFALSE ;
88  }
89  virtual RooCatType evaluate() const = 0 ;
90 
91  // Type definition management
92  const RooCatType* defineType(const char* label) ;
93  const RooCatType* defineType(const char* label, Int_t index) ;
94  const RooCatType* defineTypeUnchecked(const char* label, Int_t index) ;
95  const RooCatType* getOrdinal(UInt_t n, const char* rangeName=0) const;
96  void clearTypes() ;
97 
98  virtual Bool_t isValid() const ;
99  virtual Bool_t isValid(const RooCatType& value) const ;
100 
101  friend class RooVectorDataStore ;
102  virtual void syncCache(const RooArgSet* set=0) ;
103  virtual void copyCache(const RooAbsArg* source, Bool_t valueOnly=kFALSE, Bool_t setValueDirty=kTRUE) ;
104  virtual void attachToTree(TTree& t, Int_t bufSize=32000) ;
105  virtual void attachToVStore(RooVectorDataStore& vstore) ;
106  virtual void setTreeBranchStatus(TTree& t, Bool_t active) ;
107  virtual void fillTreeBranch(TTree& t) ;
108 
109  mutable UChar_t _byteValue ; //! Transient cache for byte values from tree branches
110  mutable RooCatType _value ; // Current value
111  TObjArray _types ; // Array of allowed values
113 
114  Bool_t _treeVar ; //! do not persist
115 
116  ClassDef(RooAbsCategory,1) // Abstract discrete variable
117 };
118 
119 #endif
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.
An array of TObjects.
Definition: TObjArray.h:37
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from stream (dummy for now)
virtual void setTreeBranchStatus(TTree &t, Bool_t active)
(De)activate associate tree branch
Bool_t isValidLabel(const char *label) const
Check if state with given name is defined.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to ostream.
RooCatType _value
Transient cache for byte values from tree branches.
const RooCatType * getOrdinal(UInt_t n, const char *rangeName=0) const
Return state definition of ordinal nth defined state, needed by the generator mechanism.
Bool_t operator!=(Int_t index)
virtual void attachToVStore(RooVectorDataStore &vstore)
Attach the category index and label to as branches to the given vector store.
virtual Bool_t isIntegrationSafeLValue(const RooArgSet *) const
void clearTypes()
Delete all currently defined states.
Roo1DTable * createTable(const char *label) const
Create a table matching the shape of this category.
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t operator==(Int_t index) const
Equality operator with a integer (compares with state index number)
virtual Int_t getIndex() const
Return index number of current state.
virtual RooCatType evaluate() const =0
virtual void syncCache(const RooArgSet *set=0)
Explicitly synchronize RooAbsCategory internal cache.
Iterator abstract base class.
Definition: TIterator.h:30
void setValueDirty() const
Definition: RooAbsArg.h:441
virtual Bool_t isValid() const
Check if current value is a valid state.
Int_t numTypes(const char *=0) const
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void printValue(std::ostream &os) const
Print value (label name)
RooVectorDataStore is the abstract base class for data collection that use a TTree as internal storag...
Bool_t operator!=(const RooAbsArg &other)
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:22
const RooCatType * defineType(const char *label)
Define a new state with given name.
Bool_t isSignType(Bool_t mustHaveZero=kFALSE) const
Determine if category has 2 or 3 states with index values -1,0,1.
virtual Bool_t isIdentical(const RooAbsArg &other, Bool_t assumeSameType=kFALSE)
virtual void attachToTree(TTree &t, Int_t bufSize=32000)
Attach the category index and label to as branches to the given TTree.
TIterator * typeIterator() const
Return iterator over all defined states.
const RooCatType * lookupType(Int_t index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return 0 for no match.
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t isValidIndex(Int_t index) const
Check if state with given index is defined.
virtual const char * getLabel() const
Return label string of current state.
RooCatType traceEval() const
Recalculate current value and check validity of new result.
RooAbsArg * createFundamental(const char *newname=0) const
Create a RooCategory fundamental object with our properties.
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
virtual ~RooAbsCategory()
Destructor.
const Bool_t kFALSE
Definition: RtypesCore.h:88
TIterator * MakeIterator(Bool_t dir=kIterForward) const
Returns an array iterator.
Definition: TObjArray.cxx:633
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.
int type
Definition: TGX11.cxx:120
virtual Bool_t traceEvalHook(RooCatType) const
TIterator * _typeIter
virtual void fillTreeBranch(TTree &t)
Fill tree branches associated with current object with current value.
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
TObjArray _types
Int_t GetEntries() const
Return the number of objects in array (i.e.
Definition: TObjArray.cxx:522
A TTree object has a header with a name and a title.
Definition: TTree.h:70
unsigned char UChar_t
Definition: RtypesCore.h:34
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
Bool_t operator!=(const char *label)
const Bool_t kTRUE
Definition: RtypesCore.h:87
const Int_t n
Definition: legend1.C:16
Roo1DTable implements a one-dimensional table.
Definition: Roo1DTable.h:24
const RooCatType * defineTypeUnchecked(const char *label, Int_t index)
Internal version of defineType that does not check if type already exists.
char name[80]
Definition: TGX11.cxx:109