Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooWorkspace.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooWorkspace.h,v 1.3 2007/07/16 21:04:28 wouter Exp $
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16#ifndef ROO_WORKSPACE
17#define ROO_WORKSPACE
18
19#include "RooPrintable.h"
20#include "RooArgSet.h"
21#include "RooLinkedList.h"
22#include "RooCmdArg.h"
24#include "TUUID.h"
25#include <map>
26#include <list>
27#include <memory>
28#include <string>
29
30class TClass ;
31class RooAbsPdf ;
32class RooAbsData ;
33class RooRealVar ;
34class RooCategory ;
35class RooAbsReal ;
36class RooAbsCategory ;
37class RooFactoryWSTool ;
38class RooAbsStudy ;
39
40#include "TNamed.h"
41#include "TDirectoryFile.h"
42
43class RooWorkspace : public TNamed {
44public:
45
46 RooWorkspace() ;
47 RooWorkspace(const char* name, bool doCINTExport)
48 R__SUGGEST_ALTERNATIVE("The \"doCINTExport\" argument has no effect anymore since ROOT 6."
49 "Consider using RooWorkspace(const char* name, const char* title=nullptr).");
50 RooWorkspace(const char* name, const char* title=nullptr) ;
52 ~RooWorkspace() override ;
53
54 TObject *Clone(const char *newname="") const override;
55
56 bool importClassCode(const char* pat="*", bool doReplace=false) ;
57 bool importClassCode(TClass* theClass, bool doReplace=false) ;
58
59 // Import functions for dataset, functions, generic objects
60 bool import(const RooAbsArg& arg,
61 const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
62 const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
63 const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
64 bool import(const RooArgSet& args,
65 const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
66 const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
67 const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
68 bool import(RooAbsData const& data,
69 const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
70 const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
71 const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
72 bool import(const char *fileSpec,
73 const RooCmdArg& arg1={},const RooCmdArg& arg2={},const RooCmdArg& arg3={},
74 const RooCmdArg& arg4={},const RooCmdArg& arg5={},const RooCmdArg& arg6={},
75 const RooCmdArg& arg7={},const RooCmdArg& arg8={},const RooCmdArg& arg9={}) ;
76 bool import(TObject const& object, bool replaceExisting=false) ;
77 bool import(TObject const& object, const char* aliasName, bool replaceExisting=false) ;
78
79 // Transaction management interface for multi-step import operations
80 bool startTransaction() ;
81 bool cancelTransaction() ;
82 bool commitTransaction() ;
83
84 // Named set management
85 bool defineSet(const char* name, const RooArgSet& aset, bool importMissing=false) ;
86 bool defineSet(const char* name, const char* contentList) ;
87 bool extendSet(const char* name, const char* newContents) ;
88 bool renameSet(const char* name, const char* newName) ;
89 bool removeSet(const char* name) ;
91 inline const std::map<std::string,RooArgSet>& sets() const { return _namedSets; }
92
93 // Import, load and save parameter value snapshots
94 bool saveSnapshot(RooStringView, const char* paramNames) ;
95 bool saveSnapshot(RooStringView, const RooArgSet& params, bool importValues=false) ;
96 bool loadSnapshot(const char* name) ;
97 const RooArgSet* getSnapshot(const char* name) const ;
98
99 // Retrieve list of parameter snapshots
100 RooLinkedList const& getSnapshots() const { return _snapshots; }
101
102 // Accessor functions
113 const RooArgSet& components() const { return _allOwnedNodes ; }
115 TObject* obj(RooStringView name) const ;
116
117 // Group accessors
118 RooArgSet allVars() const;
119 RooArgSet allCats() const ;
120 RooArgSet allFunctions() const ;
121 RooArgSet allCatFunctions() const ;
122 RooArgSet allPdfs() const ;
124 std::list<RooAbsData*> allData() const ;
125 std::list<RooAbsData*> allEmbeddedData() const ;
126 std::list<TObject*> allGenericObjects() const ;
127
128 bool makeDir() ;
129 bool cd(const char* path = nullptr) ;
130
131 bool writeToFile(const char* fileName, bool recreate=true) ;
132
133 /// Make internal collection use an unordered_map for
134 /// faster searching. Important when large trees are
135 /// imported / or modified in the workspace.
136 /// Note that RooAbsCollection may eventually switch
137 /// this on by itself.
141
142 void RecursiveRemove(TObject *obj) override;
143
144 // Tools management
147
148 // RooStudyManager modules
149 bool addStudy(RooAbsStudy& study) ;
151 void clearStudies() ;
152
153 // Print function
154 void Print(Option_t* opts=nullptr) const override ;
155
156 static void autoImportClassCode(bool flag) ;
157
158 static void addClassDeclImportDir(const char* dir) ;
159 static void addClassImplImportDir(const char* dir) ;
160 static void setClassFileExportDir(const char* dir=nullptr) ;
161
162 const TUUID& uuid() const { return _uuid ; }
163
165
166 class CodeRepo : public TObject {
167 public:
168 CodeRepo(RooWorkspace* wspace=nullptr) : _wspace(wspace), _compiledOK(true) {} ;
169
170 CodeRepo(const CodeRepo& other, RooWorkspace* wspace=nullptr) : TObject(other) ,
171 _wspace(wspace?wspace:other._wspace),
176
177 bool autoImportClass(TClass* tc, bool doReplace=false) ;
178 bool compileClasses() ;
179
180 bool compiledOK() const { return _compiledOK ; }
181
182 std::string listOfClassNames() const ;
183
184
185
191
200
201
203 public:
206 } ;
207
208 protected:
209 RooWorkspace* _wspace ; // owning workspace
210 std::map<TString,ClassRelInfo> _c2fmap ; // List of contained classes
211 std::map<TString,ClassFiles> _fmap ; // List of contained files
212 std::map<TString,ExtraHeader> _ehmap ; // List of extra header files
213 bool _compiledOK ; //! Flag indicating that classes compiled OK
214
215 ClassDefOverride(CodeRepo,2) ; // Code repository for RooWorkspace
216 } ;
217
218
219 class WSDir : public TDirectoryFile {
220 public:
221 WSDir(const char* name, const char* title, RooWorkspace* wspace) :
222 TDirectoryFile(name,title,"RooWorkspace::WSDir",nullptr),
223 _wspace(wspace)
224 {
225 }
226
227 ~WSDir() override { Clear("nodelete") ; }
228
229
230 void Add(TObject*,bool) override ;
231 void Append(TObject*,bool) override ;
232
233 protected:
234 friend class RooWorkspace ;
235 void InternalAppend(TObject* obj) ;
236 RooWorkspace* _wspace ; //! do not persist
237
238 ClassDefOverride(WSDir,1) ; // TDirectory representation of RooWorkspace
239 } ;
240
241
242 private:
243 friend class RooAbsArg;
244 friend class RooAbsPdf;
245 friend class RooConstraintSum;
246 bool defineSetInternal(const char *name, const RooArgSet &aset);
247
248 friend class CodeRepo;
249 static std::list<std::string> _classDeclDirList;
250 static std::list<std::string> _classImplDirList;
251 static std::string _classFileExportDir;
252
253 TUUID _uuid; // Unique workspace ID
254
255 static bool _autoClass; // Automatic import of non-distribution class code
256
257 CodeRepo _classes; // Repository of embedded class code. This data member _must_ be first
258
259 RooArgSet _allOwnedNodes; ///< List of owned pdfs and components
260 RooLinkedList _dataList; ///< List of owned datasets
261 RooLinkedList _embeddedDataList; ///< List of owned datasets that are embedded in pdfs
262 RooLinkedList _views; ///< List of model views
263 RooLinkedList _snapshots; ///< List of parameter snapshots
264 RooLinkedList _genObjects; ///< List of generic objects
265 RooLinkedList _studyMods; ///< List if StudyManager modules
266 std::map<std::string, RooArgSet> _namedSets; ///< Map of named RooArgSets
267
268 WSDir *_dir = nullptr; ///<! Transient ROOT directory representation of workspace
269
270 RooExpensiveObjectCache _eocache; ///< Cache for expensive objects
271
272 std::unique_ptr<RooFactoryWSTool> _factory; ///<! Factory tool associated with workspace
273
274 bool _doExport; ///<! Export contents of workspace to CINT?
275 std::string _exportNSName; ///<! Name of CINT namespace to which contents are exported
276
277 bool _openTrans = false; ///<! Is there a transaction open?
278 RooArgSet _sandboxNodes; ///<! Sandbox for incoming objects in a transaction
279
280 ClassDefOverride(RooWorkspace, 8) // Persistable project container for (composite) pdfs, functions, variables and datasets
281} ;
282
283#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition RConfig.hxx:520
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char name[80]
Definition TGX11.cxx:110
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
A space to attach TBranches.
void useHashMapForFind(bool flag) const
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:32
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
Abstract base class for RooStudyManager modules.
Definition RooAbsStudy.h:33
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Object to represent discrete states.
Definition RooCategory.h:28
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent constraint function...
Singleton class that serves as repository for objects that are expensive to calculate.
Implementation detail of the RooWorkspace.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
Variable that can be changed from the outside.
Definition RooRealVar.h:37
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
std::map< TString, ExtraHeader > _ehmap
CodeRepo(const CodeRepo &other, RooWorkspace *wspace=nullptr)
RooWorkspace * _wspace
std::string listOfClassNames() const
Return STL string with last of class names contained in the code repository.
bool autoImportClass(TClass *tc, bool doReplace=false)
Import code of class 'tc' into the repository.
bool compileClasses()
For all classes in the workspace for which no class definition is found in the ROOT class table extra...
std::map< TString, ClassRelInfo > _c2fmap
CodeRepo(RooWorkspace *wspace=nullptr)
std::map< TString, ClassFiles > _fmap
void InternalAppend(TObject *obj)
Internal access to TDirectory append method.
void Add(TObject *, bool) override
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
WSDir(const char *name, const char *title, RooWorkspace *wspace)
RooWorkspace * _wspace
void Append(TObject *, bool) override
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
Persistable container for RooFit projects.
RooExpensiveObjectCache _eocache
Cache for expensive objects.
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooLinkedList _genObjects
List of generic objects.
static bool _autoClass
std::string _exportNSName
! Name of CINT namespace to which contents are exported
static std::list< std::string > _classDeclDirList
const RooArgSet * getSnapshot(const char *name) const
Return the RooArgSet containing a snapshot of variables contained in the workspace.
static void addClassDeclImportDir(const char *dir)
Add dir to search path for class declaration (header) files.
void Print(Option_t *opts=nullptr) const override
Print contents of the workspace.
RooLinkedList _dataList
List of owned datasets.
RooAbsCategory * catfunc(RooStringView name) const
Retrieve discrete function (RooAbsCategory) with given name. A null pointer is returned if not found.
WSDir * _dir
! Transient ROOT directory representation of workspace
static void addClassImplImportDir(const char *dir)
Add dir to search path for class implementation (.cxx) files.
RooAbsPdf * pdf(RooStringView name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
std::map< std::string, RooArgSet > _namedSets
Map of named RooArgSets.
RooAbsData * embeddedData(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
RooCategory * cat(RooStringView name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
void clearStudies()
Remove all RooStudyManager modules.
bool renameSet(const char *name, const char *newName)
Rename set to a new name.
void useFindsWithHashLookup(bool flag)
Make internal collection use an unordered_map for faster searching.
std::unique_ptr< RooFactoryWSTool > _factory
! Factory tool associated with workspace
RooArgSet allVars() const
Return set with all variable objects.
RooArgSet argSet(RooStringView nameList) const
Return set of RooAbsArgs matching to given list of names.
bool writeToFile(const char *fileName, bool recreate=true)
Save this current workspace into given file.
const RooArgSet * set(RooStringView name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
bool cd(const char *path=nullptr)
RooArgSet allCats() const
Return set with all category objects.
void RecursiveRemove(TObject *obj) override
If one of the TObject we have a referenced to is deleted, remove the reference.
RooAbsArg * fundArg(RooStringView name) const
Return fundamental (i.e.
bool _doExport
! Export contents of workspace to CINT?
RooLinkedList _views
List of model views.
bool commitTransaction()
Commit an ongoing import transaction.
~RooWorkspace() override
Workspace destructor.
const std::map< std::string, RooArgSet > & sets() const
TIterator * studyIterator()
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
TObject * Clone(const char *newname="") const override
TObject::Clone() needs to be overridden.
RooArgSet allResolutionModels() const
Return set with all resolution model objects.
RooLinkedList _snapshots
List of parameter snapshots.
bool saveSnapshot(RooStringView, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
RooArgSet allPdfs() const
Return set with all probability density function objects.
TObject * genobj(RooStringView name) const
Return generic object with given name.
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
RooLinkedList const & getSnapshots() const
RooLinkedList _studyMods
List if StudyManager modules.
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
static void setClassFileExportDir(const char *dir=nullptr)
Specify the name of the directory in which embedded source code is unpacked and compiled.
bool importClassCode(const char *pat="*", bool doReplace=false)
Import code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
bool makeDir()
Create transient TDirectory representation of this workspace.
RooArgSet allCatFunctions() const
Return set with all category function objects.
static std::string _classFileExportDir
static std::list< std::string > _classImplDirList
RooAbsReal * function(RooStringView name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
RooAbsArg * arg(RooStringView name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
RooWorkspace()
Default constructor.
bool removeSet(const char *name)
Remove a named set from the workspace.
CodeRepo _classes
const RooArgSet & components() const
RooArgSet allFunctions() const
Return set with all function objects.
RooFactoryWSTool & factory()
Return instance to factory tool.
bool extendSet(const char *name, const char *newContents)
Define a named set in the workspace through a comma separated list of names of objects already in the...
RooExpensiveObjectCache & expensiveObjectCache()
RooArgSet _sandboxNodes
! Sandbox for incoming objects in a transaction
bool defineSetInternal(const char *name, const RooArgSet &aset)
bool _openTrans
! Is there a transaction open?
const TUUID & uuid() const
RooRealVar * var(RooStringView name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
bool addStudy(RooAbsStudy &study)
Insert RooStudyManager module.
static void autoImportClassCode(bool flag)
If flag is true, source code of classes not the ROOT distribution is automatically imported if on obj...
RooLinkedList _embeddedDataList
List of owned datasets that are embedded in pdfs.
RooArgSet _allOwnedNodes
List of owned pdfs and components.
std::list< RooAbsData * > allEmbeddedData() const
Return list of all dataset in the workspace.
bool loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
bool defineSet(const char *name, const RooArgSet &aset, bool importMissing=false)
Define a named RooArgSet with given constituents.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
A ROOT file is structured in Directories (like a file system).
void Clear(Option_t *option="") override
Delete all objects from a Directory list.
Iterator abstract base class.
Definition TIterator.h:30
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:138
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition TUUID.h:42