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