Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooWorkspace.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooWorkspace.h,v 1.3 2007/07/16 21:04:28 wouter Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_WORKSPACE
0017 #define ROO_WORKSPACE
0018 
0019 #include "RooPrintable.h"
0020 #include "RooArgSet.h"
0021 #include "RooLinkedList.h"
0022 #include "RooCmdArg.h"
0023 #include "RooExpensiveObjectCache.h"
0024 #include "TUUID.h"
0025 #include <map>
0026 #include <list>
0027 #include <memory>
0028 #include <string>
0029 
0030 class TClass ;
0031 class RooAbsPdf ;
0032 class RooAbsData ;
0033 class RooRealVar ;
0034 class RooCategory ;
0035 class RooAbsReal ;
0036 class RooAbsCategory ;
0037 class RooFactoryWSTool ;
0038 class RooAbsStudy ;
0039 
0040 #include "TNamed.h"
0041 #include "TDirectoryFile.h"
0042 
0043 class RooWorkspace : public TNamed {
0044 public:
0045 
0046   RooWorkspace() ;
0047   RooWorkspace(const char* name, bool doCINTExport)
0048   R__SUGGEST_ALTERNATIVE("The \"doCINTExport\" argument has no effect anymore since ROOT 6."
0049           "Consider using RooWorkspace(const char* name, const char* title=nullptr).");
0050   RooWorkspace(const char* name, const char* title=nullptr) ;
0051   RooWorkspace(const RooWorkspace& other) ;
0052   ~RooWorkspace() override ;
0053 
0054   TObject *Clone(const char *newname="") const override;
0055 
0056   bool importClassCode(const char* pat="*", bool doReplace=false) ;
0057   bool importClassCode(TClass* theClass, bool doReplace=false) ;
0058 
0059   // Import functions for dataset, functions, generic objects
0060   bool import(const RooAbsArg& arg,
0061       const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
0062       const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
0063       const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
0064   bool import(const RooArgSet& args,
0065       const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
0066       const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
0067       const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
0068   bool import(RooAbsData const& data,
0069       const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
0070       const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
0071       const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
0072   bool import(const char *fileSpec,
0073       const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
0074       const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
0075       const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
0076   bool import(TObject const& object, bool replaceExisting=false) ;
0077   bool import(TObject const& object, const char* aliasName, bool replaceExisting=false) ;
0078 
0079   // Transaction management interface for multi-step import operations
0080   bool startTransaction() ;
0081   bool cancelTransaction() ;
0082   bool commitTransaction() ;
0083 
0084   // Named set management
0085   bool defineSet(const char* name, const RooArgSet& aset, bool importMissing=false) ;
0086   bool defineSet(const char* name, const char* contentList) ;
0087   bool extendSet(const char* name, const char* newContents) ;
0088   bool renameSet(const char* name, const char* newName) ;
0089   bool removeSet(const char* name) ;
0090   const RooArgSet* set(RooStringView name) ;
0091   inline const std::map<std::string,RooArgSet>& sets() const { return _namedSets; }
0092 
0093   // Import, load and save parameter value snapshots
0094   bool saveSnapshot(RooStringView, const char* paramNames) ;
0095   bool saveSnapshot(RooStringView, const RooArgSet& params, bool importValues=false) ;
0096   bool loadSnapshot(const char* name) ;
0097   const RooArgSet* getSnapshot(const char* name) const ;
0098 
0099   // Retrieve list of parameter snapshots
0100   RooLinkedList const& getSnapshots() const { return _snapshots; }
0101 
0102   // Accessor functions
0103   RooAbsPdf* pdf(RooStringView name) const ;
0104   RooAbsReal* function(RooStringView name) const ;
0105   RooRealVar* var(RooStringView name) const ;
0106   RooCategory* cat(RooStringView name) const ;
0107   RooAbsCategory* catfunc(RooStringView name) const ;
0108   RooAbsData* data(RooStringView name) const ;
0109   RooAbsData* embeddedData(RooStringView name) const ;
0110   RooAbsArg* arg(RooStringView name) const ;
0111   RooAbsArg* fundArg(RooStringView name) const ;
0112   RooArgSet argSet(RooStringView nameList) const ;
0113   const RooArgSet& components() const { return _allOwnedNodes ; }
0114   TObject* genobj(RooStringView name) const ;
0115   TObject* obj(RooStringView name) const ;
0116 
0117   // Group accessors
0118   RooArgSet allVars() const;
0119   RooArgSet allCats() const ;
0120   RooArgSet allFunctions() const ;
0121   RooArgSet allCatFunctions() const ;
0122   RooArgSet allPdfs() const ;
0123   RooArgSet allResolutionModels() const ;
0124   std::list<RooAbsData*> allData() const ;
0125   std::list<RooAbsData*> allEmbeddedData() const ;
0126   std::list<TObject*> allGenericObjects() const ;
0127 
0128   bool makeDir() ;
0129   bool cd(const char* path = nullptr) ;
0130 
0131   bool writeToFile(const char* fileName, bool recreate=true) ;
0132 
0133   /// Make internal collection use an unordered_map for
0134   /// faster searching. Important when large trees are
0135   /// imported / or modified in the workspace.
0136   /// Note that RooAbsCollection may eventually switch
0137   /// this on by itself.
0138   void useFindsWithHashLookup(bool flag) {
0139     _allOwnedNodes.useHashMapForFind(flag);
0140   }
0141 
0142   void RecursiveRemove(TObject *obj) override;
0143 
0144   // Tools management
0145   RooFactoryWSTool& factory() ;
0146   RooAbsArg* factory(RooStringView expr) ;
0147 
0148   // RooStudyManager modules
0149   bool addStudy(RooAbsStudy& study) ;
0150   TIterator* studyIterator() { return _studyMods.MakeIterator() ; }
0151   void clearStudies() ;
0152 
0153   // Print function
0154   void Print(Option_t* opts=nullptr) const override ;
0155 
0156   static void autoImportClassCode(bool flag) ;
0157 
0158   static void addClassDeclImportDir(const char* dir) ;
0159   static void addClassImplImportDir(const char* dir) ;
0160   static void setClassFileExportDir(const char* dir=nullptr) ;
0161 
0162   const TUUID& uuid() const { return _uuid ; }
0163 
0164   RooExpensiveObjectCache& expensiveObjectCache() { return _eocache ; }
0165 
0166   class CodeRepo : public TObject {
0167   public:
0168     CodeRepo(RooWorkspace* wspace=nullptr) : _wspace(wspace), _compiledOK(true) {} ;
0169 
0170     CodeRepo(const CodeRepo& other, RooWorkspace* wspace=nullptr) : TObject(other) ,
0171           _wspace(wspace?wspace:other._wspace),
0172           _c2fmap(other._c2fmap),
0173           _fmap(other._fmap),
0174           _ehmap(other._ehmap),
0175           _compiledOK(other._compiledOK) {} ;
0176 
0177     bool autoImportClass(TClass* tc, bool doReplace=false) ;
0178     bool compileClasses() ;
0179 
0180     bool compiledOK() const { return _compiledOK ; }
0181 
0182     std::string listOfClassNames() const ;
0183 
0184 
0185 
0186     class ClassRelInfo {
0187     public:
0188       TString _baseName;
0189       TString _fileBase ;
0190     } ;
0191 
0192     class ClassFiles {
0193     public:
0194       ClassFiles() : _extracted(false) {}
0195       TString _hext ;
0196       TString _hfile ;
0197       TString _cxxfile ;
0198       bool _extracted ;
0199     } ;
0200 
0201 
0202     class ExtraHeader {
0203     public:
0204       TString _hname ;
0205       TString _hfile ;
0206    } ;
0207 
0208   protected:
0209     RooWorkspace* _wspace ; // owning workspace
0210     std::map<TString,ClassRelInfo> _c2fmap ; // List of contained classes
0211     std::map<TString,ClassFiles> _fmap ; // List of contained files
0212     std::map<TString,ExtraHeader> _ehmap ; // List of extra header files
0213     bool _compiledOK ; //! Flag indicating that classes compiled OK
0214 
0215     ClassDefOverride(CodeRepo,2) ; // Code repository for RooWorkspace
0216   } ;
0217 
0218 
0219   class WSDir : public TDirectoryFile {
0220   public:
0221     WSDir(const char* name, const char* title, RooWorkspace* wspace) :
0222       TDirectoryFile(name,title,"RooWorkspace::WSDir",nullptr),
0223       _wspace(wspace)
0224       {
0225       }
0226 
0227     ~WSDir() override { Clear("nodelete") ; }
0228 
0229 
0230     void Add(TObject*,bool) override ;
0231     void Append(TObject*,bool) override ;
0232 
0233   protected:
0234     friend class RooWorkspace ;
0235     void InternalAppend(TObject* obj) ;
0236     RooWorkspace* _wspace ; //! do not persist
0237 
0238     ClassDefOverride(WSDir,1) ; // TDirectory representation of RooWorkspace
0239   } ;
0240 
0241 
0242  private:
0243     friend class RooAbsArg;
0244     friend class RooAbsPdf;
0245     friend class RooConstraintSum;
0246     bool defineSetInternal(const char *name, const RooArgSet &aset);
0247 
0248     friend class CodeRepo;
0249     static std::list<std::string> _classDeclDirList;
0250     static std::list<std::string> _classImplDirList;
0251     static std::string _classFileExportDir;
0252 
0253     TUUID _uuid; // Unique workspace ID
0254 
0255     static bool _autoClass; // Automatic import of non-distribution class code
0256 
0257     CodeRepo _classes; // Repository of embedded class code. This data member _must_ be first
0258 
0259     RooArgSet _allOwnedNodes;                    ///< List of owned pdfs and components
0260     RooLinkedList _dataList;                     ///< List of owned datasets
0261     RooLinkedList _embeddedDataList;             ///< List of owned datasets that are embedded in pdfs
0262     RooLinkedList _views;                        ///< List of model views
0263     RooLinkedList _snapshots;                    ///< List of parameter snapshots
0264     RooLinkedList _genObjects;                   ///< List of generic objects
0265     RooLinkedList _studyMods;                    ///< List if StudyManager modules
0266     std::map<std::string, RooArgSet> _namedSets; ///< Map of named RooArgSets
0267 
0268     WSDir *_dir = nullptr; ///<! Transient ROOT directory representation of workspace
0269 
0270     RooExpensiveObjectCache _eocache; ///< Cache for expensive objects
0271 
0272     std::unique_ptr<RooFactoryWSTool> _factory; ///<! Factory tool associated with workspace
0273 
0274     bool _doExport;          ///<! Export contents of workspace to CINT?
0275     std::string _exportNSName; ///<! Name of CINT namespace to which contents are exported
0276 
0277     bool _openTrans = false; ///<! Is there a transaction open?
0278     RooArgSet _sandboxNodes; ///<! Sandbox for incoming objects in a transaction
0279 
0280     ClassDefOverride(RooWorkspace, 8) // Persistable project container for (composite) pdfs, functions, variables and datasets
0281 } ;
0282 
0283 #endif