RooCompositeDataStore.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooCompositeDataStore.cxx 36222 2010-10-09 18:27:06Z 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 // RooCompositeDataStore is the abstract base class for data collection that
00021 // use a TTree as internal storage mechanism
00022 // END_HTML
00023 //
00024 
00025 #include "RooFit.h"
00026 #include "RooMsgService.h"
00027 #include "RooCompositeDataStore.h"
00028 
00029 #include "Riostream.h"
00030 #include "TTree.h"
00031 #include "TChain.h"
00032 #include "TDirectory.h"
00033 #include "TROOT.h"
00034 #include "RooFormulaVar.h"
00035 #include "RooRealVar.h"
00036 #include "RooCategory.h"
00037 #include <iomanip>
00038 using namespace std ;
00039 
00040 ClassImp(RooCompositeDataStore)
00041 ;
00042 
00043 
00044 //_____________________________________________________________________________
00045 RooCompositeDataStore::RooCompositeDataStore() : _curStore(0), _curIndex(0)
00046 {
00047 }
00048 
00049 
00050 
00051 //_____________________________________________________________________________
00052 RooCompositeDataStore::RooCompositeDataStore(const char* name, const char* title, const RooArgSet& vars, RooCategory& indexCat,map<string,RooAbsDataStore*> inputData) :
00053   RooAbsDataStore(name,title,RooArgSet(vars,indexCat)), _dataMap(inputData), _indexCat(&indexCat), _curStore(0), _curIndex(0)
00054 {
00055 }
00056 
00057 
00058 
00059 
00060 //_____________________________________________________________________________
00061 RooCompositeDataStore::RooCompositeDataStore(const RooCompositeDataStore& other, const char* newname) :
00062   RooAbsDataStore(other,newname), _dataMap(other._dataMap), _indexCat(other._indexCat), _curStore(other._curStore), _curIndex(other._curIndex)
00063 {
00064 }
00065 
00066 
00067 //_____________________________________________________________________________
00068 RooCompositeDataStore::RooCompositeDataStore(const RooCompositeDataStore& other, const RooArgSet& vars, const char* newname) :
00069   RooAbsDataStore(other,vars,newname), _dataMap(other._dataMap), _indexCat(other._indexCat), _curStore(other._curStore), _curIndex(other._curIndex)
00070 {
00071 }
00072 
00073 
00074 
00075 
00076 //_____________________________________________________________________________
00077 RooCompositeDataStore::~RooCompositeDataStore()
00078 {
00079   // Destructor
00080 }
00081 
00082 
00083 //_____________________________________________________________________________
00084 Bool_t RooCompositeDataStore::valid() const 
00085 {
00086   // Return true if currently loaded coordinate is considered valid within
00087   // the current range definitions of all observables
00088   return kTRUE ;
00089 }
00090 
00091 
00092 
00093 
00094 //_____________________________________________________________________________
00095 Int_t RooCompositeDataStore::fill()
00096 {
00097   // Forward fill request to appropriate subset
00098   RooAbsDataStore* subset = _dataMap[_indexCat->getLabel()] ;
00099   *const_cast<RooArgSet*>((subset->get())) = _vars ;
00100   return subset->fill() ;
00101 }
00102  
00103 
00104 
00105 //_____________________________________________________________________________
00106 const RooArgSet* RooCompositeDataStore::get(Int_t index) const 
00107 {
00108   // Load the n-th data point (n='index') in memory
00109   // and return a pointer to the internal RooArgSet
00110   // holding its coordinates.
00111 
00112   Int_t offset(0) ;
00113   map<string,RooAbsDataStore*>::const_iterator iter ;
00114   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00115     if (index>=(offset+iter->second->numEntries())) {
00116       offset += iter->second->numEntries() ;
00117       continue ;
00118     }    
00119     const_cast<RooCompositeDataStore*>(this)->_vars = (*iter->second->get(index-offset)) ;
00120     _indexCat->setLabel(iter->first.c_str()) ;
00121     _curStore = iter->second ;
00122     _curIndex = index-offset ;
00123     
00124     return &_vars ;
00125   }
00126   return 0 ;
00127 }
00128 
00129 
00130 
00131 //_____________________________________________________________________________
00132 Double_t RooCompositeDataStore::weight() const 
00133 {  
00134   if (!_curStore) get(0) ;
00135   // coverity[FORWARD_NULL]
00136   return _curStore->weight(_curIndex) ;
00137 }
00138 
00139 
00140 
00141 
00142 
00143 //_____________________________________________________________________________
00144 Double_t RooCompositeDataStore::weight(Int_t index) const 
00145 {
00146   get(index) ;
00147   return weight() ;
00148 }
00149 
00150 
00151 
00152 
00153 //_____________________________________________________________________________
00154 Double_t RooCompositeDataStore::weightError(RooAbsData::ErrorType etype) const 
00155 {  
00156   if (!_curStore) get(0) ;
00157   // coverity[FORWARD_NULL]
00158   return _curStore->weightError(etype) ;
00159 }
00160 
00161 
00162 
00163 
00164 //_____________________________________________________________________________
00165 void RooCompositeDataStore::weightError(Double_t& lo, Double_t& hi, RooAbsData::ErrorType etype) const 
00166 {
00167   if (!_curStore) get(0) ;
00168   // coverity[FORWARD_NULL]
00169   return _curStore->weightError(lo,hi,etype) ;
00170 }
00171 
00172 
00173 
00174 
00175 //_____________________________________________________________________________
00176 Bool_t RooCompositeDataStore::isWeighted() const 
00177 {
00178   map<string,RooAbsDataStore*>::const_iterator iter ;
00179   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00180     if (iter->second->isWeighted()) return kTRUE ;
00181   }
00182   return kFALSE ; ;
00183 }
00184 
00185 
00186 
00187 
00188 //_____________________________________________________________________________
00189 Bool_t RooCompositeDataStore::changeObservableName(const char* from, const char* to) 
00190 {
00191   // Change name of internal observable named 'from' into 'to'
00192 
00193 
00194   // Find observable to be changed
00195   RooAbsArg* var = _vars.find(from) ;
00196 
00197   // Check that we found it
00198   if (!var) {
00199     coutE(InputArguments) << "RooCompositeDataStore::changeObservableName(" << GetName() << " no observable " << from << " in this dataset" << endl ;
00200     return kTRUE ;
00201   }
00202   
00203   // Process name change
00204   var->SetName(to) ;  
00205 
00206   // Forward name change request to component datasets
00207   Bool_t ret(kFALSE) ;
00208   map<string,RooAbsDataStore*>::const_iterator iter ;
00209   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00210     ret |= iter->second->changeObservableName(from,to) ;
00211   }
00212     
00213   return ret ;
00214 }
00215 
00216   
00217 
00218 //_____________________________________________________________________________
00219 RooAbsArg* RooCompositeDataStore::addColumn(RooAbsArg& newVar, Bool_t adjustRange)
00220 {
00221   // WVE ownership issue here!! Caller (a RooAbsData) should take ownership of all
00222   // arguments, but only does for the first one here...
00223   RooAbsArg* ret(0) ;
00224   map<string,RooAbsDataStore*>::const_iterator iter ;
00225   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00226     ret = iter->second->addColumn(newVar,adjustRange) ;
00227   }
00228   return ret ;
00229 }
00230 
00231 
00232 
00233 //_____________________________________________________________________________
00234 RooArgSet* RooCompositeDataStore::addColumns(const RooArgList& varList)
00235 {
00236   // WVE ownership issue here!! Caller (a RooAbsData) should take ownership of all
00237   // arguments, but only does for the first one here...
00238   RooArgSet* ret(0) ;
00239   map<string,RooAbsDataStore*>::const_iterator iter ;
00240   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00241     ret = iter->second->addColumns(varList) ;
00242   }
00243   return ret ;
00244 }
00245 
00246 
00247 
00248 
00249 //_____________________________________________________________________________
00250 RooAbsDataStore* RooCompositeDataStore::merge(const RooArgSet& /*allVars*/, list<RooAbsDataStore*> /*dstoreList*/)
00251 {
00252   throw string("RooCompositeDataStore::merge() is not implemented yet") ;
00253 }
00254 
00255 
00256 
00257 
00258 
00259 //_____________________________________________________________________________
00260 void RooCompositeDataStore::append(RooAbsDataStore& other) 
00261 {
00262   Int_t nevt = other.numEntries() ;
00263   for (int i=0 ; i<nevt ; i++) {  
00264     _vars = *other.get(i) ;
00265     fill() ;
00266   }
00267 }
00268 
00269 
00270 
00271 //_____________________________________________________________________________
00272 Int_t RooCompositeDataStore::numEntries() const 
00273 {
00274   Int_t n(0) ;
00275   map<string,RooAbsDataStore*>::const_iterator iter ;
00276   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00277     n += iter->second->numEntries() ;
00278   }
00279   return n ;
00280 }
00281 
00282 
00283 
00284 
00285 //_____________________________________________________________________________
00286 void RooCompositeDataStore::reset() 
00287 {
00288   map<string,RooAbsDataStore*>::const_iterator iter ;
00289   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00290     iter->second->reset() ;
00291   }
00292 }
00293 
00294 
00295 
00296 //_____________________________________________________________________________
00297 void RooCompositeDataStore::cacheArgs(const RooAbsArg* owner, RooArgSet& newVarSet, const RooArgSet* nset) 
00298 {
00299   map<string,RooAbsDataStore*>::const_iterator iter ;
00300   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00301     iter->second->cacheArgs(owner,newVarSet,nset) ;
00302   }
00303 }
00304 
00305 
00306 
00307 //_____________________________________________________________________________
00308 void RooCompositeDataStore::setArgStatus(const RooArgSet& set, Bool_t active) 
00309 {
00310   map<string,RooAbsDataStore*>::const_iterator iter ;
00311   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00312     RooArgSet* subset = (RooArgSet*) set.selectCommon(*iter->second->get()) ;
00313     iter->second->setArgStatus(*subset,active) ;
00314     delete subset ;
00315   }
00316   return ;
00317 }
00318 
00319 
00320 
00321 //_____________________________________________________________________________
00322 void RooCompositeDataStore::attachCache(const RooAbsArg* newOwner, const RooArgSet& inCachedVars) 
00323 {
00324   // Initialize cache of dataset: attach variables of cache ArgSet
00325   // to the corresponding TTree branches
00326   map<string,RooAbsDataStore*>::const_iterator iter ;
00327   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00328     iter->second->attachCache(newOwner,inCachedVars) ;
00329   }
00330   return ;
00331 }
00332 
00333 
00334 
00335 //_____________________________________________________________________________
00336 void RooCompositeDataStore::resetCache() 
00337 {
00338   map<string,RooAbsDataStore*>::const_iterator iter ;
00339   for (iter = _dataMap.begin() ; iter!=_dataMap.end() ; ++iter) {    
00340     iter->second->resetCache() ;
00341   }
00342   return ;
00343 }
00344 
00345 
00346 
00347 

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