Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsArg.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/** \class RooAbsArg
19 \ingroup Roofitcore
20
21Common abstract base class for objects that
22represent a value and a "shape" in RooFit. Values or shapes usually depend on values
23or shapes of other RooAbsArg instances. Connecting several RooAbsArg in
24a computation graph models an expression tree that can be evaluated.
25
26### Building a computation graph of RooFit objects
27Therefore, RooAbsArg provides functionality to connect objects of type RooAbsArg into
28a computation graph to pass values between those objects.
29A value can e.g. be a real-valued number, (instances of RooAbsReal), or an integer, that is,
30category index (instances of RooAbsCategory). The third subclass of RooAbsArg is RooStringVar,
31but it is rarely used.
32
33The "shapes" that a RooAbsArg can possess can e.g. be the definition
34range of an observable, or how many states a category object has. In computations,
35values are expected to change often, while shapes remain mostly constant
36(unless e.g. a new range is set for an observable).
37
38Nodes of a computation graph are connected using instances of RooAbsProxy.
39If Node B declares a member `RooTemplateProxy<TypeOfNodeA>`, Node A will be
40registered as a server of values to Node B, and Node B will know that it is
41a client of node A. Using functions like dependsOn(), or getObservables()
42/ getParameters(), the relation of `A --> B` can be queried. Using graphVizTree(),
43one can create a visualisation of the expression tree.
44
45
46An instance of RooAbsArg can have named attributes. It also has flags
47to indicate that either its value or its shape were changed (= it is dirty).
48RooAbsArg provides functionality to manage client/server relations in
49a computation graph (\ref clientServerInterface), and helps propagating
50value/shape changes through the graph. RooAbsArg implements interfaces
51for inspecting client/server relationships (\ref clientServerInterface) and
52setting/clearing/querying named attributes.
53
54### Caching of values
55The values of nodes in the computation graph are cached in RooFit. If
56a value is used in two nodes of a graph, it doesn't need to be recomputed. If
57a node acquires a new value, it notifies its consumers ("clients") that
58their cached values are dirty. See the functions in \ref optimisationInterface
59for details.
60A node uses its isValueDirty() and isShapeDirty() functions to decide if a
61computation is necessary. Caching can be vetoed globally by setting a
62bit using setDirtyInhibit(). This will make computations slower, but all the
63nodes of the computation graph will be evaluated irrespective of whether their
64state is clean or dirty. Using setOperMode(), caching can also be enabled/disabled
65for single nodes.
66
67*/
68
69#include <RooAbsArg.h>
70
72#include <RooAbsData.h>
73#include <RooAbsDataStore.h>
74#include <RooArgProxy.h>
75#include <RooArgSet.h>
76#include <RooConstVar.h>
78#include <RooHelpers.h>
79#include "RooFitImplHelpers.h"
80#include <RooListProxy.h>
81#include <RooMsgService.h>
82#include <RooRealIntegral.h>
83#include <RooResolutionModel.h>
84#include <RooSetProxy.h>
85#include <RooTrace.h>
86#include <RooTreeDataStore.h>
87#include <RooVectorDataStore.h>
88#include <RooWorkspace.h>
89
90#include <TBuffer.h>
91#include <TClass.h>
93
94#include <algorithm>
95#include <cstring>
96#include <fstream>
97#include <sstream>
98
99using std::cout, std::endl, std::ostream, std::string, std::set, std::map, std::istream, std::pair, std::ofstream, std::make_pair;
100
102
103bool RooAbsArg::_verboseDirty(false) ;
104bool RooAbsArg::_inhibitDirty(false) ;
106
107std::map<RooAbsArg*,std::unique_ptr<TRefArray>> RooAbsArg::_ioEvoList;
108std::stack<RooAbsArg*> RooAbsArg::_ioReadStack ;
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Default constructor
113
114RooAbsArg::RooAbsArg() : _namePtr(RooNameReg::instance().constPtr(GetName())) {}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Create an object with the specified name and descriptive title.
118/// The newly created object has no clients or servers and has its
119/// dirty flags set.
120
121RooAbsArg::RooAbsArg(const char *name, const char *title)
122 : TNamed(name, title)
123{
124 if (name == nullptr || strlen(name) == 0) {
125 throw std::logic_error("Each RooFit object needs a name. "
126 "Objects representing the same entity (e.g. an observable 'x') are identified using their name.");
127 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Copy constructor transfers all boolean and string properties of the original
133/// object. Transient properties and client-server links are not copied
134
135RooAbsArg::RooAbsArg(const RooAbsArg &other, const char *name)
136 : TNamed(name ? name : other.GetName(), other.GetTitle()),
137 RooPrintable(other),
138 _boolAttrib(other._boolAttrib),
139 _stringAttrib(other._stringAttrib),
140 _deleteWatch(other._deleteWatch),
141 _namePtr(name ? RooNameReg::instance().constPtr(name) : other._namePtr),
142 _isConstant(other._isConstant),
143 _localNoInhibitDirty(other._localNoInhibitDirty)
144{
145
146 // Copy server list by hand
147 bool valueProp;
148 bool shapeProp;
149 for (const auto server : other._serverList) {
150 valueProp = server->_clientListValue.containsByNamePtr(&other);
151 shapeProp = server->_clientListShape.containsByNamePtr(&other);
152 addServer(*server,valueProp,shapeProp) ;
153 }
154
155 setValueDirty() ;
156 setShapeDirty() ;
157}
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Destructor.
162
164{
165 // Notify all servers that they no longer need to serve us
166 while (!_serverList.empty()) {
167 removeServer(*_serverList.containedObjects().back(), true);
168 }
169
170 // Notify all clients that they are in limbo
171 std::vector<RooAbsArg*> clientListTmp(_clientList.begin(), _clientList.end()); // have to copy, as we invalidate iterators
172 bool first(true) ;
173 for (auto client : clientListTmp) {
174 client->setAttribute("ServerDied") ;
175 std::stringstream attr;
176 attr << "ServerDied:" << GetName() << "(" << reinterpret_cast<std::size_t>(this) << ")";
177 client->setAttribute(attr.str().c_str());
178 client->removeServer(*this,true);
179
180 if (_verboseDirty) {
181
182 if (first) {
183 cxcoutD(Tracing) << "RooAbsArg::dtor(" << GetName() << "," << this << ") DeleteWatch: object is being destroyed" << endl ;
184 first = false ;
185 }
186
187 cxcoutD(Tracing) << fName << "::" << ClassName() << ":~RooAbsArg: dependent \""
188 << client->GetName() << "\" should have been deleted first" << endl ;
189 }
190 }
191
192 if (_ownedComponents) {
193 delete _ownedComponents ;
194 _ownedComponents = nullptr ;
195 }
196
197}
198
199
200////////////////////////////////////////////////////////////////////////////////
201/// Control global dirty inhibit mode. When set to true no value or shape dirty
202/// flags are propagated and cache is always considered to be dirty.
203
205{
206 _inhibitDirty = flag ;
207}
208
209
210////////////////////////////////////////////////////////////////////////////////
211/// Activate verbose messaging related to dirty flag propagation
212
214{
215 _verboseDirty = flag ;
216}
217
218
219////////////////////////////////////////////////////////////////////////////////
220/// Set (default) or clear a named boolean attribute of this object.
221
223{
224 // Preserve backward compatibility - any strong
225 if(std::string{"Constant"} == name) {
227 }
228
229 if (value) {
230 _boolAttrib.insert(name) ;
231 } else {
232 set<string>::iterator iter = _boolAttrib.find(name) ;
233 if (iter != _boolAttrib.end()) {
234 _boolAttrib.erase(iter) ;
235 }
236
237 }
238
239}
240
241
242////////////////////////////////////////////////////////////////////////////////
243/// Check if a named attribute is set. By default, all attributes are unset.
244
246{
247 return (_boolAttrib.find(name) != _boolAttrib.end()) ;
248}
249
250
251////////////////////////////////////////////////////////////////////////////////
252/// Associate string 'value' to this object under key 'key'
253
255{
256 if (value) {
257 _stringAttrib[key] = value ;
258 } else {
260 }
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Delete a string attribute with a given key.
265
267{
268 _stringAttrib.erase(key) ;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Get string attribute mapped under key 'key'. Returns null pointer
273/// if no attribute exists under that key
274
276{
277 map<string,string>::const_iterator iter = _stringAttrib.find(key) ;
278 if (iter!=_stringAttrib.end()) {
279 return iter->second.c_str() ;
280 } else {
281 return nullptr ;
282 }
283}
284
285
286////////////////////////////////////////////////////////////////////////////////
287/// Set (default) or clear a named boolean attribute of this object.
288
290{
291 if (value) {
292
293 _boolAttribTransient.insert(name) ;
294
295 } else {
296
297 set<string>::iterator iter = _boolAttribTransient.find(name) ;
298 if (iter != _boolAttribTransient.end()) {
299 _boolAttribTransient.erase(iter) ;
300 }
301
302 }
303
304}
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// Check if a named attribute is set. By default, all attributes
309/// are unset.
310
312{
313 return (_boolAttribTransient.find(name) != _boolAttribTransient.end()) ;
314}
315
316
317
318
319////////////////////////////////////////////////////////////////////////////////
320/// Register another RooAbsArg as a server to us, ie, declare that
321/// we depend on it.
322/// \param server The server to be registered.
323/// \param valueProp In addition to the basic client-server relationship, declare dependence on the server's value.
324/// \param shapeProp In addition to the basic client-server relationship, declare dependence on the server's shape.
325/// \param refCount Optionally add with higher reference count (if multiple components depend on it)
326
327void RooAbsArg::addServer(RooAbsArg& server, bool valueProp, bool shapeProp, std::size_t refCount)
328{
330 cxcoutF(LinkStateMgmt) << "RooAbsArg::addServer(" << this << "," << GetName()
331 << "): PROHIBITED SERVER ADDITION REQUESTED: adding server " << server.GetName()
332 << "(" << &server << ") for " << (valueProp?"value ":"") << (shapeProp?"shape":"") << endl ;
333 throw std::logic_error("PROHIBITED SERVER ADDITION REQUESTED in RooAbsArg::addServer");
334 }
335
336 cxcoutD(LinkStateMgmt) << "RooAbsArg::addServer(" << this << "," << GetName() << "): adding server " << server.GetName()
337 << "(" << &server << ") for " << (valueProp?"value ":"") << (shapeProp?"shape":"") << endl ;
338
339 if (server.operMode()==ADirty && operMode()!=ADirty && valueProp) {
341 }
342
343
344 // LM: use hash tables for larger lists
345// if (_serverList.GetSize() > 999 && _serverList.getHashTableSize() == 0) _serverList.setHashTableSize(1000);
346// if (server._clientList.GetSize() > 999 && server._clientList.getHashTableSize() == 0) server._clientList.setHashTableSize(1000);
347// if (server._clientListValue.GetSize() > 999 && server._clientListValue.getHashTableSize() == 0) server._clientListValue.setHashTableSize(1000);
348
349 // Add server link to given server
350 _serverList.Add(&server, refCount) ;
351
352 server._clientList.Add(this, refCount);
353 if (valueProp) server._clientListValue.Add(this, refCount);
354 if (shapeProp) server._clientListShape.Add(this, refCount);
355}
356
357
358
359////////////////////////////////////////////////////////////////////////////////
360/// Register a list of RooAbsArg as servers to us by calling
361/// addServer() for each arg in the list
362
363void RooAbsArg::addServerList(RooAbsCollection& serverList, bool valueProp, bool shapeProp)
364{
365 _serverList.reserve(_serverList.size() + serverList.size());
366
367 for (const auto arg : serverList) {
368 addServer(*arg,valueProp,shapeProp) ;
369 }
370}
371
372
373
374////////////////////////////////////////////////////////////////////////////////
375/// Unregister another RooAbsArg as a server to us, ie, declare that
376/// we no longer depend on its value and shape.
377
378void RooAbsArg::removeServer(RooAbsArg& server, bool force)
379{
381 std::stringstream ss;
382 ss << "RooAbsArg::addServer(" << this << "," << GetName() << "): PROHIBITED SERVER REMOVAL REQUESTED: removing server "
383 << server.GetName() << "(" << &server << ")";
384 cxcoutF(LinkStateMgmt) << ss.str() << std::endl;
385 throw std::runtime_error(ss.str());
386 }
387
388 if (_verboseDirty) {
389 cxcoutD(LinkStateMgmt) << "RooAbsArg::removeServer(" << GetName() << "): removing server "
390 << server.GetName() << "(" << &server << ")" << endl ;
391 }
392
393 // Remove server link to given server
394 _serverList.Remove(&server, force) ;
395
396 server._clientList.Remove(this, force) ;
397 server._clientListValue.Remove(this, force) ;
398 server._clientListShape.Remove(this, force) ;
399}
400
401
402////////////////////////////////////////////////////////////////////////////////
403/// Replace 'oldServer' with 'newServer', specifying whether the new server has
404/// value or shape server properties.
405///
406/// \warning This function should not be used! This method is quite unsafe for
407/// many reasons. For once, the new server will be put at the end of the server
408/// list, no matter the position of the original server. This might mess up
409/// code that expects the servers to be in a certain order. Furthermore, the
410/// proxy objects corresponding to the server are not updated, leaving the
411/// object in an invalid state where the servers are out of sync with the
412/// proxies. This can have very bad consequences. Finally, by having to
413/// manually specify the value and shape server properties, it is very easy to
414/// get them wrong.
415///
416/// If you want to safely replace a server, you should use
417/// RooAbsArg::redirectServers(), which replaces the server in-place at the
418/// same position of the server list, keeps the same value and shape server
419/// properties, and also updates the corresponding proxies.
420
421void RooAbsArg::replaceServer(RooAbsArg& oldServer, RooAbsArg& newServer, bool propValue, bool propShape)
422{
423 coutW(LinkStateMgmt) << "replaceServer()"
424 << " is unsafe, because the server list will be out of sync with the proxy objects!"
425 << " If you want to safely replace a server, use RooAbsArg::redirectServers()."
426 << " See the docs to replaceServers() for more info." << std::endl;
427
428 Int_t count = _serverList.refCount(&oldServer);
429 removeServer(oldServer, true);
430
431 addServer(newServer, propValue, propShape, count);
432}
433
434
435////////////////////////////////////////////////////////////////////////////////
436/// Change dirty flag propagation mask for specified server
437
438void RooAbsArg::changeServer(RooAbsArg& server, bool valueProp, bool shapeProp)
439{
440 if (!_serverList.containsByNamePtr(&server)) {
441 coutE(LinkStateMgmt) << "RooAbsArg::changeServer(" << GetName() << "): Server "
442 << server.GetName() << " not registered" << endl ;
443 return ;
444 }
445
446 // This condition should not happen, but check anyway
447 if (!server._clientList.containsByNamePtr(this)) {
448 coutE(LinkStateMgmt) << "RooAbsArg::changeServer(" << GetName() << "): Server "
449 << server.GetName() << " doesn't have us registered as client" << endl ;
450 return ;
451 }
452
453 // Remove all propagation links, then reinstall requested ones ;
454 Int_t vcount = server._clientListValue.refCount(this) ;
455 Int_t scount = server._clientListShape.refCount(this) ;
456 server._clientListValue.RemoveAll(this) ;
457 server._clientListShape.RemoveAll(this) ;
458 if (valueProp) {
459 server._clientListValue.Add(this, vcount) ;
460 }
461 if (shapeProp) {
462 server._clientListShape.Add(this, scount) ;
463 }
464}
465
466
467
468////////////////////////////////////////////////////////////////////////////////
469/// Fill supplied list with all leaf nodes of the arg tree, starting with
470/// ourself as top node. A leaf node is node that has no servers declared.
471
472void RooAbsArg::leafNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, bool recurseNonDerived) const
473{
474 treeNodeServerList(list,arg,false,true,false,recurseNonDerived) ;
475}
476
477
478
479////////////////////////////////////////////////////////////////////////////////
480/// Fill supplied list with all branch nodes of the arg tree starting with
481/// ourself as top node. A branch node is node that has one or more servers declared.
482
483void RooAbsArg::branchNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, bool recurseNonDerived) const
484{
485 treeNodeServerList(list,arg,true,false,false,recurseNonDerived) ;
486}
487
488
489////////////////////////////////////////////////////////////////////////////////
490/// Fill supplied list with nodes of the arg tree, following all server links,
491/// starting with ourself as top node.
492/// \param[in] list Output list
493/// \param[in] arg Start searching at this element of the tree.
494/// \param[in] doBranch Add branch nodes to the list.
495/// \param[in] doLeaf Add leaf nodes to the list.
496/// \param[in] valueOnly Only check if an element is a value server (no shape server).
497/// \param[in] recurseFundamental
498
499void RooAbsArg::treeNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, bool doBranch, bool doLeaf, bool valueOnly, bool recurseFundamental) const
500{
501// if (arg==0) {
502// cout << "treeNodeServerList(" << GetName() << ") doBranch=" << (doBranch?"T":"F") << " doLeaf = " << (doLeaf?"T":"F") << " valueOnly=" << (valueOnly?"T":"F") << endl ;
503// }
504
505 if (!arg) {
506 list->reserve(10);
507 arg=this ;
508 }
509
510 // Decide if to add current node
511 if ((doBranch&&doLeaf) ||
512 (doBranch&&arg->isDerived()) ||
513 (doLeaf&&arg->isFundamental()&&(!(recurseFundamental&&arg->isDerived()))) ||
514 (doLeaf && !arg->isFundamental() && !arg->isDerived())) {
515
516 list->add(*arg,true) ;
517 }
518
519 // Recurse if current node is derived
520 if (arg->isDerived() && (!arg->isFundamental() || recurseFundamental)) {
521 for (const auto server : arg->_serverList) {
522
523 // Skip non-value server nodes if requested
524 bool isValueSrv = server->_clientListValue.containsByNamePtr(arg);
525 if (valueOnly && !isValueSrv) {
526 continue ;
527 }
528 treeNodeServerList(list,server,doBranch,doLeaf,valueOnly,recurseFundamental) ;
529 }
530 }
531}
532
533
534////////////////////////////////////////////////////////////////////////////////
535/// Create a list of leaf nodes in the arg tree starting with
536/// ourself as top node that don't match any of the names of the variable list
537/// of the supplied data set (the dependents). The caller of this
538/// function is responsible for deleting the returned argset.
539/// The complement of this function is getObservables()
540
541RooFit::OwningPtr<RooArgSet> RooAbsArg::getParameters(const RooAbsData* set, bool stripDisconnected) const
542{
543 return getParameters(set?set->get():nullptr,stripDisconnected) ;
544}
545
546
547/// Return the parameters of this p.d.f when used in conjunction with dataset 'data'.
549{
550 return getParameters(&data,stripDisconnected) ;
551}
552
553
554/// Return the parameters of the p.d.f given the provided set of observables.
555RooFit::OwningPtr<RooArgSet> RooAbsArg::getParameters(const RooArgSet& observables, bool stripDisconnected) const
556{
557 return getParameters(&observables,stripDisconnected);
558}
559
560
561////////////////////////////////////////////////////////////////////////////////
562/// Create a list of leaf nodes in the arg tree starting with
563/// ourself as top node that don't match any of the names the args in the
564/// supplied argset. The caller of this function is responsible
565/// for deleting the returned argset. The complement of this function
566/// is getObservables().
567
568RooFit::OwningPtr<RooArgSet> RooAbsArg::getParameters(const RooArgSet* observables, bool stripDisconnected) const
569{
570 auto * outputSet = new RooArgSet;
571 getParameters(observables, *outputSet, stripDisconnected);
572 return RooFit::OwningPtr<RooArgSet>{outputSet};
573}
574
575
576////////////////////////////////////////////////////////////////////////////////
577/// Add all parameters of the function and its daughters to `params`.
578/// \param[in] params Collection that stores all parameters. Add all new parameters to this.
579/// \param[in] nset Normalisation set (optional). If a value depends on this set, it's not a parameter.
580/// \param[in] stripDisconnected Passed on to getParametersHook().
581
582void RooAbsArg::addParameters(RooAbsCollection& params, const RooArgSet* nset, bool stripDisconnected) const
583{
584
585 RooArgSet nodeParamServers;
586 std::vector<RooAbsArg*> branchList;
587 for (const auto server : _serverList) {
588 if (server->isValueServer(*this)) {
589 if (server->isFundamental()) {
590 if (!nset || !server->dependsOn(*nset)) {
591 nodeParamServers.add(*server);
592 }
593 } else {
594 branchList.push_back(server);
595 }
596 }
597 }
598
599 // Allow pdf to strip parameters from list before adding it
600 getParametersHook(nset,&nodeParamServers,stripDisconnected) ;
601
602 // Add parameters of this node to the combined list
603 params.add(nodeParamServers,true) ;
604
605 // Now recurse into branch servers
606 std::sort(branchList.begin(), branchList.end());
607 const auto last = std::unique(branchList.begin(), branchList.end());
608 for (auto serverIt = branchList.begin(); serverIt < last; ++serverIt) {
609 (*serverIt)->addParameters(params, nset);
610 }
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Obtain an estimate of the number of parameters of the function and its daughters.
615/// Calling `addParameters` for large functions (NLL) can cause many reallocations of
616/// `params` due to the recursive behaviour. This utility function aims to pre-compute
617/// the total number of parameters, so that enough memory is reserved.
618/// The estimate is not fully accurate (overestimate) as there is no equivalent to `getParametersHook`.
619/// \param[in] nset Normalisation set (optional). If a value depends on this set, it's not a parameter.
620
622{
623
624 std::size_t res = 0;
625 std::vector<RooAbsArg*> branchList;
626 for (const auto server : _serverList) {
627 if (server->isValueServer(*this)) {
628 if (server->isFundamental()) {
629 if (!nset || !server->dependsOn(*nset)) {
630 res++;
631 }
632 } else {
633 branchList.push_back(server);
634 }
635 }
636 }
637
638 // Now recurse into branch servers
639 std::sort(branchList.begin(), branchList.end());
640 const auto last = std::unique(branchList.begin(), branchList.end());
641 for (auto serverIt = branchList.begin(); serverIt < last; ++serverIt) {
642 res += (*serverIt)->getParametersSizeEstimate(nset);
643 }
644
645 return res;
646}
647
648
649////////////////////////////////////////////////////////////////////////////////
650/// Fills a list with leaf nodes in the arg tree starting with
651/// ourself as top node that don't match any of the names the args in the
652/// supplied argset. Returns `true` only if something went wrong.
653/// The complement of this function is getObservables().
654/// \param[in] observables Set of leaves to ignore because they are observables and not parameters.
655/// \param[out] outputSet Output set.
656/// \param[in] stripDisconnected Allow pdf to strip parameters from list before adding it.
657
658bool RooAbsArg::getParameters(const RooArgSet* observables, RooArgSet& outputSet, bool stripDisconnected) const
659{
661
662 // Check for cached parameter set
663 if (_myws) {
664 auto nsetObs = getColonSeparatedNameString(observables ? *observables : RooArgSet());
665 const RooArgSet *paramSet = _myws->set(Form("CACHE_PARAMS_OF_PDF_%s_FOR_OBS_%s", GetName(), nsetObs.c_str()));
666 if (paramSet) {
667 outputSet.add(*paramSet);
668 return false;
669 }
670 }
671
672 outputSet.clear();
673 outputSet.setName("parameters");
674
675 RooArgList tempList;
676 // reserve all memory needed in one go
677 tempList.reserve(getParametersSizeEstimate(observables));
678
679 addParameters(tempList, observables, stripDisconnected);
680
681 // The adding from the list to the set has to be silent to not complain
682 // about duplicate parameters. After all, it's normal that parameters can
683 // appear in sifferent components of the model.
684 outputSet.add(tempList, /*silent=*/true);
685 outputSet.sort();
686
687 // Cache parameter set
688 if (_myws && outputSet.size() > 10) {
689 auto nsetObs = getColonSeparatedNameString(observables ? *observables : RooArgSet());
690 _myws->defineSetInternal(Form("CACHE_PARAMS_OF_PDF_%s_FOR_OBS_%s", GetName(), nsetObs.c_str()), outputSet);
691 }
692
693 return false;
694}
695
696
697/// Given a set of possible observables, return the observables that this PDF depends on.
699{
700 return getObservables(&set, valueOnly);
701}
702
703/// Return the observables of this pdf given the observables defined by `data`.
705{
706 return getObservables(&data);
707}
708
709
710////////////////////////////////////////////////////////////////////////////////
711/// Create a list of leaf nodes in the arg tree starting with
712/// ourself as top node that match any of the names of the variable list
713/// of the supplied data set (the dependents). The caller of this
714/// function is responsible for deleting the returned argset.
715/// The complement of this function is getParameters().
716
718{
719 if (!set) return RooFit::OwningPtr<RooArgSet>{new RooArgSet};
720
721 return getObservables(set->get()) ;
722}
723
724
725////////////////////////////////////////////////////////////////////////////////
726/// Create a list of leaf nodes in the arg tree starting with
727/// ourself as top node that match any of the names the args in the
728/// supplied argset. The caller of this function is responsible
729/// for deleting the returned argset. The complement of this function
730/// is getParameters().
731
733{
734 auto depList = new RooArgSet;
735 getObservables(dataList, *depList, valueOnly);
736 return RooFit::OwningPtr<RooArgSet>{depList};
737}
738
739
740////////////////////////////////////////////////////////////////////////////////
741/// Create a list of leaf nodes in the arg tree starting with
742/// ourself as top node that match any of the names the args in the
743/// supplied argset.
744/// Returns `true` only if something went wrong.
745/// The complement of this function is getParameters().
746/// \param[in] dataList Set of leaf nodes to match.
747/// \param[out] outputSet Output set.
748/// \param[in] valueOnly If this parameter is true, we only match leaves that
749/// depend on the value of any arg in `dataList`.
750
751bool RooAbsArg::getObservables(const RooAbsCollection* dataList, RooArgSet& outputSet, bool valueOnly) const
752{
753 outputSet.clear();
754 outputSet.setName("dependents");
755
756 if (!dataList) return false;
757
758 // Make iterator over tree leaf node list
759 RooArgSet leafList("leafNodeServerList") ;
760 treeNodeServerList(&leafList,nullptr,false,true,valueOnly) ;
761
762 if (valueOnly) {
763 for (const auto arg : leafList) {
764 if (arg->dependsOnValue(*dataList) && arg->isLValue()) {
765 outputSet.add(*arg) ;
766 }
767 }
768 } else {
769 for (const auto arg : leafList) {
770 if (arg->dependsOn(*dataList) && arg->isLValue()) {
771 outputSet.add(*arg) ;
772 }
773 }
774 }
775
776 return false;
777}
778
779
780////////////////////////////////////////////////////////////////////////////////
781/// Create a RooArgSet with all components (branch nodes) of the
782/// expression tree headed by this object.
784{
785 RooArgSet* set = new RooArgSet((std::string(GetName()) + "_components").c_str()) ;
787
789}
790
791
792
793////////////////////////////////////////////////////////////////////////////////
794/// Overloadable function in which derived classes can implement
795/// consistency checks of the variables. If this function returns
796/// true, indicating an error, the fitter or generator will abort.
797
799{
800 return false ;
801}
802
803
804////////////////////////////////////////////////////////////////////////////////
805/// Recursively call checkObservables on all nodes in the expression tree
806
808{
809 RooArgSet nodeList ;
810 treeNodeServerList(&nodeList) ;
811
812 bool ret(false) ;
813 for(RooAbsArg * arg : nodeList) {
814 if (arg->getAttribute("ServerDied")) {
815 coutE(LinkStateMgmt) << "RooAbsArg::recursiveCheckObservables(" << GetName() << "): ERROR: one or more servers of node "
816 << arg->GetName() << " no longer exists!" << endl ;
817 arg->Print("v") ;
818 ret = true ;
819 }
820 ret |= arg->checkObservables(nset) ;
821 }
822
823 return ret ;
824}
825
826
827////////////////////////////////////////////////////////////////////////////////
828/// Test whether we depend on (ie, are served by) any object in the
829/// specified collection. Uses the dependsOn(RooAbsArg&) member function.
830
831bool RooAbsArg::dependsOn(const RooAbsCollection& serverList, const RooAbsArg* ignoreArg, bool valueOnly) const
832{
833 // Test whether we depend on (ie, are served by) any object in the
834 // specified collection. Uses the dependsOn(RooAbsArg&) member function.
835
836 for (auto server : serverList) {
837 if (dependsOn(*server,ignoreArg,valueOnly)) {
838 return true;
839 }
840 }
841 return false;
842}
843
844
845////////////////////////////////////////////////////////////////////////////////
846/// Test whether we depend on (ie, are served by) an object with a specific name.
847bool RooAbsArg::dependsOn(TNamed const* testArgNamePtr, const RooAbsArg* ignoreArg, bool valueOnly) const
848{
849 if (this==ignoreArg) return false ;
850
851 // First check if testArg is self
852 if (testArgNamePtr == namePtr()) return true ;
853
854 // Next test direct dependence
855 RooAbsArg *foundServer = _serverList.findByNamePointer(testArgNamePtr);
856 if (foundServer) {
857
858 // Return true if valueOnly is FALSE or if server is value server, otherwise keep looking
859 if ( !valueOnly || foundServer->isValueServer(*this)) {
860 return true ;
861 }
862 }
863
864 // If not, recurse
865 for (const auto server : _serverList) {
866 if ( !valueOnly || server->isValueServer(*this)) {
867 if (server->dependsOn(testArgNamePtr,ignoreArg,valueOnly)) {
868 return true ;
869 }
870 }
871 }
872
873 return false ;
874}
875
876
877
878////////////////////////////////////////////////////////////////////////////////
879/// Test if any of the nodes of tree are shared with that of the given tree
880
881bool RooAbsArg::overlaps(const RooAbsArg& testArg, bool valueOnly) const
882{
883 RooArgSet list("treeNodeList") ;
884 treeNodeServerList(&list) ;
885
886 return valueOnly ? testArg.dependsOnValue(list) : testArg.dependsOn(list) ;
887}
888
889
890
891////////////////////////////////////////////////////////////////////////////////
892/// Test if any of the dependents of the arg tree (as determined by getObservables)
893/// overlaps with those of the testArg.
894
895bool RooAbsArg::observableOverlaps(const RooAbsData* dset, const RooAbsArg& testArg) const
896{
897 return observableOverlaps(dset->get(),testArg) ;
898}
899
900
901////////////////////////////////////////////////////////////////////////////////
902/// Test if any of the dependents of the arg tree (as determined by getObservables)
903/// overlaps with those of the testArg.
904
905bool RooAbsArg::observableOverlaps(const RooArgSet* nset, const RooAbsArg& testArg) const
906{
907 return testArg.dependsOn(*std::unique_ptr<RooArgSet>{getObservables(nset)});
908}
909
910
911
912////////////////////////////////////////////////////////////////////////////////
913/// Mark this object as having changed its value, and propagate this status
914/// change to all of our clients. If the object is not in automatic dirty
915/// state propagation mode, this call has no effect.
916
918{
919 if (_operMode!=Auto || _inhibitDirty) return ;
920
921 // Handle no-propagation scenarios first
922 if (_clientListValue.empty()) {
923 _valueDirty = true ;
924 return ;
925 }
926
927 // Cyclical dependency interception
928 if (source==nullptr) {
929 source=this ;
930 } else if (source==this) {
931 // Cyclical dependency, abort
932 coutE(LinkStateMgmt) << "RooAbsArg::setValueDirty(" << GetName()
933 << "): cyclical dependency detected, source = " << source->GetName() << endl ;
934 //assert(0) ;
935 return ;
936 }
937
938 // Propagate dirty flag to all clients if this is a down->up transition
939 if (_verboseDirty) {
940 cxcoutD(LinkStateMgmt) << "RooAbsArg::setValueDirty(" << (source?source->GetName():"self") << "->" << GetName() << "," << this
941 << "): dirty flag " << (_valueDirty?"already ":"") << "raised" << endl ;
942 }
943
944 _valueDirty = true ;
945
946
947 for (auto client : _clientListValue) {
948 client->setValueDirty(source) ;
949 }
950
951
952}
953
954
955////////////////////////////////////////////////////////////////////////////////
956/// Mark this object as having changed its shape, and propagate this status
957/// change to all of our clients.
958
960{
961 if (_verboseDirty) {
962 cxcoutD(LinkStateMgmt) << "RooAbsArg::setShapeDirty(" << GetName()
963 << "): dirty flag " << (_shapeDirty?"already ":"") << "raised" << endl ;
964 }
965
966 if (_clientListShape.empty()) {
967 _shapeDirty = true ;
968 return ;
969 }
970
971 // Set 'dirty' shape state for this object and propagate flag to all its clients
972 if (source==nullptr) {
973 source=this ;
974 } else if (source==this) {
975 // Cyclical dependency, abort
976 coutE(LinkStateMgmt) << "RooAbsArg::setShapeDirty(" << GetName()
977 << "): cyclical dependency detected" << endl ;
978 return ;
979 }
980
981 // Propagate dirty flag to all clients if this is a down->up transition
982 _shapeDirty=true ;
983
984 for (auto client : _clientListShape) {
985 client->setShapeDirty(source) ;
986 client->setValueDirty(source) ;
987 }
988
989}
990
991
992
993////////////////////////////////////////////////////////////////////////////////
994/// Replace all direct servers of this object with the new servers in `newServerList`.
995/// This substitutes objects that we receive values from with new objects that have the same name.
996/// \see recursiveRedirectServers() Use recursive version if servers that are only indirectly serving this object should be replaced as well.
997/// \see redirectServers() If only the direct servers of an object need to be replaced.
998///
999/// Note that changing the types of objects is generally allowed, but can be wrong if the interface of an object changes.
1000/// For example, one can reparametrise a model by substituting a variable with a function:
1001/// \f[
1002/// f(x\, |\, a) = a \cdot x \rightarrow f(x\, |\, b) = (2.1 \cdot b) \cdot x
1003/// \f]
1004/// If an object, however, expects a PDF, and this is substituted with a function that isn't normalised, wrong results might be obtained
1005/// or it might even crash the program. The types of the objects being substituted are not checked.
1006///
1007/// \param[in] newSetOrig Set of new servers that should be used instead of the current servers.
1008/// \param[in] mustReplaceAll A warning is printed and error status is returned if not all servers could be
1009/// substituted successfully.
1010/// \param[in] nameChange If false, an object named "x" is only replaced with an object also named "x" in `newSetOrig`.
1011/// If the object in `newSet` is called differently, set `nameChange` to true and use setAttribute() on the x object:
1012/// ```
1013/// objectToReplaceX.setAttribute("ORIGNAME:x")
1014/// ```
1015/// Now, the renamed object will be selected based on the attribute "ORIGNAME:<name>".
1016/// \param[in] isRecursionStep Internal switch used when called from recursiveRedirectServers().
1017bool RooAbsArg::redirectServers(const RooAbsCollection& newSetOrig, bool mustReplaceAll, bool nameChange, bool isRecursionStep)
1018{
1019 // Trivial case, no servers
1020 if (_serverList.empty()) return false ;
1021
1022 // We don't need to do anything if there are no new servers or if the only
1023 // new server is this RooAbsArg itself. And by returning early, we avoid
1024 // potentially annoying side effects of the redirectServersHook.
1025 if (newSetOrig.empty() || (newSetOrig.size() == 1 && newSetOrig[0] == this)) return false ;
1026
1027 // Strip any non-matching removal nodes from newSetOrig
1028 std::unique_ptr<RooArgSet> newSetOwned;
1029 RooAbsCollection const* newSet = &newSetOrig;
1030
1031 if (nameChange) {
1032 newSetOwned = std::make_unique<RooArgSet>();
1033 for (auto arg : *newSet) {
1034
1035 if (string("REMOVAL_DUMMY")==arg->GetName()) {
1036
1037 if (arg->getAttribute("REMOVE_ALL")) {
1038 newSetOwned->add(*arg) ;
1039 } else if (arg->getAttribute(Form("REMOVE_FROM_%s",getStringAttribute("ORIGNAME")))) {
1040 newSetOwned->add(*arg) ;
1041 }
1042 } else {
1043 newSetOwned->add(*arg) ;
1044 }
1045 }
1046 newSet = newSetOwned.get();
1047 }
1048
1049 // Replace current servers with new servers with the same name from the given list
1050 for (auto oldServer : _serverList) {
1051
1052 RooAbsArg * newServer= oldServer->findNewServer(*newSet, nameChange);
1053
1054 if (!newServer) {
1055 if (mustReplaceAll) {
1056 std::stringstream ss;
1057 ss << "RooAbsArg::redirectServers(" << (void*)this << "," << GetName() << "): server " << oldServer->GetName()
1058 << " (" << (void*)oldServer << ") not redirected" << (nameChange?"[nameChange]":"");
1059 const std::string errorMsg = ss.str();
1060 coutE(LinkStateMgmt) << errorMsg << std::endl;
1061 throw std::runtime_error(errorMsg);
1062 }
1063 continue ;
1064 }
1065
1066 if (newServer != this) {
1067 substituteServer(oldServer, newServer);
1068 }
1069 }
1070
1071 setValueDirty() ;
1072 setShapeDirty() ;
1073
1074 bool ret(false) ;
1075
1076 // Process the proxies
1077 for (int i=0 ; i<numProxies() ; i++) {
1078 RooAbsProxy* p = getProxy(i) ;
1079 if (!p) continue ;
1080 bool ret2 = p->changePointer(*newSet,nameChange,false) ;
1081
1082 if (mustReplaceAll && !ret2) {
1083 auto ap = dynamic_cast<const RooArgProxy*>(p);
1084 coutE(LinkStateMgmt) << "RooAbsArg::redirectServers(" << GetName()
1085 << "): ERROR, proxy '" << p->name()
1086 << "' with arg '" << (ap ? ap->absArg()->GetName() : "<could not cast>") << "' could not be adjusted" << endl;
1087 ret = true ;
1088 }
1089 }
1090
1091 // Optional subclass post-processing
1092 ret |= callRedirectServersHook(*newSet, mustReplaceAll, nameChange, isRecursionStep);
1093 return ret;
1094}
1095
1096/// Private helper function for RooAbsArg::redirectServers().
1098{
1099 _serverList.Replace(oldServer, newServer);
1100
1101 const int clientListRefCount = oldServer->_clientList.Remove(this, true);
1102 const int clientListValueRefCount = oldServer->_clientListValue.Remove(this, true);
1103 const int clientListShapeRefCount = oldServer->_clientListShape.Remove(this, true);
1104
1105 newServer->_clientList.Add(this, clientListRefCount);
1106 newServer->_clientListValue.Add(this, clientListValueRefCount);
1107 newServer->_clientListShape.Add(this, clientListShapeRefCount);
1108
1109 if (clientListValueRefCount > 0 && newServer->operMode() == ADirty && operMode() != ADirty) {
1111 }
1112}
1113
1114/// Private helper function for RooAbsArg::redirectServers().
1115bool RooAbsArg::callRedirectServersHook(RooAbsCollection const &newSet, bool mustReplaceAll, bool nameChange,
1116 bool isRecursionStep)
1117{
1118 bool ret = false;
1119 for (Int_t i = 0; i < numCaches(); i++) {
1120 ret |= getCache(i)->redirectServersHook(newSet, mustReplaceAll, nameChange, isRecursionStep);
1121 }
1122 ret |= redirectServersHook(newSet, mustReplaceAll, nameChange, isRecursionStep);
1123
1124 return ret;
1125}
1126
1127////////////////////////////////////////////////////////////////////////////////
1128/// Replace some servers of this object. If there are proxies that correspond
1129/// to the replaced servers, these proxies are adjusted as well.
1130/// \param[in] replacements Map that specifies which args replace which servers.
1131bool RooAbsArg::redirectServers(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements)
1132{
1133 bool ret(false);
1134 bool nameChange = false;
1135
1136 RooArgList newList;
1137
1138 // Replace current servers with new servers with the same name from the given list
1139 for (auto oldServer : _serverList) {
1140
1141 auto newServerFound = replacements.find(oldServer);
1142 RooAbsArg *newServer = newServerFound != replacements.end() ? newServerFound->second : nullptr;
1143
1144 if (!newServer || newServer == this) {
1145 continue;
1146 }
1147
1148 if (nameChange == false)
1149 nameChange = strcmp(newServerFound->first->GetName(), newServerFound->second->GetName()) != 0;
1150
1151 substituteServer(oldServer, newServer);
1152 newList.add(*newServer);
1153 }
1154
1155 // No servers were replaced, we don't need to process proxies and call the
1156 // redirectServersHook.
1157 if (newList.empty())
1158 return ret;
1159
1160 setValueDirty();
1161 setShapeDirty();
1162
1163 // Process the proxies
1164 for (int i = 0; i < numProxies(); i++) {
1165 if (RooAbsProxy *p = getProxy(i)) {
1166 p->changePointer(replacements);
1167 }
1168 }
1169
1170 // Optional subclass post-processing
1171 ret |= callRedirectServersHook(newList, false, nameChange, false);
1172 return ret;
1173}
1174
1175////////////////////////////////////////////////////////////////////////////////
1176/// Find the new server in the specified set that matches the old server.
1177///
1178/// \param[in] newSet Search this set by name for a new server.
1179/// \param[in] nameChange If true, search for an item with the bool attribute "ORIGNAME:<oldName>" set.
1180/// Use `<object>.setAttribute("ORIGNAME:<oldName>")` to set this attribute.
1181/// \return Pointer to the new server or `nullptr` if there's no unique match.
1182RooAbsArg *RooAbsArg::findNewServer(const RooAbsCollection &newSet, bool nameChange) const
1183{
1184 RooAbsArg *newServer = nullptr;
1185 if (!nameChange) {
1186 newServer = newSet.find(*this) ;
1187 }
1188 else {
1189 // Name changing server redirect:
1190 // use 'ORIGNAME:<oldName>' attribute instead of name of new server
1191 TString nameAttrib("ORIGNAME:") ;
1192 nameAttrib.Append(GetName()) ;
1193
1194 if (auto tmp = std::unique_ptr<RooAbsCollection>{newSet.selectByAttrib(nameAttrib,true)}) {
1195
1196 // Check if any match was found
1197 if (tmp->empty()) {
1198 return nullptr;
1199 }
1200
1201 // Check if match is unique
1202 if(tmp->size()>1) {
1203 std::stringstream ss;
1204 ss << "RooAbsArg::redirectServers(" << GetName() << "): FATAL Error, " << tmp->size() << " servers with "
1205 << nameAttrib << " attribute";
1206 coutF(LinkStateMgmt) << ss.str() << std::endl;
1207 tmp->Print("v") ;
1208 throw std::runtime_error(ss.str());
1209 }
1210
1211 // use the unique element in the set
1212 newServer= tmp->first();
1213 }
1214 }
1215 return newServer;
1216}
1217
1218
1219namespace {
1220
1221bool recursiveRedirectServersImpl(RooAbsArg *arg, RooAbsCollection const &newSet, bool mustReplaceAll, bool nameChange,
1222 bool recurseInNewSet, std::set<RooAbsArg const *> &callStack)
1223{
1224 // Cyclic recursion protection
1225 {
1226 auto it = callStack.lower_bound(arg);
1227 if (it != callStack.end() && arg == *it) {
1228 return false;
1229 }
1230 callStack.insert(it, arg);
1231 }
1232
1233 // Do not recurse into newset if not so specified
1234 // if (!recurseInNewSet && newSet.contains(*arg)) {
1235 // return false;
1236 // }
1237
1238 // Apply the redirectServers function recursively on all branch nodes in this argument tree.
1239 bool ret(false);
1240
1241 oocxcoutD(arg, LinkStateMgmt) << "RooAbsArg::recursiveRedirectServers(" << arg << "," << arg->GetName()
1242 << ") newSet = " << newSet << " mustReplaceAll = " << (mustReplaceAll ? "T" : "F")
1243 << " nameChange = " << (nameChange ? "T" : "F")
1244 << " recurseInNewSet = " << (recurseInNewSet ? "T" : "F") << endl;
1245
1246 // Do redirect on self (identify operation as recursion step)
1247 ret |= arg->redirectServers(newSet, mustReplaceAll, nameChange, true);
1248
1249 // Do redirect on servers
1250 for (const auto server : arg->servers()) {
1251 ret |= recursiveRedirectServersImpl(server, newSet, mustReplaceAll, nameChange, recurseInNewSet, callStack);
1252 }
1253
1254 callStack.erase(arg);
1255 return ret;
1256}
1257
1258} // namespace
1259
1260////////////////////////////////////////////////////////////////////////////////
1261/// Recursively replace all servers with the new servers in `newSet`.
1262/// This substitutes objects that we receive values from (also indirectly
1263/// through other objects) with new objects that have the same name.
1264///
1265/// *Copied from redirectServers:*
1266///
1267/// \copydetails RooAbsArg::redirectServers
1268/// \param newSet Roo collection
1269/// \param recurseInNewSet be recursive
1270bool RooAbsArg::recursiveRedirectServers(RooAbsCollection const &newSet, bool mustReplaceAll, bool nameChange,
1271 bool recurseInNewSet)
1272{
1273 // For cyclic recursion protection
1274 std::set<const RooAbsArg *> callStack;
1275
1276 return recursiveRedirectServersImpl(this, newSet, mustReplaceAll, nameChange, recurseInNewSet, callStack);
1277}
1278
1279
1280////////////////////////////////////////////////////////////////////////////////
1281/// Function that is called at the end of redirectServers(). Can be overloaded
1282/// to inject some class-dependent behavior after server redirection, e.g.
1283/// resetting of caches. The return value is meant to be an error flag, so in
1284/// case something goes wrong the function should return `true`. If you
1285/// overload this function, don't forget to also call the function of the
1286/// base class.
1287///
1288/// \see redirectServers() For a detailed explanation of the function parameters.
1289///
1290// \param[in] newServerList One of the original parameters passed to redirectServers().
1291// \param[in] mustReplaceAll One of the original parameters passed to redirectServers().
1292// \param[in] nameChange One of the original parameters passed to redirectServers().
1293// \param[in] isRecursiveStep One of the original parameters passed to redirectServers().
1294bool RooAbsArg::redirectServersHook(const RooAbsCollection & /*newServerList*/, bool /*mustReplaceAll*/,
1295 bool /*nameChange*/, bool /*isRecursiveStep*/)
1296{
1297 setProxyNormSet(nullptr);
1298 return false;
1299}
1300
1301
1302
1303////////////////////////////////////////////////////////////////////////////////
1304/// Register an RooArgProxy in the proxy list. This function is called by owned
1305/// proxies upon creation. After registration, this arg will forward pointer
1306/// changes from serverRedirects and updates in cached normalization sets
1307/// to the proxies immediately after they occur. The proxied argument is
1308/// also added as value and/or shape server
1309
1311{
1312 // Every proxy can be registered only once
1313 if (_proxyList.FindObject(&proxy)) {
1314 coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
1315 << proxy.GetName() << " for arg " << proxy.absArg()->GetName()
1316 << " already registered" << endl ;
1317 return ;
1318 }
1319
1320// cout << (void*)this << " " << GetName() << ": registering proxy "
1321// << (void*)&proxy << " with name " << proxy.name() << " in mode "
1322// << (proxy.isValueServer()?"V":"-") << (proxy.isShapeServer()?"S":"-") << endl ;
1323
1324 // Register proxied object as server
1325 if (proxy.absArg()) {
1326 addServer(*proxy.absArg(),proxy.isValueServer(),proxy.isShapeServer()) ;
1327 }
1328
1329 // Register proxy itself
1330 _proxyList.Add(&proxy) ;
1331 _proxyListCache.isDirty = true;
1332}
1333
1334
1335////////////////////////////////////////////////////////////////////////////////
1336/// Remove proxy from proxy list. This functions is called by owned proxies
1337/// upon their destruction.
1338
1340{
1341 _proxyList.Remove(&proxy) ;
1343 _proxyListCache.isDirty = true;
1344}
1345
1346
1347
1348////////////////////////////////////////////////////////////////////////////////
1349/// Register an RooSetProxy in the proxy list. This function is called by owned
1350/// proxies upon creation. After registration, this arg will forward pointer
1351/// changes from serverRedirects and updates in cached normalization sets
1352/// to the proxies immediately after they occur.
1353
1355{
1356 // Every proxy can be registered only once
1357 if (_proxyList.FindObject(&proxy)) {
1358 coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
1359 << proxy.GetName() << " already registered" << endl ;
1360 return ;
1361 }
1362
1363 // Register proxy itself
1364 _proxyList.Add(&proxy) ;
1365 _proxyListCache.isDirty = true;
1366}
1367
1368
1369
1370////////////////////////////////////////////////////////////////////////////////
1371/// Remove proxy from proxy list. This functions is called by owned proxies
1372/// upon their destruction.
1373
1375{
1376 _proxyList.Remove(&proxy) ;
1378 _proxyListCache.isDirty = true;
1379}
1380
1381
1382
1383////////////////////////////////////////////////////////////////////////////////
1384/// Register an RooListProxy in the proxy list. This function is called by owned
1385/// proxies upon creation. After registration, this arg will forward pointer
1386/// changes from serverRedirects and updates in cached normalization sets
1387/// to the proxies immediately after they occur.
1388
1390{
1391 // Every proxy can be registered only once
1392 if (_proxyList.FindObject(&proxy)) {
1393 coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
1394 << proxy.GetName() << " already registered" << endl ;
1395 return ;
1396 }
1397
1398 // Register proxy itself
1399 Int_t nProxyOld = _proxyList.GetEntries() ;
1400 _proxyList.Add(&proxy) ;
1401 _proxyListCache.isDirty = true;
1402 if (_proxyList.GetEntries()!=nProxyOld+1) {
1403 cout << "RooAbsArg::registerProxy(" << GetName() << ") proxy registration failure! nold=" << nProxyOld << " nnew=" << _proxyList.GetEntries() << endl ;
1404 }
1405}
1406
1407
1408
1409////////////////////////////////////////////////////////////////////////////////
1410/// Remove proxy from proxy list. This functions is called by owned proxies
1411/// upon their destruction.
1412
1414{
1415 _proxyList.Remove(&proxy) ;
1417 _proxyListCache.isDirty = true;
1418}
1419
1420
1421
1422////////////////////////////////////////////////////////////////////////////////
1423/// Return the nth proxy from the proxy list.
1424
1426{
1427 // Cross cast: proxy list returns TObject base pointer, we need
1428 // a RooAbsProxy base pointer. C++ standard requires
1429 // a dynamic_cast for this.
1430 return dynamic_cast<RooAbsProxy*> (_proxyList.At(index)) ;
1431}
1432
1433
1434
1435////////////////////////////////////////////////////////////////////////////////
1436/// Return the number of registered proxies.
1437
1439{
1440 return _proxyList.GetEntriesFast();
1441}
1442
1443
1444
1445////////////////////////////////////////////////////////////////////////////////
1446/// Forward a change in the cached normalization argset
1447/// to all the registered proxies.
1448
1450{
1452 // First time we loop over proxies: cache the results to avoid future
1453 // costly dynamic_casts
1454 _proxyListCache.cache.clear();
1455 for (int i=0 ; i<numProxies() ; i++) {
1456 RooAbsProxy* p = getProxy(i) ;
1457 if (!p) continue ;
1458 _proxyListCache.cache.push_back(p);
1459 }
1460 _proxyListCache.isDirty = false;
1461 }
1462
1463 for ( auto& p : _proxyListCache.cache ) {
1464 p->changeNormSet(nset);
1465 }
1466
1467 // If the proxy normSet changed, we also have to set our value dirty flag.
1468 // Otherwise, value for the new normalization set might not get recomputed!
1469 setValueDirty();
1470}
1471
1472
1473
1474////////////////////////////////////////////////////////////////////////////////
1475/// Overloadable function for derived classes to implement
1476/// attachment as branch to a TTree
1477
1479{
1480 coutE(Contents) << "RooAbsArg::attachToTree(" << GetName()
1481 << "): Cannot be attached to a TTree" << endl ;
1482}
1483
1484
1485
1486////////////////////////////////////////////////////////////////////////////////
1487/// WVE (08/21/01) Probably obsolete now
1488
1490{
1491 return true ;
1492}
1493
1494
1495
1496
1497////////////////////////////////////////////////////////////////////////////////
1498/// Print object name
1499
1500void RooAbsArg::printName(ostream& os) const
1501{
1502 os << GetName() ;
1503}
1504
1505
1506
1507////////////////////////////////////////////////////////////////////////////////
1508/// Print object title
1509
1510void RooAbsArg::printTitle(ostream& os) const
1511{
1512 os << GetTitle() ;
1513}
1514
1515
1516
1517////////////////////////////////////////////////////////////////////////////////
1518/// Print object class name
1519
1520void RooAbsArg::printClassName(ostream& os) const
1521{
1522 os << ClassName() ;
1523}
1524
1525
1526/// Print address of this RooAbsArg.
1527void RooAbsArg::printAddress(ostream& os) const
1528{
1529 os << this ;
1530}
1531
1532
1533
1534////////////////////////////////////////////////////////////////////////////////
1535/// Print object arguments, ie its proxies
1536
1537void RooAbsArg::printArgs(ostream& os) const
1538{
1539 // Print nothing if there are no dependencies
1540 if (numProxies()==0) return ;
1541
1542 os << "[ " ;
1543 for (Int_t i=0 ; i<numProxies() ; i++) {
1544 RooAbsProxy* p = getProxy(i) ;
1545 if (p==nullptr) continue ;
1546 if (!TString(p->name()).BeginsWith("!")) {
1547 p->print(os) ;
1548 os << " " ;
1549 }
1550 }
1551 printMetaArgs(os) ;
1552 os << "]" ;
1553}
1554
1555
1556
1557////////////////////////////////////////////////////////////////////////////////
1558/// Define default contents to print
1559
1561{
1562 return kName|kClassName|kValue|kArgs ;
1563}
1564
1565
1566
1567////////////////////////////////////////////////////////////////////////////////
1568/// Implement multi-line detailed printing
1569
1570void RooAbsArg::printMultiline(ostream& os, Int_t /*contents*/, bool /*verbose*/, TString indent) const
1571{
1572 os << indent << "--- RooAbsArg ---" << endl;
1573 // dirty state flags
1574 os << indent << " Value State: " ;
1575 switch(_operMode) {
1576 case ADirty: os << "FORCED DIRTY" ; break ;
1577 case AClean: os << "FORCED clean" ; break ;
1578 case Auto: os << (isValueDirty() ? "DIRTY":"clean") ; break ;
1579 }
1580 os << endl
1581 << indent << " Shape State: " << (isShapeDirty() ? "DIRTY":"clean") << endl;
1582 // attribute list
1583 os << indent << " Attributes: " ;
1584 printAttribList(os) ;
1585 os << endl ;
1586 // our memory address (for x-referencing with client addresses of other args)
1587 os << indent << " Address: " << (void*)this << endl;
1588 // client list
1589 os << indent << " Clients: " << endl;
1590 for (const auto client : _clientList) {
1591 os << indent << " (" << (void*)client << ","
1592 << (_clientListValue.containsByNamePtr(client)?"V":"-")
1593 << (_clientListShape.containsByNamePtr(client)?"S":"-")
1594 << ") " ;
1595 client->printStream(os,kClassName|kTitle|kName,kSingleLine);
1596 }
1597
1598 // server list
1599 os << indent << " Servers: " << endl;
1600 for (const auto server : _serverList) {
1601 os << indent << " (" << (void*)server << ","
1602 << (server->_clientListValue.containsByNamePtr(this)?"V":"-")
1603 << (server->_clientListShape.containsByNamePtr(this)?"S":"-")
1604 << ") " ;
1605 server->printStream(os,kClassName|kName|kTitle,kSingleLine);
1606 }
1607
1608 // proxy list
1609 os << indent << " Proxies: " << std::endl;
1610 for (int i=0 ; i<numProxies() ; i++) {
1611 RooAbsProxy* proxy=getProxy(i) ;
1612 if (!proxy) continue ;
1613 os << indent << " " << proxy->name() << " -> " ;
1614 if(auto * argProxy = dynamic_cast<RooArgProxy*>(proxy)) {
1615 if (RooAbsArg* parg = argProxy->absArg()) {
1616 parg->printStream(os,kName,kSingleLine) ;
1617 } else {
1618 os << " (empty)" << std::endl;
1619 }
1620 // If a RooAbsProxy is not a RooArgProxy, it is a RooSetProxy or a
1621 // RooListProxy. However, they are treated the same in this function, so
1622 // we try the dynamic cast to their common base class, RooAbsCollection.
1623 } else if(auto * collProxy = dynamic_cast<RooAbsCollection*>(proxy)) {
1624 os << std::endl;
1625 TString moreIndent(indent) ;
1626 moreIndent.Append(" ") ;
1627 collProxy->printStream(os,kName,kStandard,moreIndent.Data());
1628 } else {
1629 throw std::runtime_error("Unsupported proxy type.");
1630 }
1631 }
1632}
1633
1634
1635////////////////////////////////////////////////////////////////////////////////
1636/// Print object tree structure
1637
1638void RooAbsArg::printTree(ostream& os, TString /*indent*/) const
1639{
1640 const_cast<RooAbsArg*>(this)->printCompactTree(os) ;
1641}
1642
1643
1644////////////////////////////////////////////////////////////////////////////////
1645/// Ostream operator
1646
1647ostream& operator<<(ostream& os, RooAbsArg const& arg)
1648{
1649 arg.writeToStream(os,true) ;
1650 return os ;
1651}
1652
1653////////////////////////////////////////////////////////////////////////////////
1654/// Istream operator
1655
1656istream& operator>>(istream& is, RooAbsArg &arg)
1657{
1658 arg.readFromStream(is,true,false) ;
1659 return is ;
1660}
1661
1662////////////////////////////////////////////////////////////////////////////////
1663/// Print the attribute list
1664
1665void RooAbsArg::printAttribList(ostream& os) const
1666{
1667 set<string>::const_iterator iter = _boolAttrib.begin() ;
1668 bool first(true) ;
1669 while (iter != _boolAttrib.end()) {
1670 os << (first?" [":",") << *iter ;
1671 first=false ;
1672 ++iter ;
1673 }
1674 if (!first) os << "] " ;
1675}
1676
1677
1678////////////////////////////////////////////////////////////////////////////////
1679/// Bind this node to objects in `set`.
1680/// Search the set for objects that have the same name as our servers, and
1681/// attach ourselves to those. After this operation, this node is computing its
1682/// values based on the new servers. This can be used to e.g. read values from
1683// a dataset.
1684
1685
1687{
1688 RooArgSet branches;
1689 branchNodeServerList(&branches,nullptr,true);
1690
1691 for(auto const& branch : branches) {
1692 branch->redirectServers(set,false,false);
1693 }
1694}
1695
1696
1697////////////////////////////////////////////////////////////////////////////////
1698/// Replace server nodes with names matching the dataset variable names
1699/// with those data set variables, making this PDF directly dependent on the dataset.
1700
1702{
1703 attachArgs(*data.get());
1704}
1705
1706
1707////////////////////////////////////////////////////////////////////////////////
1708/// Replace server nodes with names matching the dataset variable names
1709/// with those data set variables, making this PDF directly dependent on the dataset
1710
1712{
1713 attachArgs(*dstore.get());
1714}
1715
1716
1717////////////////////////////////////////////////////////////////////////////////
1718/// Utility function used by TCollection::Sort to compare contained TObjects
1719/// We implement comparison by name, resulting in alphabetical sorting by object name.
1720
1722{
1723 return strcmp(GetName(),other->GetName()) ;
1724}
1725
1726
1727
1728////////////////////////////////////////////////////////////////////////////////
1729/// Print information about current value dirty state information.
1730/// If depth flag is true, information is recursively printed for
1731/// all nodes in this arg tree.
1732
1733void RooAbsArg::printDirty(bool depth) const
1734{
1735 if (depth) {
1736
1737 RooArgSet branchList ;
1738 branchNodeServerList(&branchList) ;
1739 for(RooAbsArg * branch : branchList) {
1740 branch->printDirty(false) ;
1741 }
1742
1743 } else {
1744 cout << GetName() << " : " ;
1745 switch (_operMode) {
1746 case AClean: cout << "FORCED clean" ; break ;
1747 case ADirty: cout << "FORCED DIRTY" ; break ;
1748 case Auto: cout << "Auto " << (isValueDirty()?"DIRTY":"clean") ;
1749 }
1750 cout << endl ;
1751 }
1752}
1753
1754
1755////////////////////////////////////////////////////////////////////////////////
1756/// Activate cache mode optimization with given definition of observables.
1757/// The cache operation mode of all objects in the expression tree will
1758/// modified such that all nodes that depend directly or indirectly on
1759/// any of the listed observables will be set to ADirty, as they are
1760/// expected to change every time. This save change tracking overhead for
1761/// nodes that are a priori known to change every time
1762
1764{
1765 RooLinkedList proc;
1766 RooArgSet opt ;
1767 optimizeCacheMode(observables,opt,proc) ;
1768
1769 coutI(Optimization) << "RooAbsArg::optimizeCacheMode(" << GetName() << ") nodes " << opt << " depend on observables, "
1770 << "changing cache operation mode from change tracking to unconditional evaluation" << endl ;
1771}
1772
1773
1774////////////////////////////////////////////////////////////////////////////////
1775/// Activate cache mode optimization with given definition of observables.
1776/// The cache operation mode of all objects in the expression tree will
1777/// modified such that all nodes that depend directly or indirectly on
1778/// any of the listed observables will be set to ADirty, as they are
1779/// expected to change every time. This save change tracking overhead for
1780/// nodes that are a priori known to change every time
1781
1782void RooAbsArg::optimizeCacheMode(const RooArgSet& observables, RooArgSet& optimizedNodes, RooLinkedList& processedNodes)
1783{
1784 // Optimization applies only to branch nodes, not to leaf nodes
1785 if (!isDerived()) {
1786 return ;
1787 }
1788
1789
1790 // Terminate call if this node was already processed (tree structure may be cyclical)
1791 // LM : RooLinkedList::findArg looks by name and not but by object pointer,
1792 // should one use RooLinkedList::FindObject (look byt pointer) instead of findArg when
1793 // tree contains nodes with the same name ?
1794 // Add an info message if the require node does not exist but a different node already exists with same name
1795
1796 if (processedNodes.FindObject(this))
1797 return;
1798
1799 // check if findArgs returns something different (i.e. a different node with same name) when
1800 // this node has not been processed (FindObject returns a null pointer)
1801 auto obj = processedNodes.findArg(this);
1802 assert(obj != this); // obj == this cannot happen
1803 if (obj) {
1804 // here for nodes with duplicate names
1805 cxcoutI(Optimization) << "RooAbsArg::optimizeCacheMode(" << GetName() << " node " << this << " exists already as "
1806 << obj << " but with the SAME name !" << endl;
1807 }
1808
1809 processedNodes.Add(this);
1810
1811 // Set cache mode operator to 'AlwaysDirty' if we depend on any of the given observables
1812 if (dependsOnValue(observables)) {
1813
1814 if (dynamic_cast<RooRealIntegral*>(this)) {
1815 cxcoutI(Integration) << "RooAbsArg::optimizeCacheMode(" << GetName() << ") integral depends on value of one or more observables and will be evaluated for every event" << endl ;
1816 }
1817 optimizedNodes.add(*this,true) ;
1818 if (operMode()==AClean) {
1819 } else {
1820 setOperMode(ADirty,true) ; // WVE propagate flag recursively to top of tree
1821 }
1822 } else {
1823 }
1824 // Process any RooAbsArgs contained in any of the caches of this object
1825 for (Int_t i=0 ;i<numCaches() ; i++) {
1826 getCache(i)->optimizeCacheMode(observables,optimizedNodes,processedNodes) ;
1827 }
1828
1829 // Forward calls to all servers
1830 for (const auto server : _serverList) {
1831 server->optimizeCacheMode(observables,optimizedNodes,processedNodes) ;
1832 }
1833
1834}
1835
1836////////////////////////////////////////////////////////////////////////////////
1837/// Find branch nodes with all-constant parameters, and add them to the list of
1838/// nodes that can be cached with a dataset in a test statistic calculation
1839
1840bool RooAbsArg::findConstantNodes(const RooArgSet& observables, RooArgSet& cacheList)
1841{
1842 RooLinkedList proc ;
1843 bool ret = findConstantNodes(observables,cacheList,proc) ;
1844
1845 // If node can be optimized and hasn't been identified yet, add it to the list
1846 coutI(Optimization) << "RooAbsArg::findConstantNodes(" << GetName() << "): components "
1847 << cacheList << " depend exclusively on constant parameters and will be precalculated and cached" << endl ;
1848
1849 return ret ;
1850}
1851
1852
1853
1854////////////////////////////////////////////////////////////////////////////////
1855/// Find branch nodes with all-constant parameters, and add them to the list of
1856/// nodes that can be cached with a dataset in a test statistic calculation
1857
1858bool RooAbsArg::findConstantNodes(const RooArgSet& observables, RooArgSet& cacheList, RooLinkedList& processedNodes)
1859{
1860 // Caching only applies to branch nodes
1861 if (!isDerived()) {
1862 return false;
1863 }
1864
1865 // Terminate call if this node was already processed (tree structure may be cyclical)
1866 if (processedNodes.findArg(this)) {
1867 return false ;
1868 } else {
1869 processedNodes.Add(this) ;
1870 }
1871
1872 // Check if node depends on any non-constant parameter
1873 bool canOpt(true) ;
1874 RooArgSet paramSet;
1875 getParameters(&observables, paramSet);
1876 for(RooAbsArg * param : paramSet) {
1877 if (!param->isConstant()) {
1878 canOpt=false ;
1879 break ;
1880 }
1881 }
1882
1883
1884 if (getAttribute("NeverConstant")) {
1885 canOpt = false ;
1886 }
1887
1888 if (canOpt) {
1889 setAttribute("ConstantExpression") ;
1890 }
1891
1892 // If yes, list node eligible for caching, if not test nodes one level down
1893 if (canOpt||getAttribute("CacheAndTrack")) {
1894
1895 if (!cacheList.find(*this) && dependsOnValue(observables) && !observables.find(*this) ) {
1896
1897 // Add to cache list
1898 cxcoutD(Optimization) << "RooAbsArg::findConstantNodes(" << GetName() << ") adding self to list of constant nodes" << endl ;
1899
1900 if (canOpt) setAttribute("ConstantExpressionCached") ;
1901 cacheList.add(*this,false) ;
1902 }
1903 }
1904
1905 if (!canOpt) {
1906
1907 // If not, see if next level down can be cached
1908 for (const auto server : _serverList) {
1909 if (server->isDerived()) {
1910 server->findConstantNodes(observables,cacheList,processedNodes) ;
1911 }
1912 }
1913 }
1914
1915 // Forward call to all cached contained in current object
1916 for (Int_t i=0 ;i<numCaches() ; i++) {
1917 getCache(i)->findConstantNodes(observables,cacheList,processedNodes) ;
1918 }
1919
1920 return false ;
1921}
1922
1923
1924
1925
1926////////////////////////////////////////////////////////////////////////////////
1927/// Interface function signaling a request to perform constant term
1928/// optimization. This default implementation takes no action other than to
1929/// forward the calls to all servers
1930
1931void RooAbsArg::constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt)
1932{
1933 for (const auto server : _serverList) {
1934 server->constOptimizeTestStatistic(opcode,doAlsoTrackingOpt) ;
1935 }
1936}
1937
1938
1939////////////////////////////////////////////////////////////////////////////////
1940/// Change cache operation mode to given mode. If recurseAdirty
1941/// is true, then a mode change to AlwaysDirty will automatically
1942/// be propagated recursively to all client nodes
1943
1944void RooAbsArg::setOperMode(OperMode mode, bool recurseADirty)
1945{
1946 // Prevent recursion loops
1947 if (mode==_operMode) return ;
1948
1949 _operMode = mode ;
1950 _fast = ((mode==AClean) || dynamic_cast<RooRealVar*>(this) || dynamic_cast<RooConstVar*>(this) ) ;
1951 for (Int_t i=0 ;i<numCaches() ; i++) {
1952 getCache(i)->operModeHook() ;
1953 }
1954 operModeHook() ;
1955
1956 // Propagate to all clients
1957 if (mode==ADirty && recurseADirty) {
1958 for (auto clientV : _clientListValue) {
1959 clientV->setOperMode(mode) ;
1960 }
1961 }
1962}
1963
1964
1965////////////////////////////////////////////////////////////////////////////////
1966/// Print tree structure of expression tree on stdout, or to file if filename is specified.
1967/// If namePat is not "*", only nodes with names matching the pattern will be printed.
1968/// The client argument is used in recursive calls to properly display the value or shape nature
1969/// of the client-server links. It should be zero in calls initiated by users.
1970
1971void RooAbsArg::printCompactTree(const char* indent, const char* filename, const char* namePat, RooAbsArg* client)
1972{
1973 if (filename) {
1974 ofstream ofs(filename) ;
1975 printCompactTree(ofs,indent,namePat,client) ;
1976 } else {
1977 printCompactTree(cout,indent,namePat,client) ;
1978 }
1979}
1980
1981
1982////////////////////////////////////////////////////////////////////////////////
1983/// Print tree structure of expression tree on given ostream.
1984/// If namePat is not "*", only nodes with names matching the pattern will be printed.
1985/// The client argument is used in recursive calls to properly display the value or shape nature
1986/// of the client-server links. It should be zero in calls initiated by users.
1987
1988void RooAbsArg::printCompactTree(ostream& os, const char* indent, const char* namePat, RooAbsArg* client)
1989{
1990 if ( !namePat || TString(GetName()).Contains(namePat)) {
1991 os << indent << this ;
1992 if (client) {
1993 os << "/" ;
1994 if (isValueServer(*client)) os << "V" ; else os << "-" ;
1995 if (isShapeServer(*client)) os << "S" ; else os << "-" ;
1996 }
1997 os << " " ;
1998
1999 os << ClassName() << "::" << GetName() << " = " ;
2000 printValue(os) ;
2001
2002 if (!_serverList.empty()) {
2003 switch(operMode()) {
2004 case Auto: os << " [Auto," << (isValueDirty()?"Dirty":"Clean") << "] " ; break ;
2005 case AClean: os << " [ACLEAN] " ; break ;
2006 case ADirty: os << " [ADIRTY] " ; break ;
2007 }
2008 }
2009 os << endl ;
2010
2011 for (Int_t i=0 ;i<numCaches() ; i++) {
2013 }
2015 }
2016
2017 TString indent2(indent) ;
2018 indent2 += " " ;
2019 for (const auto arg : _serverList) {
2020 arg->printCompactTree(os,indent2,namePat,this) ;
2021 }
2022}
2023
2024
2025////////////////////////////////////////////////////////////////////////////////
2026/// Print tree structure of expression tree on given ostream, only branch nodes are printed.
2027/// Lead nodes (variables) will not be shown
2028///
2029/// If namePat is not "*", only nodes with names matching the pattern will be printed.
2030
2031void RooAbsArg::printComponentTree(const char* indent, const char* namePat, Int_t nLevel)
2032{
2033 if (nLevel==0) return ;
2034 if (isFundamental()) return ;
2035 auto rmodel = dynamic_cast<RooResolutionModel*>(this) ;
2036 if (rmodel && rmodel->isConvolved()) return ;
2037 if (InheritsFrom("RooConstVar")) return ;
2038
2039 if ( !namePat || TString(GetName()).Contains(namePat)) {
2040 cout << indent ;
2041 Print() ;
2042 }
2043
2044 TString indent2(indent) ;
2045 indent2 += " " ;
2046 for (const auto arg : _serverList) {
2047 arg->printComponentTree(indent2.Data(),namePat,nLevel-1) ;
2048 }
2049}
2050
2051
2052////////////////////////////////////////////////////////////////////////////////
2053/// Construct a mangled name from the actual name that
2054/// is free of any math symbols that might be interpreted by TTree
2055
2057{
2058 // Check for optional alternate name of branch for this argument
2059 TString rawBranchName = GetName() ;
2060 if (getStringAttribute("BranchName")) {
2061 rawBranchName = getStringAttribute("BranchName") ;
2062 }
2063
2064 TString cleanName(rawBranchName) ;
2065 cleanName.ReplaceAll("/","D") ;
2066 cleanName.ReplaceAll("-","M") ;
2067 cleanName.ReplaceAll("+","P") ;
2068 cleanName.ReplaceAll("*","X") ;
2069 cleanName.ReplaceAll("[","L") ;
2070 cleanName.ReplaceAll("]","R") ;
2071 cleanName.ReplaceAll("(","L") ;
2072 cleanName.ReplaceAll(")","R") ;
2073 cleanName.ReplaceAll("{","L") ;
2074 cleanName.ReplaceAll("}","R") ;
2075
2076 return cleanName;
2077}
2078
2079
2080////////////////////////////////////////////////////////////////////////////////
2081/// Hook function interface for object to insert additional information
2082/// when printed in the context of a tree structure. This default
2083/// implementation prints nothing
2084
2085void RooAbsArg::printCompactTreeHook(ostream&, const char *)
2086{
2087}
2088
2089
2090////////////////////////////////////////////////////////////////////////////////
2091/// Register RooAbsCache with this object. This function is called
2092/// by RooAbsCache constructors for objects that are a datamember
2093/// of this RooAbsArg. By registering itself the RooAbsArg is aware
2094/// of all its cache data members and will forward server change
2095/// and cache mode change calls to the cache objects, which in turn
2096/// can forward them their contents
2097
2099{
2100 _cacheList.push_back(&cache) ;
2101}
2102
2103
2104////////////////////////////////////////////////////////////////////////////////
2105/// Unregister a RooAbsCache. Called from the RooAbsCache destructor
2106
2108{
2109 _cacheList.erase(std::remove(_cacheList.begin(), _cacheList.end(), &cache),
2110 _cacheList.end());
2111}
2112
2113
2114////////////////////////////////////////////////////////////////////////////////
2115/// Return number of registered caches
2116
2118{
2119 return _cacheList.size() ;
2120}
2121
2122
2123////////////////////////////////////////////////////////////////////////////////
2124/// Return registered cache object by index
2125
2127{
2128 return _cacheList[index] ;
2129}
2130
2131
2132////////////////////////////////////////////////////////////////////////////////
2133/// Return RooArgSet with all variables (tree leaf nodes of expression tree)
2134
2136{
2137 return getParameters(RooArgSet(),stripDisconnected) ;
2138}
2139
2140
2141////////////////////////////////////////////////////////////////////////////////
2142/// Create a GraphViz .dot file visualizing the expression tree headed by
2143/// this RooAbsArg object. Use the GraphViz tool suite to make e.g. a gif
2144/// or ps file from the .dot file.
2145/// If a node derives from RooAbsReal, its current (unnormalised) value is
2146/// printed as well.
2147///
2148/// Based on concept developed by Kyle Cranmer.
2149
2150void RooAbsArg::graphVizTree(const char* fileName, const char* delimiter, bool useTitle, bool useLatex)
2151{
2152 ofstream ofs(fileName) ;
2153 if (!ofs) {
2154 coutE(InputArguments) << "RooAbsArg::graphVizTree() ERROR: Cannot open graphViz output file with name " << fileName << endl ;
2155 return ;
2156 }
2157 graphVizTree(ofs, delimiter, useTitle, useLatex) ;
2158}
2159
2160////////////////////////////////////////////////////////////////////////////////
2161/// Write the GraphViz representation of the expression tree headed by
2162/// this RooAbsArg object to the given ostream.
2163/// If a node derives from RooAbsReal, its current (unnormalised) value is
2164/// printed as well.
2165///
2166/// Based on concept developed by Kyle Cranmer.
2167
2168void RooAbsArg::graphVizTree(ostream& os, const char* delimiter, bool useTitle, bool useLatex)
2169{
2170 if (!os) {
2171 coutE(InputArguments) << "RooAbsArg::graphVizTree() ERROR: output stream provided as input argument is in invalid state" << endl ;
2172 }
2173
2174 // silent warning messages coming when evaluating a RooAddPdf without a normalization set
2176
2177 // Write header
2178 os << "digraph \"" << GetName() << "\"{" << endl ;
2179
2180 // First list all the tree nodes
2181 RooArgSet nodeSet ;
2182 treeNodeServerList(&nodeSet) ;
2183
2184 // iterate over nodes
2185 for(RooAbsArg * node : nodeSet) {
2186 string nodeName = node->GetName();
2187 string nodeTitle = node->GetTitle();
2188 string nodeLabel = (useTitle && !nodeTitle.empty()) ? nodeTitle : nodeName;
2189
2190 // if using latex, replace ROOT's # with normal latex backslash
2191 string::size_type position = nodeLabel.find('#') ;
2192 while(useLatex && position!=nodeLabel.npos){
2193 nodeLabel.replace(position, 1, "\\");
2194 }
2195
2196 string typeFormat = "\\texttt{";
2197 string nodeType = (useLatex) ? typeFormat+node->ClassName()+"}" : node->ClassName();
2198
2199 if (auto realNode = dynamic_cast<RooAbsReal*>(node)) {
2200 nodeLabel += delimiter + std::to_string(realNode->getVal());
2201 }
2202
2203 os << "\"" << nodeName << "\" [ color=" << (node->isFundamental()?"blue":"red")
2204 << ", label=\"" << nodeType << delimiter << nodeLabel << "\"];" << endl ;
2205
2206 }
2207
2208 // Get set of all server links
2209 set<pair<RooAbsArg*,RooAbsArg*> > links ;
2210 graphVizAddConnections(links) ;
2211
2212 // And write them out
2213 for(auto const& link : links) {
2214 os << "\"" << link.first->GetName() << "\" -> \"" << link.second->GetName() << "\";" << endl ;
2215 }
2216
2217 // Write trailer
2218 os << "}" << endl ;
2219
2220}
2221
2222////////////////////////////////////////////////////////////////////////////////
2223/// Utility function that inserts all point-to-point client-server connections
2224/// between any two RooAbsArgs in the expression tree headed by this object
2225/// in the linkSet argument.
2226
2227void RooAbsArg::graphVizAddConnections(set<pair<RooAbsArg*,RooAbsArg*> >& linkSet)
2228{
2229 for (const auto server : _serverList) {
2230 linkSet.insert(make_pair(this,server)) ;
2231 server->graphVizAddConnections(linkSet) ;
2232 }
2233}
2234
2235
2236////////////////////////////////////////////////////////////////////////////////
2237/// Take ownership of the contents of 'comps'.
2238
2240{
2241 if (!_ownedComponents) {
2242 _ownedComponents = new RooArgSet("owned components") ;
2243 }
2244 return _ownedComponents->addOwned(comps) ;
2245}
2246
2247
2248////////////////////////////////////////////////////////////////////////////////
2249/// Take ownership of the contents of 'comps'. Different from the overload that
2250/// taked the RooArgSet by `const&`, this version can also take an owning
2251/// RooArgSet without error, because the ownership will not be ambiguous afterwards.
2252
2254{
2255 if (!_ownedComponents) {
2256 _ownedComponents = new RooArgSet("owned components") ;
2257 }
2258 return _ownedComponents->addOwned(std::move(comps)) ;
2259}
2260
2261
2262////////////////////////////////////////////////////////////////////////////////
2263/// \copydoc RooAbsArg::addOwnedComponents(RooAbsCollection&& comps)
2264
2266 return addOwnedComponents(static_cast<RooAbsCollection&&>(std::move(comps)));
2267}
2268
2269
2270////////////////////////////////////////////////////////////////////////////////
2271/// Clone tree expression of objects. All tree nodes will be owned by
2272/// the head node return by cloneTree()
2273
2274RooAbsArg* RooAbsArg::cloneTree(const char* newname) const
2275{
2276 // In the RooHelpers, there is a more general implementation that we will reuse here
2278
2279 // Adjust name of head node if requested
2280 if (newname) {
2281 head->SetName(newname) ;
2282 }
2283
2284 // Return the head
2285 return head ;
2286}
2287
2288
2289
2290////////////////////////////////////////////////////////////////////////////////
2291
2293{
2294 if (dynamic_cast<RooTreeDataStore*>(&store)) {
2295 attachToTree((static_cast<RooTreeDataStore&>(store)).tree()) ;
2296 } else if (dynamic_cast<RooVectorDataStore*>(&store)) {
2297 attachToVStore(static_cast<RooVectorDataStore&>(store)) ;
2298 }
2299}
2300
2301
2302
2303////////////////////////////////////////////////////////////////////////////////
2304
2306{
2307 if (_eocache) {
2308 return *_eocache ;
2309 } else {
2311 }
2312}
2313
2314
2315////////////////////////////////////////////////////////////////////////////////
2316
2318{
2319 string suffix ;
2320
2321 RooArgSet branches ;
2322 branchNodeServerList(&branches) ;
2323 for(RooAbsArg * arg : branches) {
2324 const char* tmp = arg->cacheUniqueSuffix() ;
2325 if (tmp) suffix += tmp ;
2326 }
2327 return Form("%s",suffix.c_str()) ;
2328}
2329
2330
2331////////////////////////////////////////////////////////////////////////////////
2332
2334{
2335 RooArgSet branches ;
2336 branchNodeServerList(&branches) ;
2337 for(auto const& arg : branches) {
2338 for (auto const& arg2 : arg->_cacheList) {
2339 arg2->wireCache() ;
2340 }
2341 }
2342}
2343
2344
2345
2346////////////////////////////////////////////////////////////////////////////////
2347
2348void RooAbsArg::SetName(const char* name)
2349{
2351 auto newPtr = RooNameReg::instance().constPtr(GetName()) ;
2352 if (newPtr != _namePtr) {
2353 //cout << "Rename '" << _namePtr->GetName() << "' to '" << name << "' (set flag in new name)" << endl;
2354 _namePtr = newPtr;
2357 }
2358}
2359
2360
2361
2362
2363////////////////////////////////////////////////////////////////////////////////
2364
2365void RooAbsArg::SetNameTitle(const char *name, const char *title)
2366{
2367 TNamed::SetTitle(title) ;
2368 SetName(name);
2369}
2370
2371
2372////////////////////////////////////////////////////////////////////////////////
2373/// Stream an object of class RooAbsArg.
2374
2375void RooAbsArg::Streamer(TBuffer &R__b)
2376{
2377 if (R__b.IsReading()) {
2378 _ioReadStack.push(this) ;
2379 R__b.ReadClassBuffer(RooAbsArg::Class(),this);
2380 _ioReadStack.pop() ;
2382 _isConstant = getAttribute("Constant") ;
2383 } else {
2385 }
2386}
2387
2388////////////////////////////////////////////////////////////////////////////////
2389/// Method called by workspace container to finalize schema evolution issues
2390/// that cannot be handled in a single ioStreamer pass.
2391///
2392/// A second pass is typically needed when evolving data member of RooAbsArg-derived
2393/// classes that are container classes with references to other members, which may
2394/// not yet be 'live' in the first ioStreamer() evolution pass.
2395///
2396/// Classes may overload this function, but must call the base method in the
2397/// overloaded call to ensure base evolution is handled properly
2398
2400{
2401 // Handling of v5-v6 migration (TRefArray _proxyList --> RooRefArray _proxyList)
2402 auto iter = _ioEvoList.find(this);
2403 if (iter != _ioEvoList.end()) {
2404
2405 // Transfer contents of saved TRefArray to RooRefArray now
2407 _proxyList.Expand(iter->second->GetEntriesFast());
2408 for (int i = 0; i < iter->second->GetEntriesFast(); i++) {
2409 _proxyList.Add(iter->second->At(i));
2410 }
2411 // Delete TRefArray and remove from list
2412 _ioEvoList.erase(iter);
2413 }
2414}
2415
2416
2417
2418
2419////////////////////////////////////////////////////////////////////////////////
2420/// Method called by workspace container to finalize schema evolution issues
2421/// that cannot be handled in a single ioStreamer pass. This static finalize method
2422/// is called after ioStreamerPass2() is called on each directly listed object
2423/// in the workspace. It's purpose is to complete schema evolution of any
2424/// objects in the workspace that are not directly listed as content elements
2425/// (e.g. analytical convolution tokens )
2426
2428{
2429 // Handling of v5-v6 migration (TRefArray _proxyList --> RooRefArray _proxyList)
2430 for (const auto& iter : _ioEvoList) {
2431
2432 // Transfer contents of saved TRefArray to RooRefArray now
2433 if (!iter.first->_proxyList.GetEntriesFast())
2434 iter.first->_proxyList.Expand(iter.second->GetEntriesFast());
2435 for (int i = 0; i < iter.second->GetEntriesFast(); i++) {
2436 iter.first->_proxyList.Add(iter.second->At(i));
2437 }
2438 }
2439
2440 _ioEvoList.clear();
2441}
2442
2443
2446 return new RefCountListLegacyIterator_t(list.containedObjects());
2447}
2448
2449////////////////////////////////////////////////////////////////////////////////
2450/// Stream an object of class RooRefArray.
2451
2453{
2454 UInt_t R__s;
2455 UInt_t R__c;
2456 if (R__b.IsReading()) {
2457
2458 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
2459 if (R__v) {
2460 }
2461
2462 // Make temporary refArray and read that from the streamer
2463 auto refArray = std::make_unique<TRefArray>();
2464 refArray->Streamer(R__b);
2465 R__b.CheckByteCount(R__s, R__c, refArray->IsA());
2466
2467 // Schedule deferred processing of TRefArray into proxy list
2468 RooAbsArg::_ioEvoList[RooAbsArg::_ioReadStack.top()] = std::move(refArray);
2469
2470 } else {
2471
2472 R__c = R__b.WriteVersion(RooRefArray::IsA(), true);
2473
2474 // Make a temporary refArray and write that to the streamer
2475 TRefArray refArray;
2476 for (TObject *tmpObj : *this) {
2477 refArray.Add(tmpObj);
2478 }
2479
2480 refArray.Streamer(R__b);
2481 R__b.SetByteCount(R__c, true);
2482 }
2483}
2484
2485/// Print at the prompt
2486namespace cling {
2487std::string printValue(RooAbsArg *raa)
2488{
2489 std::stringstream s;
2490 if (0 == *raa->GetName() && 0 == *raa->GetTitle()) {
2491 s << "An instance of " << raa->ClassName() << ".";
2492 return s.str();
2493 }
2494 raa->printStream(s, raa->defaultPrintContents(""), raa->defaultPrintStyle(""));
2495 return s.str();
2496}
2497} // namespace cling
2498
2499
2500/// Disables or enables the usage of squared weights. Needs to be overloaded in
2501/// the likelihood classes for which this is relevant.
2503 for(auto * server : servers()) {
2504 server->applyWeightSquared(flag);
2505 }
2506}
2507
2508
2509std::unique_ptr<RooAbsArg> RooAbsArg::compileForNormSet(RooArgSet const & normSet, RooFit::Detail::CompileContext & ctx) const
2510{
2511 auto newArg = std::unique_ptr<RooAbsArg>{static_cast<RooAbsArg *>(Clone())};
2512 ctx.markAsCompiled(*newArg);
2513 ctx.compileServers(*newArg, normSet);
2514 return newArg;
2515}
2516
2517
2518/// Sets the token for retrieving results in the BatchMode. For internal use only.
2520{
2521 if (_dataToken == index) {
2522 return;
2523 }
2524 if (_dataToken != std::numeric_limits<std::size_t>::max()) {
2525 std::stringstream errMsg;
2526 errMsg << "The data token for \"" << GetName() << "\" is already set!"
2527 << " Are you trying to evaluate the same object by multiple RooFit::Evaluator instances?"
2528 << " This is not allowed.";
2529 throw std::runtime_error(errMsg.str());
2530 }
2531 _dataToken = index;
2532}
istream & operator>>(istream &is, RooAbsArg &arg)
Istream operator.
static Roo_reg_AGKInteg1D instance
#define coutI(a)
#define cxcoutI(a)
#define cxcoutD(a)
#define oocxcoutD(o, a)
#define coutW(a)
#define coutF(a)
#define coutE(a)
#define cxcoutF(a)
char Text_t
Definition RtypesCore.h:62
short Version_t
Definition RtypesCore.h:65
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:397
static void indent(ostringstream &buf, int indent_level)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
RooExpensiveObjectCache & expensiveObjectCache() const
bool overlaps(const RooAbsArg &testArg, bool valueOnly=false) const
Test if any of the nodes of tree are shared with that of the given tree.
RooRefArray _proxyList
Definition RooAbsArg.h:578
void replaceServer(RooAbsArg &oldServer, RooAbsArg &newServer, bool valueProp, bool shapeProp)
Replace 'oldServer' with 'newServer', specifying whether the new server has value or shape server pro...
bool _isConstant
De-duplicated name pointer. This will be equal for all objects with the same name.
Definition RooAbsArg.h:666
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
Definition RooAbsArg.h:263
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
void attachToStore(RooAbsDataStore &store)
Attach this argument to the data store such that it reads data from there.
bool recursiveRedirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool recurseInNewSet=true)
Recursively replace all servers with the new servers in newSet.
const TNamed * namePtr() const
De-duplicated pointer to this object's name.
Definition RooAbsArg.h:504
const char * aggregateCacheUniqueSuffix() const
void printArgs(std::ostream &os) const override
Print object arguments, ie its proxies.
void printClassName(std::ostream &os) const override
Print object class name.
ProxyListCache _proxyListCache
Definition RooAbsArg.h:631
RooWorkspace * _myws
Prevent 'AlwaysDirty' mode for this node.
Definition RooAbsArg.h:673
~RooAbsArg() override
Destructor.
void attachDataStore(const RooAbsDataStore &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
RooArgSet * _ownedComponents
Definition RooAbsArg.h:659
void printAddress(std::ostream &os) const override
Print address of this RooAbsArg.
void setShapeDirty()
Notify that a shape-like property (e.g. binning) has changed.
Definition RooAbsArg.h:436
void setDataToken(std::size_t index)
Sets the token for retrieving results in the BatchMode. For internal use only.
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
void setOperMode(OperMode mode, bool recurseADirty=true)
Set the operation mode of this node.
bool callRedirectServersHook(RooAbsCollection const &newSet, bool mustReplaceAll, bool nameChange, bool isRecursionStep)
Private helper function for RooAbsArg::redirectServers().
void attachArgs(const RooAbsCollection &set)
Bind this node to objects in set.
void setStringAttribute(const Text_t *key, const Text_t *value)
Associate string 'value' to this object under key 'key'.
bool isShapeServer(const RooAbsArg &arg) const
Check if this is serving shape to arg.
Definition RooAbsArg.h:174
bool isShapeDirty() const
Definition RooAbsArg.h:357
static void ioStreamerPass2Finalize()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
bool _fast
Definition RooAbsArg.h:656
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
void addParameters(RooAbsCollection &params, const RooArgSet *nset=nullptr, bool stripDisconnected=true) const
Add all parameters of the function and its daughters to params.
void removeServer(RooAbsArg &server, bool force=false)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
RooFit::OwningPtr< RooArgSet > getObservables(const RooArgSet &set, bool valueOnly=true) const
Given a set of possible observables, return the observables that this PDF depends on.
void setTransientAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void graphVizAddConnections(std::set< std::pair< RooAbsArg *, RooAbsArg * > > &)
Utility function that inserts all point-to-point client-server connections between any two RooAbsArgs...
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
bool _shapeDirty
Definition RooAbsArg.h:653
void SetName(const char *name) override
Set the name of the TNamed.
std::set< std::string > _boolAttrib
Definition RooAbsArg.h:598
void unRegisterCache(RooAbsCache &cache)
Unregister a RooAbsCache. Called from the RooAbsCache destructor.
RefCountList_t _clientListValue
Definition RooAbsArg.h:576
bool addOwnedComponents(const RooAbsCollection &comps)
Take ownership of the contents of 'comps'.
void printAttribList(std::ostream &os) const
Transient boolean attributes (not copied in ctor)
void printTree(std::ostream &os, TString indent="") const override
Print object tree structure.
void SetNameTitle(const char *name, const char *title) override
Set all the TNamed parameters (name and title).
friend void RooRefArray::Streamer(TBuffer &)
const Text_t * getStringAttribute(const Text_t *key) const
Get string attribute mapped under key 'key'.
bool findConstantNodes(const RooArgSet &observables, RooArgSet &cacheList)
Find branch nodes with all-constant parameters, and add them to the list of nodes that can be cached ...
static bool _verboseDirty
cache of the list of proxies. Avoids type casting.
Definition RooAbsArg.h:634
void addServerList(RooAbsCollection &serverList, bool valueProp=true, bool shapeProp=false)
Register a list of RooAbsArg as servers to us by calling addServer() for each arg in the list.
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)=0
bool redirectServers(const RooAbsCollection &newServerList, bool mustReplaceAll=false, bool nameChange=false, bool isRecursionStep=false)
Replace all direct servers of this object with the new servers in newServerList.
static void setDirtyInhibit(bool flag)
Control global dirty inhibit mode.
virtual void printCompactTreeHook(std::ostream &os, const char *ind="")
Hook function interface for object to insert additional information when printed in the context of a ...
const TNamed * _namePtr
Pointer to global cache manager for any expensive components created by this object.
Definition RooAbsArg.h:665
void printCompactTree(const char *indent="", const char *fileName=nullptr, const char *namePat=nullptr, RooAbsArg *client=nullptr)
Print tree structure of expression tree on stdout, or to file if filename is specified.
virtual std::unique_ptr< RooAbsArg > compileForNormSet(RooArgSet const &normSet, RooFit::Detail::CompileContext &ctx) const
virtual void getParametersHook(const RooArgSet *, RooArgSet *, bool) const
Definition RooAbsArg.h:535
virtual void ioStreamerPass2()
Method called by workspace container to finalize schema evolution issues that cannot be handled in a ...
RooFit::OwningPtr< RooArgSet > getComponents() const
Create a RooArgSet with all components (branch nodes) of the expression tree headed by this object.
void wireAllCaches()
bool _valueDirty
Definition RooAbsArg.h:652
bool _prohibitServerRedirect
Set of owned component.
Definition RooAbsArg.h:661
virtual const char * cacheUniqueSuffix() const
Definition RooAbsArg.h:439
RefCountListLegacyIterator_t * makeLegacyIterator(const RefCountList_t &list) const
const RefCountList_t & servers() const
List of all servers of this object.
Definition RooAbsArg.h:149
std::size_t _dataToken
In which workspace do I live, if any.
Definition RooAbsArg.h:675
bool dependsOnValue(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr) const
Check whether this object depends on values from an element in the serverList.
Definition RooAbsArg.h:106
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
void removeStringAttribute(const Text_t *key)
Delete a string attribute with a given key.
Int_t Compare(const TObject *other) const override
Utility function used by TCollection::Sort to compare contained TObjects We implement comparison by n...
Int_t defaultPrintContents(Option_t *opt) const override
Define default contents to print.
virtual bool isDerived() const
Does value or shape of this arg depend on any other arg?
Definition RooAbsArg.h:97
virtual void attachToTree(TTree &t, Int_t bufSize=32000)=0
Overloadable function for derived classes to implement attachment as branch to a TTree.
void printComponentTree(const char *indent="", const char *namePat=nullptr, Int_t nLevel=999)
Print tree structure of expression tree on given ostream, only branch nodes are printed.
OperMode _operMode
Definition RooAbsArg.h:655
virtual void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true)
Interface function signaling a request to perform constant term optimization.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
Definition RooAbsArg.h:431
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
static void verboseDirty(bool flag)
Activate verbose messaging related to dirty flag propagation.
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
RooAbsCache * getCache(Int_t index) const
Return registered cache object by index.
virtual void writeToStream(std::ostream &os, bool compact) const =0
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Implement multi-line detailed printing.
virtual RooAbsArg * cloneTree(const char *newname=nullptr) const
Clone tree expression of objects.
void registerCache(RooAbsCache &cache)
Register RooAbsCache with this object.
virtual void optimizeCacheMode(const RooArgSet &observables)
Activate cache mode optimization with given definition of observables.
RefCountList_t _clientListShape
Definition RooAbsArg.h:575
virtual void attachToVStore(RooVectorDataStore &vstore)=0
TString cleanBranchName() const
Construct a mangled name from the actual name that is free of any math symbols that might be interpre...
bool inhibitDirty() const
Delete watch flag.
bool observableOverlaps(const RooAbsData *dset, const RooAbsArg &testArg) const
Test if any of the dependents of the arg tree (as determined by getObservables) overlaps with those o...
void changeServer(RooAbsArg &server, bool valueProp, bool shapeProp)
Change dirty flag propagation mask for specified server.
Int_t numProxies() const
Return the number of registered proxies.
void printName(std::ostream &os) const override
Print object name.
bool isValueDirty() const
Definition RooAbsArg.h:362
bool _localNoInhibitDirty
Cached isConstant status.
Definition RooAbsArg.h:668
virtual void printMetaArgs(std::ostream &) const
Definition RooAbsArg.h:273
virtual void applyWeightSquared(bool flag)
Disables or enables the usage of squared weights.
static bool _inhibitDirty
Definition RooAbsArg.h:635
void setAttribute(const Text_t *name, bool value=true)
Set (default) or clear a named boolean attribute of this object.
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
void branchNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all branch nodes of the arg tree starting with ourself as top node.
RefCountList_t _clientList
Definition RooAbsArg.h:574
void printDirty(bool depth=true) const
Print information about current value dirty state information.
RooAbsProxy * getProxy(Int_t index) const
Return the nth proxy from the proxy list.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:89
RefCountList_t _serverList
Definition RooAbsArg.h:573
void leafNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool recurseNonDerived=false) const
Fill supplied list with all leaf nodes of the arg tree, starting with ourself as top node.
RooExpensiveObjectCache * _eocache
Prohibit server redirects – Debugging tool.
Definition RooAbsArg.h:663
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:192
virtual bool isValid() const
WVE (08/21/01) Probably obsolete now.
std::set< std::string > _boolAttribTransient
Definition RooAbsArg.h:600
void printTitle(std::ostream &os) const override
Print object title.
virtual bool redirectServersHook(const RooAbsCollection &newServerList, bool mustReplaceAll, bool nameChange, bool isRecursiveStep)
Function that is called at the end of redirectServers().
std::size_t getParametersSizeEstimate(const RooArgSet *nset=nullptr) const
Obtain an estimate of the number of parameters of the function and its daughters.
void graphVizTree(const char *fileName, const char *delimiter="\n", bool useTitle=false, bool useLatex=false)
Create a GraphViz .dot file visualizing the expression tree headed by this RooAbsArg object.
void substituteServer(RooAbsArg *oldServer, RooAbsArg *newServer)
Set by the RooFitDriver for this arg to retrieve its result in the run context.
bool getTransientAttribute(const Text_t *name) const
Check if a named attribute is set.
virtual void operModeHook()
Definition RooAbsArg.h:529
bool recursiveCheckObservables(const RooArgSet *nset) const
Recursively call checkObservables on all nodes in the expression tree.
bool isValueServer(const RooAbsArg &arg) const
Check if this is serving values to arg.
Definition RooAbsArg.h:166
std::map< std::string, std::string > _stringAttrib
Definition RooAbsArg.h:599
Int_t numCaches() const
Return number of registered caches.
virtual bool checkObservables(const RooArgSet *nset) const
Overloadable function in which derived classes can implement consistency checks of the variables.
RooAbsArg()
Default constructor.
void attachDataSet(const RooAbsData &set)
Replace server nodes with names matching the dataset variable names with those data set variables,...
TIteratorToSTLInterface< RefCountList_t::Container_t > RefCountListLegacyIterator_t
Definition RooAbsArg.h:80
std::vector< RooAbsCache * > _cacheList
Definition RooAbsArg.h:580
void treeNodeServerList(RooAbsCollection *list, const RooAbsArg *arg=nullptr, bool doBranch=true, bool doLeaf=true, bool valueOnly=false, bool recurseNonDerived=false) const
Fill supplied list with nodes of the arg tree, following all server links, starting with ourself as t...
RooAbsArg * findNewServer(const RooAbsCollection &newSet, bool nameChange) const
Find the new server in the specified set that matches the old server.
OperMode operMode() const
Query the operation mode of this node.
Definition RooAbsArg.h:425
Abstract base class for data members of RooAbsArgs that cache other (composite) RooAbsArg expressions...
Definition RooAbsCache.h:27
virtual void operModeHook()
Interface for operation mode changes.
Definition RooAbsCache.h:46
virtual void findConstantNodes(const RooArgSet &, RooArgSet &, RooLinkedList &)
Interface for constant term node finding calls.
Definition RooAbsCache.h:52
virtual void printCompactTreeHook(std::ostream &, const char *)
Interface for printing of cache guts in tree mode printing.
Definition RooAbsCache.h:55
virtual bool redirectServersHook(const RooAbsCollection &, bool, bool, bool)
Interface for server redirect calls.
Definition RooAbsCache.h:40
virtual void optimizeCacheMode(const RooArgSet &, RooArgSet &, RooLinkedList &)
Interface for processing of cache mode optimization calls.
Definition RooAbsCache.h:49
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
Storage_t const & get() const
Const access to the underlying stl container.
const char * GetName() const override
Returns name of object.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
void reserve(Storage_t::size_type count)
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
void sort(bool reverse=false)
Sort collection using std::sort and name comparison.
void setName(const char *name)
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for a data collection.
virtual const RooArgSet * get(Int_t index) const =0
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
virtual const RooArgSet * get() const
Definition RooAbsData.h:101
Abstract interface for proxy classes.
Definition RooAbsProxy.h:37
virtual const char * name() const
Definition RooAbsProxy.h:47
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:59
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
Abstract interface for RooAbsArg proxy classes.
Definition RooArgProxy.h:24
bool isShapeServer() const
Returns true if contents is shape server of owner.
Definition RooArgProxy.h:64
RooAbsArg * absArg() const
Return pointer to contained argument.
Definition RooArgProxy.h:46
bool isValueServer() const
Returns true of contents is value server of owner.
Definition RooArgProxy.h:60
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Represents a constant real-valued object.
Definition RooConstVar.h:23
Singleton class that serves as repository for objects that are expensive to calculate.
static RooExpensiveObjectCache & instance()
Return reference to singleton instance.
void markAsCompiled(RooAbsArg &arg) const
void compileServers(RooAbsArg &arg, RooArgSet const &normSet)
Switches the message service to a different level while the instance is alive.
Definition RooHelpers.h:37
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
RooAbsArg * findArg(const RooAbsArg *) const
Return pointer to object with given name in collection.
virtual void Add(TObject *arg)
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
Registry for const char* names.
Definition RooNameReg.h:26
@ kRenamedArg
TNamed flag to indicate that some RooAbsArg has been renamed (flag set in new name)
Definition RooNameReg.h:46
const TNamed * constPtr(const char *stringPtr)
Return a unique TNamed pointer for given C++ string.
static RooNameReg & instance()
Return reference to singleton instance.
static void incrementRenameCounter()
The renaming counter has to be incremented every time a RooAbsArg is renamed.
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
virtual void printValue(std::ostream &os) const
Interface to print value of object.
Performs hybrid numerical/analytical integrals of RooAbsReal objects.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
TClass * IsA() const override
Definition RooAbsArg.h:68
void Streamer(TBuffer &) override
Stream an object of class RooRefArray.
RooResolutionModel is the base class for PDFs that represent a resolution model that can be convolute...
TTree-backed data storage.
Uses std::vector to store data columns.
const RooArgSet * set(RooStringView name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
bool defineSetInternal(const char *name, const RooArgSet &aset)
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
Bool_t IsReading() const
Definition TBuffer.h:86
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TIterator and GenericRooFIter front end with STL back end.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fName
Definition TNamed.h:32
static TClass * Class()
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
Int_t GetEntriesFast() const
Definition TObjArray.h:58
virtual void Expand(Int_t newSize)
Expand or shrink the array to newSize elements.
virtual void Compress()
Remove empty slots from array.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
TObject * Remove(TObject *obj) override
Remove object from array.
TObject * FindObject(const char *name) const override
Find an object in this collection using its name.
void Add(TObject *obj) override
Definition TObjArray.h:68
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:225
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
An array of references to TObjects.
Definition TRefArray.h:33
void Add(TObject *obj) override
Definition TRefArray.h:74
void Streamer(TBuffer &) override
Stream all objects in the array to or from the I/O buffer.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:704
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:623
TString & Append(const char *cs)
Definition TString.h:572
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
A TTree represents a columnar dataset.
Definition TTree.h:79
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
Definition Config.h:35
RooAbsArg * cloneTreeWithSameParametersImpl(RooAbsArg const &arg, RooArgSet const *observables)
std::string getColonSeparatedNameString(RooArgSet const &argSet, char delim=':')
std::vector< RooAbsProxy * > cache
Definition RooAbsArg.h:628