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