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\class RooMultiCatIter
19\ingroup Roofitlegacy
20
21\deprecated RooMultiCatIter is unnecessary, since all multi category classes know how to generate
22their own states. Use begin() / end() and range-based for loops on instances of these classes.
23
24RooMultiCatIter iterates over all state permutations of a list of categories.
25It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
26Since this iterator only constructs state labels and does not change the value
27of its input categories, it is not required that its inputs are LValues.
28For cases where all inputs are LValues (such as for RooSuperCategory) the
29values of the input can be changes by assigning the super category the
30string label generated by this iterator
31**/
32
33#include "RooMultiCatIter.h"
34
35#include "RooFit.h"
38
39
40using namespace std;
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Construct iterator over all permutations of states of categories in catList.
45/// If rangeName is not null, iteration is restricted to states that are selected
46/// in the given range name
47
48RooMultiCatIter::RooMultiCatIter(const RooArgSet& catList, const char* rangeName) : _catList("catList")
49{
50 if (rangeName) {
51 _rangeName = rangeName ;
52 }
53 initialize(catList) ;
54}
55
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy constructor
60
61RooMultiCatIter::RooMultiCatIter(const RooMultiCatIter& other) : TIterator(other), _catList("catList")
62{
63 initialize(other._catList) ;
64}
65
66
67
68////////////////////////////////////////////////////////////////////////////////
69/// Build iterator array for given catList
70
72{
73 // Copy RooCategory list into internal argset
74 TIterator* catIter = catList.createIterator() ;
75 TObject* obj ;
76 while ((obj = catIter->Next())) {
77 _catList.add((RooAbsArg&)*obj) ;
78 }
79 delete catIter ;
80
81 // Allocate storage for component iterators
82 _nIter = catList.getSize() ;
86
87 // Construct component iterators
88 _curIter = 0 ;
89 _curItem = 0 ;
92 while((cat=(RooAbsCategoryLValue*)cIter->Next())) {
93 _catPtrList[_curIter] = cat ;
96// _curTypeList[_curIter] = *first ;
97// _curTypeList[_curIter].SetName(first->GetName()) ;
98// cout << "init: _curTypeList[" << _curIter << "] set to " << first->GetName() << endl ;
99// _iterList[_curIter]->Reset() ;
100 _curIter++ ;
101 }
102 delete cIter ;
103
104 Reset() ;
105}
106
107
108
109////////////////////////////////////////////////////////////////////////////////
110/// Destructor
111
113{
114 for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
115 delete _iterList[_curIter] ;
116 }
117 delete[] _iterList ;
118 delete[] _catPtrList ;
119 delete[] _curTypeList ;
120}
121
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Dummy implementation, always returns zero
126
128{
129 //return &_catList.getCollection() ;
130 return 0 ;
131}
132
133
134
135////////////////////////////////////////////////////////////////////////////////
136/// Construct string with composite object
137/// label corresponding to the state name
138/// of a RooMultiCategory or RooSuperCategory
139/// constructed from this set of input categories
140
142{
144
145 str = "{" ;
146 Int_t i ;
147 for (i=0 ; i<_nIter ; i++) {
148 if (i>0) str.Append(";") ;
149 str.Append(_curTypeList[i].GetName()) ;
150 }
151 str.Append("}") ;
152
153 return &_compositeLabel ;
154}
155
156
157
158////////////////////////////////////////////////////////////////////////////////
159/// Iterator increment operator
160
162{
163 // Check for end
164 if (_curIter==_nIter) {
165 _curItem = 0;
166 return 0 ;
167 }
168
170 if (next) {
171
172 // Increment current iterator
173 _curTypeList[_curIter] = *next ;
175
176 // If higher order increment was successful, reset master iterator
177 if (_curIter>0) _curIter=0 ;
178
180 return _curItem ;
181 } else {
182
183 // Reset current iterator
185 next = (RooCatType*) _iterList[_curIter]->Next() ;
186 if (next) {
187 _curTypeList[_curIter] = *next ;
189 }
190 //if (next) _catPtrList[_curIter]->setIndex(next->getVal()) ;
191
192 // Increment next iterator
193 _curIter++ ;
194 _curItem = Next() ;
195 return _curItem ;
196 }
197}
198
199
200
201////////////////////////////////////////////////////////////////////////////////
202/// Rewind master iterator
203
205{
206 for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
207 TIterator* cIter = _iterList[_curIter] ;
208 cIter->Reset() ;
209 RooCatType* first = (RooCatType*) cIter->Next() ;
210 if (first) {
211 if (_curIter==0) cIter->Reset() ;
213 _curTypeList[_curIter].SetName(first->GetName()) ;
214 }
215 }
216 _curIter=0 ;
217}
218
219
220////////////////////////////////////////////////////////////////////////////////
221/// Return current item (dummy)
222
224{
225 return _curItem ;
226}
227
228
229////////////////////////////////////////////////////////////////////////////////
230/// Comparison operator to other iterator
231/// Returns true if both iterator iterate over the
232/// same set of input categories and are not at the
233/// same sequential position
234
236{
237 auto otherMCIt = dynamic_cast<const RooMultiCatIter*>(&aIter);
238 if (!otherMCIt)
239 return true;
240
241 return (_curItem != otherMCIt->_curItem);
242
243}
244
int Int_t
Definition: RtypesCore.h:43
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
TIterator * typeIterator() const
Int_t getSize() const
TIterator * createIterator(Bool_t dir=kIterForward) const
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.
virtual const Text_t * GetName() const
Returns name of object.
void SetName(const Text_t *name)
Constructor with name argument.
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
Definition: first.py:1