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
22 their own states. Use begin() / end() and range-based for loops on instances of these classes.
23 
24 RooMultiCatIter iterates over all state permutations of a list of categories.
25 It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
26 Since this iterator only constructs state labels and does not change the value
27 of its input categories, it is not required that its inputs are LValues.
28 For cases where all inputs are LValues (such as for RooSuperCategory) the
29 values of the input can be changes by assigning the super category the
30 string label generated by this iterator
31 **/
32 
33 #include "RooMultiCatIter.h"
34 
35 #include "RooFit.h"
36 #include "RooAbsCategoryLValue.h"
38 
39 
40 using 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 
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 
169  RooCatType* next = (RooCatType*) _iterList[_curIter]->Next() ;
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
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() ;
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  auto otherMCIt = dynamic_cast<const RooMultiCatIter*>(&aIter);
238  if (!otherMCIt)
239  return true;
240 
241  return (_curItem != otherMCIt->_curItem);
242 
243 }
244 
RooMultiCatIter::_curIter
Int_t _curIter
Definition: RooMultiCatIter.h:55
first
Definition: first.py:1
RooMultiCatIter::RooMultiCatIter
RooMultiCatIter(const RooArgSet &catList, const char *rangeName=0)
Construct iterator over all permutations of states of categories in catList.
Definition: RooMultiCatIter.cxx:48
RooMultiCatIter::_rangeName
TString _rangeName
Definition: RooMultiCatIter.h:57
RooFit.h
RooMultiCatIter
Definition: RooMultiCatIter.h:29
RooCatType::GetName
virtual const Text_t * GetName() const
Returns name of object.
Definition: RooCatTypeLegacy.h:59
RooMultiCatIter::_curTypeList
RooCatType * _curTypeList
Definition: RooMultiCatIter.h:53
RooArgSet::add
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
TString
Definition: TString.h:136
RooMultiCatIter::~RooMultiCatIter
virtual ~RooMultiCatIter()
Destructor.
Definition: RooMultiCatIter.cxx:112
TIterator
Definition: TIterator.h:30
TObjString::String
TString & String()
Definition: TObjString.h:54
TObjString
Definition: TObjString.h:28
RooCatType::SetName
void SetName(const Text_t *name)
Constructor with name argument.
Definition: RooCatTypeLegacy.cxx:46
RooMultiCatIter::Next
virtual TObject * Next()
Iterator increment operator.
Definition: RooMultiCatIter.cxx:161
RooMultiCatIter::GetCollection
virtual const TCollection * GetCollection() const
Dummy implementation, always returns zero.
Definition: RooMultiCatIter.cxx:127
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
RooMultiCatIter::_compositeLabel
TObjString _compositeLabel
Definition: RooMultiCatIter.h:56
RooMultiCatIter::operator*
virtual TObject * operator*() const
Return current item (dummy)
Definition: RooMultiCatIter.cxx:223
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:118
RooMultiCatIter::_iterList
pTIterator * _iterList
Definition: RooMultiCatIter.h:51
RooMultiCatIter::_catList
RooArgSet _catList
Definition: RooMultiCatIter.h:50
RooAbsCategory::typeIterator
TIterator * typeIterator() const
Definition: RooAbsCategory.cxx:653
TIterator::Next
virtual TObject * Next()=0
RooMultiCatIter::initialize
void initialize(const RooArgSet &catList)
Build iterator array for given catList.
Definition: RooMultiCatIter.cxx:71
TIterator::Reset
virtual void Reset()=0
RooAbsCategoryLValue.h
RooMultiCatIter::operator!=
virtual bool operator!=(const TIterator &aIter) const
Comparison operator to other iterator Returns true if both iterator iterate over the same set of inpu...
Definition: RooMultiCatIter.cxx:235
TObject
Definition: TObject.h:37
RooCatType
Definition: RooCatTypeLegacy.h:23
RooMultiCatIter::_catPtrList
pRooCategory * _catPtrList
Definition: RooMultiCatIter.h:52
RooMultiCatIter::Reset
virtual void Reset()
Rewind master iterator.
Definition: RooMultiCatIter.cxx:204
RooAbsArg
Definition: RooAbsArg.h:73
RooMultiCatIter::_curItem
TObject * _curItem
Definition: RooMultiCatIter.h:58
TCollection
Definition: TCollection.h:63
RooAbsCategoryLValue
Definition: RooAbsCategoryLValue.h:25
RooCatTypeLegacy.h
RooMultiCatIter.h
RooMultiCatIter::_nIter
Int_t _nIter
Definition: RooMultiCatIter.h:54
RooMultiCatIter::compositeLabel
TObjString * compositeLabel()
Construct string with composite object label corresponding to the state name of a RooMultiCategory or...
Definition: RooMultiCatIter.cxx:141
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooArgSet
Definition: RooArgSet.h:28
int