RooObjCacheManager.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooObjCacheManager.cxx 25184 2008-08-20 13:59:55Z 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 // Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement>
00021 // and specializes in the storage of cache elements that contain RooAbsArg objects.
00022 // Caches with RooAbsArg derived payload require special care as server redirects
00023 // cache operation mode changes and constant term optimization calls may need to be
00024 // forwarded to such cache payload. This cache manager takes are of all these operations
00025 // by forwarding these calls to the RooAbsCacheElement interface functions, which
00026 // have a sensible default implementation. 
00027 // END_HTML
00028 //
00029 
00030 #include "RooFit.h"
00031 #include "Riostream.h"
00032 #include <vector>
00033 #include "RooObjCacheManager.h"
00034 #include "RooMsgService.h"
00035 
00036 using namespace std ;
00037 
00038 ClassImp(RooObjCacheManager)
00039    ;
00040 
00041 
00042 //_____________________________________________________________________________
00043 RooObjCacheManager::RooObjCacheManager(RooAbsArg* owner, Int_t maxSize, Bool_t clearCacheOnServerRedirect) : 
00044   RooCacheManager<RooAbsCacheElement>(owner,maxSize), 
00045   _clearOnRedirect(clearCacheOnServerRedirect), 
00046   _optCacheModeSeen(kFALSE),
00047   _optCacheObservables(0)
00048 {
00049   // Constructor of object cache manager for given owner. If clearCacheOnServerRedirect is true
00050   // all cache elements will be cleared when a server redirect is intercepted by the cache manager.
00051   // This is the default strategy and should only be overridden when you really understand
00052   // what you're doing as properly implementing server redirect in cache elements can get very
00053   // complicated, especially if there are (cyclical) reference back to the owning object
00054 }
00055 
00056 
00057 //_____________________________________________________________________________
00058 RooObjCacheManager::RooObjCacheManager(const RooObjCacheManager& other, RooAbsArg* owner) : 
00059   RooCacheManager<RooAbsCacheElement>(other,owner),
00060   _clearOnRedirect(other._clearOnRedirect),
00061   _optCacheModeSeen(kFALSE), // cache mode properties are not transferred in copy ctor
00062   _optCacheObservables(0)
00063 {
00064   // Copy constructor
00065 }
00066 
00067 
00068 //_____________________________________________________________________________
00069 RooObjCacheManager::~RooObjCacheManager()
00070 {
00071   // Destructor
00072 
00073   if (_optCacheObservables) {
00074 
00075     list<RooArgSet*>::iterator iter = _optCacheObsList.begin() ;
00076     for (; iter!=_optCacheObsList.end() ; ++iter) {
00077       delete *iter ;
00078     }
00079 
00080     _optCacheObservables=0 ;
00081   }
00082 }
00083 
00084 
00085 //_____________________________________________________________________________
00086 Bool_t RooObjCacheManager::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive) 
00087 { 
00088   // Intercept server redirect calls. If clearOnRedirect was set, sterilize
00089   // the cache (i.e. keep the structure but delete all contents). If not
00090   // forward serverRedirect to cache elements
00091 
00092   
00093   if (_clearOnRedirect) {
00094 
00095     sterilize() ;
00096     
00097   } else {
00098 
00099     for (Int_t i=0 ; i<_size ; i++) {
00100       _object[i]->redirectServersHook(newServerList,mustReplaceAll,nameChange,isRecursive) ;
00101     }
00102 
00103   }
00104 
00105   return kFALSE ; 
00106 } 
00107 
00108 
00109 
00110 //_____________________________________________________________________________
00111 void RooObjCacheManager::operModeHook() 
00112 {
00113   // Intercept changes to cache operation mode and forward to cache elements
00114 
00115   if (!_owner) {
00116     return ;
00117   }
00118 
00119   for (Int_t i=0 ; i<_size ; i++) {
00120     if (_object[i]) {
00121       _object[i]->operModeHook(_owner->operMode()) ;
00122     }
00123   }
00124 } 
00125 
00126 
00127 
00128 //_____________________________________________________________________________
00129 void RooObjCacheManager::optimizeCacheMode(const RooArgSet& obs, RooArgSet& optNodes, RooLinkedList& processedNodes) 
00130 {
00131   // Intercept calls to perform automatic optimization of cache mode operation. 
00132   // Forward calls to existing cache elements and save configuration of
00133   // cache mode optimization so that it can be applied on new cache elements
00134   // upon insertion 
00135 
00136   oocxcoutD(_owner,Caching) << "RooObjCacheManager::optimizeCacheMode(owner=" << _owner->GetName() << ") obs = " << obs << endl ;
00137 
00138   _optCacheModeSeen = kTRUE ;
00139 
00140   _optCacheObservables = (RooArgSet*) obs.snapshot() ;
00141   _optCacheObsList.push_back(_optCacheObservables) ;
00142 
00143   for (Int_t i=0 ; i<_size ; i++) {
00144     if (_object[i]) {
00145       _object[i]->optimizeCacheMode(obs,optNodes,processedNodes) ;
00146     }
00147   }
00148 }
00149 
00150 
00151 
00152 //_____________________________________________________________________________
00153 void RooObjCacheManager::insertObjectHook(RooAbsCacheElement& obj) 
00154 {
00155   // Set owner link on all object inserted into cache.
00156   // Also if cache mode optimization was requested, apply
00157   // it now to cache element being inserted
00158 
00159   obj.setOwner(_owner) ;
00160 
00161   // If value caching mode optimization has happened, process it now on object being inserted
00162   if (_optCacheModeSeen) {
00163     RooLinkedList l ;
00164     RooArgSet s ;
00165     obj.optimizeCacheMode(*_optCacheObservables,s,l) ;
00166   }
00167 
00168 }
00169 
00170 
00171 
00172 
00173 //_____________________________________________________________________________
00174 void RooObjCacheManager::printCompactTreeHook(std::ostream& os, const char *indent)
00175 {
00176   // Add details on cache contents when printing in tree mode
00177 
00178   for (Int_t i=0 ; i<_size ; i++) {
00179     if (_object[i]) {
00180       _object[i]->printCompactTreeHook(os,indent,i,_size-1) ;
00181     }
00182   }  
00183 }
00184 
00185 
00186 
00187 //_____________________________________________________________________________
00188 void RooObjCacheManager::findConstantNodes(const RooArgSet& obs, RooArgSet& cacheList, RooLinkedList& processedNodes) 
00189 {
00190   // If clearOnRedirect is false, forward constant term optimization calls to
00191   // cache elements
00192 
00193   if (_clearOnRedirect) {
00194     return ;
00195   }
00196   
00197   for (Int_t i=0 ; i<_size ; i++) {
00198       if (_object[i]) {
00199         _object[i]->findConstantNodes(obs,cacheList, processedNodes) ;
00200       }
00201   }    
00202 }
00203 
00204 

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