Logo ROOT  
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
22RooMultiCatIter iterators over all state permutations of a list of categories.
23It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
24Since this iterator only constructs state labels and does not change the value
25of its input categories, it is not required that its inputs are LValues.
26For cases where all inputs are LValues (such as for RooSuperCategory) the
27values of the input can be changes by assigning the super category the
28string label generated by this iterator
29**/
30
31#include "RooFit.h"
32
35#include "RooMultiCatIter.h"
36
37using 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
49RooMultiCatIter::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
62RooMultiCatIter::RooMultiCatIter(const RooMultiCatIter& other) : TIterator(other), _catList("catList")
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() ;
87
88 // Construct component iterators
89 _curIter = 0 ;
90 _curItem = 0 ;
93 while((cat=(RooAbsCategoryLValue*)cIter->Next())) {
94 _catPtrList[_curIter] = cat ;
95 _iterList[_curIter] = cat->typeIterator() ;
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{
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
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
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() ;
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
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
void Class()
Definition: Class.C:29
int Int_t
Definition: RtypesCore.h:41
#define ClassImp(name)
Definition: Rtypes.h:365
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
Int_t getSize() const
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
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:88
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Definition: RooCatType.h:22
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:44
void SetName(const Text_t *name)
Constructor with name argument.
Definition: RooCatType.cxx:46
RooMultiCatIter iterators over all state permutations of a list of categories.
pTIterator * _iterList
virtual TObject * Next()
Iterator increment operator.
RooCatType * _curTypeList
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...
pRooCategory * _catPtrList
virtual void Reset()
Rewind master iterator.
RooMultiCatIter(const RooArgSet &catList, const char *rangeName=0)
Construct iterator over all permutations of states of categories in catList.
TObjString * compositeLabel()
Construct string with composite object label corresponding to the state name of a RooMultiCategory or...
RooArgSet _catList
void initialize(const RooArgSet &catList)
Build iterator array for given catList.
TObjString _compositeLabel
TObject * _curItem
virtual ~RooMultiCatIter()
Destructor.
virtual const TCollection * GetCollection() const
Dummy implementation, always returns zero.
Collection abstract base class.
Definition: TCollection.h:63
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
Collectable string class.
Definition: TObjString.h:28
TString & String()
Definition: TObjString.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
TString & Append(const char *cs)
Definition: TString.h:559
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:150
Definition: first.py:1