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