00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ROO_CACHE_MANAGER
00017 #define ROO_CACHE_MANAGER
00018
00019 #include "Rtypes.h"
00020
00021 #include "Riostream.h"
00022 #include "RooMsgService.h"
00023 #include "RooNormSetCache.h"
00024 #include "RooAbsReal.h"
00025 #include "RooArgSet.h"
00026 #include "RooArgList.h"
00027 #include "RooAbsCache.h"
00028 #include "RooAbsCacheElement.h"
00029 #include <vector>
00030
00031 class RooNameSet ;
00032
00033
00034 template<class T>
00035 class RooCacheManager : public RooAbsCache {
00036
00037 public:
00038
00039 RooCacheManager(Int_t maxSize=10) ;
00040 RooCacheManager(RooAbsArg* owner, Int_t maxSize=10) ;
00041 RooCacheManager(const RooCacheManager& other, RooAbsArg* owner=0) ;
00042 virtual ~RooCacheManager() ;
00043
00044 T* getObj(const RooArgSet* nset, Int_t* sterileIndex=0, const TNamed* isetRangeName=0) {
00045
00046 return getObj(nset,0,sterileIndex,isetRangeName) ;
00047 }
00048
00049 Int_t setObj(const RooArgSet* nset, T* obj, const TNamed* isetRangeName=0) {
00050
00051 return setObj(nset,0,obj,isetRangeName) ;
00052 }
00053
00054 T* getObj(const RooArgSet* nset, const RooArgSet* iset, Int_t* sterileIndex=0, const TNamed* isetRangeName=0) ;
00055 Int_t setObj(const RooArgSet* nset, const RooArgSet* iset, T* obj, const TNamed* isetRangeName=0) ;
00056
00057 void reset() ;
00058 void sterilize() ;
00059
00060 Int_t lastIndex() const {
00061
00062 return _lastIndex ;
00063 }
00064 Int_t cacheSize() const {
00065
00066 return _size ;
00067 }
00068
00069 virtual Bool_t redirectServersHook(const RooAbsCollection& , Bool_t ,
00070 Bool_t , Bool_t ) {
00071
00072 return kFALSE ;
00073 }
00074 virtual void operModeHook() {
00075
00076 }
00077 virtual void printCompactTreeHook(std::ostream&, const char *) {
00078
00079 }
00080
00081 T* getObjByIndex(Int_t index) const ;
00082 const RooNameSet* nameSet1ByIndex(Int_t index) const ;
00083 const RooNameSet* nameSet2ByIndex(Int_t index) const ;
00084
00085 virtual void insertObjectHook(T&) {
00086
00087 }
00088
00089 protected:
00090
00091 Int_t _maxSize ;
00092 Int_t _size ;
00093 Int_t _lastIndex ;
00094
00095 RooNormSetCache* _nsetCache ;
00096 T** _object ;
00097
00098 ClassDef(RooCacheManager,1)
00099 } ;
00100
00101
00102 template<class T>
00103 RooCacheManager<T>::RooCacheManager(Int_t maxSize) : RooAbsCache(0)
00104 {
00105
00106
00107
00108
00109
00110 _maxSize = maxSize ;
00111 _nsetCache = new RooNormSetCache[maxSize] ;
00112 _object = new T*[maxSize] ;
00113 }
00114
00115 template<class T>
00116 RooCacheManager<T>::RooCacheManager(RooAbsArg* owner, Int_t maxSize) : RooAbsCache(owner)
00117 {
00118
00119
00120
00121
00122
00123 _maxSize = maxSize ;
00124 _size = 0 ;
00125
00126 _nsetCache = new RooNormSetCache[maxSize] ;
00127 _object = new T*[maxSize] ;
00128 _lastIndex = -1 ;
00129
00130 Int_t i ;
00131 for (i=0 ; i<_maxSize ; i++) {
00132 _object[i]=0 ;
00133 }
00134
00135 }
00136
00137
00138 template<class T>
00139 RooCacheManager<T>::RooCacheManager(const RooCacheManager& other, RooAbsArg* owner) : RooAbsCache(other,owner)
00140 {
00141
00142
00143 _maxSize = other._maxSize ;
00144 _size = other._size ;
00145
00146 _nsetCache = new RooNormSetCache[_maxSize] ;
00147 _object = new T*[_maxSize] ;
00148 _lastIndex = -1 ;
00149
00150
00151
00152 Int_t i ;
00153 for (i=0 ; i<other._size ; i++) {
00154 _nsetCache[i].initialize(other._nsetCache[i]) ;
00155 _object[i] = 0 ;
00156 }
00157
00158 for (i=other._size ; i<_maxSize ; i++) {
00159 _object[i] = 0 ;
00160 }
00161 }
00162
00163
00164 template<class T>
00165 RooCacheManager<T>::~RooCacheManager()
00166 {
00167
00168
00169 delete[] _nsetCache ;
00170 Int_t i ;
00171 for (i=0 ; i<_size ; i++) {
00172 delete _object[i] ;
00173 }
00174 delete[] _object ;
00175 }
00176
00177
00178 template<class T>
00179 void RooCacheManager<T>::reset()
00180 {
00181
00182
00183 Int_t i ;
00184 for (i=0 ; i<_maxSize ; i++) {
00185 delete _object[i] ;
00186 _object[i]=0 ;
00187 _nsetCache[i].clear() ;
00188 }
00189 _lastIndex = -1 ;
00190 _size = 0 ;
00191 }
00192
00193
00194
00195 template<class T>
00196 void RooCacheManager<T>::sterilize()
00197 {
00198
00199
00200
00201 Int_t i ;
00202 for (i=0 ; i<_maxSize ; i++) {
00203 delete _object[i] ;
00204 _object[i]=0 ;
00205 }
00206 }
00207
00208
00209
00210 template<class T>
00211 Int_t RooCacheManager<T>::setObj(const RooArgSet* nset, const RooArgSet* iset, T* obj, const TNamed* isetRangeName)
00212 {
00213
00214
00215
00216 Int_t sterileIdx(-1) ;
00217 if (getObj(nset,iset,&sterileIdx,isetRangeName)) {
00218 return lastIndex() ;
00219 }
00220
00221
00222 if (sterileIdx>=0) {
00223
00224 _object[sterileIdx] = obj ;
00225
00226
00227 insertObjectHook(*obj) ;
00228
00229 return lastIndex() ;
00230 }
00231
00232 if (_size==_maxSize) {
00233 return -1 ;
00234 }
00235
00236 _nsetCache[_size].autoCache(_owner,nset,iset,isetRangeName,kTRUE) ;
00237 if (_object[_size]) {
00238 delete _object[_size] ;
00239 }
00240
00241 _object[_size] = obj ;
00242 _size++ ;
00243
00244
00245 insertObjectHook(*obj) ;
00246
00247 return _size-1 ;
00248 }
00249
00250
00251 template<class T>
00252 T* RooCacheManager<T>::getObj(const RooArgSet* nset, const RooArgSet* iset, Int_t* sterileIdx, const TNamed* isetRangeName)
00253 {
00254
00255
00256
00257
00258 Int_t i ;
00259 for (i=0 ; i<_size ; i++) {
00260 if (_nsetCache[i].contains(nset,iset,isetRangeName)==kTRUE) {
00261 _lastIndex = i ;
00262 if(_object[i]==0 && sterileIdx) *sterileIdx=i ;
00263 return _object[i] ;
00264 }
00265 }
00266
00267 for (i=0 ; i<_size ; i++) {
00268 if (_nsetCache[i].autoCache(_owner,nset,iset,isetRangeName,kFALSE)==kFALSE) {
00269 _lastIndex = i ;
00270 if(_object[i]==0 && sterileIdx) *sterileIdx=i ;
00271 return _object[i] ;
00272 }
00273 }
00274 return 0 ;
00275 }
00276
00277
00278
00279 template<class T>
00280 T* RooCacheManager<T>::getObjByIndex(Int_t index) const
00281 {
00282
00283
00284 if (index<0||index>=_size) {
00285 oocoutE(_owner,ObjectHandling) << "RooCacheManager::getNormListByIndex: ERROR index ("
00286 << index << ") out of range [0," << _size-1 << "]" << endl ;
00287 return 0 ;
00288 }
00289 return _object[index] ;
00290 }
00291
00292 template<class T>
00293 const RooNameSet* RooCacheManager<T>::nameSet1ByIndex(Int_t index) const
00294 {
00295
00296
00297 if (index<0||index>=_size) {
00298 oocoutE(_owner,ObjectHandling) << "RooCacheManager::getNormListByIndex: ERROR index ("
00299 << index << ") out of range [0," << _size-1 << "]" << endl ;
00300 return 0 ;
00301 }
00302 return &_nsetCache[index].nameSet1() ;
00303 }
00304
00305 template<class T>
00306 const RooNameSet* RooCacheManager<T>::nameSet2ByIndex(Int_t index) const
00307 {
00308
00309
00310 if (index<0||index>=_size) {
00311 oocoutE(_owner,ObjectHandling) << "RooCacheManager::getNormListByIndex: ERROR index ("
00312 << index << ") out of range [0," << _size-1 << "]" << endl ;
00313 return 0 ;
00314 }
00315 return &_nsetCache[index].nameSet2() ;
00316 }
00317
00318
00319 #endif