RooWorkspace.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooWorkspace.h,v 1.3 2007/07/16 21:04:28 wouter Exp $
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 #ifndef ROO_WORKSPACE
00017 #define ROO_WORKSPACE
00018 
00019 #include "RooPrintable.h"
00020 #include "RooArgSet.h"
00021 #include "RooLinkedList.h"
00022 #include "RooCmdArg.h"
00023 #include "RooExpensiveObjectCache.h" 
00024 #include "TUUID.h"
00025 #include <map>
00026 #include <list>
00027 #include <string>
00028 
00029 class TClass ;
00030 class RooAbsPdf ;
00031 class RooAbsData ;
00032 class RooRealVar ;
00033 class RooCategory ;
00034 class RooAbsReal ;
00035 class RooAbsCategory ;
00036 class RooFactoryWSTool ;
00037 class RooAbsStudy ;
00038 
00039 #include "TNamed.h"
00040 #include "TDirectoryFile.h"
00041 
00042 class RooWorkspace : public TNamed {
00043 public:
00044 
00045   RooWorkspace() ;
00046   RooWorkspace(const char* name, Bool_t doCINTExport) ;
00047   RooWorkspace(const char* name, const char* title=0) ;
00048   RooWorkspace(const RooWorkspace& other) ;
00049   ~RooWorkspace() ;
00050 
00051   void exportToCint(const char* namespaceName=0) ;
00052 
00053   Bool_t importClassCode(const char* pat="*", Bool_t doReplace=kFALSE) ;
00054   Bool_t importClassCode(TClass* theClass, Bool_t doReplace=kFALSE) ;
00055 
00056   // Import functions for dataset, functions, generic objects
00057   Bool_t import(const RooAbsArg& arg, const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg()) ;
00058   Bool_t import(const RooArgSet& args, const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg()) ;
00059   Bool_t import(RooAbsData& data, const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg()) ;
00060   Bool_t import(const char *fileSpec, const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg()) ;
00061   Bool_t import(TObject& object, Bool_t replaceExisting=kFALSE) ;
00062   Bool_t import(TObject& object, const char* aliasName, Bool_t replaceExisting=kFALSE) ;
00063 
00064   // Transaction management interface for multi-step import operations
00065   Bool_t startTransaction() ;
00066   Bool_t cancelTransaction() ;
00067   Bool_t commitTransaction() ;
00068 
00069   // Named set management
00070   Bool_t defineSet(const char* name, const RooArgSet& aset, Bool_t importMissing=kFALSE) ;
00071   Bool_t defineSet(const char* name, const char* contentList) ;
00072   Bool_t extendSet(const char* name, const char* newContents) ;
00073   const RooArgSet* set(const char* name) ;
00074 
00075   // Import, load and save parameter value snapshots
00076   Bool_t saveSnapshot(const char* name, const char* paramNames) ;
00077   Bool_t saveSnapshot(const char* name, const RooArgSet& params, Bool_t importValues=kFALSE) ;
00078   Bool_t loadSnapshot(const char* name) ;  
00079 
00080   void merge(const RooWorkspace& /*other*/) {} ;
00081 
00082   // Join p.d.f.s and datasets for simultaneous analysis
00083   //   RooAbsPdf* joinPdf(const char* jointPdfName, const char* indexName, const char* inputMapping) ; 
00084   //   RooAbsData* joinData(const char* jointDataName, const char* indexName, const char* inputMapping) ; 
00085 
00086   // Accessor functions 
00087   RooAbsPdf* pdf(const char* name) const ;
00088   RooAbsReal* function(const char* name) const ;
00089   RooRealVar* var(const char* name) const ;
00090   RooCategory* cat(const char* name) const ;
00091   RooAbsCategory* catfunc(const char* name) const ;
00092   RooAbsData* data(const char* name) const ;
00093   RooAbsArg* arg(const char* name) const ;
00094   RooAbsArg* fundArg(const char* name) const ;
00095   RooArgSet argSet(const char* nameList) const ;
00096   TIterator* componentIterator() const { return _allOwnedNodes.createIterator() ; }
00097   const RooArgSet& components() const { return _allOwnedNodes ; }
00098   TObject* genobj(const char* name) const ;
00099   TObject* obj(const char* name) const ;
00100 
00101   // Group accessors
00102   RooArgSet allVars() const;
00103   RooArgSet allCats() const ;
00104   RooArgSet allFunctions() const ;
00105   RooArgSet allCatFunctions() const ;
00106   RooArgSet allPdfs() const ;
00107   RooArgSet allResolutionModels() const ;
00108   std::list<RooAbsData*> allData() const ;
00109   std::list<TObject*> allGenericObjects() const ;
00110 
00111   Bool_t makeDir() ; 
00112   Bool_t cd(const char* path = 0) ;
00113 
00114   Bool_t writeToFile(const char* fileName, Bool_t recreate=kTRUE) ;
00115 
00116 
00117   // Tools management
00118   RooFactoryWSTool& factory() ;
00119   RooAbsArg* factory(const char* expr) ;
00120 
00121   // RooStudyManager modules
00122   Bool_t addStudy(RooAbsStudy& study) ;  
00123   TIterator* studyIterator() { return _studyMods.MakeIterator() ; }
00124   void clearStudies() ;
00125 
00126   // Print function
00127   void Print(Option_t* opts=0) const ;
00128 
00129   static void autoImportClassCode(Bool_t flag) ;
00130  
00131   static void addClassDeclImportDir(const char* dir) ;
00132   static void addClassImplImportDir(const char* dir) ;
00133   static void setClassFileExportDir(const char* dir=0) ; 
00134 
00135   const TUUID& uuid() const { return _uuid ; }
00136 
00137   RooExpensiveObjectCache& expensiveObjectCache() { return _eocache ; }
00138 
00139   class CodeRepo : public TObject {
00140   public:
00141     CodeRepo(RooWorkspace* wspace=0) : _wspace(wspace), _compiledOK(kTRUE) {} ;
00142     virtual ~CodeRepo() {} ;
00143 
00144     Bool_t autoImportClass(TClass* tc, Bool_t doReplace=kFALSE) ;
00145     Bool_t compileClasses() ;
00146 
00147     Bool_t compiledOK() const { return _compiledOK ; }
00148 
00149     std::string listOfClassNames() const ;
00150 
00151     class ClassRelInfo {
00152     public:
00153       TString _baseName;      
00154       TString _fileBase ;
00155     } ;
00156 
00157     class ClassFiles {
00158     public:
00159       ClassFiles() : _extracted(kFALSE) {}
00160       TString _hext ;
00161       TString _hfile ;
00162       TString _cxxfile ;
00163       Bool_t _extracted ; 
00164     } ;    
00165     
00166   protected:
00167     RooWorkspace* _wspace ; // owning workspace
00168     std::map<TString,ClassRelInfo> _c2fmap ; // List of contained classes
00169     std::map<TString,ClassFiles> _fmap ; // List of contained files
00170     Bool_t _compiledOK ; //! Flag indicating that classes compiled OK
00171 
00172     ClassDef(CodeRepo,1) ; // Code repository for RooWorkspace
00173   } ;
00174 
00175 
00176   class WSDir : public TDirectoryFile {    
00177   public:
00178     WSDir(const char* name, const char* title, RooWorkspace* wspace) : 
00179       TDirectoryFile(name,title,"RooWorkspace::WSDir",0), 
00180       _wspace(wspace) 
00181       {
00182       }
00183 
00184     virtual ~WSDir() { Clear("nodelete") ; } ; 
00185 
00186 
00187 #if ROOT_VERSION_CODE <= 332546
00188     virtual void Add(TObject*) ;
00189     virtual void Append(TObject*) ;
00190 #else 
00191     virtual void Add(TObject*,Bool_t) ; 
00192     virtual void Append(TObject*,Bool_t) ; 
00193 #endif 
00194 
00195   protected:
00196     friend class RooWorkspace ;
00197     void InternalAppend(TObject* obj) ;
00198     RooWorkspace* _wspace ; //! do not persist
00199 
00200     ClassDef(WSDir,1) ; // TDirectory representation of RooWorkspace
00201   } ;
00202 
00203 
00204  private:
00205 
00206   Bool_t isValidCPPID(const char* name) ;
00207   void exportObj(TObject* obj) ;
00208   void unExport() ;
00209 
00210   friend class CodeRepo ;
00211   static std::list<std::string> _classDeclDirList ;
00212   static std::list<std::string> _classImplDirList ;
00213   static std::string            _classFileExportDir ;
00214 
00215   TUUID       _uuid ;  // Unique workspace ID
00216 
00217   static Bool_t _autoClass ; // Automatic import of non-distribution class code
00218   
00219   CodeRepo _classes ; // Repository of embedded class code. This data member _must_ be first
00220 
00221   RooArgSet _allOwnedNodes ; // List of owned pdfs and components
00222   RooLinkedList _dataList ; // List of owned datasets
00223   RooLinkedList _views ; // List of model views  
00224   RooLinkedList _snapshots ; // List of parameter snapshots
00225   RooLinkedList _genObjects ; // List of generic objects
00226   RooLinkedList _studyMods ; // List if StudyManager modules
00227   std::map<std::string,RooArgSet> _namedSets ; // Map of named RooArgSets
00228 
00229   WSDir* _dir ; //! Transient ROOT directory representation of workspace
00230 
00231   RooExpensiveObjectCache _eocache ; // Cache for expensive objects  
00232 
00233   RooFactoryWSTool* _factory ; //! Factory tool associated with workspace
00234 
00235   Bool_t      _doExport ;     //! Export contents of workspace to CINT?
00236   std::string _exportNSName ; //! Name of CINT namespace to which contents are exported
00237 
00238   Bool_t      _openTrans ;    //! Is there a transaction open?
00239   RooArgSet   _sandboxNodes ; //! Sandbox for incoming objects in a transaction
00240 
00241   ClassDef(RooWorkspace,7)  // Persistable project container for (composite) pdfs, functions, variables and datasets
00242   
00243 } ;
00244 
00245 #endif

Generated on Tue Jul 5 14:26:28 2011 for ROOT_528-00b_version by  doxygen 1.5.1