Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TROOT.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 08/12/94
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TROOT
13 #define ROOT_TROOT
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TROOT //
19 // //
20 // The TROOT object is the entry point to the system. //
21 // The single instance of TROOT is accessible via the global gROOT. //
22 // Using the gROOT pointer one has access to basically every object //
23 // created in a ROOT based program. The TROOT object is essentially a //
24 // "dispatcher" with several lists pointing to the ROOT main objects. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include "TDirectory.h"
29 #include "TList.h"
30 #include "RConfigure.h"
31 
32 #include <atomic>
33 #include <string>
34 #include <vector>
35 
36 class TClass;
37 class TCanvas;
38 class TColor;
39 class TDataType;
40 class TFile;
41 class TStyle;
42 class TVirtualPad;
43 class TApplication;
44 class TInterpreter;
45 class TBrowser;
46 class TGlobal;
47 class TFunction;
48 class TFolder;
49 class TPluginManager;
50 class TProcessUUID;
51 class TClassGenerator;
52 class TVirtualMutex;
53 class TROOT;
54 class TListOfDataMembers;
55 class TListOfEnums;
56 class TListOfFunctions;
57 class TListOfFunctionTemplates;
58 class TFunctionTemplate;
59 class TGlobalMappedFunction;
60 
61 R__EXTERN TVirtualMutex *gROOTMutex;
62 
63 namespace ROOT {
64 namespace Internal {
65  class TROOTAllocator;
66 
67  TROOT *GetROOT2();
68 
69  // Manage parallel branch processing
70  void EnableParBranchProcessing();
71  void DisableParBranchProcessing();
72  Bool_t IsParBranchProcessingEnabled();
73  class TParBranchProcessingRAII {
74  public:
75  TParBranchProcessingRAII() { EnableParBranchProcessing(); }
76  ~TParBranchProcessingRAII() { DisableParBranchProcessing(); }
77  };
78 
79  // Manage parallel tree processing
80  void EnableParTreeProcessing();
81  void DisableParTreeProcessing();
82  Bool_t IsParTreeProcessingEnabled();
83  class TParTreeProcessingRAII {
84  public:
85  TParTreeProcessingRAII() { EnableParTreeProcessing(); }
86  ~TParTreeProcessingRAII() { DisableParTreeProcessing(); }
87  };
88 } } // End ROOT::Internal
89 
90 namespace ROOT {
91  // Enable support for multi-threading within the ROOT code,
92  // in particular, enables the global mutex to make ROOT thread safe/aware.
93  void EnableThreadSafety();
94  /// \brief Enable ROOT's implicit multi-threading for all objects and methods that provide an internal
95  /// parallelisation mechanism.
96  void EnableImplicitMT(UInt_t numthreads = 0);
97  void DisableImplicitMT();
98  Bool_t IsImplicitMTEnabled();
99  UInt_t GetImplicitMTPoolSize();
100 }
101 
102 class TROOT : public TDirectory {
103 
104 friend class TCling;
105 friend TROOT *ROOT::Internal::GetROOT2();
106 
107 private:
108  Int_t fLineIsProcessing; //To synchronize multi-threads
109 
110  static Int_t fgDirLevel; //Indentation level for ls()
111  static Bool_t fgRootInit; //Singleton initialization flag
112  static Bool_t fgMemCheck; //Turn on memory leak checker
113 
114  TROOT(const TROOT&); //Not implemented
115  TROOT& operator=(const TROOT&); //Not implemented
116 
117 protected:
118  typedef std::atomic<TListOfEnums*> AListOfEnums_t;
119 
120  TString fConfigOptions; //ROOT ./configure set build options
121  TString fConfigFeatures; //ROOT ./configure detected build features
122  TString fVersion; //ROOT version (from CMZ VERSQQ) ex 0.05/01
123  Int_t fVersionInt; //ROOT version in integer format (501)
124  Int_t fVersionCode; //ROOT version code as used in RVersion.h
125  Int_t fVersionDate; //Date of ROOT version (ex 951226)
126  Int_t fVersionTime; //Time of ROOT version (ex 1152)
127  Int_t fBuiltDate; //Date of ROOT built
128  Int_t fBuiltTime; //Time of ROOT built
129  TString fGitCommit; //Git commit SHA1 of built
130  TString fGitBranch; //Git branch
131  TString fGitDate; //Date and time when make was run
132  Int_t fTimer; //Timer flag
133  std::atomic<TApplication*> fApplication; //Pointer to current application
134  TInterpreter *fInterpreter; //Command interpreter
135  Bool_t fBatch; //True if session without graphics
136  TString fWebDisplay; //If not empty it defines where web graphics should be rendered (cef, qt5, browser...)
137  Bool_t fIsWebDisplay; //True if session with graphics on web
138  Bool_t fIsWebDisplayBatch; //True if session with graphics on web and batch mode
139  Bool_t fEditHistograms; //True if histograms can be edited with the mouse
140  Bool_t fFromPopUp; //True if command executed from a popup menu
141  Bool_t fMustClean; //True if object destructor scans canvases
142  Bool_t fReadingObject; //True while reading an object [Deprecated (will be removed in next release)
143  Bool_t fForceStyle; //Force setting of current style when reading objects
144  Bool_t fInterrupt; //True if macro should be interrupted
145  Bool_t fEscape; //True if ESC has been pressed
146  Bool_t fExecutingMacro; //True while executing a TMacro
147  Int_t fEditorMode; //Current Editor mode
148  const TObject *fPrimitive; //Currently selected primitive
149  TVirtualPad *fSelectPad; //Currently selected pad
150  TCollection *fClasses; //List of classes definition
151  TCollection *fTypes; //List of data types definition
152  TListOfFunctionTemplates *fFuncTemplate; //List of global function templates
153  TListOfDataMembers*fGlobals; //List of global variables
154  TListOfFunctions*fGlobalFunctions; //List of global functions
155  TSeqCollection *fClosedObjects; //List of closed objects from the list of files and sockets, so we can delete them if neededCl.
156  TSeqCollection *fFiles; //List of files
157  TSeqCollection *fMappedFiles; //List of memory mapped files
158  TSeqCollection *fSockets; //List of network sockets
159  TSeqCollection *fCanvases; //List of canvases
160  TSeqCollection *fStyles; //List of styles
161  TCollection *fFunctions; //List of analytic functions
162  TSeqCollection *fTasks; //List of tasks
163  TSeqCollection *fColors; //List of colors
164  TSeqCollection *fGeometries; //List of geometries
165  TSeqCollection *fBrowsers; //List of browsers
166  TSeqCollection *fSpecials; //List of special objects
167  TSeqCollection *fCleanups; //List of recursiveRemove collections
168  TSeqCollection *fMessageHandlers; //List of message handlers
169  TSeqCollection *fStreamerInfo; //List of active StreamerInfo classes
170  TCollection *fClassGenerators; //List of user defined class generators;
171  TSeqCollection *fSecContexts; //List of security contexts (TSecContext)
172  TSeqCollection *fProofs; //List of proof sessions
173  TSeqCollection *fClipboard; //List of clipboard objects
174  TSeqCollection *fDataSets; //List of data sets (TDSet or TChain)
175  AListOfEnums_t fEnums; //List of enum types
176  TProcessUUID *fUUIDs; //Pointer to TProcessID managing TUUIDs
177  TFolder *fRootFolder; //top level folder //root
178  TList *fBrowsables; //List of browsables
179  TPluginManager *fPluginManager; //Keeps track of plugin library handlers
180  TString fCutClassName; //Name of default CutG class in graphics editor
181  TString fDefCanvasName; //Name of default canvas
182 
183  TROOT(); //Only used by Dictionary
184  void InitSystem(); //Operating System interface
185  void InitThreads(); //Initialize threads library
186  void InitInterpreter(); //Initialize interpreter (cling)
187  void ReadGitInfo(); //Read Git commit SHA1 and branch name
188  void *operator new(size_t l) { return TObject::operator new(l); }
189  void *operator new(size_t l, void *ptr) { return TObject::operator new(l,ptr); }
190 
191  friend class ::ROOT::Internal::TROOTAllocator;
192 
193  TListOfFunctions*GetGlobalFunctions();
194 
195 public:
196 
197  typedef std::vector<std::pair<std::string, int> > FwdDeclArgsToKeepCollection_t;
198 
199  TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc = 0);
200  virtual ~TROOT();
201  void AddClass(TClass *cl);
202  void AddClassGenerator(TClassGenerator *gen);
203  virtual void Append(TObject *obj, Bool_t replace = kFALSE);
204  void Browse(TBrowser *b);
205  Bool_t ClassSaved(TClass *cl);
206  void CloseFiles();
207  void EndOfProcessCleanups();
208  virtual TObject *FindObject(const char *name) const;
209  virtual TObject *FindObject(const TObject *obj) const;
210  virtual TObject *FindObjectAny(const char *name) const;
211  virtual TObject *FindObjectAnyFile(const char *name) const;
212  TObject *FindSpecialObject(const char *name, void *&where);
213  const char *FindObjectClassName(const char *name) const;
214  const char *FindObjectPathName(const TObject *obj) const;
215  TClass *FindSTLClass(const char *name, Bool_t load, Bool_t silent = kFALSE) const;
216  void ForceStyle(Bool_t force = kTRUE) { fForceStyle = force; }
217  Bool_t FromPopUp() const { return fFromPopUp; }
218  TPluginManager *GetPluginManager() const { return fPluginManager; }
219  TApplication *GetApplication() const { return fApplication; }
220  TInterpreter *GetInterpreter() const { return fInterpreter; }
221  TClass *GetClass(const char *name, Bool_t load = kTRUE, Bool_t silent = kFALSE) const;
222  TClass *GetClass(const std::type_info &typeinfo, Bool_t load = kTRUE, Bool_t silent = kFALSE) const;
223  TColor *GetColor(Int_t color) const;
224  const char *GetConfigOptions() const { return fConfigOptions; }
225  const char *GetConfigFeatures() const { return fConfigFeatures; }
226  const char *GetCutClassName() const { return fCutClassName; }
227  const char *GetDefCanvasName() const { return fDefCanvasName; }
228  Bool_t GetEditHistograms() const { return fEditHistograms; }
229  Int_t GetEditorMode() const { return fEditorMode; }
230  Bool_t GetForceStyle() const { return fForceStyle; }
231  Int_t GetBuiltDate() const { return fBuiltDate; }
232  Int_t GetBuiltTime() const { return fBuiltTime; }
233  const char *GetGitCommit() const { return fGitCommit; }
234  const char *GetGitBranch() const { return fGitBranch; }
235  const char *GetGitDate();
236  Int_t GetVersionDate() const { return fVersionDate; }
237  Int_t GetVersionTime() const { return fVersionTime; }
238  Int_t GetVersionInt() const { return fVersionInt; }
239  Int_t GetVersionCode() const { return fVersionCode; }
240  const char *GetVersion() const { return fVersion; }
241  TCollection *GetListOfClasses() const { return fClasses; }
242  TSeqCollection *GetListOfColors() const { return fColors; }
243  TCollection *GetListOfTypes(Bool_t load = kFALSE);
244  TCollection *GetListOfGlobals(Bool_t load = kFALSE);
245  TCollection *GetListOfGlobalFunctions(Bool_t load = kFALSE);
246  TSeqCollection *GetListOfClosedObjects() const { return fClosedObjects; }
247  TSeqCollection *GetListOfFiles() const { return fFiles; }
248  TSeqCollection *GetListOfMappedFiles() const { return fMappedFiles; }
249  TSeqCollection *GetListOfSockets() const { return fSockets; }
250  TSeqCollection *GetListOfCanvases() const { return fCanvases; }
251  TSeqCollection *GetListOfStyles() const { return fStyles; }
252  TCollection *GetListOfFunctions() const { return fFunctions; }
253  TCollection *GetListOfFunctionOverloads(const char* name) const;
254  TSeqCollection *GetListOfGeometries() const { return fGeometries; }
255  TSeqCollection *GetListOfBrowsers() const { return fBrowsers; }
256  TSeqCollection *GetListOfSpecials() const { return fSpecials; }
257  TSeqCollection *GetListOfTasks() const { return fTasks; }
258  TSeqCollection *GetListOfCleanups() const { return fCleanups; }
259  TSeqCollection *GetListOfStreamerInfo() const { return fStreamerInfo; }
260  TSeqCollection *GetListOfMessageHandlers() const { return fMessageHandlers; }
261  TCollection *GetListOfClassGenerators() const { return fClassGenerators; }
262  TSeqCollection *GetListOfSecContexts() const { return fSecContexts; }
263  TSeqCollection *GetListOfProofs() const { return fProofs; }
264  TSeqCollection *GetClipboard() const { return fClipboard; }
265  TSeqCollection *GetListOfDataSets() const { return fDataSets; }
266  TCollection *GetListOfEnums(Bool_t load = kFALSE);
267  TCollection *GetListOfFunctionTemplates();
268  TList *GetListOfBrowsables() const { return fBrowsables; }
269  TDataType *GetType(const char *name, Bool_t load = kFALSE) const;
270  TFile *GetFile() const { if (gDirectory != this) return gDirectory->GetFile(); else return 0;}
271  TFile *GetFile(const char *name) const;
272  TFunctionTemplate*GetFunctionTemplate(const char *name);
273  TStyle *GetStyle(const char *name) const;
274  TObject *GetFunction(const char *name) const;
275  TGlobal *GetGlobal(const char *name, Bool_t load = kFALSE) const;
276  TGlobal *GetGlobal(const TObject *obj, Bool_t load = kFALSE) const;
277  TFunction *GetGlobalFunction(const char *name, const char *params = 0, Bool_t load = kFALSE);
278  TFunction *GetGlobalFunctionWithPrototype(const char *name, const char *proto = 0, Bool_t load = kFALSE);
279  TObject *GetGeometry(const char *name) const;
280  const TObject *GetSelectedPrimitive() const { return fPrimitive; }
281  TVirtualPad *GetSelectedPad() const { return fSelectPad; }
282  Int_t GetNclasses() const { return fClasses->GetSize(); }
283  Int_t GetNtypes() const { return fTypes->GetSize(); }
284  TFolder *GetRootFolder() const { return fRootFolder; }
285  TProcessUUID *GetUUIDs() const { return fUUIDs; }
286  const TString &GetWebDisplay() const { return fWebDisplay; }
287  void Idle(UInt_t idleTimeInSec, const char *command = 0);
288  Int_t IgnoreInclude(const char *fname, const char *expandedfname);
289  Bool_t IsBatch() const { return fBatch; }
290  Bool_t IsExecutingMacro() const { return fExecutingMacro; }
291  Bool_t IsFolder() const { return kTRUE; }
292  Bool_t IsInterrupted() const { return fInterrupt; }
293  Bool_t IsEscaped() const { return fEscape; }
294  Bool_t IsLineProcessing() const { return fLineIsProcessing ? kTRUE : kFALSE; }
295  Bool_t IsProofServ() const { return fName == "proofserv" ? kTRUE : kFALSE; }
296  Bool_t IsRootFile(const char *filename) const;
297  Bool_t IsWebDisplay() const { return fIsWebDisplay; }
298  Bool_t IsWebDisplayBatch() const { return fIsWebDisplayBatch; }
299  void ls(Option_t *option = "") const;
300  Int_t LoadClass(const char *classname, const char *libname, Bool_t check = kFALSE);
301  TClass *LoadClass(const char *name, Bool_t silent = kFALSE) const;
302  Int_t LoadMacro(const char *filename, Int_t *error = 0, Bool_t check = kFALSE);
303  Long_t Macro(const char *filename, Int_t *error = 0, Bool_t padUpdate = kTRUE);
304  TCanvas *MakeDefCanvas() const;
305  void Message(Int_t id, const TObject *obj);
306  Bool_t MustClean() const { return fMustClean; }
307  Long_t ProcessLine(const char *line, Int_t *error = 0);
308  Long_t ProcessLineSync(const char *line, Int_t *error = 0);
309  Long_t ProcessLineFast(const char *line, Int_t *error = 0);
310  Bool_t ReadingObject() const;
311  void RecursiveRemove(TObject *obj);
312  void RefreshBrowsers();
313  static void RegisterModule(const char* modulename,
314  const char** headers,
315  const char** includePaths,
316  const char* payLoadCode,
317  const char* fwdDeclCode,
318  void (*triggerFunc)(),
319  const FwdDeclArgsToKeepCollection_t& fwdDeclsArgToSkip,
320  const char** classesHeaders,
321  bool hasCxxModule = false);
322  TObject *Remove(TObject*);
323  void RemoveClass(TClass *);
324  void Reset(Option_t *option="");
325  void SaveContext();
326  void SetApplication(TApplication *app) { fApplication = app; }
327  void SetBatch(Bool_t batch = kTRUE) { fBatch = batch; }
328  void SetWebDisplay(const char *webdisplay);
329  void SetCutClassName(const char *name = "TCutG");
330  void SetDefCanvasName(const char *name = "c1") { fDefCanvasName = name; }
331  void SetEditHistograms(Bool_t flag = kTRUE) { fEditHistograms = flag; }
332  void SetEditorMode(const char *mode = "");
333  void SetExecutingMacro(Bool_t flag = kTRUE) { fExecutingMacro = flag; }
334  void SetFromPopUp(Bool_t flag = kTRUE) { fFromPopUp = flag; }
335  void SetInterrupt(Bool_t flag = kTRUE) { fInterrupt = flag; }
336  void SetEscape(Bool_t flag = kTRUE) { fEscape = flag; }
337  void SetLineIsProcessing() { fLineIsProcessing++; }
338  void SetLineHasBeenProcessed() { if (fLineIsProcessing) fLineIsProcessing--; }
339  void SetReadingObject(Bool_t flag = kTRUE);
340  void SetMustClean(Bool_t flag = kTRUE) { fMustClean=flag; }
341  void SetSelectedPrimitive(const TObject *obj) { fPrimitive = obj; }
342  void SetSelectedPad(TVirtualPad *pad) { fSelectPad = pad; }
343  void SetStyle(const char *stylename = "Default");
344  void Time(Int_t casetime=1) { fTimer = casetime; }
345  Int_t Timer() const { return fTimer; }
346 
347  //---- static functions
348  static Int_t DecreaseDirLevel();
349  static Int_t GetDirLevel();
350  static const char *GetMacroPath();
351  static void SetMacroPath(const char *newpath);
352  static Int_t IncreaseDirLevel();
353  static void IndentLevel();
354  static void Initialize();
355  static Bool_t Initialized();
356  static Bool_t MemCheck();
357  static void SetDirLevel(Int_t level = 0);
358  static Int_t ConvertVersionCode2Int(Int_t code);
359  static Int_t ConvertVersionInt2Code(Int_t v);
360  static Int_t RootVersionCode();
361  static const std::vector<std::string> &AddExtraInterpreterArgs(const std::vector<std::string> &args);
362  static const char**&GetExtraInterpreterArgs();
363 
364  static const TString& GetRootSys();
365  static const TString& GetBinDir();
366  static const TString& GetLibDir();
367  static const TString& GetIncludeDir();
368  static const TString& GetEtcDir();
369  static const TString& GetDataDir();
370  static const TString& GetDocDir();
371  static const TString& GetMacroDir();
372  static const TString& GetTutorialDir();
373  static const TString& GetSourceDir();
374  static const TString& GetIconPath();
375  static const TString& GetTTFFontDir();
376 
377  // Backward compatibility function - do not use for new code
378  static const char *GetTutorialsDir();
379  static void ShutDown();
380 
381  ClassDef(TROOT,0) //Top level (or root) structure for all classes
382 };
383 
384 
385 namespace ROOT {
386  TROOT *GetROOT();
387  namespace Internal {
388  R__EXTERN TROOT *gROOTLocal;
389 
390  inline void SetRequireCleanup(TObject &obj) {
391  obj.SetBit(kIsReferenced);
392  obj.SetUniqueID(0);
393  }
394 
395  inline Bool_t RequiresCleanup(TObject &obj) {
396  return obj.TestBit(kIsReferenced) && obj.GetUniqueID() == 0;
397  }
398  }
399 
400  /// \brief call RecursiveRemove for obj if gROOT is valid
401  /// and obj.TestBit(kMustCleanup) is true.
402  /// Note: this reset the kMustCleanup bit to allow
403  /// harmless multiple call to this function.
404  inline void CallRecursiveRemoveIfNeeded(TObject &obj)
405  {
406  if (obj.TestBit(kMustCleanup)) {
407  TROOT *root = ROOT::Internal::gROOTLocal;
408  if (root && root != &obj && (root->MustClean() || Internal::RequiresCleanup(obj))) {
409  root->RecursiveRemove(&obj);
410  obj.ResetBit(kMustCleanup);
411  }
412  }
413  }
414 }
415 #define gROOT (ROOT::GetROOT())
416 
417 #endif