ROOT  6.06/09
Reference Guide
RooObjCacheManager.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 // Class RooObjCacheManager is an implementation of class RooCacheManager<RooAbsCacheElement>
21 // and specializes in the storage of cache elements that contain RooAbsArg objects.
22 // Caches with RooAbsArg derived payload require special care as server redirects
23 // cache operation mode changes and constant term optimization calls may need to be
24 // forwarded to such cache payload. This cache manager takes are of all these operations
25 // by forwarding these calls to the RooAbsCacheElement interface functions, which
26 // have a sensible default implementation.
27 // END_HTML
28 //
29 
30 #include "RooFit.h"
31 #include "Riostream.h"
32 #include <vector>
33 #include "RooObjCacheManager.h"
34 #include "RooMsgService.h"
35 
36 using namespace std ;
37 
39  ;
40 
41 
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Constructor of object cache manager for given owner. If clearCacheOnServerRedirect is true
46 /// all cache elements will be cleared when a server redirect is intercepted by the cache manager.
47 /// This is the default strategy and should only be overridden when you really understand
48 /// what you're doing as properly implementing server redirect in cache elements can get very
49 /// complicated, especially if there are (cyclical) reference back to the owning object
50 
51 RooObjCacheManager::RooObjCacheManager(RooAbsArg* owner, Int_t maxSize, Bool_t clearCacheOnServerRedirect, Bool_t allowOptimize) :
52  RooCacheManager<RooAbsCacheElement>(owner,maxSize),
53  _clearOnRedirect(clearCacheOnServerRedirect),
54  _allowOptimize(allowOptimize),
55  _optCacheModeSeen(kFALSE),
56  _optCacheObservables(0)
57 {
58 }
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Copy constructor
63 
65  RooCacheManager<RooAbsCacheElement>(other,owner),
66  _clearOnRedirect(other._clearOnRedirect),
67  _allowOptimize(other._allowOptimize),
68  _optCacheModeSeen(kFALSE), // cache mode properties are not transferred in copy ctor
69  _optCacheObservables(0)
70 {
71 }
72 
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Destructor
76 
78 {
80  delete _optCacheObservables ;
81  }
82 }
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Intercept server redirect calls. If clearOnRedirect was set, sterilize
87 /// the cache (i.e. keep the structure but delete all contents). If not
88 /// forward serverRedirect to cache elements
89 
90 Bool_t RooObjCacheManager::redirectServersHook(const RooAbsCollection& newServerList, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursive)
91 {
92  if (_clearOnRedirect) {
93 
94  sterilize() ;
95 
96  } else {
97 
98  for (Int_t i=0 ; i<cacheSize() ; i++) {
99  if (_object[i]) {
100  _object[i]->redirectServersHook(newServerList,mustReplaceAll,nameChange,isRecursive) ;
101  }
102  }
103 
104  }
105 
106  return kFALSE ;
107 }
108 
109 
110 
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Intercept changes to cache operation mode and forward to cache elements
113 
115 {
116  if (!_owner) {
117  return ;
118  }
119 
120  for (Int_t i=0 ; i<cacheSize() ; i++) {
121  if (_object[i]) {
122  _object[i]->operModeHook(_owner->operMode()) ;
123  }
124  }
125 }
126 
127 
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Intercept calls to perform automatic optimization of cache mode operation.
131 /// Forward calls to existing cache elements and save configuration of
132 /// cache mode optimization so that it can be applied on new cache elements
133 /// upon insertion
134 
135 void RooObjCacheManager::optimizeCacheMode(const RooArgSet& obs, RooArgSet& optNodes, RooLinkedList& processedNodes)
136 {
137  oocxcoutD(_owner,Caching) << "RooObjCacheManager::optimizeCacheMode(owner=" << _owner->GetName() << ") obs = " << obs << endl ;
138 
140 
141  if (_optCacheObservables) {
143  _optCacheObservables->add(obs) ;
144  } else {
146  }
147 
148  for (Int_t i=0 ; i<cacheSize() ; i++) {
149  if (_object[i]) {
150  _object[i]->optimizeCacheMode(obs,optNodes,processedNodes) ;
151  }
152  }
153 }
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 
159 {
161 
162  // WVE - adding this causes trouble with IntegralMorpht????
163  // Perhaps this should not be done in sterilize, but be a separate operation
164  // called specially from RooAbsObsTestStatistic::setData()
165 
167  delete _optCacheObservables ;
170  }
171 
172 }
173 
174 
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Set owner link on all object inserted into cache.
178 /// Also if cache mode optimization was requested, apply
179 /// it now to cache element being inserted
180 
182 {
183  obj.setOwner(_owner) ;
184 
185  // If value caching mode optimization has happened, process it now on object being inserted
186  if (_optCacheModeSeen) {
187  RooLinkedList l ;
188  RooArgSet s ;
190  }
191 
192 }
193 
194 
195 
196 
197 ////////////////////////////////////////////////////////////////////////////////
198 /// Add details on cache contents when printing in tree mode
199 
200 void RooObjCacheManager::printCompactTreeHook(std::ostream& os, const char *indent)
201 {
202  for (Int_t i=0 ; i<cacheSize() ; i++) {
203  if (_object[i]) {
204  _object[i]->printCompactTreeHook(os,indent,i,cacheSize()-1) ;
205  }
206  }
207 }
208 
209 
210 
211 ////////////////////////////////////////////////////////////////////////////////
212 /// If clearOnRedirect is false, forward constant term optimization calls to
213 /// cache elements
214 
215 void RooObjCacheManager::findConstantNodes(const RooArgSet& obs, RooArgSet& cacheList, RooLinkedList& processedNodes)
216 {
217  if (!_allowOptimize) {
218  return ;
219  }
220 
221  for (Int_t i=0 ; i<cacheSize() ; i++) {
222  if (_object[i]) {
223  _object[i]->findConstantNodes(obs,cacheList, processedNodes) ;
224  }
225  }
226 }
227 
228 
virtual void findConstantNodes(const RooArgSet &, RooArgSet &, RooLinkedList &)
If clearOnRedirect is false, forward constant term optimization calls to cache elements.
virtual Bool_t redirectServersHook(const RooAbsCollection &, Bool_t, Bool_t, Bool_t)
Intercept server redirect calls.
RooObjCacheManager(RooAbsArg *owner=0, Int_t maxSize=2, Bool_t clearCacheOnServerRedirect=kTRUE, Bool_t allowOptimize=kFALSE)
Constructor of object cache manager for given owner.
virtual ~RooObjCacheManager()
Destructor.
RooAbsArg * _owner
Definition: RooAbsCache.h:45
virtual void printCompactTreeHook(std::ostream &, const char *)
Add details on cache contents when printing in tree mode.
virtual void sterilize()
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual void operModeHook()
Intercept changes to cache operation mode and forward to cache elements.
#define oocxcoutD(o, a)
Definition: RooMsgService.h:82
return
Definition: TBase64.cxx:62
virtual void insertObjectHook(RooAbsCacheElement &)
Set owner link on all object inserted into cache.
ClassImp(RooObjCacheManager)
TLine * l
Definition: textangle.C:4
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
static void indent(ostringstream &buf, int indent_level)
virtual void optimizeCacheMode(const RooArgSet &obs, RooArgSet &optNodes, RooLinkedList &processedNodes)
Interface for cache optimization calls.
RooArgSet * _optCacheObservables
static Bool_t _clearObsList
current optCacheObservables
void setOwner(RooAbsArg *owner)
OperMode operMode() const
Definition: RooAbsArg.h:399
virtual void optimizeCacheMode(const RooArgSet &, RooArgSet &, RooLinkedList &)
Intercept calls to perform automatic optimization of cache mode operation.
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
std::vector< RooAbsCacheElement * > _object
Normalization/Integration set manager.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448