Logo ROOT   master
Reference Guide
RooMultiCategory.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 RooMultiCategory.cxx
19 \class RooMultiCategory
20 \ingroup Roofitcore
21 
22 RooMultiCategory consolidates several RooAbsCategory objects into
23 a single category. The states of the multi-category consist of all the permutations
24 of the input categories.
25 RooMultiCategory state are automatically defined and updated whenever an input
26 category modifies its list of states
27 **/
28 
29 #include "RooFit.h"
30 
31 #include "Riostream.h"
32 #include <stdlib.h>
33 #include "TString.h"
34 #include "RooMultiCategory.h"
35 #include "RooStreamParser.h"
36 #include "RooArgSet.h"
37 #include "RooMultiCatIter.h"
38 #include "RooAbsCategory.h"
39 #include "RooMsgService.h"
40 
41 using namespace std;
42 
44 
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Construct a product of the given set of input RooAbsCategories in 'inInputCatList'
49 /// The state names of this product category are {S1;S2,S3,...Sn} where Si are the state names
50 /// of the input categories. A RooMultiCategory is not an lvalue
51 
52 RooMultiCategory::RooMultiCategory(const char *name, const char *title, const RooArgSet& inputCatList2) :
53  RooAbsCategory(name, title), _catSet("input","Input category set",this,kTRUE,kTRUE)
54 {
55  // Copy category list
56  TIterator* iter = inputCatList2.createIterator() ;
57  RooAbsArg* arg ;
58  while ((arg=(RooAbsArg*)iter->Next())) {
59  if (!dynamic_cast<RooAbsCategory*>(arg)) {
60  coutE(InputArguments) << "RooMultiCategory::RooMultiCategory(" << GetName() << "): input argument " << arg->GetName()
61  << " is not a RooAbsCategory" << endl ;
62  }
63  _catSet.add(*arg) ;
64  }
65  delete iter ;
66 
67  updateIndexList() ;
68 }
69 
70 
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Copy constructor
74 
76  RooAbsCategory(other,name), _catSet("input",this,other._catSet)
77 {
78  updateIndexList() ;
79 }
80 
81 
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Destructor
85 
87 {
88 }
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Update the list of super-category states
94 
96 {
97  // WVE broken if used with derived categories!
98  clearTypes() ;
99 
100  RooMultiCatIter iter(_catSet) ;
101  TObjString* obj ;
102  while((obj=(TObjString*)iter.Next())) {
103  // Register composite label
104  defineType(obj->String()) ;
105  }
106 
107  // Renumbering will invalidate cache
108  setValueDirty() ;
109 }
110 
111 
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Return the name of the current state,
115 /// constructed from the state names of the input categories
116 
118 {
119  TIterator* lIter = _catSet.createIterator() ;
120 
121  // Construct composite label name
122  TString label ;
123  RooAbsCategory* cat ;
124  Bool_t first(kTRUE) ;
125  while((cat=(RooAbsCategory*) lIter->Next())) {
126  label.Append(first?"{":";") ;
127  label.Append(cat->getLabel()) ;
128  first=kFALSE ;
129  }
130  label.Append("}") ;
131  delete lIter ;
132 
133  return label ;
134 }
135 
136 
137 
138 ////////////////////////////////////////////////////////////////////////////////
139 /// Calculate the current value
140 
142 {
143  if (isShapeDirty()) const_cast<RooMultiCategory*>(this)->updateIndexList() ;
144 
145  // current label is can be looked up by definition
146  // coverity[NULL_RETURNS]
147  return *lookupType(currentLabel()) ;
148 }
149 
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Print the state of this object to the specified output stream.
154 
156 {
158 
159  if (verbose) {
160  os << indent << "--- RooMultiCategory ---" << endl;
161  os << indent << " Input category list:" << endl ;
162  TString moreIndent(indent) ;
163  moreIndent.Append(" ") ;
164  _catSet.printStream(os,kName|kValue,kStandard,moreIndent.Data()) ;
165  }
166 }
167 
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Read object contents from given stream
172 
173 Bool_t RooMultiCategory::readFromStream(istream& /*is*/, Bool_t /*compact*/, Bool_t /*verbose*/)
174 {
175  return kTRUE ;
176 }
177 
178 
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Write object contents to given stream
182 
183 void RooMultiCategory::writeToStream(ostream& os, Bool_t compact) const
184 {
185  RooAbsCategory::writeToStream(os,compact) ;
186 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
#define coutE(a)
Definition: RooMsgService.h:33
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
virtual ~RooMultiCategory()
Destructor.
RooSetProxy _catSet
Collectable string class.
Definition: TObjString.h:28
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to ostream.
virtual RooCatType evaluate() const
Calculate the current value.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
void clearTypes()
Delete all currently defined states.
Basic string class.
Definition: TString.h:131
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:30
void updateIndexList()
Update the list of super-category states.
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to given stream.
virtual TObject * Next()
Iterator increment operator.
TString & Append(const char *cs)
Definition: TString.h:559
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:22
TString currentLabel() const
Return the name of the current state, constructed from the state names of the input categories...
const RooCatType * defineType(const char *label)
Define a new state with given name.
virtual void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print the state of this object to the specified output stream.
const RooCatType * lookupType(value_type index, Bool_t printError=kFALSE) const
Find our type corresponding to the specified index, or return 0 for no match.
virtual const char * getLabel() const
Return label string of current state.
static void indent(ostringstream &buf, int indent_level)
TString & String()
Definition: TObjString.h:48
const Bool_t kFALSE
Definition: RtypesCore.h:88
RooMultiCategory consolidates several RooAbsCategory objects into a single category.
#define ClassImp(name)
Definition: Rtypes.h:365
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.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition: RooAbsArg.h:465
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from given stream.
virtual TObject * Next()=0
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
Definition: first.py:1
Bool_t isShapeDirty() const
Definition: RooAbsArg.h:384
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
const Bool_t kTRUE
Definition: RtypesCore.h:87
RooMultiCatIter iterators over all state permutations of a list of categories.
char name[80]
Definition: TGX11.cxx:109
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...
const char * Data() const
Definition: TString.h:364