Logo ROOT  
Reference Guide
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 \"doCINTExprot\" 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) ;
51 RooWorkspace(const RooWorkspace& other) ;
52 ~RooWorkspace() override ;
53
54 bool importClassCode(const char* pat="*", bool doReplace=false) ;
55 bool importClassCode(TClass* theClass, bool doReplace=false) ;
56
57 // Import functions for dataset, functions, generic objects
58 bool import(const RooAbsArg& arg,
59 const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg(),
60 const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),
61 const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg(),const RooCmdArg& arg9=RooCmdArg()) ;
62 bool import(const RooArgSet& args,
63 const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg(),
64 const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),
65 const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg(),const RooCmdArg& arg9=RooCmdArg()) ;
66 bool import(RooAbsData& data,
67 const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg(),
68 const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),
69 const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg(),const RooCmdArg& arg9=RooCmdArg()) ;
70 bool import(const char *fileSpec,
71 const RooCmdArg& arg1=RooCmdArg(),const RooCmdArg& arg2=RooCmdArg(),const RooCmdArg& arg3=RooCmdArg(),
72 const RooCmdArg& arg4=RooCmdArg(),const RooCmdArg& arg5=RooCmdArg(),const RooCmdArg& arg6=RooCmdArg(),
73 const RooCmdArg& arg7=RooCmdArg(),const RooCmdArg& arg8=RooCmdArg(),const RooCmdArg& arg9=RooCmdArg()) ;
74 bool import(TObject& object, bool replaceExisting=false) ;
75 bool import(TObject& object, const char* aliasName, bool replaceExisting=false) ;
76
77 // Transaction management interface for multi-step import operations
78 bool startTransaction() ;
79 bool cancelTransaction() ;
80 bool commitTransaction() ;
81
82 // Named set management
83 bool defineSet(const char* name, const RooArgSet& aset, bool importMissing=false) ;
84 bool defineSet(const char* name, const char* contentList) ;
85 bool extendSet(const char* name, const char* newContents) ;
86 bool renameSet(const char* name, const char* newName) ;
87 bool removeSet(const char* name) ;
88 const RooArgSet* set(const char* name) ;
89 inline const std::map<std::string,RooArgSet>& sets() const { return _namedSets; }
90
91 // Import, load and save parameter value snapshots
92 bool saveSnapshot(const char* name, const char* paramNames) ;
93 bool saveSnapshot(const char* name, const RooArgSet& params, bool importValues=false) ;
94 bool loadSnapshot(const char* name) ;
95 const RooArgSet* getSnapshot(const char* name) const ;
96
97 // Retrieve list of parameter snapshots
98 RooLinkedList const& getSnapshots() const { return _snapshots; }
99
100 void merge(const RooWorkspace& /*other*/) {} ;
101
102 // Accessor functions
112 RooArgSet argSet(RooStringView nameList) const ;
114 R__SUGGEST_ALTERNATIVE("Better iterate over RooWorkspace::components() with range-based loop instead of using RooWorkspace::componentIterator().")
115 { return _allOwnedNodes.createIterator() ; }
116 const RooArgSet& components() const { return _allOwnedNodes ; }
118 TObject* obj(RooStringView name) const ;
119
120 // Group accessors
121 RooArgSet allVars() const;
122 RooArgSet allCats() const ;
123 RooArgSet allFunctions() const ;
124 RooArgSet allCatFunctions() const ;
125 RooArgSet allPdfs() const ;
127 std::list<RooAbsData*> allData() const ;
128 std::list<RooAbsData*> allEmbeddedData() const ;
129 std::list<TObject*> allGenericObjects() const ;
130
131 bool makeDir() ;
132 bool cd(const char* path = nullptr) ;
133
134 bool writeToFile(const char* fileName, bool recreate=true) ;
135
136 /// Make internal collection use an unordered_map for
137 /// faster searching. Important when large trees are
138 /// imported / or modified in the workspace.
139 /// Note that RooAbsCollection may eventually switch
140 /// this on by itself.
141 void useFindsWithHashLookup(bool flag) {
143 }
144
145 void RecursiveRemove(TObject *obj) override;
146
147 // Tools management
150
151 // RooStudyManager modules
152 bool addStudy(RooAbsStudy& study) ;
154 void clearStudies() ;
155
156 // Print function
157 void Print(Option_t* opts=nullptr) const override ;
158
159 static void autoImportClassCode(bool flag) ;
160
161 static void addClassDeclImportDir(const char* dir) ;
162 static void addClassImplImportDir(const char* dir) ;
163 static void setClassFileExportDir(const char* dir=nullptr) ;
164
165 const TUUID& uuid() const { return _uuid ; }
166
168
169 class CodeRepo : public TObject {
170 public:
171 CodeRepo(RooWorkspace* wspace=nullptr) : _wspace(wspace), _compiledOK(true) {} ;
172
173 CodeRepo(const CodeRepo& other, RooWorkspace* wspace=nullptr) : TObject(other) ,
174 _wspace(wspace?wspace:other._wspace),
175 _c2fmap(other._c2fmap),
176 _fmap(other._fmap),
177 _ehmap(other._ehmap),
178 _compiledOK(other._compiledOK) {} ;
179
180 ~CodeRepo() override {} ;
181
182 bool autoImportClass(TClass* tc, bool doReplace=false) ;
183 bool compileClasses() ;
184
185 bool compiledOK() const { return _compiledOK ; }
186
187 std::string listOfClassNames() const ;
188
189
190
192 public:
195 } ;
196
198 public:
199 ClassFiles() : _extracted(false) {}
204 } ;
205
206
208 public:
211 } ;
212
213 protected:
214 RooWorkspace* _wspace ; // owning workspace
215 std::map<TString,ClassRelInfo> _c2fmap ; // List of contained classes
216 std::map<TString,ClassFiles> _fmap ; // List of contained files
217 std::map<TString,ExtraHeader> _ehmap ; // List of extra header files
218 bool _compiledOK ; //! Flag indicating that classes compiled OK
219
220 ClassDefOverride(CodeRepo,2) ; // Code repository for RooWorkspace
221 } ;
222
223
224 class WSDir : public TDirectoryFile {
225 public:
226 WSDir(const char* name, const char* title, RooWorkspace* wspace) :
227 TDirectoryFile(name,title,"RooWorkspace::WSDir",nullptr),
228 _wspace(wspace)
229 {
230 }
231
232 ~WSDir() override { Clear("nodelete") ; }
233
234
235 void Add(TObject*,bool) override ;
236 void Append(TObject*,bool) override ;
237
238 protected:
239 friend class RooWorkspace ;
240 void InternalAppend(TObject* obj) ;
241 RooWorkspace* _wspace ; //! do not persist
242
243 ClassDefOverride(WSDir,1) ; // TDirectory representation of RooWorkspace
244 } ;
245
246
247 private:
248 friend class RooAbsArg;
249 friend class RooAbsPdf;
250 friend class RooConstraintSum;
251 bool defineSetInternal(const char *name, const RooArgSet &aset);
252
253 friend class CodeRepo;
254 static std::list<std::string> _classDeclDirList;
255 static std::list<std::string> _classImplDirList;
256 static std::string _classFileExportDir;
257
258 TUUID _uuid; // Unique workspace ID
259
260 static bool _autoClass; // Automatic import of non-distribution class code
261
262 CodeRepo _classes; // Repository of embedded class code. This data member _must_ be first
263
264 RooArgSet _allOwnedNodes; ///< List of owned pdfs and components
265 RooLinkedList _dataList; ///< List of owned datasets
266 RooLinkedList _embeddedDataList; ///< List of owned datasets that are embedded in pdfs
267 RooLinkedList _views; ///< List of model views
268 RooLinkedList _snapshots; ///< List of parameter snapshots
269 RooLinkedList _genObjects; ///< List of generic objects
270 RooLinkedList _studyMods; ///< List if StudyManager modules
271 std::map<std::string, RooArgSet> _namedSets; ///< Map of named RooArgSets
272
273 WSDir *_dir = nullptr; ///<! Transient ROOT directory representation of workspace
274
275 RooExpensiveObjectCache _eocache; ///< Cache for expensive objects
276
277 std::unique_ptr<RooFactoryWSTool> _factory; ///<! Factory tool associated with workspace
278
279 bool _doExport; ///<! Export contents of workspace to CINT?
280 std::string _exportNSName; ///<! Name of CINT namespace to which contents are exported
281
282 bool _openTrans = false; ///<! Is there a transaction open?
283 RooArgSet _sandboxNodes; ///<! Sandbox for incoming objects in a transaction
284
285 ClassDefOverride(RooWorkspace, 8) // Persistable project container for (composite) pdfs, functions, variables and datasets
286} ;
287
288#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition: RConfig.hxx:524
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
A space to attach TBranches.
void useHashMapForFind(bool flag) const
TIterator * createIterator(bool dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:61
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:60
RooAbsStudy is an abstract base class for RooStudyManager modules.
Definition: RooAbsStudy.h:33
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:56
RooCategory is an object to represent discrete states.
Definition: RooCategory.h:28
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
RooConstraintSum calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent co...
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
RooFactoryWSTool is a class similar to TTree::MakeClass() that generates skeleton code for RooAbsPdf ...
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
TIterator * MakeIterator(bool forward=true) const
Create a TIterator for this list.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:40
The RooStringView is a wrapper around a C-syle string that can also be constructed from a std::string...
Definition: RooStringView.h:27
std::map< TString, ExtraHeader > _ehmap
Definition: RooWorkspace.h:217
CodeRepo(const CodeRepo &other, RooWorkspace *wspace=nullptr)
Definition: RooWorkspace.h:173
RooWorkspace * _wspace
Definition: RooWorkspace.h:214
std::string listOfClassNames() const
Return STL string with last of class names contained in the code repository.
bool compiledOK() const
Definition: RooWorkspace.h:185
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
Definition: RooWorkspace.h:215
CodeRepo(RooWorkspace *wspace=nullptr)
Definition: RooWorkspace.h:171
std::map< TString, ClassFiles > _fmap
Definition: RooWorkspace.h:216
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)
Definition: RooWorkspace.h:226
RooWorkspace * _wspace
Definition: RooWorkspace.h:241
void Append(TObject *, bool) override
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
RooExpensiveObjectCache _eocache
Cache for expensive objects.
Definition: RooWorkspace.h:275
TObject * obj(RooStringView name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
RooLinkedList _genObjects
List of generic objects.
Definition: RooWorkspace.h:269
static bool _autoClass
Definition: RooWorkspace.h:260
std::string _exportNSName
! Name of CINT namespace to which contents are exported
Definition: RooWorkspace.h:280
static std::list< std::string > _classDeclDirList
Definition: RooWorkspace.h:254
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.
Definition: RooWorkspace.h:265
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
Definition: RooWorkspace.h:273
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.
Definition: RooWorkspace.h:271
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.
Definition: RooWorkspace.h:141
std::unique_ptr< RooFactoryWSTool > _factory
! Factory tool associated with workspace
Definition: RooWorkspace.h:277
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.
bool saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
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?
Definition: RooWorkspace.h:279
RooLinkedList _views
List of model views.
Definition: RooWorkspace.h:267
bool commitTransaction()
~RooWorkspace() override
Workspace destructor.
const std::map< std::string, RooArgSet > & sets() const
Definition: RooWorkspace.h:89
TIterator * studyIterator()
Definition: RooWorkspace.h:153
bool cancelTransaction()
Cancel an ongoing import transaction.
bool startTransaction()
Open an import transaction operations.
RooArgSet allResolutionModels() const
Return set with all resolution model objects.
RooLinkedList _snapshots
List of parameter snapshots.
Definition: RooWorkspace.h:268
void merge(const RooWorkspace &)
Definition: RooWorkspace.h:100
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
Definition: RooWorkspace.h:98
RooLinkedList _studyMods
List if StudyManager modules.
Definition: RooWorkspace.h:270
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)
Inport 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
Definition: RooWorkspace.h:256
static std::list< std::string > _classImplDirList
Definition: RooWorkspace.h:255
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
Definition: RooWorkspace.h:262
const RooArgSet & components() const
Definition: RooWorkspace.h:116
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 work space through a comma separated list of names of objects already in th...
RooExpensiveObjectCache & expensiveObjectCache()
Definition: RooWorkspace.h:167
RooArgSet _sandboxNodes
! Sandbox for incoming objects in a transaction
Definition: RooWorkspace.h:283
bool defineSetInternal(const char *name, const RooArgSet &aset)
bool _openTrans
! Is there a transaction open?
Definition: RooWorkspace.h:282
const TUUID & uuid() const
Definition: RooWorkspace.h:165
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.
Definition: RooWorkspace.h:266
RooArgSet _allOwnedNodes
List of owned pdfs and components.
Definition: RooWorkspace.h:264
RooAbsData * data(RooStringView name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
const RooArgSet * set(const char *name)
Return pointer to previously defined named set with given nmame If no such set is found a null pointe...
std::list< RooAbsData * > allEmbeddedData() const
Return list of all dataset in the workspace.
TIterator * componentIterator() const
Definition: RooWorkspace.h:113
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:81
A ROOT file is structured in Directories (like a file system).
void Clear(Option_t *option="") override
Delete all objects from a Directory list.
Definition: TDirectory.cxx:629
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:136
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition: TUUID.h:42
int iterate(rng_state_t *X)
Definition: mixmax.icc:34