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