RooMultiCatIter.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooMultiCatIter.cxx 25400 2008-09-15 10:08:28Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooMultiCatIter iterators over all state permutations of a list of categories.
00021 // It serves as the state iterator for a RooSuperCategory or a RooMultiCategory.
00022 // Since this iterator only constructs state labels and does not change the value
00023 // of its input categories, it is not required that its inputs are LValues.  
00024 // For cases where all inputs are LValues (such as for RooSuperCategory) the
00025 // values of the input can be changes by assigning the super category the
00026 // string label generated by this iterator
00027 // END_HTML
00028 //
00029 
00030 #include "RooFit.h"
00031 
00032 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,19,04)
00033 #ifndef nullptr
00034 #define nullptr 0
00035 #endif
00036 #endif
00037 
00038 #include "RooAbsCategoryLValue.h"
00039 #include "RooAbsCategoryLValue.h"
00040 #include "RooMultiCatIter.h"
00041 
00042 ClassImp(RooMultiCatIter)
00043 ;
00044 
00045 
00046 
00047 //_____________________________________________________________________________
00048 RooMultiCatIter::RooMultiCatIter(const RooArgSet& catList, const char* rangeName) : _catList("catList") 
00049 {
00050   // Construct iterator over all permutations of states of categories in catList.
00051   // If rangeName is not null, iteration is restricted to states that are selected
00052   // in the given range name
00053 
00054   if (rangeName) {
00055     _rangeName = rangeName ;
00056   }
00057   initialize(catList) ;
00058 }
00059 
00060 
00061 
00062 //_____________________________________________________________________________
00063 RooMultiCatIter::RooMultiCatIter(const RooMultiCatIter& other) : TIterator(other), _catList("catList")
00064 {
00065   // Copy constructor
00066 
00067   initialize(other._catList) ;
00068 }
00069 
00070 
00071 
00072 //_____________________________________________________________________________
00073 void RooMultiCatIter::initialize(const RooArgSet& catList) 
00074 {
00075   // Build iterator array for given catList
00076 
00077   // Copy RooCategory list into internal argset
00078   TIterator* catIter = catList.createIterator() ;
00079   TObject* obj ;
00080   while ((obj = catIter->Next())) {
00081     _catList.add((RooAbsArg&)*obj) ;
00082   }
00083   delete catIter ;
00084   
00085   // Allocate storage for component iterators
00086   _nIter = catList.getSize() ;
00087   _iterList   = new pTIterator[_nIter] ;
00088   _catPtrList = new pRooCategory[_nIter] ;
00089   _curTypeList = new RooCatType[_nIter] ;
00090 
00091   // Construct component iterators
00092   _curIter = 0 ;
00093   _curItem = 0 ;
00094   TIterator* cIter = _catList.createIterator() ;
00095   RooAbsCategoryLValue* cat ;
00096   while((cat=(RooAbsCategoryLValue*)cIter->Next())) {
00097     _catPtrList[_curIter] = cat ;
00098     _iterList[_curIter++] = cat->typeIterator() ;
00099   }
00100   delete cIter ;
00101 
00102   Reset() ;
00103 }
00104 
00105 
00106 
00107 //_____________________________________________________________________________
00108 RooMultiCatIter::~RooMultiCatIter() 
00109 {
00110   // Destructor
00111 
00112   for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
00113     delete _iterList[_curIter] ;
00114   }
00115   delete[] _iterList ;
00116   delete[] _catPtrList ;
00117   delete[] _curTypeList ;
00118 }
00119 
00120 
00121 
00122 //_____________________________________________________________________________
00123 const TCollection* RooMultiCatIter::GetCollection() const 
00124 {
00125   // Dummy implementation, always returns zero
00126 
00127   //return &_catList.getCollection() ;
00128   return 0 ;
00129 }
00130 
00131 
00132 
00133 //_____________________________________________________________________________
00134 TObjString* RooMultiCatIter::compositeLabel() 
00135 {
00136   // Construct string with composite object
00137   // label corresponding to the state name
00138   // of a RooMultiCategory or RooSuperCategory
00139   // constructed from this set of input categories
00140 
00141   TString& str = _compositeLabel.String() ;
00142 
00143   str = "{" ;
00144   Int_t i ;
00145   for (i=0 ; i<_nIter ; i++) {
00146     if (i>0) str.Append(";") ;
00147     str.Append(_curTypeList[i].GetName()) ;
00148   }
00149   str.Append("}") ;
00150 
00151   return &_compositeLabel ;
00152 }
00153 
00154 
00155 
00156 //_____________________________________________________________________________
00157 TObject* RooMultiCatIter::Next() 
00158 {
00159   // Iterator increment operator
00160 
00161   // Check for end
00162   if (_curIter==_nIter) {
00163     _curItem = 0;
00164     return 0 ;
00165   }
00166 
00167   RooCatType* next = (RooCatType*) _iterList[_curIter]->Next() ;
00168   if (next) { 
00169 
00170     // Increment current iterator
00171     _curTypeList[_curIter] = *next ;
00172     //_catPtrList[_curIter]->setIndex(next->getVal()) ;
00173 
00174     // If higher order increment was successful, reset master iterator
00175     if (_curIter>0) _curIter=0 ;
00176 
00177     _curItem = compositeLabel() ;
00178     return _curItem ;    
00179   } else {
00180 
00181     // Reset current iterator
00182     _iterList[_curIter]->Reset() ;
00183     next = (RooCatType*) _iterList[_curIter]->Next() ;
00184     if (next) _curTypeList[_curIter] = *next ; 
00185     //if (next) _catPtrList[_curIter]->setIndex(next->getVal()) ;
00186 
00187     // Increment next iterator 
00188     _curIter++ ;
00189     _curItem = Next() ;
00190     return _curItem ;
00191   }
00192 }
00193 
00194 
00195 
00196 //_____________________________________________________________________________
00197 void RooMultiCatIter::Reset() 
00198 {
00199   // Rewind master iterator
00200 
00201   for (_curIter=0 ; _curIter<_nIter ; _curIter++) {
00202     TIterator* cIter = _iterList[_curIter] ;
00203     cIter->Reset() ;
00204     RooCatType* first = (RooCatType*) cIter->Next() ;
00205     if (first) {
00206       if (_curIter==0) cIter->Reset() ;
00207       _curTypeList[_curIter] = *first ;
00208     }
00209   }
00210   _curIter=0 ;
00211 }
00212 
00213 
00214 //_____________________________________________________________________________
00215 TObject *RooMultiCatIter::operator*() const
00216 {
00217   // Return current item (dummy)
00218   return _curItem ;
00219 }
00220 
00221 
00222 //_____________________________________________________________________________
00223 bool RooMultiCatIter::operator!=(const TIterator &aIter) const
00224 {
00225   // Comparison operator to other iterator
00226   // Returns true if both iterator iterate over the
00227   // same set of input categories and are not at the
00228   // same sequential position
00229 
00230    if (nullptr == &aIter)
00231       return false;
00232    
00233    if ((aIter.IsA() == RooMultiCatIter::Class())) {
00234       const RooMultiCatIter &iter(dynamic_cast<const RooMultiCatIter &>(aIter));
00235       return (_curItem != iter._curItem);
00236    }
00237    
00238    return false;
00239 }
00240 

Generated on Tue Jul 5 15:06:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1