// RooAbsArg is the common abstract base class for objects that
// represent a value (of arbitrary type) and "shape" that in general
// depends on (is a client of) other RooAbsArg subclasses. The only
// state information about a value that is maintained in this base
// class consists of named attributes and flags that track when either
// the value or the shape of this object changes. The meaning of shape
// depends on the client implementation but could be, for example, the
// allowed range of a value. The base class is also responsible for
// managing client/server links and propagating value/shape changes
// through an expression tree. RooAbsArg implements public interfaces
// for inspecting client/server relationships and
// setting/clearing/testing named attributes.
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "TClass.h"
#include "TObjString.h"
#include "RooMsgService.h"
#include "RooAbsArg.h"
#include "RooArgSet.h"
#include "RooArgProxy.h"
#include "RooSetProxy.h"
#include "RooListProxy.h"
#include "RooAbsData.h"
#include "RooAbsCategoryLValue.h"
#include "RooAbsRealLValue.h"
#include "RooTrace.h"
#include "RooStringVar.h"
#include "RooRealIntegral.h"
#include "RooMsgService.h"
#include "RooExpensiveObjectCache.h"
#include <string.h>
#include <iomanip>
#include <fstream>
#include <algorithm>
using namespace std ;
#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
char* operator+( streampos&, char* );
#endif
ClassImp(RooAbsArg)
;
Bool_t RooAbsArg::_verboseDirty(kFALSE) ;
Bool_t RooAbsArg::_inhibitDirty(kFALSE) ;
Bool_t RooAbsArg::_flipAClean(kFALSE) ;
RooAbsArg::RooAbsArg() :
TNamed(),
_deleteWatch(kFALSE),
_operMode(Auto),
_ownedComponents(0),
_prohibitServerRedirect(kFALSE),
_eocache(0)
{
_clientShapeIter = _clientListShape.MakeIterator() ;
_clientValueIter = _clientListValue.MakeIterator() ;
RooTrace::create(this) ;
}
RooAbsArg::RooAbsArg(const char *name, const char *title) :
TNamed(name,title),
_deleteWatch(kFALSE),
_valueDirty(kTRUE),
_shapeDirty(kTRUE),
_operMode(Auto),
_ownedComponents(0),
_prohibitServerRedirect(kFALSE),
_eocache(0)
{
_clientShapeIter = _clientListShape.MakeIterator() ;
_clientValueIter = _clientListValue.MakeIterator() ;
RooTrace::create(this) ;
}
RooAbsArg::RooAbsArg(const RooAbsArg& other, const char* name)
: TNamed(other.GetName(),other.GetTitle()),
RooPrintable(other),
_boolAttrib(other._boolAttrib),
_stringAttrib(other._stringAttrib),
_deleteWatch(other._deleteWatch),
_operMode(Auto),
_ownedComponents(0),
_prohibitServerRedirect(kFALSE),
_eocache(other._eocache)
{
if (name) SetName(name) ;
TIterator* sIter = other._serverList.MakeIterator() ;
RooAbsArg* server ;
Bool_t valueProp, shapeProp ;
while ((server = (RooAbsArg*) sIter->Next())) {
valueProp = server->_clientListValue.FindObject((TObject*)&other)?kTRUE:kFALSE ;
shapeProp = server->_clientListShape.FindObject((TObject*)&other)?kTRUE:kFALSE ;
addServer(*server,valueProp,shapeProp) ;
}
delete sIter ;
_clientShapeIter = _clientListShape.MakeIterator() ;
_clientValueIter = _clientListValue.MakeIterator() ;
setValueDirty() ;
setShapeDirty() ;
setAttribute(Form("CloneOf(%08x)",&other)) ;
RooTrace::create(this) ;
}
RooAbsArg::~RooAbsArg()
{
TIterator* serverIter = _serverList.MakeIterator() ;
RooAbsArg* server ;
while ((server=(RooAbsArg*)serverIter->Next())) {
removeServer(*server,kTRUE) ;
}
delete serverIter ;
TIterator* clientIter = _clientList.MakeIterator() ;
RooAbsArg* client = 0;
Bool_t first(kTRUE) ;
while ((client=(RooAbsArg*)clientIter->Next())) {
client->setAttribute("ServerDied") ;
TString attr("ServerDied:");
attr.Append(GetName());
attr.Append(Form("(%lx)",this)) ;
client->setAttribute(attr.Data());
client->removeServer(*this,kTRUE);
if (_verboseDirty) {
if (first) {
cxcoutD(Tracing) << "RooAbsArg::dtor(" << GetName() << "," << this << ") DeleteWatch: object is being destroyed" << endl ;
first = kFALSE ;
}
cxcoutD(Tracing) << fName << "::" << ClassName() << ":~RooAbsArg: dependent \""
<< client->GetName() << "\" should have been deleted first" << endl ;
}
}
delete clientIter ;
delete _clientShapeIter ;
delete _clientValueIter ;
if (_ownedComponents) {
delete _ownedComponents ;
_ownedComponents = 0 ;
}
RooTrace::destroy(this) ;
}
void RooAbsArg::setDirtyInhibit(Bool_t flag)
{
_inhibitDirty = flag ;
}
void RooAbsArg::setACleanADirty(Bool_t flag)
{
_flipAClean = flag ;
}
void RooAbsArg::verboseDirty(Bool_t flag)
{
_verboseDirty = flag ;
}
Bool_t RooAbsArg::isCloneOf(const RooAbsArg& other) const
{
return (getAttribute(Form("CloneOf(%08x)",&other)) ||
other.getAttribute(Form("CloneOf(%08x)",this))) ;
}
void RooAbsArg::setAttribute(const Text_t* name, Bool_t value)
{
if (value) {
_boolAttrib.insert(name) ;
} else {
set<string>::iterator iter = _boolAttrib.find(name) ;
if (iter != _boolAttrib.end()) {
_boolAttrib.erase(iter) ;
}
}
}
Bool_t RooAbsArg::getAttribute(const Text_t* name) const
{
return (_boolAttrib.find(name) != _boolAttrib.end()) ;
}
void RooAbsArg::setStringAttribute(const Text_t* key, const Text_t* value)
{
if (value) {
_stringAttrib[key] = value ;
} else {
if (_stringAttrib.find(key)!=_stringAttrib.end()) {
_stringAttrib.erase(key) ;
}
}
}
const Text_t* RooAbsArg::getStringAttribute(const Text_t* key) const
{
map<string,string>::const_iterator iter = _stringAttrib.find(key) ;
if (iter!=_stringAttrib.end()) {
return iter->second.c_str() ;
} else {
return 0 ;
}
}
void RooAbsArg::setTransientAttribute(const Text_t* name, Bool_t value)
{
if (value) {
_boolAttribTransient.insert(name) ;
} else {
set<string>::iterator iter = _boolAttribTransient.find(name) ;
if (iter != _boolAttribTransient.end()) {
_boolAttribTransient.erase(iter) ;
}
}
}
Bool_t RooAbsArg::getTransientAttribute(const Text_t* name) const
{
return (_boolAttribTransient.find(name) != _boolAttribTransient.end()) ;
}
void RooAbsArg::addServer(RooAbsArg& server, Bool_t valueProp, Bool_t shapeProp)
{
if (_prohibitServerRedirect) {
cxcoutF(LinkStateMgmt) << "RooAbsArg::addServer(" << this << "," << GetName()
<< "): PROHIBITED SERVER ADDITION REQUESTED: adding server " << server.GetName()
<< "(" << &server << ") for " << (valueProp?"value ":"") << (shapeProp?"shape":"") << endl ;
assert(0) ;
}
cxcoutD(LinkStateMgmt) << "RooAbsArg::addServer(" << this << "," << GetName() << "): adding server " << server.GetName()
<< "(" << &server << ") for " << (valueProp?"value ":"") << (shapeProp?"shape":"") << endl ;
_serverList.Add(&server) ;
server._clientList.Add(this) ;
if (valueProp) server._clientListValue.Add(this) ;
if (shapeProp) server._clientListShape.Add(this) ;
}
void RooAbsArg::addServerList(RooAbsCollection& serverList, Bool_t valueProp, Bool_t shapeProp)
{
RooAbsArg* arg ;
TIterator* iter = serverList.createIterator() ;
while ((arg=(RooAbsArg*)iter->Next())) {
addServer(*arg,valueProp,shapeProp) ;
}
delete iter ;
}
void RooAbsArg::removeServer(RooAbsArg& server, Bool_t force)
{
if (_prohibitServerRedirect) {
cxcoutF(LinkStateMgmt) << "RooAbsArg::addServer(" << this << "," << GetName() << "): PROHIBITED SERVER REMOVAL REQUESTED: removing server "
<< server.GetName() << "(" << &server << ")" << endl ;
assert(0) ;
}
if (_verboseDirty) {
cxcoutD(LinkStateMgmt) << "RooAbsArg::removeServer(" << GetName() << "): removing server "
<< server.GetName() << "(" << &server << ")" << endl ;
}
if (!force) {
_serverList.Remove(&server) ;
server._clientList.Remove(this) ;
server._clientListValue.Remove(this) ;
server._clientListShape.Remove(this) ;
} else {
_serverList.RemoveAll(&server) ;
server._clientList.RemoveAll(this) ;
server._clientListValue.RemoveAll(this) ;
server._clientListShape.RemoveAll(this) ;
}
}
void RooAbsArg::replaceServer(RooAbsArg& oldServer, RooAbsArg& newServer, Bool_t propValue, Bool_t propShape)
{
Int_t count = _serverList.refCount(&oldServer) ;
removeServer(oldServer,kTRUE) ;
while(count--) {
addServer(newServer,propValue,propShape) ;
}
}
void RooAbsArg::changeServer(RooAbsArg& server, Bool_t valueProp, Bool_t shapeProp)
{
if (!_serverList.FindObject(&server)) {
coutE(LinkStateMgmt) << "RooAbsArg::changeServer(" << GetName() << "): Server "
<< server.GetName() << " not registered" << endl ;
return ;
}
if (!server._clientList.FindObject(this)) {
coutE(LinkStateMgmt) << "RooAbsArg::changeServer(" << GetName() << "): Server "
<< server.GetName() << " doesn't have us registered as client" << endl ;
return ;
}
Int_t vcount = server._clientListValue.refCount(this) ;
Int_t scount = server._clientListShape.refCount(this) ;
server._clientListValue.RemoveAll(this) ;
server._clientListShape.RemoveAll(this) ;
if (valueProp) {
while (vcount--) server._clientListValue.Add(this) ;
}
if (shapeProp) {
while(scount--) server._clientListShape.Add(this) ;
}
}
void RooAbsArg::leafNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, Bool_t recurseNonDerived) const
{
treeNodeServerList(list,arg,kFALSE,kTRUE,kFALSE,recurseNonDerived) ;
}
void RooAbsArg::branchNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, Bool_t recurseNonDerived) const
{
treeNodeServerList(list,arg,kTRUE,kFALSE,kFALSE,recurseNonDerived) ;
}
void RooAbsArg::treeNodeServerList(RooAbsCollection* list, const RooAbsArg* arg, Bool_t doBranch, Bool_t doLeaf, Bool_t valueOnly, Bool_t recurseFundamental) const
{
if (!arg) {
if (list->getHashTableSize()==0) {
list->setHashTableSize(1000) ;
}
arg=this ;
}
if ((doBranch&&doLeaf) ||
(doBranch&&arg->isDerived()) ||
(doLeaf&&arg->isFundamental()&&(!(recurseFundamental&&arg->isDerived()))) ) {
list->add(*arg,kTRUE) ;
}
if (arg->isDerived() && (!arg->isFundamental() || recurseFundamental)) {
RooAbsArg* server ;
TIterator* sIter = arg->serverIterator() ;
while ((server=(RooAbsArg*)sIter->Next())) {
Bool_t isValueSrv = server->_clientListValue.FindObject((TObject*)arg)?kTRUE:kFALSE ;
if (valueOnly && !isValueSrv) {
continue ;
}
treeNodeServerList(list,server,doBranch,doLeaf,valueOnly,recurseFundamental) ;
}
delete sIter ;
}
}
RooArgSet* RooAbsArg::getParameters(const RooAbsData* set) const
{
return getParameters(set?set->get():0) ;
}
RooArgSet* RooAbsArg::getParameters(const RooArgSet* nset) const
{
RooArgSet parList("parameters") ;
RooArgSet leafList("leafNodeServerList") ;
treeNodeServerList(&leafList,0,kFALSE,kTRUE,kTRUE) ;
TIterator* sIter = leafList.createIterator() ;
RooAbsArg* arg ;
while ((arg=(RooAbsArg*)sIter->Next())) {
if ((!nset || !arg->dependsOn(*nset)) && arg->isLValue()) {
parList.add(*arg) ;
}
}
delete sIter ;
RooArgSet branchList ;
branchNodeServerList(&branchList) ;
RooAbsArg* branch ;
TIterator* bIter = branchList.createIterator() ;
while((branch=(RooAbsArg*)bIter->Next())) {
branch->getParametersHook(nset, &parList) ;
}
delete bIter ;
RooArgList tmp(parList) ;
tmp.sort() ;
return new RooArgSet(tmp) ;
}
RooArgSet* RooAbsArg::getObservables(const RooAbsData* set) const
{
if (!set) return new RooArgSet ;
return getObservables(set->get()) ;
}
RooArgSet* RooAbsArg::getObservables(const RooArgSet* dataList) const
{
RooArgSet* depList = new RooArgSet("dependents") ;
if (!dataList) return depList ;
RooArgSet leafList("leafNodeServerList") ;
treeNodeServerList(&leafList,0,kFALSE,kTRUE,kTRUE) ;
TIterator *sIter = leafList.createIterator() ;
RooAbsArg* arg ;
while ((arg=(RooAbsArg*)sIter->Next())) {
if (arg->dependsOnValue(*dataList) && arg->isLValue()) {
depList->add(*arg) ;
}
}
delete sIter ;
RooArgSet branchList ;
branchNodeServerList(&branchList) ;
RooAbsArg* branch ;
TIterator* bIter = branchList.createIterator() ;
while((branch=(RooAbsArg*)bIter->Next())) {
branch->getObservablesHook(dataList, depList) ;
}
delete bIter ;
return depList ;
}
RooArgSet* RooAbsArg::getComponents() const
{
TString name(GetName()) ;
name.Append("_components") ;
RooArgSet* set = new RooArgSet(name) ;
branchNodeServerList(set) ;
return set ;
}
Bool_t RooAbsArg::checkObservables(const RooArgSet*) const
{
return kFALSE ;
}
Bool_t RooAbsArg::recursiveCheckObservables(const RooArgSet* nset) const
{
RooArgSet nodeList ;
treeNodeServerList(&nodeList) ;
TIterator* iter = nodeList.createIterator() ;
RooAbsArg* arg ;
Bool_t ret(kFALSE) ;
while((arg=(RooAbsArg*)iter->Next())) {
if (arg->getAttribute("ServerDied")) {
coutE(LinkStateMgmt) << "RooAbsArg::recursiveCheckObservables(" << GetName() << "): ERROR: one or more servers of node "
<< arg->GetName() << " no longer exists!" << endl ;
arg->Print("v") ;
ret = kTRUE ;
}
ret |= arg->checkObservables(nset) ;
}
delete iter ;
return ret ;
}
Bool_t RooAbsArg::dependsOn(const RooAbsCollection& serverList, const RooAbsArg* ignoreArg, Bool_t valueOnly) const
{
Bool_t result(kFALSE);
TIterator* sIter = serverList.createIterator();
RooAbsArg* server ;
while ((!result && (server=(RooAbsArg*)sIter->Next()))) {
if (dependsOn(*server,ignoreArg,valueOnly)) {
result= kTRUE;
}
}
delete sIter;
return result;
}
Bool_t RooAbsArg::dependsOn(const RooAbsArg& testArg, const RooAbsArg* ignoreArg, Bool_t valueOnly) const
{
if (this==ignoreArg) return kFALSE ;
if (!TString(testArg.GetName()).CompareTo(GetName())) return kTRUE ;
RooAbsArg* server = findServer(testArg.GetName()) ;
if (server!=0) {
if ( !valueOnly || server->isValueServer(GetName())) {
return kTRUE ;
}
}
TIterator* sIter = serverIterator() ;
while ((server=(RooAbsArg*)sIter->Next())) {
if ( !valueOnly || server->isValueServer(GetName())) {
if (server->dependsOn(testArg,ignoreArg,valueOnly)) {
delete sIter ;
return kTRUE ;
}
}
}
delete sIter ;
return kFALSE ;
}
Bool_t RooAbsArg::overlaps(const RooAbsArg& testArg) const
{
RooArgSet list("treeNodeList") ;
treeNodeServerList(&list) ;
return testArg.dependsOn(list) ;
}
Bool_t RooAbsArg::observableOverlaps(const RooAbsData* dset, const RooAbsArg& testArg) const
{
return observableOverlaps(dset->get(),testArg) ;
}
Bool_t RooAbsArg::observableOverlaps(const RooArgSet* nset, const RooAbsArg& testArg) const
{
RooArgSet* depList = getObservables(nset) ;
Bool_t ret = testArg.dependsOn(*depList) ;
delete depList ;
return ret ;
}
void RooAbsArg::setValueDirty(const RooAbsArg* source) const
{
if (_operMode!=Auto || _inhibitDirty) return ;
if (_clientListValue.GetSize()==0) {
_valueDirty = kTRUE ;
return ;
}
if (source==0) {
source=this ;
} else if (source==this) {
coutE(LinkStateMgmt) << "RooAbsArg::setValueDirty(" << GetName()
<< "): cyclical dependency detected" << endl ;
return ;
}
if (_verboseDirty) {
cxcoutD(LinkStateMgmt) << "RooAbsArg::setValueDirty(" << (source?source->GetName():"self") << "->" << GetName() << "," << this
<< "): dirty flag " << (_valueDirty?"already ":"") << "raised" << endl ;
}
_valueDirty = kTRUE ;
_clientValueIter->Reset() ;
RooAbsArg* client ;
while ((client=(RooAbsArg*)_clientValueIter->Next())) {
client->setValueDirty(source) ;
}
}
void RooAbsArg::setShapeDirty(const RooAbsArg* source) const
{
if (_verboseDirty) {
cxcoutD(LinkStateMgmt) << "RooAbsArg::setShapeDirty(" << GetName()
<< "): dirty flag " << (_shapeDirty?"already ":"") << "raised" << endl ;
}
if (_clientListShape.GetSize()==0) {
_shapeDirty = kTRUE ;
return ;
}
if (source==0) {
source=this ;
} else if (source==this) {
coutE(LinkStateMgmt) << "RooAbsArg::setShapeDirty(" << GetName()
<< "): cyclical dependency detected" << endl ;
return ;
}
_shapeDirty=kTRUE ;
_clientShapeIter->Reset() ;
RooAbsArg* client ;
while ((client=(RooAbsArg*)_clientShapeIter->Next())) {
client->setShapeDirty(source) ;
client->setValueDirty(source) ;
}
}
Bool_t RooAbsArg::redirectServers(const RooAbsCollection& newSet, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t isRecursionStep)
{
if (!_serverList.First()) return kFALSE ;
if (newSet.getSize()==0) return kFALSE ;
Bool_t ret(kFALSE) ;
THashList origServerList, origServerValue, origServerShape ;
RooAbsArg *oldServer, *newServer ;
TIterator* sIter = _serverList.MakeIterator() ;
while ((oldServer=(RooAbsArg*)sIter->Next())) {
origServerList.Add(oldServer) ;
if (oldServer->_clientListValue.FindObject(this)) {
origServerValue.Add(oldServer) ;
}
if (oldServer->_clientListShape.FindObject(this)) {
origServerShape.Add(oldServer) ;
}
}
delete sIter ;
sIter = origServerList.MakeIterator() ;
Bool_t propValue, propShape ;
while ((oldServer=(RooAbsArg*)sIter->Next())) {
newServer= oldServer->findNewServer(newSet, nameChange);
if (newServer && _verboseDirty) {
cxcoutD(LinkStateMgmt) << "RooAbsArg::redirectServers(" << (void*)this << "," << GetName() << "): server " << oldServer->GetName()
<< " redirected from " << oldServer << " to " << newServer << endl ;
}
if (!newServer) {
if (mustReplaceAll) {
cxcoutD(LinkStateMgmt) << "RooAbsArg::redirectServers(" << (void*)this << "," << GetName() << "): server " << oldServer->GetName()
<< " (" << (void*)oldServer << ") not redirected" << (nameChange?"[nameChange]":"") << endl ;
ret = kTRUE ;
}
continue ;
}
propValue=origServerValue.FindObject(oldServer)?kTRUE:kFALSE ;
propShape=origServerShape.FindObject(oldServer)?kTRUE:kFALSE ;
replaceServer(*oldServer,*newServer,propValue,propShape) ;
}
delete sIter ;
setValueDirty() ;
setShapeDirty() ;
Bool_t allReplaced=kTRUE ;
for (int i=0 ; i<numProxies() ; i++) {
Bool_t ret2 = getProxy(i)->changePointer(newSet,nameChange) ;
allReplaced &= ret2 ;
}
if (mustReplaceAll && !allReplaced) {
coutE(LinkStateMgmt) << "RooAbsArg::redirectServers(" << GetName()
<< "): ERROR, some proxies could not be adjusted" << endl ;
ret = kTRUE ;
}
for (Int_t i=0 ;i<numCaches() ; i++) {
ret |= getCache(i)->redirectServersHook(newSet,mustReplaceAll,nameChange,isRecursionStep) ;
}
ret |= redirectServersHook(newSet,mustReplaceAll,nameChange,isRecursionStep) ;
return ret ;
}
RooAbsArg *RooAbsArg::findNewServer(const RooAbsCollection &newSet, Bool_t nameChange) const
{
RooAbsArg *newServer = 0;
if (!nameChange) {
newServer = newSet.find(GetName()) ;
}
else {
TString nameAttrib("ORIGNAME:") ;
nameAttrib.Append(GetName()) ;
RooArgSet* tmp = (RooArgSet*) newSet.selectByAttrib(nameAttrib,kTRUE) ;
if(0 != tmp) {
if (tmp->getSize()==0) {
delete tmp ;
return 0 ;
}
if(tmp->getSize()>1) {
coutF(LinkStateMgmt) << "RooAbsArg::redirectServers(" << GetName() << "): FATAL Error, " << tmp->getSize() << " servers with "
<< nameAttrib << " attribute" << endl ;
tmp->Print("v") ;
assert(0) ;
}
newServer= tmp->first();
delete tmp ;
}
}
return newServer;
}
Bool_t RooAbsArg::recursiveRedirectServers(const RooAbsCollection& newSet, Bool_t mustReplaceAll, Bool_t nameChange, Bool_t recurseInNewSet)
{
static RooLinkedList callStack ;
if (callStack.FindObject(this)) {
return kFALSE ;
} else {
callStack.Add(this) ;
}
Bool_t ret(kFALSE) ;
cxcoutD(LinkStateMgmt) << "RooAbsArg::recursiveRedirectServers(" << this << "," << GetName() << ") newSet = " << newSet << " mustReplaceAll = "
<< (mustReplaceAll?"T":"F") << " nameChange = " << (nameChange?"T":"F") << " recurseInNewSet = " << (recurseInNewSet?"T":"F") << endl ;
ret |= redirectServers(newSet,mustReplaceAll,nameChange,kTRUE) ;
TIterator* sIter = serverIterator() ;
RooAbsArg* server ;
while((server=(RooAbsArg*)sIter->Next())) {
ret |= server->recursiveRedirectServers(newSet,mustReplaceAll,nameChange,recurseInNewSet) ;
}
delete sIter ;
callStack.Remove(this) ;
return ret ;
}
void RooAbsArg::registerProxy(RooArgProxy& proxy)
{
if (_proxyList.FindObject(&proxy)) {
coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
<< proxy.GetName() << " for arg " << proxy.absArg()->GetName()
<< " already registered" << endl ;
return ;
}
addServer(*proxy.absArg(),proxy.isValueServer(),proxy.isShapeServer()) ;
_proxyList.Add(&proxy) ;
}
void RooAbsArg::unRegisterProxy(RooArgProxy& proxy)
{
_proxyList.Remove(&proxy) ;
}
void RooAbsArg::registerProxy(RooSetProxy& proxy)
{
if (_proxyList.FindObject(&proxy)) {
coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
<< proxy.GetName() << " already registered" << endl ;
return ;
}
_proxyList.Add(&proxy) ;
}
void RooAbsArg::unRegisterProxy(RooSetProxy& proxy)
{
_proxyList.Remove(&proxy) ;
}
void RooAbsArg::registerProxy(RooListProxy& proxy)
{
if (_proxyList.FindObject(&proxy)) {
coutE(LinkStateMgmt) << "RooAbsArg::registerProxy(" << GetName() << "): proxy named "
<< proxy.GetName() << " already registered" << endl ;
return ;
}
_proxyList.Add(&proxy) ;
}
void RooAbsArg::unRegisterProxy(RooListProxy& proxy)
{
_proxyList.Remove(&proxy) ;
}
RooAbsProxy* RooAbsArg::getProxy(Int_t index) const
{
return dynamic_cast<RooAbsProxy*> (_proxyList.At(index)) ;
}
Int_t RooAbsArg::numProxies() const
{
return _proxyList.GetSize() ;
}
void RooAbsArg::setProxyNormSet(const RooArgSet* nset)
{
for (int i=0 ; i<numProxies() ; i++) {
getProxy(i)->changeNormSet(nset) ;
}
}
void RooAbsArg::attachToTree(TTree& ,Int_t)
{
coutE(Contents) << "RooAbsArg::attachToTree(" << GetName()
<< "): Cannot be attached to a TTree" << endl ;
}
Bool_t RooAbsArg::isValid() const
{
return kTRUE ;
}
void RooAbsArg::copyList(TList& dest, const TList& source)
{
dest.Clear() ;
TIterator* sIter = source.MakeIterator() ;
TObject* obj ;
while ((obj = sIter->Next())) {
dest.Add(obj) ;
}
delete sIter ;
}
void RooAbsArg::printName(ostream& os) const
{
os << GetName() ;
}
void RooAbsArg::printTitle(ostream& os) const
{
os << GetTitle() ;
}
void RooAbsArg::printClassName(ostream& os) const
{
os << IsA()->GetName() ;
}
void RooAbsArg::printAddress(ostream& os) const
{
os << this ;
}
void RooAbsArg::printArgs(ostream& os) const
{
if (numProxies()==0) return ;
os << "[ " ;
for (Int_t i=0 ; i<numProxies() ; i++) {
RooAbsProxy* p = getProxy(i) ;
if (!TString(p->name()).BeginsWith("!")) {
p->print(os) ;
os << " " ;
}
}
os << "]" ;
}
Int_t RooAbsArg::defaultPrintContents(Option_t* ) const
{
return kName|kClassName|kValue|kArgs ;
}
void RooAbsArg::printMultiline(ostream& os, Int_t , Bool_t , TString indent) const
{
os << indent << "--- RooAbsArg ---" << endl;
os << indent << " Value State: " ;
switch(_operMode) {
case ADirty: os << "FORCED DIRTY" ; break ;
case AClean: os << "FORCED clean" ; break ;
case Auto: os << (isValueDirty() ? "DIRTY":"clean") ; break ;
}
os << endl
<< indent << " Shape State: " << (isShapeDirty() ? "DIRTY":"clean") << endl;
os << indent << " Attributes: " ;
printAttribList(os) ;
os << endl ;
os << indent << " Address: " << (void*)this << endl;
os << indent << " Clients: " << endl;
TIterator *clientIter= _clientList.MakeIterator();
RooAbsArg* client ;
while ((client=(RooAbsArg*)clientIter->Next())) {
os << indent << " (" << (void*)client << ","
<< (_clientListValue.FindObject(client)?"V":"-")
<< (_clientListShape.FindObject(client)?"S":"-")
<< ") " ;
client->printStream(os,kClassName|kTitle|kName,kSingleLine);
}
delete clientIter;
os << indent << " Servers: " << endl;
TIterator *serverIter= _serverList.MakeIterator();
RooAbsArg* server ;
while ((server=(RooAbsArg*)serverIter->Next())) {
os << indent << " (" << (void*)server << ","
<< (server->_clientListValue.FindObject((TObject*)this)?"V":"-")
<< (server->_clientListShape.FindObject((TObject*)this)?"S":"-")
<< ") " ;
server->printStream(os,kClassName|kName|kTitle,kSingleLine);
}
delete serverIter;
os << indent << " Proxies: " << endl ;
for (int i=0 ; i<numProxies() ; i++) {
RooAbsProxy* proxy=getProxy(i) ;
if (proxy->IsA()->InheritsFrom(RooArgProxy::Class())) {
os << indent << " " << proxy->name() << " -> " ;
((RooArgProxy*)proxy)->absArg()->printStream(os,kName,kSingleLine) ;
} else {
os << indent << " " << proxy->name() << " -> " ;
TString moreIndent(indent) ;
moreIndent.Append(" ") ;
((RooSetProxy*)proxy)->printStream(os,kName,kStandard,moreIndent.Data()) ;
}
}
}
void RooAbsArg::printTree(ostream& os, TString ) const
{
const_cast<RooAbsArg*>(this)->printCompactTree(os) ;
}
ostream& operator<<(ostream& os, RooAbsArg &arg)
{
arg.writeToStream(os,kTRUE) ;
return os ;
}
istream& operator>>(istream& is, RooAbsArg &arg)
{
arg.readFromStream(is,kTRUE,kFALSE) ;
return is ;
}
void RooAbsArg::printAttribList(ostream& os) const
{
set<string>::const_iterator iter = _boolAttrib.begin() ;
Bool_t first(kTRUE) ;
while (iter != _boolAttrib.end()) {
os << (first?" [":",") << *iter ;
first=kFALSE ;
++iter ;
}
if (!first) os << "] " ;
}
void RooAbsArg::attachDataSet(const RooAbsData &data)
{
const RooArgSet* set = data.get() ;
RooArgSet branches ;
branchNodeServerList(&branches,0,kTRUE) ;
TIterator* iter = branches.createIterator() ;
RooAbsArg* branch ;
while((branch=(RooAbsArg*)iter->Next())) {
branch->redirectServers(*set,kFALSE,kFALSE) ;
}
delete iter ;
}
Int_t RooAbsArg::Compare(const TObject* other) const
{
return strcmp(GetName(),other->GetName()) ;
}
void RooAbsArg::printDirty(Bool_t depth) const
{
if (depth) {
RooArgSet branchList ;
branchNodeServerList(&branchList) ;
TIterator* bIter = branchList.createIterator() ;
RooAbsArg* branch ;
while((branch=(RooAbsArg*)bIter->Next())) {
branch->printDirty(kFALSE) ;
}
} else {
cout << GetName() << " : " ;
switch (_operMode) {
case AClean: cout << "FORCED clean" ; break ;
case ADirty: cout << "FORCED DIRTY" ; break ;
case Auto: cout << "Auto " << (isValueDirty()?"DIRTY":"clean") ;
}
cout << endl ;
}
}
void RooAbsArg::optimizeCacheMode(const RooArgSet& observables)
{
RooLinkedList proc;
RooArgSet opt ;
optimizeCacheMode(observables,opt,proc) ;
coutI(Optimization) << "RooAbsArg::optimizeCacheMode(" << GetName() << ") nodes " << opt << " depend on observables, "
<< "changing cache operation mode from change tracking to unconditional evaluation" << endl ;
}
void RooAbsArg::optimizeCacheMode(const RooArgSet& observables, RooArgSet& optimizedNodes, RooLinkedList& processedNodes)
{
if (!isDerived()) {
return ;
}
if (processedNodes.FindObject(this)) {
return ;
} else {
processedNodes.Add(this) ;
}
if (dependsOnValue(observables)) {
if (dynamic_cast<RooRealIntegral*>(this)) {
cxcoutI(Integration) << "RooAbsArg::optimizeCacheMode(" << GetName() << ") integral depends on value of one or more observables and will be evaluated for every event" << endl ;
}
optimizedNodes.add(*this,kTRUE) ;
if (operMode()==AClean) {
} else {
setOperMode(ADirty) ;
}
}
for (Int_t i=0 ;i<numCaches() ; i++) {
getCache(i)->optimizeCacheMode(observables,optimizedNodes,processedNodes) ;
}
TIterator* sIter = serverIterator() ;
RooAbsArg* server ;
while((server=(RooAbsArg*)sIter->Next())) {
server->optimizeCacheMode(observables,optimizedNodes,processedNodes) ;
}
delete sIter ;
}
Bool_t RooAbsArg::findConstantNodes(const RooArgSet& observables, RooArgSet& cacheList)
{
RooLinkedList proc ;
Bool_t ret = findConstantNodes(observables,cacheList,proc) ;
coutI(Optimization) << "RooAbsArg::findConstantNodes(" << GetName() << "): components "
<< cacheList << " depend exclusively on constant parameters and will be precalculated and cached" << endl ;
return ret ;
}
Bool_t RooAbsArg::findConstantNodes(const RooArgSet& observables, RooArgSet& cacheList, RooLinkedList& processedNodes)
{
if (!isDerived()) {
return kFALSE;
}
if (processedNodes.FindObject(this)) {
return kFALSE ;
} else {
processedNodes.Add(this) ;
}
Bool_t canOpt(kTRUE) ;
RooArgSet* paramSet = getParameters(observables) ;
TIterator* iter = paramSet->createIterator() ;
RooAbsArg* param ;
while((param = (RooAbsArg*)iter->Next())) {
if (!param->isConstant()) {
canOpt=kFALSE ;
break ;
}
}
delete iter ;
delete paramSet ;
if (canOpt) {
if (!cacheList.find(GetName()) && dependsOnValue(observables) && !observables.find(GetName()) ) {
cxcoutD(Optimization) << "RooAbsArg::findConstantNodes(" << GetName() << ") adding self to list of constant nodes" << endl ;
cacheList.add(*this) ;
}
} else {
TIterator* sIter = serverIterator() ;
RooAbsArg* server ;
while((server=(RooAbsArg*)sIter->Next())) {
if (server->isDerived()) {
server->findConstantNodes(observables,cacheList,processedNodes) ;
}
}
delete sIter ;
}
for (Int_t i=0 ;i<numCaches() ; i++) {
getCache(i)->findConstantNodes(observables,cacheList,processedNodes) ;
}
return kFALSE ;
}
void RooAbsArg::constOptimizeTestStatistic(ConstOpCode opcode)
{
TIterator* sIter = serverIterator() ;
RooAbsArg* server ;
while((server=(RooAbsArg*)sIter->Next())) {
server->constOptimizeTestStatistic(opcode) ;
}
delete sIter ;
}
void RooAbsArg::setOperMode(OperMode mode, Bool_t recurseADirty)
{
if (mode==_operMode) return ;
_operMode = mode ;
for (Int_t i=0 ;i<numCaches() ; i++) {
getCache(i)->operModeHook() ;
}
operModeHook() ;
if (mode==ADirty && recurseADirty) {
TIterator* iter = valueClientIterator() ;
RooAbsArg* client ;
while((client=(RooAbsArg*)iter->Next())) {
client->setOperMode(mode) ;
}
delete iter ;
}
}
void RooAbsArg::printCompactTree(const char* indent, const char* filename, const char* namePat, RooAbsArg* client)
{
if (filename) {
ofstream ofs(filename) ;
printCompactTree(ofs,indent,namePat,client) ;
} else {
printCompactTree(cout,indent,namePat,client) ;
}
}
void RooAbsArg::printCompactTree(ostream& os, const char* indent, const char* namePat, RooAbsArg* client)
{
if ( !namePat || TString(GetName()).Contains(namePat)) {
os << indent << this << " " << IsA()->GetName() << "::" << GetName() << " (" << GetTitle() << ") " ;
if (_serverList.GetSize()>0) {
switch(operMode()) {
case Auto: os << " [Auto] " ; break ;
case AClean: os << " [ACLEAN] " ; break ;
case ADirty: os << " [ADIRTY] " ; break ;
}
}
if (client) {
if (isValueServer(*client)) os << "V" ;
if (isShapeServer(*client)) os << "S" ;
}
os << endl ;
for (Int_t i=0 ;i<numCaches() ; i++) {
getCache(i)->printCompactTreeHook(os,indent) ;
}
printCompactTreeHook(os,indent) ;
}
TString indent2(indent) ;
indent2 += " " ;
TIterator * iter = serverIterator() ;
RooAbsArg* arg ;
while((arg=(RooAbsArg*)iter->Next())) {
arg->printCompactTree(os,indent2,namePat,this) ;
}
delete iter ;
}
TString RooAbsArg::cleanBranchName() const
{
TString rawBranchName = GetName() ;
if (getStringAttribute("BranchName")) {
rawBranchName = getStringAttribute("BranchName") ;
}
TString cleanName(rawBranchName) ;
cleanName.ReplaceAll("/","D") ;
cleanName.ReplaceAll("-","M") ;
cleanName.ReplaceAll("+","P") ;
cleanName.ReplaceAll("*","X") ;
cleanName.ReplaceAll("[","L") ;
cleanName.ReplaceAll("]","R") ;
cleanName.ReplaceAll("(","L") ;
cleanName.ReplaceAll(")","R") ;
cleanName.ReplaceAll("{","L") ;
cleanName.ReplaceAll("}","R") ;
if (cleanName.Length()<=60) return cleanName ;
static char buf[1024] ;
strcpy(buf,cleanName.Data()) ;
sprintf(buf+46,"_CRC%08x",crc32(cleanName.Data())) ;
return TString(buf) ;
}
UInt_t RooAbsArg::crc32(const char* data)
{
Int_t len = strlen(data) ;
if (len<4) {
oocoutE((RooAbsArg*)0,InputArguments) << "RooAbsReal::crc32 cannot calculate checksum of less than 4 bytes of data" << endl ;
return 0 ;
}
static Bool_t init(kFALSE) ;
static unsigned int crctab[256];
if (!init) {
int i, j;
unsigned int crc;
for (i = 0; i < 256; i++){
crc = i << 24;
for (j = 0; j < 8; j++) {
if (crc & 0x80000000) {
crc = (crc << 1) ^ 0x04c11db7 ;
} else {
crc = crc << 1;
}
}
crctab[i] = crc;
}
init = kTRUE ;
}
unsigned int result(0);
int i(0);
result = *data++ << 24;
result |= *data++ << 16;
result |= *data++ << 8;
result |= *data++;
result = ~ result;
len -=4;
for (i=0; i<len; i++) {
result = (result << 8 | *data++) ^ crctab[result >> 24];
}
return ~result;
}
void RooAbsArg::printCompactTreeHook(ostream&, const char *)
{
}
void RooAbsArg::registerCache(RooAbsCache& cache)
{
_cacheList.push_back(&cache) ;
}
void RooAbsArg::unRegisterCache(RooAbsCache& cache)
{
std::remove(_cacheList.begin(), _cacheList.end(), &cache);
}
Int_t RooAbsArg::numCaches() const
{
return _cacheList.size() ;
}
RooAbsCache* RooAbsArg::getCache(Int_t index) const
{
return _cacheList[index] ;
}
RooArgSet* RooAbsArg::getVariables() const
{
return getParameters(RooArgSet()) ;
}
RooLinkedList RooAbsArg::getCloningAncestors() const
{
RooLinkedList retVal ;
set<string>::const_iterator iter= _boolAttrib.begin() ;
while(iter != _boolAttrib.end()) {
if (TString(*iter).BeginsWith("CloneOf(")) {
char buf[128] ;
strcpy(buf,iter->c_str()) ;
strtok(buf,"(") ;
char* ptrToken = strtok(0,")") ;
RooAbsArg* ptr = (RooAbsArg*) strtol(ptrToken,0,16) ;
retVal.Add(ptr) ;
}
}
return retVal ;
}
void RooAbsArg::graphVizTree(const char* fileName)
{
ofstream ofs(fileName) ;
if (!ofs) {
coutE(InputArguments) << "RooAbsArg::graphVizTree() ERROR: Cannot open graphViz output file with name " << fileName << endl ;
return ;
}
graphVizTree(ofs) ;
}
void RooAbsArg::graphVizTree(ostream& os)
{
if (!os) {
coutE(InputArguments) << "RooAbsArg::graphVizTree() ERROR: output stream provided as input argument is in invalid state" << endl ;
}
os << "digraph " << GetName() << "{" << endl ;
RooArgSet nodeSet ;
treeNodeServerList(&nodeSet) ;
TIterator* iter = nodeSet.createIterator() ;
RooAbsArg* node ;
while((node=(RooAbsArg*)iter->Next())) {
os << "\"" << node->GetName() << "\" [ color=" << (node->isFundamental()?"blue":"red") << ", label=\"" << node->IsA()->GetName() << "\\n" << node->GetName() << "\"];" << endl ;
}
delete iter ;
set<pair<RooAbsArg*,RooAbsArg*> > links ;
graphVizAddConnections(links) ;
set<pair<RooAbsArg*,RooAbsArg*> >::iterator liter = links.begin() ;
for( ; liter != links.end() ; ++liter ) {
os << "\"" << liter->first->GetName() << "\" -> \"" << liter->second->GetName() << "\";" << endl ;
}
os << "}" << endl ;
}
void RooAbsArg::graphVizAddConnections(set<pair<RooAbsArg*,RooAbsArg*> >& linkSet)
{
TIterator* sIter = serverIterator() ;
RooAbsArg* server ;
while((server=(RooAbsArg*)sIter->Next())) {
linkSet.insert(make_pair(this,server)) ;
server->graphVizAddConnections(linkSet) ;
}
delete sIter ;
}
Bool_t RooAbsArg::inhibitDirty()
{
return _inhibitDirty ;
}
Bool_t RooAbsArg::addOwnedComponents(const RooArgSet& comps)
{
if (!_ownedComponents) {
_ownedComponents = new RooArgSet("owned components") ;
}
return _ownedComponents->addOwned(comps) ;
}
RooAbsArg* RooAbsArg::cloneTree(const char* newname) const
{
RooArgSet* clonedNodes = (RooArgSet*) RooArgSet(*this).snapshot(kTRUE) ;
RooAbsArg* head = clonedNodes->find(GetName()) ;
clonedNodes->remove(*head) ;
head->addOwnedComponents(*clonedNodes) ;
clonedNodes->releaseOwnership() ;
delete clonedNodes ;
if (newname) {
head->SetName(newname) ;
}
return head ;
}
RooExpensiveObjectCache& RooAbsArg::expensiveObjectCache() const
{
if (_eocache) {
return *_eocache ;
} else {
return RooExpensiveObjectCache::instance() ;
}
}
Bool_t RooAbsArg::flipAClean()
{
return _flipAClean ;
}
Last change: Mon Dec 15 13:02:44 2008
Last generated: 2008-12-15 13:02
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.