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 <string>
28#include "ROOT/RMakeUnique.hxx"
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_t doCINTExport) ;
48 RooWorkspace(const char* name, const char* title=0) ;
49 RooWorkspace(const RooWorkspace& other) ;
51
52 void exportToCint(const char* namespaceName=0) ;
53
54 Bool_t importClassCode(const char* pat="*", Bool_t doReplace=kFALSE) ;
55 Bool_t importClassCode(TClass* theClass, Bool_t doReplace=kFALSE) ;
56
57 // Import functions for dataset, functions, generic objects
58 Bool_t 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_t 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_t 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_t 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_t import(TObject& object, Bool_t replaceExisting=kFALSE) ;
75 Bool_t import(TObject& object, const char* aliasName, Bool_t replaceExisting=kFALSE) ;
76
77 // Transaction management interface for multi-step import operations
81
82 // Named set management
83 Bool_t defineSet(const char* name, const RooArgSet& aset, Bool_t importMissing=kFALSE) ;
84 Bool_t defineSet(const char* name, const char* contentList) ;
85 Bool_t extendSet(const char* name, const char* newContents) ;
86 Bool_t renameSet(const char* name, const char* newName) ;
87 Bool_t removeSet(const char* name) ;
88 const RooArgSet* set(const char* name) ;
89
90 // Import, load and save parameter value snapshots
91 Bool_t saveSnapshot(const char* name, const char* paramNames) ;
92 Bool_t saveSnapshot(const char* name, const RooArgSet& params, Bool_t importValues=kFALSE) ;
93 Bool_t loadSnapshot(const char* name) ;
94 const RooArgSet* getSnapshot(const char* name) const ;
95
96 void merge(const RooWorkspace& /*other*/) {} ;
97
98 // Join p.d.f.s and datasets for simultaneous analysis
99 // RooAbsPdf* joinPdf(const char* jointPdfName, const char* indexName, const char* inputMapping) ;
100 // RooAbsData* joinData(const char* jointDataName, const char* indexName, const char* inputMapping) ;
101
102 // Accessor functions
103 RooAbsPdf* pdf(const char* name) const ;
104 RooAbsReal* function(const char* name) const ;
105 RooRealVar* var(const char* name) const ;
106 RooCategory* cat(const char* name) const ;
107 RooAbsCategory* catfunc(const char* name) const ;
108 RooAbsData* data(const char* name) const ;
109 RooAbsData* embeddedData(const char* name) const ;
110 RooAbsArg* arg(const char* name) const ;
111 RooAbsArg* fundArg(const char* name) const ;
112 RooArgSet argSet(const char* nameList) const ;
114 const RooArgSet& components() const { return _allOwnedNodes ; }
115 TObject* genobj(const char* name) const ;
116 TObject* obj(const char* name) const ;
117
118 // Group accessors
119 RooArgSet allVars() const;
120 RooArgSet allCats() const ;
121 RooArgSet allFunctions() const ;
122 RooArgSet allCatFunctions() const ;
123 RooArgSet allPdfs() const ;
125 std::list<RooAbsData*> allData() const ;
126 std::list<RooAbsData*> allEmbeddedData() const ;
127 std::list<TObject*> allGenericObjects() const ;
128
129 Bool_t makeDir() ;
130 Bool_t cd(const char* path = 0) ;
131
132 Bool_t writeToFile(const char* fileName, Bool_t recreate=kTRUE) ;
133
134 virtual void RecursiveRemove(TObject *obj);
135
136 // Tools management
138 RooAbsArg* factory(const char* expr) ;
139
140 // RooStudyManager modules
141 Bool_t addStudy(RooAbsStudy& study) ;
143 void clearStudies() ;
144
145 // Print function
146 void Print(Option_t* opts=0) const ;
147
148 static void autoImportClassCode(Bool_t flag) ;
149
150 static void addClassDeclImportDir(const char* dir) ;
151 static void addClassImplImportDir(const char* dir) ;
152 static void setClassFileExportDir(const char* dir=0) ;
153
154 const TUUID& uuid() const { return _uuid ; }
155
157
158 class CodeRepo : public TObject {
159 public:
160 CodeRepo(RooWorkspace* wspace=0) : _wspace(wspace), _compiledOK(kTRUE) {} ;
161
162 CodeRepo(const CodeRepo& other, RooWorkspace* wspace=0) : TObject(other) ,
163 _wspace(wspace?wspace:other._wspace),
164 _c2fmap(other._c2fmap),
165 _fmap(other._fmap),
166 _ehmap(other._ehmap),
167 _compiledOK(other._compiledOK) {} ;
168
169 virtual ~CodeRepo() {} ;
170
171 Bool_t autoImportClass(TClass* tc, Bool_t doReplace=kFALSE) ;
173
174 Bool_t compiledOK() const { return _compiledOK ; }
175
176 std::string listOfClassNames() const ;
177
178
179
181 public:
184 } ;
185
187 public:
193 } ;
194
195
196 class ExtraHeader {
197 public:
200 } ;
201
202 protected:
203 RooWorkspace* _wspace ; // owning workspace
204 std::map<TString,ClassRelInfo> _c2fmap ; // List of contained classes
205 std::map<TString,ClassFiles> _fmap ; // List of contained files
206 std::map<TString,ExtraHeader> _ehmap ; // List of extra header files
207 Bool_t _compiledOK ; //! Flag indicating that classes compiled OK
208
209 ClassDef(CodeRepo,2) ; // Code repository for RooWorkspace
210 } ;
211
212
213 class WSDir : public TDirectoryFile {
214 public:
215 WSDir(const char* name, const char* title, RooWorkspace* wspace) :
216 TDirectoryFile(name,title,"RooWorkspace::WSDir",0),
217 _wspace(wspace)
218 {
219 }
220
221 virtual ~WSDir() { Clear("nodelete") ; } ;
222
223
224 virtual void Add(TObject*,Bool_t) ;
225 virtual void Append(TObject*,Bool_t) ;
226
227 protected:
228 friend class RooWorkspace ;
229 void InternalAppend(TObject* obj) ;
230 RooWorkspace* _wspace ; //! do not persist
231
232 ClassDef(WSDir,1) ; // TDirectory representation of RooWorkspace
233 } ;
234
235
236 private:
237 friend class RooAbsArg;
238 friend class RooAbsPdf;
239 Bool_t defineSetInternal(const char *name, const RooArgSet &aset);
240
241 Bool_t isValidCPPID(const char *name);
242 void exportObj(TObject *obj);
243 void unExport();
244
245 friend class CodeRepo;
246 static std::list<std::string> _classDeclDirList;
247 static std::list<std::string> _classImplDirList;
248 static std::string _classFileExportDir;
249
250 TUUID _uuid; // Unique workspace ID
251
252 static Bool_t _autoClass; // Automatic import of non-distribution class code
253
254 CodeRepo _classes; // Repository of embedded class code. This data member _must_ be first
255
256 RooArgSet _allOwnedNodes; // List of owned pdfs and components
257 RooLinkedList _dataList; // List of owned datasets
258 RooLinkedList _embeddedDataList; // List of owned datasets that are embedded in pdfs
259 RooLinkedList _views; // List of model views
260 RooLinkedList _snapshots; // List of parameter snapshots
261 RooLinkedList _genObjects; // List of generic objects
262 RooLinkedList _studyMods; // List if StudyManager modules
263 std::map<std::string, RooArgSet> _namedSets; // Map of named RooArgSets
264
265 WSDir *_dir; //! Transient ROOT directory representation of workspace
266
267 RooExpensiveObjectCache _eocache; // Cache for expensive objects
268
269 std::unique_ptr<RooFactoryWSTool> _factory; //! Factory tool associated with workspace
270
271 Bool_t _doExport; //! Export contents of workspace to CINT?
272 std::string _exportNSName; //! Name of CINT namespace to which contents are exported
273
274 Bool_t _openTrans; //! Is there a transaction open?
275 RooArgSet _sandboxNodes; //! Sandbox for incoming objects in a transaction
276
277 ClassDef(RooWorkspace, 8) // Persistable project container for (composite) pdfs, functions, variables and datasets
278} ;
279
280#endif
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:39
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:59
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:28
RooCategory represents a fundamental (non-derived) discrete value object.
Definition: RooCategory.h:24
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
RooExpensiveObjectCache is a singleton class that serves as repository for objects that are expensive...
RooFactoryWSTool is a clase like TTree::MakeClass() that generates skeleton code for RooAbsPdf and Ro...
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:36
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
Bool_t autoImportClass(TClass *tc, Bool_t doReplace=kFALSE)
Import code of class 'tc' into the repository.
std::map< TString, ExtraHeader > _ehmap
Definition: RooWorkspace.h:206
CodeRepo(RooWorkspace *wspace=0)
Definition: RooWorkspace.h:160
RooWorkspace * _wspace
Definition: RooWorkspace.h:203
std::string listOfClassNames() const
Return STL string with last of class names contained in the code repository.
Bool_t compiledOK() const
Definition: RooWorkspace.h:174
std::map< TString, ClassRelInfo > _c2fmap
Definition: RooWorkspace.h:204
Bool_t compileClasses()
For all classes in the workspace for which no class definition is found in the ROOT class table extra...
CodeRepo(const CodeRepo &other, RooWorkspace *wspace=0)
Definition: RooWorkspace.h:162
std::map< TString, ClassFiles > _fmap
Definition: RooWorkspace.h:205
virtual void Append(TObject *, Bool_t)
Overload TDirectory interface method to prohibit insertion of objects in read-only directory workspac...
void InternalAppend(TObject *obj)
Internal access to TDirectory append method.
virtual void Add(TObject *, Bool_t)
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:215
RooWorkspace * _wspace
Definition: RooWorkspace.h:230
The RooWorkspace is a persistable container for RooFit projects.
Definition: RooWorkspace.h:43
Bool_t makeDir()
Create transient TDirectory representation of this workspace.
RooExpensiveObjectCache _eocache
Transient ROOT directory representation of workspace.
Definition: RooWorkspace.h:267
RooLinkedList _genObjects
Definition: RooWorkspace.h:261
void exportToCint(const char *namespaceName=0)
Activate export of workspace symbols to CINT in a namespace with given name.
std::string _exportNSName
Export contents of workspace to CINT?
Definition: RooWorkspace.h:272
static std::list< std::string > _classDeclDirList
Definition: RooWorkspace.h:246
const RooArgSet * getSnapshot(const char *name) const
Return the RooArgSet containing a snapshot of variables contained in the workspace.
Bool_t 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...
static void addClassDeclImportDir(const char *dir)
Add dir to search path for class declaration (header) files.
Bool_t defineSetInternal(const char *name, const RooArgSet &aset)
void unExport()
Delete exported reference in CINT namespace.
RooLinkedList _dataList
Definition: RooWorkspace.h:257
RooAbsData * data(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
RooAbsData * embeddedData(const char *name) const
Retrieve dataset (binned or unbinned) with given name. A null pointer is returned if not found.
WSDir * _dir
Definition: RooWorkspace.h:265
static void addClassImplImportDir(const char *dir)
Add dir to search path for class implementation (.cxx) files.
TObject * genobj(const char *name) const
Return generic object with given name.
std::map< std::string, RooArgSet > _namedSets
Definition: RooWorkspace.h:263
Bool_t _openTrans
Name of CINT namespace to which contents are exported.
Definition: RooWorkspace.h:274
std::list< RooAbsData * > allData() const
Return list of all dataset in the workspace.
void clearStudies()
Remove all RooStudyManager modules.
RooAbsArg * fundArg(const char *name) const
Return fundamental (i.e.
RooArgSet argSet(const char *nameList) const
Return set of RooAbsArgs matching to given list of names.
std::unique_ptr< RooFactoryWSTool > _factory
Definition: RooWorkspace.h:269
RooArgSet allVars() const
Return set with all variable objects.
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
RooArgSet allCats() const
Return set with all category objects.
Bool_t commitTransaction()
RooLinkedList _views
Definition: RooWorkspace.h:259
Bool_t startTransaction()
Open an import transaction operations.
RooAbsReal * function(const char *name) const
Retrieve function (RooAbsReal) with given name. Note that all RooAbsPdfs are also RooAbsReals....
TIterator * studyIterator()
Definition: RooWorkspace.h:142
RooArgSet allResolutionModels() const
Return set with all resolution model objects.
RooLinkedList _snapshots
Definition: RooWorkspace.h:260
Bool_t importClassCode(const char *pat="*", Bool_t doReplace=kFALSE)
Inport code of all classes in the workspace that have a class name that matches pattern 'pat' and whi...
void merge(const RooWorkspace &)
Definition: RooWorkspace.h:96
RooCategory * cat(const char *name) const
Retrieve discrete variable (RooCategory) with given name. A null pointer is returned if not found.
Bool_t renameSet(const char *name, const char *newName)
Rename set to a new name.
RooAbsArg * arg(const char *name) const
Return RooAbsArg with given name. A null pointer is returned if none is found.
std::list< RooAbsData * > allEmbeddedData() const
Return list of all dataset in the workspace.
void Print(Option_t *opts=0) const
Print contents of the workspace.
RooArgSet allPdfs() const
Return set with all probability density function objects.
Bool_t addStudy(RooAbsStudy &study)
Insert RooStudyManager module.
Bool_t writeToFile(const char *fileName, Bool_t recreate=kTRUE)
Save this current workspace into given file.
std::list< TObject * > allGenericObjects() const
Return list of all generic objects in the workspace.
static void setClassFileExportDir(const char *dir=0)
Specify the name of the directory in which embedded source code is unpacked and compiled.
Bool_t _doExport
Factory tool associated with workspace.
Definition: RooWorkspace.h:271
Bool_t removeSet(const char *name)
Remove a named set from the workspace.
static void autoImportClassCode(Bool_t flag)
If flag is true, source code of classes not the the ROOT distribution is automatically imported if on...
RooAbsCategory * catfunc(const char *name) const
Retrieve discrete function (RooAbsCategory) with given name. A null pointer is returned if not found.
RooLinkedList _studyMods
Definition: RooWorkspace.h:262
RooArgSet allCatFunctions() const
Return set with all category function objects.
static std::string _classFileExportDir
Definition: RooWorkspace.h:248
static std::list< std::string > _classImplDirList
Definition: RooWorkspace.h:247
~RooWorkspace()
Workspace destructor.
Bool_t defineSet(const char *name, const RooArgSet &aset, Bool_t importMissing=kFALSE)
Define a named RooArgSet with given constituents.
RooWorkspace()
Default constructor.
Bool_t cd(const char *path=0)
Bool_t saveSnapshot(const char *name, const char *paramNames)
Save snapshot of values and attributes (including "Constant") of given parameters.
Bool_t loadSnapshot(const char *name)
Load the values and attributes of the parameters in the snapshot saved with the given name.
CodeRepo _classes
Definition: RooWorkspace.h:254
RooRealVar * var(const char *name) const
Retrieve real-valued variable (RooRealVar) with given name. A null pointer is returned if not found.
const RooArgSet & components() const
Definition: RooWorkspace.h:114
RooArgSet allFunctions() const
Return set with all function objects.
RooFactoryWSTool & factory()
Return instance to factory tool.
RooExpensiveObjectCache & expensiveObjectCache()
Definition: RooWorkspace.h:156
Bool_t isValidCPPID(const char *name)
Return true if given name is a valid C++ identifier name.
RooArgSet _sandboxNodes
Is there a transaction open?
Definition: RooWorkspace.h:275
Bool_t cancelTransaction()
Cancel an ongoing import transaction.
void exportObj(TObject *obj)
Export reference to given workspace object to CINT.
const TUUID & uuid() const
Definition: RooWorkspace.h:154
static Bool_t _autoClass
Definition: RooWorkspace.h:252
RooLinkedList _embeddedDataList
Definition: RooWorkspace.h:258
RooArgSet _allOwnedNodes
Definition: RooWorkspace.h:256
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...
TObject * obj(const char *name) const
Return any type of object (RooAbsArg, RooAbsData or generic object) with given name)
TIterator * componentIterator() const
Definition: RooWorkspace.h:113
RooAbsPdf * pdf(const char *name) const
Retrieve p.d.f (RooAbsPdf) with given name. A null pointer is returned if not found.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
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:572
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:37
Basic string class.
Definition: TString.h:131
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition: TUUID.h:42