ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TObject.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 26/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_TObject
13 #define ROOT_TObject
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TObject //
19 // //
20 // Mother of all ROOT objects. //
21 // //
22 // The TObject class provides default behaviour and protocol for all //
23 // objects in the ROOT system. It provides protocol for object I/O, //
24 // error handling, sorting, inspection, printing, drawing, etc. //
25 // Every object which inherits from TObject can be stored in the //
26 // ROOT collection classes. //
27 // //
28 //////////////////////////////////////////////////////////////////////////
29 
30 #ifndef ROOT_Rtypes
31 #include "Rtypes.h"
32 #endif
33 #ifndef ROOT_TStorage
34 #include "TStorage.h"
35 #endif
36 #ifndef ROOT_TVersionCheck
37 #include "TVersionCheck.h"
38 #endif
39 #ifndef ROOT_Riosfwd
40 #include "Riosfwd.h"
41 #endif
42 
43 #include <stdarg.h>
44 #include <string>
45 
46 #ifdef WIN32
47 #undef RemoveDirectory
48 #endif
49 
50 class TList;
51 class TBrowser;
52 class TBuffer;
53 class TObjArray;
54 class TMethod;
55 class TTimer;
56 
57 
58 class TObject {
59 
60 private:
61  UInt_t fUniqueID; //object unique identifier
62  UInt_t fBits; //bit field status word
63 
64  static Long_t fgDtorOnly; //object for which to call dtor only (i.e. no delete)
65  static Bool_t fgObjectStat; //if true keep track of objects in TObjectTable
66 
67 protected:
68  void MakeZombie() { fBits |= kZombie; }
69  virtual void DoError(int level, const char *location, const char *fmt, va_list va) const;
70 
71 public:
72  //----- Global bits (can be set for any object and should not be reused).
73  //----- Bits 0 - 13 are reserved as global bits. Bits 14 - 23 can be used
74  //----- in different class hierarchies (make sure there is no overlap in
75  //----- any given hierarchy).
76  enum EStatusBits {
77  kCanDelete = BIT(0), // if object in a list can be deleted
78  kMustCleanup = BIT(3), // if object destructor must call RecursiveRemove()
79  kObjInCanvas = BIT(3), // for backward compatibility only, use kMustCleanup
80  kIsReferenced = BIT(4), // if object is referenced by a TRef or TRefArray
81  kHasUUID = BIT(5), // if object has a TUUID (its fUniqueID=UUIDNumber)
82  kCannotPick = BIT(6), // if object in a pad cannot be picked
83  kNoContextMenu = BIT(8), // if object does not want context menu
84  kInvalidObject = BIT(13) // if object ctor succeeded but object should not be used
85  };
86 
87  //----- Private bits, clients can only test but not change them
88  enum {
89  kIsOnHeap = 0x01000000, // object is on heap
90  kNotDeleted = 0x02000000, // object has not been deleted
91  kZombie = 0x04000000, // object ctor failed
92  kBitMask = 0x00ffffff
93  };
94 
95  //----- Write() options
96  enum {
97  kSingleKey = BIT(0), // write collection with single key
98  kOverwrite = BIT(1), // overwrite existing object with same name
99  kWriteDelete = BIT(2) // write object, then delete previous key with same name
100  };
101 
102  TObject();
103  TObject(const TObject &object);
104  TObject &operator=(const TObject &rhs);
105  virtual ~TObject();
106 
107  virtual void AppendPad(Option_t *option="");
108  virtual void Browse(TBrowser *b);
109  virtual const char *ClassName() const;
110  virtual void Clear(Option_t * /*option*/ ="") { }
111  virtual TObject *Clone(const char *newname="") const;
112  virtual Int_t Compare(const TObject *obj) const;
113  virtual void Copy(TObject &object) const;
114  virtual void Delete(Option_t *option=""); // *MENU*
116  virtual void Draw(Option_t *option="");
117  virtual void DrawClass() const; // *MENU*
118  virtual TObject *DrawClone(Option_t *option="") const; // *MENU*
119  virtual void Dump() const; // *MENU*
120  virtual void Execute(const char *method, const char *params, Int_t *error=0);
121  virtual void Execute(TMethod *method, TObjArray *params, Int_t *error=0);
122  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
123  virtual TObject *FindObject(const char *name) const;
124  virtual TObject *FindObject(const TObject *obj) const;
125  virtual Option_t *GetDrawOption() const;
126  virtual UInt_t GetUniqueID() const;
127  virtual const char *GetName() const;
128  virtual const char *GetIconName() const;
129  virtual Option_t *GetOption() const { return ""; }
130  virtual char *GetObjectInfo(Int_t px, Int_t py) const;
131  virtual const char *GetTitle() const;
132  virtual Bool_t HandleTimer(TTimer *timer);
133  virtual ULong_t Hash() const;
134  virtual Bool_t InheritsFrom(const char *classname) const;
135  virtual Bool_t InheritsFrom(const TClass *cl) const;
136  virtual void Inspect() const; // *MENU*
137  virtual Bool_t IsFolder() const;
138  virtual Bool_t IsEqual(const TObject *obj) const;
139  virtual Bool_t IsSortable() const { return kFALSE; }
140  Bool_t IsOnHeap() const { return TestBit(kIsOnHeap); }
141  Bool_t IsZombie() const { return TestBit(kZombie); }
142  virtual Bool_t Notify();
143  virtual void ls(Option_t *option="") const;
144  virtual void Paint(Option_t *option="");
145  virtual void Pop();
146  virtual void Print(Option_t *option="") const;
147  virtual Int_t Read(const char *name);
148  virtual void RecursiveRemove(TObject *obj);
149  virtual void SaveAs(const char *filename="",Option_t *option="") const; // *MENU*
150  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
151  virtual void SetDrawOption(Option_t *option=""); // *MENU*
152  virtual void SetUniqueID(UInt_t uid);
153  virtual void UseCurrentStyle();
154  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
155  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
156 
157  //----- operators
158  void *operator new(size_t sz) { return TStorage::ObjectAlloc(sz); }
159  void *operator new[](size_t sz) { return TStorage::ObjectAllocArray(sz); }
160  void *operator new(size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
161  void *operator new[](size_t sz, void *vp) { return TStorage::ObjectAlloc(sz, vp); }
162  void operator delete(void *ptr);
163  void operator delete[](void *ptr);
164 #ifdef R__PLACEMENTDELETE
165  void operator delete(void *ptr, void *vp);
166  void operator delete[](void *ptr, void *vp);
167 #endif
168 
169  //----- bit manipulation
170  void SetBit(UInt_t f, Bool_t set);
171  void SetBit(UInt_t f) { fBits |= f & kBitMask; }
172  void ResetBit(UInt_t f) { fBits &= ~(f & kBitMask); }
173  Bool_t TestBit(UInt_t f) const { return (Bool_t) ((fBits & f) != 0); }
174  Int_t TestBits(UInt_t f) const { return (Int_t) (fBits & f); }
175  void InvertBit(UInt_t f) { fBits ^= f & kBitMask; }
176 
177  //---- error handling
178  virtual void Info(const char *method, const char *msgfmt, ...) const
179 #if defined(__GNUC__) && !defined(__CINT__)
180  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
181 #endif
182  ;
183  virtual void Warning(const char *method, const char *msgfmt, ...) const
184 #if defined(__GNUC__) && !defined(__CINT__)
185  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
186 #endif
187  ;
188  virtual void Error(const char *method, const char *msgfmt, ...) const
189 #if defined(__GNUC__) && !defined(__CINT__)
190  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
191 #endif
192  ;
193  virtual void SysError(const char *method, const char *msgfmt, ...) const
194 #if defined(__GNUC__) && !defined(__CINT__)
195  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
196 #endif
197  ;
198  virtual void Fatal(const char *method, const char *msgfmt, ...) const
199 #if defined(__GNUC__) && !defined(__CINT__)
200  __attribute__((format(printf, 3, 4))) /* 1 is the this pointer */
201 #endif
202  ;
203 
204  void AbstractMethod(const char *method) const;
205  void MayNotUse(const char *method) const;
206  void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const;
207 
208  //---- static functions
209  static Long_t GetDtorOnly();
210  static void SetDtorOnly(void *obj);
211  static Bool_t GetObjectStat();
212  static void SetObjectStat(Bool_t stat);
213 
214  friend class TClonesArray; // needs to reset kNotDeleted in fBits
215 
216  ClassDef(TObject,1) //Basic ROOT object
217 };
218 
219 // Global bits (can be set for any object and should not be reused).
220 // Only here for backward compatibility reasons.
221 // For detailed description see TObject::EStatusBits above.
222 enum EObjBits {
231 };
232 
233 namespace cling {
234  std::string printValue(TObject *val);
235 }
236 
237 #endif
virtual void Clear(Option_t *="")
Definition: TObject.h:110
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:823
UInt_t fUniqueID
Definition: TObject.h:61
An array of TObjects.
Definition: TObjArray.h:39
Bool_t IsOnHeap() const
Definition: TObject.h:140
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:487
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition: TObject.cxx:245
virtual ULong_t Hash() const
Return hash value for this object.
Definition: TObject.cxx:477
const char Option_t
Definition: RtypesCore.h:62
#define BIT(n)
Definition: Rtypes.h:120
void MayNotUse(const char *method) const
Use this method to signal that a method (defined in a base class) may not be called in a derived clas...
Definition: TObject.cxx:971
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
static void SetDtorOnly(void *obj)
Set destructor only flag.
Definition: TObject.cxx:1015
Int_t TestBits(UInt_t f) const
Definition: TObject.h:174
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
static void SetObjectStat(Bool_t stat)
Turn on/off tracking of objects in the TObjectTable.
Definition: TObject.cxx:999
static const char * filename()
Bool_t IsZombie() const
Definition: TObject.h:141
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:178
static void * ObjectAlloc(size_t size)
Used to allocate a TObject on the heap (via TObject::operator new()).
Definition: TStorage.cxx:322
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TObject.cxx:517
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current pad.
Definition: TObject.cxx:277
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition: TObject.cxx:753
static std::string format(double x, double y, int digits, int width)
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
Definition: TObject.cxx:527
Float_t py
Definition: hprod.C:33
void InvertBit(UInt_t f)
Definition: TObject.h:175
TFile * f
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:643
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
static Long_t GetDtorOnly()
Return destructor only flag.
Definition: TObject.cxx:1007
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
Definition: TObject.cxx:616
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:164
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:946
static Long_t fgDtorOnly
Definition: TObject.h:64
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TObject.cxx:536
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
TStopwatch timer
Definition: pirndm.C:37
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:399
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:550
virtual Bool_t HandleTimer(TTimer *timer)
Execute action in response of a timer timing out.
Definition: TObject.cxx:469
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
Definition: TObject.cxx:508
virtual void Pop()
Pop on object drawn in a pad to the top of the display list.
Definition: TObject.cxx:572
virtual Option_t * GetOption() const
Definition: TObject.h:129
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:606
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition: TObject.cxx:102
virtual const char * GetIconName() const
Returns mime type name of object.
Definition: TObject.cxx:425
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
char * out
Definition: TBase64.cxx:29
virtual Bool_t IsSortable() const
Definition: TObject.h:139
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:122
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:743
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:594
A doubly linked list.
Definition: TList.h:47
std::string printValue(const TDatime &val)
Print a TDatime at the prompt.
Definition: TDatime.cxx:447
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:228
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual void DrawClass() const
Draw class inheritance tree of the class to which this object belongs.
Definition: TObject.cxx:269
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Execute method on this object with the given parameter string, e.g.
Definition: TObject.cxx:335
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual void DoError(int level, const char *location, const char *fmt, va_list va) const
Interface to ErrorHandler (protected).
Definition: TObject.cxx:879
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don't want to leave purely abstract...
Definition: TObject.cxx:960
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:57
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void SetBit(UInt_t f)
Definition: TObject.h:171
static Bool_t GetObjectStat()
Get status of object stat flag.
Definition: TObject.cxx:992
UInt_t fBits
Definition: TObject.h:62
long Long_t
Definition: RtypesCore.h:50
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition: TObject.cxx:563
void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const
Use this method to declare a method obsolete.
Definition: TObject.cxx:980
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:932
static Bool_t fgObjectStat
Definition: TObject.h:65
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:444
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:369
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
EStatusBits
Definition: TObject.h:76
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
unsigned long ULong_t
Definition: RtypesCore.h:51
virtual ~TObject()
TObject destructor.
Definition: TObject.cxx:140
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
Float_t px
Definition: hprod.C:33
An array of clone (identical) objects.
Definition: TClonesArray.h:32
void MakeZombie()
Definition: TObject.h:68
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
Definition: TObject.cxx:218
static void * ObjectAllocArray(size_t size)
Used to allocate array of TObject on the heap (via TObject::operator new[]()).
Definition: TStorage.cxx:334
void ResetBit(UInt_t f)
Definition: TObject.h:172
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TObject.cxx:715
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
TObject * obj
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:379
virtual void Dump() const
Dump contents of object on stdout.
Definition: TObject.cxx:324
EObjBits
Definition: TObject.h:222
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:702
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904