ROOT  6.06/09
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 //
19 // BEGIN_HTML
20 // RooMultiCatIter iterators over all state permutations of a list of categories.
21 // It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
22 // Since this iterator only constructs state labels and does not change the value
23 // of its input categories, it is not required that its inputs are LValues.
24 // For cases where all inputs are LValues (such as for RooSuperCategory) the
25 // values of the input can be changes by assigning the super category the
26 // string label generated by this iterator
27 // END_HTML
28 //
29 
30 #include "RooFit.h"
31 
32 #include "RooAbsCategoryLValue.h"
33 #include "RooAbsCategoryLValue.h"
34 #include "RooMultiCatIter.h"
35 
36 using namespace std;
37 
39 ;
40 
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 
48 RooMultiCatIter::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 
61 RooMultiCatIter::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() ;
83  _iterList = new pTIterator[_nIter] ;
86 
87  // Construct component iterators
88  _curIter = 0 ;
89  _curItem = 0 ;
90  TIterator* cIter = _catList.createIterator() ;
92  while((cat=(RooAbsCategoryLValue*)cIter->Next())) {
93  _catPtrList[_curIter] = cat ;
94  _iterList[_curIter] = cat->typeIterator() ;
95  _iterList[_curIter]->Next() ;
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 {
143  TString& str = _compositeLabel.String() ;
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
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
184  _iterList[_curIter]->Reset() ;
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() ;
212  _curTypeList[_curIter] = *first ;
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 
235 bool RooMultiCatIter::operator!=(const TIterator &aIter) const
236 {
237  if ((aIter.IsA() == RooMultiCatIter::Class())) {
238  const RooMultiCatIter &iter(dynamic_cast<const RooMultiCatIter &>(aIter));
239  return (_curItem != iter._curItem);
240  }
241 
242  return false;
243 }
244 
RooArgSet _catList
RooCatType * _curTypeList
TObjString * compositeLabel()
Construct string with composite object label corresponding to the state name of a RooMultiCategory or...
virtual void Reset()=0
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
Definition: TObjString.h:32
pTIterator * _iterList
RooMultiCatIter(const RooArgSet &catList, const char *rangeName=0)
Construct iterator over all permutations of states of categories in catList.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
STL namespace.
Iterator abstract base class.
Definition: TIterator.h:32
virtual bool operator!=(const TIterator &aIter) const
Comparison operator to other iterator Returns true if both iterator iterate over the same set of inpu...
virtual void Reset()
Rewind master iterator.
void Class()
Definition: Class.C:29
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
virtual TObject * Next()
Iterator increment operator.
TIterator * createIterator(Bool_t dir=kIterForward) const
TString & Append(const char *cs)
Definition: TString.h:492
virtual const TCollection * GetCollection() const
Dummy implementation, always returns zero.
virtual ~RooMultiCatIter()
Destructor.
TObject * _curItem
virtual TObject * operator*() const
Return current item (dummy)
Collection abstract base class.
Definition: TCollection.h:48
ClassImp(RooMultiCatIter)
TString & String()
Definition: TObjString.h:52
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:58
virtual TObject * Next()=0
Int_t getSize() const
pRooCategory * _catPtrList
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
TObject * obj
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatType.h:45
TIterator * typeIterator() const
Return iterator over all defined states.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
void initialize(const RooArgSet &catList)
Build iterator array for given catList.