Logo ROOT   6.14/05
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 "Riostream.h"
33 #include <stdlib.h>
34 #include "TString.h"
35 #include "RooMultiCategory.h"
36 #include "RooStreamParser.h"
37 #include "RooArgSet.h"
38 #include "RooMultiCatIter.h"
39 #include "RooAbsCategory.h"
40 #include "RooMsgService.h"
41 
42 using namespace std;
43 
45 ;
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Construct a product of the given set of input RooAbsCategories in 'inInputCatList'
50 /// The state names of this product category are {S1;S2,S3,...Sn} where Si are the state names
51 /// of the input categories. A RooMultiCategory is not an lvalue
52 
53 RooMultiCategory::RooMultiCategory(const char *name, const char *title, const RooArgSet& inputCatList2) :
54  RooAbsCategory(name, title), _catSet("input","Input category set",this,kTRUE,kTRUE)
55 {
56  // Copy category list
57  TIterator* iter = inputCatList2.createIterator() ;
58  RooAbsArg* arg ;
59  while ((arg=(RooAbsArg*)iter->Next())) {
60  if (!dynamic_cast<RooAbsCategory*>(arg)) {
61  coutE(InputArguments) << "RooMultiCategory::RooMultiCategory(" << GetName() << "): input argument " << arg->GetName()
62  << " is not a RooAbsCategory" << endl ;
63  }
64  _catSet.add(*arg) ;
65  }
66  delete iter ;
67 
68  updateIndexList() ;
69 }
70 
71 
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Copy constructor
75 
77  RooAbsCategory(other,name), _catSet("input",this,other._catSet)
78 {
79  updateIndexList() ;
80 }
81 
82 
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Destructor
86 
88 {
89 }
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Update the list of super-category states
95 
97 {
98  // WVE broken if used with derived categories!
99  clearTypes() ;
100 
101  RooMultiCatIter iter(_catSet) ;
102  TObjString* obj ;
103  while((obj=(TObjString*)iter.Next())) {
104  // Register composite label
105  defineType(obj->String()) ;
106  }
107 
108  // Renumbering will invalidate cache
109  setValueDirty() ;
110 }
111 
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Return the name of the current state,
116 /// constructed from the state names of the input categories
117 
119 {
120  TIterator* lIter = _catSet.createIterator() ;
121 
122  // Construct composite label name
123  TString label ;
124  RooAbsCategory* cat ;
125  Bool_t first(kTRUE) ;
126  while((cat=(RooAbsCategory*) lIter->Next())) {
127  label.Append(first?"{":";") ;
128  label.Append(cat->getLabel()) ;
129  first=kFALSE ;
130  }
131  label.Append("}") ;
132  delete lIter ;
133 
134  return label ;
135 }
136 
137 
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Calculate the current value
141 
143 {
144  if (isShapeDirty()) const_cast<RooMultiCategory*>(this)->updateIndexList() ;
145 
146  // current label is can be looked up by definition
147  // coverity[NULL_RETURNS]
148  return *lookupType(currentLabel()) ;
149 }
150 
151 
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Print the state of this object to the specified output stream.
155 
156 void RooMultiCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
157 {
158  RooAbsCategory::printMultiline(os,content,verbose,indent) ;
159 
160  if (verbose) {
161  os << indent << "--- RooMultiCategory ---" << endl;
162  os << indent << " Input category list:" << endl ;
163  TString moreIndent(indent) ;
164  moreIndent.Append(" ") ;
165  _catSet.printStream(os,kName|kValue,kStandard,moreIndent.Data()) ;
166  }
167 }
168 
169 
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 /// Read object contents from given stream
173 
174 Bool_t RooMultiCategory::readFromStream(istream& /*is*/, Bool_t /*compact*/, Bool_t /*verbose*/)
175 {
176  return kTRUE ;
177 }
178 
179 
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Write object contents to given stream
183 
184 void RooMultiCategory::writeToStream(ostream& os, Bool_t compact) const
185 {
186  RooAbsCategory::writeToStream(os,compact) ;
187 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TIterator * createIterator(Bool_t dir=kIterForward) const
#define coutE(a)
Definition: RooMsgService.h:34
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.
void clearTypes()
Delete all currently defined states.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:30
void setValueDirty() const
Definition: RooAbsArg.h:441
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.
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(Int_t 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.
TString & String()
Definition: TObjString.h:49
const Bool_t kFALSE
Definition: RtypesCore.h:88
RooMultiCategory consolidates several RooAbsCategory objects into a single category.
#define ClassImp(name)
Definition: Rtypes.h:359
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.
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:331
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
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...