RooListProxy.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooListProxy.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 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // RooListProxy is the concrete proxy for RooArgList objects.
00021 // A RooListProxy is the only safe mechanism to store a RooArgList
00022 // with RooAbsArg contents in another RooAbsArg.
00023 // <p>
00024 // The list proxy has the semantic of a RooArgList but also 
00025 // takes care of all bookkeeping required when composite objects
00026 // are clone and client-server links need to be redirected.
00027 // END_HTML
00028 //
00029 
00030 
00031 #include "RooFit.h"
00032 #include "Riostream.h"
00033 
00034 #include "RooListProxy.h"
00035 #include "RooArgList.h"
00036 #include "RooAbsArg.h"
00037 
00038 ClassImp(RooListProxy)
00039 ;
00040 
00041 
00042 
00043 //_____________________________________________________________________________
00044 RooListProxy::RooListProxy(const char* inName, const char* /*desc*/, RooAbsArg* owner, 
00045                          Bool_t defValueServer, Bool_t defShapeServer) :
00046   RooArgList(inName), _owner(owner), 
00047   _defValueServer(defValueServer), 
00048   _defShapeServer(defShapeServer)
00049 {
00050   // Constructor with proxy name, description and pointer to ownder of
00051   // the RooListProxy. The default strategy for value/shape dirty flag
00052   // propagation of the list contents to the list owner is controlled
00053   // by the defValueServer and defShapeServer flags.
00054 
00055   _owner->registerProxy(*this) ;
00056   _iter = createIterator() ;
00057 }
00058 
00059 
00060 
00061 //_____________________________________________________________________________
00062 RooListProxy::RooListProxy(const char* inName, RooAbsArg* owner, const RooListProxy& other) : 
00063   RooArgList(other,inName), _owner(owner),  
00064   _defValueServer(other._defValueServer), 
00065   _defShapeServer(other._defShapeServer)
00066 {
00067   // Copy constructor with name of proxy, pointer to owner of this proxy and
00068   // reference to list proxy to be copied
00069 
00070   _owner->registerProxy(*this) ;
00071   _iter = createIterator() ;
00072 }
00073 
00074 
00075 
00076 //_____________________________________________________________________________
00077 RooListProxy::~RooListProxy()
00078 {
00079   // Destructor
00080 
00081   if (_owner) _owner->unRegisterProxy(*this) ;
00082   delete _iter ;
00083 }
00084 
00085 
00086 
00087 //_____________________________________________________________________________
00088 Bool_t RooListProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
00089 {
00090   // Add object to list with explicitl directives on value and shape dirty flag propagation
00091   // of inserted object to list owner
00092 
00093   Bool_t ret=RooArgList::add(var,silent) ;
00094   if (ret) {
00095     _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
00096   }
00097   return ret ;  
00098 }
00099 
00100 
00101 
00102 //_____________________________________________________________________________
00103 Bool_t RooListProxy::add(const RooAbsArg& var, Bool_t silent) 
00104 {
00105   // Reimplementation of standard RooArgList::add()
00106 
00107   return add(var,_defValueServer,_defShapeServer,silent) ;
00108 }
00109 
00110 
00111 
00112 //_____________________________________________________________________________
00113 Bool_t RooListProxy::addOwned(RooAbsArg& var, Bool_t silent)
00114 {
00115   // Reimplementation of standard RooArgList::addOwned()
00116 
00117   Bool_t ret=RooArgList::addOwned(var,silent) ;
00118   if (ret) {
00119     _owner->addServer((RooAbsArg&)var,_defValueServer,_defShapeServer) ;
00120   }
00121   return ret ;  
00122 }
00123 
00124 
00125 //_____________________________________________________________________________
00126 Bool_t RooListProxy::replace(const RooAbsArg& var1, const RooAbsArg& var2) 
00127 {
00128   // Reimplementation of standard RooArgList::replace()
00129 
00130   Bool_t ret=RooArgList::replace(var1,var2) ;
00131   if (ret) {
00132     _owner->removeServer((RooAbsArg&)var1) ;
00133     _owner->addServer((RooAbsArg&)var2,_owner->isValueServer(var1),
00134                                        _owner->isShapeServer(var2)) ;
00135   }
00136   return ret ;
00137 }
00138 
00139 
00140 
00141 //_____________________________________________________________________________
00142 Bool_t RooListProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly) 
00143 {
00144   // Reimplementation of standard RooArgList::remove()
00145 
00146   Bool_t ret=RooArgList::remove(var,silent,matchByNameOnly) ;
00147   if (ret) {
00148     _owner->removeServer((RooAbsArg&)var) ;
00149   }
00150   return ret ;
00151 }
00152 
00153 
00154 
00155 //_____________________________________________________________________________
00156 void RooListProxy::removeAll() 
00157 {
00158   // Reimplementation of standard RooArgList::removeAll()
00159 
00160   TIterator* iter = createIterator() ;
00161   RooAbsArg* arg ;
00162   while ((arg=(RooAbsArg*)iter->Next())) {
00163     _owner->removeServer(*arg) ;
00164   }
00165   delete iter ;
00166 
00167   RooArgList::removeAll() ;
00168 }
00169 
00170 
00171 
00172 
00173 //_____________________________________________________________________________
00174 RooListProxy& RooListProxy::operator=(const RooArgList& other) 
00175 {
00176   // Reimplementation of standard RooArgList assignment operator
00177 
00178   RooArgList::operator=(other) ;
00179   return *this ;
00180 }
00181 
00182 
00183 
00184 
00185 //_____________________________________________________________________________
00186 Bool_t RooListProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode) 
00187 {
00188   // Internal function that implements consequences of a server redirect on the
00189   // owner. If the list contains any element with names identical to those in newServerList
00190   // replace them with the instance in newServerList
00191 
00192   if (getSize()==0) {
00193     if (factoryInitMode) {
00194       TIterator* iter = newServerList.createIterator() ;
00195       RooAbsArg* arg ;
00196       while((arg=(RooAbsArg*)iter->Next())) {
00197         add(*arg,kTRUE) ;
00198       }
00199       delete iter ;
00200     } else {
00201       return kTRUE ;    
00202     }
00203   }
00204   _iter->Reset() ;
00205   RooAbsArg* arg ;
00206   Bool_t error(kFALSE) ;
00207   while ((arg=(RooAbsArg*)_iter->Next())) {
00208     
00209     RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
00210     if (newArg) error |= !RooArgList::replace(*arg,*newArg) ;
00211   }
00212   return !error ;
00213 }
00214 
00215 
00216 
00217 //_____________________________________________________________________________
00218 void RooListProxy::print(ostream& os, Bool_t addContents) const 
00219 { 
00220   // Print the name of the proxy, and if requested a summary of
00221   // the contained elements as well
00222 
00223   if (!addContents) {
00224     os << name() << "=" ; printStream(os,kValue,kInline) ; 
00225   } else {
00226     os << name() << "=(" ;
00227     TIterator* iter = createIterator() ;
00228     RooAbsArg* arg ;
00229     Bool_t first2(kTRUE) ;
00230     while ((arg=(RooAbsArg*)iter->Next())) {
00231       if (first2) {
00232         first2 = kFALSE ;
00233       } else {
00234         os << "," ;
00235       }
00236       arg->printStream(os,kValue|kName,kInline) ;
00237     }
00238     os << ")" ;
00239     delete iter ;
00240   }
00241 }

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