RooArgProxy.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooArgProxy.cxx 28259 2009-04-16 16:21:16Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 #include "RooFit.h"
00018 
00019 #include "RooArgProxy.h"
00020 #include "RooArgProxy.h"
00021 #include "RooArgSet.h"
00022 #include "RooAbsArg.h"
00023 #include <iostream>
00024 using namespace std ;
00025 
00026 //////////////////////////////////////////////////////////////////////////////
00027 // 
00028 // BEGIN_HTML
00029 // RooArgProxy is the abstact interface for RooAbsArg proxy classes.
00030 // A RooArgProxy is the general mechanism to store references
00031 // to other RooAbsArgs inside a RooAbsArg
00032 //
00033 // Creating a RooArgProxy adds the proxied object to the proxy owners
00034 // server list (thus receiving value/shape dirty flags from it) and
00035 // registers itself with the owning class. The latter allows the
00036 // owning class to change the proxied pointer when the server it
00037 // points to gets redirected (e.g. in a copy or clone operation)
00038 // END_HTML
00039 //
00040 
00041 
00042 ClassImp(RooArgProxy)
00043 ;
00044 
00045 
00046 //_____________________________________________________________________________
00047 RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
00048                          Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) : 
00049   TNamed(inName,desc), _owner(owner), _arg(0),
00050   _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
00051 {
00052   // Constructor with owner and proxied variable. 
00053   _owner->registerProxy(*this) ;
00054 }
00055 
00056 
00057 
00058 //_____________________________________________________________________________
00059 RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner, RooAbsArg& arg,
00060                          Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) : 
00061   TNamed(inName,desc), _owner(owner), _arg(&arg),
00062   _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
00063 {
00064   // Constructor with owner and proxied variable. The valueServer and shapeServer booleans
00065   // control if the inserted client-server link in the owner propagates value and/or 
00066   // shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
00067 
00068   _owner->registerProxy(*this) ;
00069   _isFund = _arg->isFundamental() ;
00070 }
00071 
00072 
00073 
00074 //_____________________________________________________________________________
00075 RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) : 
00076   TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg), 
00077   _valueServer(other._valueServer), _shapeServer(other._shapeServer),
00078   _isFund(other._isFund), _ownArg(other._ownArg) 
00079 {
00080   // Copy constructor
00081 
00082   if (_ownArg) {
00083     _arg = _arg ? (RooAbsArg*) _arg->Clone() : 0 ;
00084   }
00085 
00086   _owner->registerProxy(*this) ;
00087 }
00088 
00089 
00090 
00091 //_____________________________________________________________________________
00092 RooArgProxy::~RooArgProxy()
00093 {
00094   // Destructor
00095 
00096   if (_owner) _owner->unRegisterProxy(*this) ;
00097   if (_ownArg) delete _arg ;
00098 }
00099 
00100 
00101 
00102 //_____________________________________________________________________________
00103 Bool_t RooArgProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode) 
00104 {
00105   // Change proxied object to object of same name in given list. If nameChange is true
00106   // the replacement object can have a different name and is identified as the replacement object by
00107   // the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
00108   
00109   RooAbsArg* newArg ;
00110   Bool_t initEmpty = _arg ? kFALSE : kTRUE ;
00111   if (_arg) {
00112     newArg= _arg->findNewServer(newServerList, nameChange);
00113   } else if (factoryInitMode) {
00114     newArg = newServerList.first() ;
00115     _owner->addServer(*newArg,_valueServer,_shapeServer) ;
00116   } else {
00117     newArg = 0 ;
00118   }
00119   if (newArg) {
00120     _arg = newArg ;
00121     _isFund = _arg->isFundamental() ;
00122   }  
00123   if (initEmpty && !factoryInitMode) return kTRUE ;
00124   return newArg?kTRUE:kFALSE ;
00125 }
00126 
00127 
00128 
00129 //_____________________________________________________________________________
00130 void RooArgProxy::changeDataSet(const RooArgSet* newNormSet) 
00131 {
00132   // Change the normalization set that should be offered to the
00133   // content objects getVal() when evaluated.
00134 
00135   RooAbsProxy::changeNormSet(newNormSet) ;
00136   _arg->setProxyNormSet(newNormSet) ;
00137 }
00138 
00139 
00140 
00141 //_____________________________________________________________________________
00142 void RooArgProxy::print(ostream& os, Bool_t addContents) const 
00143 { 
00144   // Print the name of the proxy on ostream. If addContents is
00145   // true also the value of the contained RooAbsArg is also printed
00146 
00147   os << name() << "=" << (_arg?_arg->GetName():"NULL")  ;
00148   if (_arg && addContents) {
00149     os << "=" ;
00150     _arg->printStream(os,RooPrintable::kValue,RooPrintable::kInline) ;
00151   }
00152 }

Generated on Tue Jul 5 15:06:02 2011 for ROOT_528-00b_version by  doxygen 1.5.1