Logo ROOT   6.14/05
Reference Guide
RooMultiCatIter.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 RooMultiCatIter.cxx
19 \class RooMultiCatIter
20 \ingroup Roofitcore
21 
22 RooMultiCatIter iterators over all state permutations of a list of categories.
23 It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
24 Since this iterator only constructs state labels and does not change the value
25 of its input categories, it is not required that its inputs are LValues.
26 For cases where all inputs are LValues (such as for RooSuperCategory) the
27 values of the input can be changes by assigning the super category the
28 string label generated by this iterator
29 **/
30 
31 #include "RooFit.h"
32 
33 #include "RooAbsCategoryLValue.h"
34 #include "RooAbsCategoryLValue.h"
35 #include "RooMultiCatIter.h"
36 
37 using namespace std;
38 
40 ;
41 
42 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Construct iterator over all permutations of states of categories in catList.
46 /// If rangeName is not null, iteration is restricted to states that are selected
47 /// in the given range name
48 
49 RooMultiCatIter::RooMultiCatIter(const RooArgSet& catList, const char* rangeName) : _catList("catList")
50 {
51  if (rangeName) {
52  _rangeName = rangeName ;
53  }
54  initialize(catList) ;
55 }
56 
57 
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Copy constructor
61 
63 {
64  initialize(other._catList) ;
65 }
66 
67 
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Build iterator array for given catList
71 
73 {
74  // Copy RooCategory list into internal argset
75  TIterator* catIter = catList.createIterator() ;
76  TObject* obj ;
77  while ((obj = catIter->Next())) {
78  _catList.add((RooAbsArg&)*obj) ;
79  }
80  delete catIter ;
81 
82  // Allocate storage for component iterators
83  _nIter = catList.getSize() ;
84  _iterList = new pTIterator[_nIter] ;
87 
88  // Construct component iterators
89  _curIter = 0 ;
90  _curItem = 0 ;
91  TIterator* cIter = _catList.createIterator() ;
93  while((cat=(RooAbsCategoryLValue*)cIter->Next())) {
94  _catPtrList[_curIter] = cat ;
95  _iterList[_curIter] = cat->typeIterator() ;
96  _iterList[_curIter]->Next() ;
97 // _curTypeList[_curIter] = *first ;
98 // _curTypeList[_curIter].SetName(first->GetName()) ;
99 // cout << "init: _curTypeList[" << _curIter << "] set to " << first->GetName() << endl ;
100 // _iterList[_curIter]->Reset() ;
101  _curIter++ ;
102  }
103  delete cIter ;
104 
105  Reset() ;
106 }
107 
108 
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Destructor
112 
114 {
115  for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
116  delete _iterList[_curIter] ;
117  }
118  delete[] _iterList ;
119  delete[] _catPtrList ;
120  delete[] _curTypeList ;
121 }
122 
123 
124 
125 ////////////////////////////////////////////////////////////////////////////////
126 /// Dummy implementation, always returns zero
127 
129 {
130  //return &_catList.getCollection() ;
131  return 0 ;
132 }
133 
134 
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Construct string with composite object
138 /// label corresponding to the state name
139 /// of a RooMultiCategory or RooSuperCategory
140 /// constructed from this set of input categories
141 
143 {
144  TString& str = _compositeLabel.String() ;
145 
146  str = "{" ;
147  Int_t i ;
148  for (i=0 ; i<_nIter ; i++) {
149  if (i>0) str.Append(";") ;
150  str.Append(_curTypeList[i].GetName()) ;
151  }
152  str.Append("}") ;
153 
154  return &_compositeLabel ;
155 }
156 
157 
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Iterator increment operator
161 
163 {
164  // Check for end
165  if (_curIter==_nIter) {
166  _curItem = 0;
167  return 0 ;
168  }
169 
170  RooCatType* next = (RooCatType*) _iterList[_curIter]->Next() ;
171  if (next) {
172 
173  // Increment current iterator
174  _curTypeList[_curIter] = *next ;
176 
177  // If higher order increment was successful, reset master iterator
178  if (_curIter>0) _curIter=0 ;
179 
181  return _curItem ;
182  } else {
183 
184  // Reset current iterator
185  _iterList[_curIter]->Reset() ;
186  next = (RooCatType*) _iterList[_curIter]->Next() ;
187  if (next) {
188  _curTypeList[_curIter] = *next ;
190  }
191  //if (next) _catPtrList[_curIter]->setIndex(next->getVal()) ;
192 
193  // Increment next iterator
194  _curIter++ ;
195  _curItem = Next() ;
196  return _curItem ;
197  }
198 }
199 
200 
201 
202 ////////////////////////////////////////////////////////////////////////////////
203 /// Rewind master iterator
204 
206 {
207  for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
208  TIterator* cIter = _iterList[_curIter] ;
209  cIter->Reset() ;
210  RooCatType* first = (RooCatType*) cIter->Next() ;
211  if (first) {
212  if (_curIter==0) cIter->Reset() ;
213  _curTypeList[_curIter] = *first ;
214  _curTypeList[_curIter].SetName(first->GetName()) ;
215  }
216  }
217  _curIter=0 ;
218 }
219 
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// Return current item (dummy)
223 
225 {
226  return _curItem ;
227 }
228 
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 /// Comparison operator to other iterator
232 /// Returns true if both iterator iterate over the
233 /// same set of input categories and are not at the
234 /// same sequential position
235 
236 bool RooMultiCatIter::operator!=(const TIterator &aIter) const
237 {
238  if ((aIter.IsA() == RooMultiCatIter::Class())) {
239  const RooMultiCatIter &iter(dynamic_cast<const RooMultiCatIter &>(aIter));
240  return (_curItem != iter._curItem);
241  }
242 
243  return false;
244 }
245 
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:145
RooArgSet _catList
TIterator * createIterator(Bool_t dir=kIterForward) const
RooCatType * _curTypeList
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:86
TObjString * compositeLabel()
Construct string with composite object label corresponding to the state name of a RooMultiCategory or...
virtual void Reset()=0
Collectable string class.
Definition: TObjString.h:28
pTIterator * _iterList
RooMultiCatIter(const RooArgSet &catList, const char *rangeName=0)
Construct iterator over all permutations of states of categories in catList.
virtual const TCollection * GetCollection() const
Dummy implementation, always returns zero.
int Int_t
Definition: RtypesCore.h:41
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()
Rewind master iterator.
void Class()
Definition: Class.C:29
virtual TObject * Next()
Iterator increment operator.
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state...
Definition: RooCatType.h:22
virtual ~RooMultiCatIter()
Destructor.
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
TObject * _curItem
Int_t getSize() const
TIterator * typeIterator() const
Return iterator over all defined states.
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
Collection abstract base class.
Definition: TCollection.h:63
virtual TObject * operator*() const
Return current item (dummy)
virtual bool operator!=(const TIterator &aIter) const
Comparison operator to other iterator Returns true if both iterator iterate over the same set of inpu...
TString & String()
Definition: TObjString.h:49
#define ClassImp(name)
Definition: Rtypes.h:359
TObjString _compositeLabel
virtual void SetName(const Text_t *name)
Constructor with name argument.
Definition: RooCatType.cxx:46
Mother of all ROOT objects.
Definition: TObject.h:37
virtual TObject * Next()=0
Definition: first.py:1
pRooCategory * _catPtrList
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooMultiCatIter iterators over all state permutations of a list of categories.
void initialize(const RooArgSet &catList)
Build iterator array for given catList.