Logo ROOT  
Reference Guide
TObject.cxx
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/** \class TObject
13\ingroup Base
14
15Mother of all ROOT objects.
16
17The TObject class provides default behaviour and protocol for all
18objects in the ROOT system. It provides protocol for object I/O,
19error handling, sorting, inspection, printing, drawing, etc.
20Every object which inherits from TObject can be stored in the
21ROOT collection classes.
22
23TObject's bits can be used as flags, bits 0 - 13 and 24-31 are
24reserved as global bits while bits 14 - 23 can be used in different
25class hierarchies (watch out for overlaps).
26*/
27
28#include <string.h>
29#if !defined(WIN32) && !defined(__MWERKS__) && !defined(R__SOLARIS)
30#include <strings.h>
31#endif
32#include <stdlib.h>
33#include <stdio.h>
34#include <sstream>
35
36#include "Varargs.h"
37#include "Riostream.h"
38#include "TObject.h"
39#include "TBuffer.h"
40#include "TClass.h"
41#include "TGuiFactory.h"
42#include "TMethod.h"
43#include "TROOT.h"
44#include "TError.h"
45#include "TObjectTable.h"
46#include "TVirtualPad.h"
47#include "TInterpreter.h"
48#include "TMemberInspector.h"
49#include "TRefTable.h"
50#include "TProcessID.h"
51
54
56
57
58////////////////////////////////////////////////////////////////////////////////
59/// Copy this to obj.
60
61void TObject::Copy(TObject &obj) const
62{
63 obj.fUniqueID = fUniqueID; // when really unique don't copy
64 if (obj.IsOnHeap()) { // test uses fBits so don't move next line
65 obj.fBits = fBits;
66 obj.fBits |= kIsOnHeap;
67 } else {
68 obj.fBits = fBits;
69 obj.fBits &= ~kIsOnHeap;
70 }
71 obj.fBits &= ~kIsReferenced;
72 obj.fBits &= ~kCanDelete;
74
75////////////////////////////////////////////////////////////////////////////////
76/// TObject destructor. Removes object from all canvases and object browsers
77/// if observer bit is on and remove from the global object table.
78
80{
81 // if (!TestBit(kNotDeleted))
82 // Fatal("~TObject", "object deleted twice");
83
85
86 fBits &= ~kNotDeleted;
87
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Private helper function which will dispatch to
93/// TObjectTable::AddObj.
94/// Included here to avoid circular dependency between header files.
95
97{
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Append graphics object to current pad. In case no current pad is set
103/// yet, create a default canvas with the name "c1".
104
106{
107 if (!gPad) {
108 gROOT->MakeDefCanvas();
109 }
110 if (!gPad->IsEditable()) return;
112 gPad->GetListOfPrimitives()->Add(this,option);
113 gPad->Modified(kTRUE);
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Browse object. May be overridden for another default action
118
120{
121 //Inspect();
122 TClass::AutoBrowse(this,b);
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Returns name of class to which the object belongs.
128const char *TObject::ClassName() const
129{
130 return IsA()->GetName();
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Make a clone of an object using the Streamer facility.
135/// If the object derives from TNamed, this function is called
136/// by TNamed::Clone. TNamed::Clone uses the optional argument to set
137/// a new name to the newly created object.
138///
139/// If the object class has a DirectoryAutoAdd function, it will be
140/// called at the end of the function with the parameter gDirectory.
141/// This usually means that the object will be appended to the current
142/// ROOT directory.
143
144TObject *TObject::Clone(const char *) const
145{
146 if (gDirectory) {
147 return gDirectory->CloneObject(this);
148 } else {
149 // Some of the streamer (eg. roofit's) expect(ed?) a valid gDirectory during streaming.
150 return gROOT->CloneObject(this);
151 }
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Compare abstract method. Must be overridden if a class wants to be able
156/// to compare itself with other objects. Must return -1 if this is smaller
157/// than obj, 0 if objects are equal and 1 if this is larger than obj.
158
160{
161 AbstractMethod("Compare");
162 return 0;
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Delete this object. Typically called as a command via the interpreter.
167/// Normally use "delete" operator when object has been allocated on the heap.
168
170{
171 if (IsOnHeap()) {
172 // Delete object from CINT symbol table so it can not be used anymore.
173 // CINT object are always on the heap.
174 gInterpreter->DeleteGlobal(this);
175
176 delete this;
177 }
178}
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Computes distance from point (px,py) to the object.
183/// This member function must be implemented for each graphics primitive.
184/// This default function returns a big number (999999).
185
187{
188 // AbstractMethod("DistancetoPrimitive");
189 return 999999;
190}
191
192////////////////////////////////////////////////////////////////////////////////
193/// Default Draw method for all objects
194
196{
197 AppendPad(option);
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Draw class inheritance tree of the class to which this object belongs.
202/// If a class B inherits from a class A, description of B is drawn
203/// on the right side of description of A.
204/// Member functions overridden by B are shown in class A with a blue line
205/// crossing-out the corresponding member function.
206/// The following picture is the class inheritance tree of class TPaveLabel:
207///
208/// \image html base_object.png
209
211{
212 IsA()->Draw();
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Draw a clone of this object in the current selected pad for instance with:
217/// `gROOT->SetSelectedPad(gPad)`.
218
220{
221 TVirtualPad *pad = gROOT->GetSelectedPad();
222 TVirtualPad *padsav = gPad;
223 if (pad) pad->cd();
224
225 TObject *newobj = Clone();
226 if (!newobj) return 0;
227 if (pad) {
228 if (strlen(option)) pad->GetListOfPrimitives()->Add(newobj,option);
229 else pad->GetListOfPrimitives()->Add(newobj,GetDrawOption());
230 pad->Modified(kTRUE);
231 pad->Update();
232 if (padsav) padsav->cd();
233 return newobj;
234 }
235 if (strlen(option)) newobj->Draw(option);
236 else newobj->Draw(GetDrawOption());
237 if (padsav) padsav->cd();
238
239 return newobj;
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Dump contents of object on stdout.
244/// Using the information in the object dictionary (class TClass)
245/// each data member is interpreted.
246/// If a data member is a pointer, the pointer value is printed
247///
248/// The following output is the Dump of a TArrow object:
249/// ~~~ {.cpp}
250/// fAngle 0 Arrow opening angle (degrees)
251/// fArrowSize 0.2 Arrow Size
252/// fOption.*fData
253/// fX1 0.1 X of 1st point
254/// fY1 0.15 Y of 1st point
255/// fX2 0.67 X of 2nd point
256/// fY2 0.83 Y of 2nd point
257/// fUniqueID 0 object unique identifier
258/// fBits 50331648 bit field status word
259/// fLineColor 1 line color
260/// fLineStyle 1 line style
261/// fLineWidth 1 line width
262/// fFillColor 19 fill area color
263/// fFillStyle 1001 fill area style
264/// ~~~
265
266void TObject::Dump() const
267{
268 // Get the actual address of the object.
269 const void *actual = IsA()->DynamicCast(TObject::Class(),this,kFALSE);
270 IsA()->Dump(actual);
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Execute method on this object with the given parameter string, e.g.
275/// "3.14,1,\"text\"".
276
277void TObject::Execute(const char *method, const char *params, Int_t *error)
278{
279 if (!IsA()) return;
280
281 Bool_t must_cleanup = TestBit(kMustCleanup);
282
283 gInterpreter->Execute(this, IsA(), method, params, error);
284
285 if (gPad && must_cleanup) gPad->Modified();
286}
287
288////////////////////////////////////////////////////////////////////////////////
289/// Execute method on this object with parameters stored in the TObjArray.
290/// The TObjArray should contain an argv vector like:
291/// ~~~ {.cpp}
292/// argv[0] ... argv[n] = the list of TObjString parameters
293/// ~~~
294
295void TObject::Execute(TMethod *method, TObjArray *params, Int_t *error)
296{
297 if (!IsA()) return;
298
299 Bool_t must_cleanup = TestBit(kMustCleanup);
300
301 gInterpreter->Execute(this, IsA(), method, params, error);
302
303 if (gPad && must_cleanup) gPad->Modified();
304}
305
306
307////////////////////////////////////////////////////////////////////////////////
308/// Execute action corresponding to an event at (px,py). This method
309/// must be overridden if an object can react to graphics events.
310
312{
313 // AbstractMethod("ExecuteEvent");
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Must be redefined in derived classes.
318/// This function is typically used with TCollections, but can also be used
319/// to find an object by name inside this object.
320
321TObject *TObject::FindObject(const char *) const
322{
323 return 0;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// Must be redefined in derived classes.
328/// This function is typically used with TCollections, but can also be used
329/// to find an object inside this object.
330
332{
333 return 0;
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Get option used by the graphics system to draw this object.
338/// Note that before calling object.GetDrawOption(), you must
339/// have called object.Draw(..) before in the current pad.
340
342{
343 if (!gPad) return "";
344
345 TListIter next(gPad->GetListOfPrimitives());
346 TObject *obj;
347 while ((obj = next())) {
348 if (obj == this) return next.GetOption();
349 }
350 return "";
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Returns name of object. This default method returns the class name.
355/// Classes that give objects a name should override this method.
356
357const char *TObject::GetName() const
358{
359 return IsA()->GetName();
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Returns mime type name of object. Used by the TBrowser (via TGMimeTypes
364/// class). Override for class of which you would like to have different
365/// icons for objects of the same class.
366
367const char *TObject::GetIconName() const
368{
369 return 0;
370}
371
372////////////////////////////////////////////////////////////////////////////////
373/// Return the unique object id.
374
376{
377 return fUniqueID;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Returns string containing info about the object at position (px,py).
382/// This method is typically overridden by classes of which the objects
383/// can report peculiarities for different positions.
384/// Returned string will be re-used (lock in MT environment).
385
387{
388 if (!gPad) return (char*)"";
389 static char info[64];
390 Float_t x = gPad->AbsPixeltoX(px);
391 Float_t y = gPad->AbsPixeltoY(py);
392 snprintf(info,64,"x=%g, y=%g",gPad->PadtoX(x),gPad->PadtoY(y));
393 return info;
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Returns title of object. This default method returns the class title
398/// (i.e. description). Classes that give objects a title should override
399/// this method.
400
401const char *TObject::GetTitle() const
402{
403 return IsA()->GetTitle();
404}
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Execute action in response of a timer timing out. This method
409/// must be overridden if an object has to react to timers.
410
412{
413 return kFALSE;
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Return hash value for this object.
418///
419/// Note: If this routine is overloaded in a derived class, this derived class
420/// should also add
421/// ~~~ {.cpp}
422/// ROOT::CallRecursiveRemoveIfNeeded(*this)
423/// ~~~
424/// Otherwise, when RecursiveRemove is called (by ~TObject or example) for this
425/// type of object, the transversal of THashList and THashTable containers will
426/// will have to be done without call Hash (and hence be linear rather than
427/// logarithmic complexity). You will also see warnings like
428/// ~~~
429/// Error in <ROOT::Internal::TCheckHashRecursiveRemoveConsistency::CheckRecursiveRemove>: The class SomeName overrides TObject::Hash but does not call TROOT::RecursiveRemove in its destructor.
430/// ~~~
431///
432
434{
435 //return (ULong_t) this >> 2;
436 const void *ptr = this;
437 return TString::Hash(&ptr, sizeof(void*));
438}
439
440////////////////////////////////////////////////////////////////////////////////
441/// Returns kTRUE if object inherits from class "classname".
442
443Bool_t TObject::InheritsFrom(const char *classname) const
444{
445 return IsA()->InheritsFrom(classname);
446}
447
448////////////////////////////////////////////////////////////////////////////////
449/// Returns kTRUE if object inherits from TClass cl.
450
452{
453 return IsA()->InheritsFrom(cl);
454}
455
456////////////////////////////////////////////////////////////////////////////////
457/// Dump contents of this object in a graphics canvas.
458/// Same action as Dump but in a graphical form.
459/// In addition pointers to other objects can be followed.
460///
461/// The following picture is the Inspect of a histogram object:
462/// \image html base_inspect.png
463
465{
466 gGuiFactory->CreateInspectorImp(this, 400, 200);
467}
468
469////////////////////////////////////////////////////////////////////////////////
470/// Returns kTRUE in case object contains browsable objects (like containers
471/// or lists of other objects).
472
474{
475 return kFALSE;
476}
477
478////////////////////////////////////////////////////////////////////////////////
479/// Default equal comparison (objects are equal if they have the same
480/// address in memory). More complicated classes might want to override
481/// this function.
482
484{
485 return obj == this;
486}
487
488////////////////////////////////////////////////////////////////////////////////
489/// The ls function lists the contents of a class on stdout. Ls output
490/// is typically much less verbose then Dump().
491
492void TObject::ls(Option_t *option) const
493{
495 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << " : ";
496 std::cout << Int_t(TestBit(kCanDelete));
497 if (option && strstr(option,"noaddr")==0) {
498 std::cout <<" at: "<< this ;
499 }
500 std::cout << std::endl;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// This method must be overridden to handle object notification.
505
507{
508 return kFALSE;
509}
510
511////////////////////////////////////////////////////////////////////////////////
512/// This method must be overridden if a class wants to paint itself.
513/// The difference between Paint() and Draw() is that when a object
514/// draws itself it is added to the display list of the pad in
515/// which it is drawn (and automatically redrawn whenever the pad is
516/// redrawn). While paint just draws the object without adding it to
517/// the pad display list.
518
520{
521 // AbstractMethod("Paint");
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// Pop on object drawn in a pad to the top of the display list. I.e. it
526/// will be drawn last and on top of all other primitives.
527
529{
530 if (!gPad) return;
531
532 if (this == gPad->GetListOfPrimitives()->Last()) return;
533
534 TListIter next(gPad->GetListOfPrimitives());
535 TObject *obj;
536 while ((obj = next()))
537 if (obj == this) {
538 char *opt = StrDup(next.GetOption());
539 gPad->GetListOfPrimitives()->Remove((TObject*)this);
540 gPad->GetListOfPrimitives()->AddLast(this, opt);
541 gPad->Modified();
542 delete [] opt;
543 return;
544 }
545}
546
547////////////////////////////////////////////////////////////////////////////////
548/// This method must be overridden when a class wants to print itself.
549
551{
552 std::cout <<"OBJ: " << IsA()->GetName() << "\t" << GetName() << "\t" << GetTitle() << std::endl;
553}
554
555////////////////////////////////////////////////////////////////////////////////
556/// Read contents of object with specified name from the current directory.
557/// First the key with the given name is searched in the current directory,
558/// next the key buffer is deserialized into the object.
559/// The object must have been created before via the default constructor.
560/// See TObject::Write().
561
563{
564 if (gDirectory) return gDirectory->ReadTObject(this,name);
565 else return 0;
566}
567
568////////////////////////////////////////////////////////////////////////////////
569/// Recursively remove this object from a list. Typically implemented
570/// by classes that can contain multiple references to a same object.
571
573{
574}
575
576
577////////////////////////////////////////////////////////////////////////////////
578/// Save this object in the file specified by filename.
579///
580/// - if "filename" contains ".root" the object is saved in filename as root
581/// binary file.
582///
583/// - if "filename" contains ".xml" the object is saved in filename as a xml
584/// ascii file.
585///
586/// - if "filename" contains ".cc" the object is saved in filename as C code
587/// independant from ROOT. The code is generated via SavePrimitive().
588/// Specific code should be implemented in each object to handle this
589/// option. Like in TF1::SavePrimitive().
590///
591/// - otherwise the object is written to filename as a CINT/C++ script. The
592/// C++ code to rebuild this object is generated via SavePrimitive(). The
593/// "option" parameter is passed to SavePrimitive. By default it is an empty
594/// string. It can be used to specify the Draw option in the code generated
595/// by SavePrimitive.
596///
597/// The function is available via the object context menu.
598
599void TObject::SaveAs(const char *filename, Option_t *option) const
600{
601 //==============Save object as a root file===================================
602 if (filename && strstr(filename,".root")) {
603 if (gDirectory) gDirectory->SaveObjectAs(this,filename,"");
604 return;
605 }
606
607 //==============Save object as a XML file====================================
608 if (filename && strstr(filename,".xml")) {
609 if (gDirectory) gDirectory->SaveObjectAs(this,filename,"");
610 return;
611 }
612
613 //==============Save object as a JSON file================================
614 if (filename && strstr(filename,".json")) {
615 if (gDirectory) gDirectory->SaveObjectAs(this,filename,option);
616 return;
617 }
618
619 //==============Save object as a C, ROOT independant, file===================
620 if (filename && strstr(filename,".cc")) {
621 TString fname;
622 if (filename && strlen(filename) > 0) {
623 fname = filename;
624 } else {
625 fname.Form("%s.cc", GetName());
626 }
627 std::ofstream out;
628 out.open(fname.Data(), std::ios::out);
629 if (!out.good ()) {
630 Error("SaveAs", "cannot open file: %s", fname.Data());
631 return;
632 }
633 ((TObject*)this)->SavePrimitive(out,"cc");
634 out.close();
635 Info("SaveAs", "cc file: %s has been generated", fname.Data());
636 return;
637 }
638
639 //==============Save as a C++ CINT file======================================
640 TString fname;
641 if (filename && strlen(filename) > 0) {
642 fname = filename;
643 } else {
644 fname.Form("%s.C", GetName());
645 }
646 std::ofstream out;
647 out.open(fname.Data(), std::ios::out);
648 if (!out.good ()) {
649 Error("SaveAs", "cannot open file: %s", fname.Data());
650 return;
651 }
652 out <<"{"<<std::endl;
653 out <<"//========= Macro generated from object: "<<GetName()<<"/"<<GetTitle()<<std::endl;
654 out <<"//========= by ROOT version"<<gROOT->GetVersion()<<std::endl;
655 ((TObject*)this)->SavePrimitive(out,option);
656 out <<"}"<<std::endl;
657 out.close();
658 Info("SaveAs", "C++ Macro file: %s has been generated", fname.Data());
659}
660
661////////////////////////////////////////////////////////////////////////////////
662/// Save a primitive as a C++ statement(s) on output stream "out".
663
664void TObject::SavePrimitive(std::ostream &out, Option_t * /*= ""*/)
665{
666 out << "//Primitive: " << GetName() << "/" << GetTitle()
667 <<". You must implement " << ClassName() << "::SavePrimitive" << std::endl;
668}
669
670////////////////////////////////////////////////////////////////////////////////
671/// Set drawing option for object. This option only affects
672/// the drawing style and is stored in the option field of the
673/// TObjOptLink supporting a TPad's primitive list (TList).
674/// Note that it does not make sense to call object.SetDrawOption(option)
675/// before having called object.Draw().
676
678{
679 if (!gPad || !option) return;
680
681 TListIter next(gPad->GetListOfPrimitives());
682 delete gPad->FindObject("Tframe");
683 TObject *obj;
684 while ((obj = next()))
685 if (obj == this) {
686 next.SetOption(option);
687 return;
688 }
689}
690
691////////////////////////////////////////////////////////////////////////////////
692/// Set or unset the user status bits as specified in f.
693
695{
696 if (set)
697 SetBit(f);
698 else
699 ResetBit(f);
700}
701
702////////////////////////////////////////////////////////////////////////////////
703/// Set the unique object id.
704
706{
707 fUniqueID = uid;
708}
709
710////////////////////////////////////////////////////////////////////////////////
711/// Set current style settings in this object
712/// This function is called when either TCanvas::UseCurrentStyle
713/// or TROOT::ForceStyle have been invoked.
714
716{
717}
718
719////////////////////////////////////////////////////////////////////////////////
720/// Write this object to the current directory.
721/// The data structure corresponding to this object is serialized.
722/// The corresponding buffer is written to the current directory
723/// with an associated key with name "name".
724///
725/// Writing an object to a file involves the following steps:
726///
727/// - Creation of a support TKey object in the current directory.
728/// The TKey object creates a TBuffer object.
729///
730/// - The TBuffer object is filled via the class::Streamer function.
731///
732/// - If the file is compressed (default) a second buffer is created to
733/// hold the compressed buffer.
734///
735/// - Reservation of the corresponding space in the file by looking
736/// in the TFree list of free blocks of the file.
737///
738/// - The buffer is written to the file.
739///
740/// Bufsize can be given to force a given buffer size to write this object.
741/// By default, the buffersize will be taken from the average buffer size
742/// of all objects written to the current file so far.
743///
744/// If a name is specified, it will be the name of the key.
745/// If name is not given, the name of the key will be the name as returned
746/// by GetName().
747///
748/// The option can be a combination of: kSingleKey, kOverwrite or kWriteDelete
749/// Using the kOverwrite option a previous key with the same name is
750/// overwritten. The previous key is deleted before writing the new object.
751/// Using the kWriteDelete option a previous key with the same name is
752/// deleted only after the new object has been written. This option
753/// is safer than kOverwrite but it is slower.
754/// NOTE: Neither kOverwrite nor kWriteDelete reduces the size of a TFile--
755/// the space is simply freed up to be overwritten; in the case of a TTree,
756/// it is more complicated. If one opens a TTree, appends some entries,
757/// then writes it out, the behaviour is effectively the same. If, however,
758/// one creates a new TTree and writes it out in this way,
759/// only the metadata is replaced, effectively making the old data invisible
760/// without deleting it. TTree::Delete() can be used to mark all disk space
761/// occupied by a TTree as free before overwriting its metadata this way.
762/// The kSingleKey option is only used by TCollection::Write() to write
763/// a container with a single key instead of each object in the container
764/// with its own key.
765///
766/// An object is read from the file into memory via TKey::Read() or
767/// via TObject::Read().
768///
769/// The function returns the total number of bytes written to the file.
770/// It returns 0 if the object cannot be written.
771
772Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize) const
773{
774 if (R__unlikely(option & kOnlyPrepStep))
775 return 0;
776
777 TString opt = "";
778 if (option & kSingleKey) opt += "SingleKey";
779 if (option & kOverwrite) opt += "OverWrite";
780 if (option & kWriteDelete) opt += "WriteDelete";
781
782 if (gDirectory) return gDirectory->WriteTObject(this,name,opt.Data(),bufsize);
783 else {
784 const char *objname = "no name specified";
785 if (name) objname = name;
786 else objname = GetName();
787 Error("Write","The current directory (gDirectory) is null. The object (%s) has not been written.",objname);
788 return 0;
789 }
790}
791
792////////////////////////////////////////////////////////////////////////////////
793/// Write this object to the current directory. For more see the
794/// const version of this method.
795
796Int_t TObject::Write(const char *name, Int_t option, Int_t bufsize)
797{
798 return ((const TObject*)this)->Write(name, option, bufsize);
799}
800
801////////////////////////////////////////////////////////////////////////////////
802/// Stream an object of class TObject.
803
804void TObject::Streamer(TBuffer &R__b)
805{
806 if (IsA()->CanIgnoreTObjectStreamer()) return;
807 UShort_t pidf;
808 if (R__b.IsReading()) {
809 R__b.SkipVersion(); // Version_t R__v = R__b.ReadVersion(); if (R__v) { }
810 R__b >> fUniqueID;
811 R__b >> fBits;
812 fBits |= kIsOnHeap; // by definition de-serialized object is on heap
813 if (TestBit(kIsReferenced)) {
814 //if the object is referenced, we must read its old address
815 //and store it in the ProcessID map in gROOT
816 R__b >> pidf;
817 pidf += R__b.GetPidOffset();
818 TProcessID *pid = R__b.ReadProcessID(pidf);
819 if (pid) {
820 UInt_t gpid = pid->GetUniqueID();
821 if (gpid>=0xff) {
822 fUniqueID = fUniqueID | 0xff000000;
823 } else {
824 fUniqueID = ( fUniqueID & 0xffffff) + (gpid<<24);
825 }
826 pid->PutObjectWithID(this);
827 }
828 }
829 } else {
830 R__b.WriteVersion(TObject::IsA());
831 if (!TestBit(kIsReferenced)) {
832 R__b << fUniqueID;
833 R__b << fBits;
834 } else {
835 //if the object is referenced, we must save its address/file_pid
836 UInt_t uid = fUniqueID & 0xffffff;
837 R__b << uid;
838 R__b << fBits;
840 //add uid to the TRefTable if there is one
842 if(table) table->Add(uid, pid);
843 pidf = R__b.WriteProcessID(pid);
844 R__b << pidf;
845 }
846 }
847}
848
849////////////////////////////////////////////////////////////////////////////////
850/// Interface to ErrorHandler (protected).
851
852void TObject::DoError(int level, const char *location, const char *fmt, va_list va) const
853{
854 const char *classname = "UnknownClass";
855 if (TROOT::Initialized())
856 classname = ClassName();
857
858 ::ErrorHandler(level, Form("%s::%s", classname, location), fmt, va);
859}
860
861////////////////////////////////////////////////////////////////////////////////
862/// Issue info message. Use "location" to specify the method where the
863/// warning occurred. Accepts standard printf formatting arguments.
864
865void TObject::Info(const char *location, const char *va_(fmt), ...) const
866{
867 va_list ap;
868 va_start(ap, va_(fmt));
869 DoError(kInfo, location, va_(fmt), ap);
870 va_end(ap);
871}
872
873////////////////////////////////////////////////////////////////////////////////
874/// Issue warning message. Use "location" to specify the method where the
875/// warning occurred. Accepts standard printf formatting arguments.
876
877void TObject::Warning(const char *location, const char *va_(fmt), ...) const
878{
879 va_list ap;
880 va_start(ap, va_(fmt));
881 DoError(kWarning, location, va_(fmt), ap);
882 va_end(ap);
883 if (TROOT::Initialized())
884 gROOT->Message(1001, this);
885}
886
887////////////////////////////////////////////////////////////////////////////////
888/// Issue error message. Use "location" to specify the method where the
889/// error occurred. Accepts standard printf formatting arguments.
890
891void TObject::Error(const char *location, const char *va_(fmt), ...) const
892{
893 va_list ap;
894 va_start(ap, va_(fmt));
895 DoError(kError, location, va_(fmt), ap);
896 va_end(ap);
897 if (TROOT::Initialized())
898 gROOT->Message(1002, this);
899}
900
901////////////////////////////////////////////////////////////////////////////////
902/// Issue system error message. Use "location" to specify the method where
903/// the system error occurred. Accepts standard printf formatting arguments.
904
905void TObject::SysError(const char *location, const char *va_(fmt), ...) const
906{
907 va_list ap;
908 va_start(ap, va_(fmt));
909 DoError(kSysError, location, va_(fmt), ap);
910 va_end(ap);
911 if (TROOT::Initialized())
912 gROOT->Message(1003, this);
913}
914
915////////////////////////////////////////////////////////////////////////////////
916/// Issue fatal error message. Use "location" to specify the method where the
917/// fatal error occurred. Accepts standard printf formatting arguments.
918
919void TObject::Fatal(const char *location, const char *va_(fmt), ...) const
920{
921 va_list ap;
922 va_start(ap, va_(fmt));
923 DoError(kFatal, location, va_(fmt), ap);
924 va_end(ap);
925 if (TROOT::Initialized())
926 gROOT->Message(1004, this);
927}
928
929////////////////////////////////////////////////////////////////////////////////
930/// Use this method to implement an "abstract" method that you don't
931/// want to leave purely abstract.
932
933void TObject::AbstractMethod(const char *method) const
934{
935 Warning(method, "this method must be overridden!");
936}
937
938////////////////////////////////////////////////////////////////////////////////
939/// Use this method to signal that a method (defined in a base class)
940/// may not be called in a derived class (in principle against good
941/// design since a child class should not provide less functionality
942/// than its parent, however, sometimes it is necessary).
943
944void TObject::MayNotUse(const char *method) const
945{
946 Warning(method, "may not use this method");
947}
948
949////////////////////////////////////////////////////////////////////////////////
950/// Use this method to declare a method obsolete. Specify as of which version
951/// the method is obsolete and as from which version it will be removed.
952
953void TObject::Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const
954{
955 const char *classname = "UnknownClass";
956 if (TROOT::Initialized())
957 classname = ClassName();
958
959 ::Obsolete(Form("%s::%s", classname, method), asOfVers, removedFromVers);
960}
961
962////////////////////////////////////////////////////////////////////////////////
963/// Get status of object stat flag.
964
966{
967 return fgObjectStat;
968}
969////////////////////////////////////////////////////////////////////////////////
970/// Turn on/off tracking of objects in the TObjectTable.
971
973{
974 fgObjectStat = stat;
975}
976
977////////////////////////////////////////////////////////////////////////////////
978/// Return destructor only flag
979
981{
982 return fgDtorOnly;
983}
984
985////////////////////////////////////////////////////////////////////////////////
986/// Set destructor only flag
987
988void TObject::SetDtorOnly(void *obj)
989{
990 fgDtorOnly = (Long_t) obj;
991}
992
993////////////////////////////////////////////////////////////////////////////////
994/// Operator delete
995
996void TObject::operator delete(void *ptr)
997{
998 if ((Long_t) ptr != fgDtorOnly)
1000 else
1001 fgDtorOnly = 0;
1002}
1003
1004////////////////////////////////////////////////////////////////////////////////
1005/// Operator delete []
1006
1007void TObject::operator delete[](void *ptr)
1008{
1009 if ((Long_t) ptr != fgDtorOnly)
1011 else
1012 fgDtorOnly = 0;
1013}
1014
1015#ifdef R__SIZEDDELETE
1016////////////////////////////////////////////////////////////////////////////////
1017/// Operator delete for sized deallocation.
1018
1019void TObject::operator delete(void *ptr, size_t size)
1020{
1021 if ((Long_t) ptr != fgDtorOnly)
1022 TStorage::ObjectDealloc(ptr, size);
1023 else
1024 fgDtorOnly = 0;
1025}
1026
1027////////////////////////////////////////////////////////////////////////////////
1028/// Operator delete [] for sized deallocation.
1029
1030void TObject::operator delete[](void *ptr, size_t size)
1031{
1032 if ((Long_t) ptr != fgDtorOnly)
1033 TStorage::ObjectDealloc(ptr, size);
1034 else
1035 fgDtorOnly = 0;
1036}
1037#endif
1038
1039////////////////////////////////////////////////////////////////////////////////
1040/// Print value overload
1041
1042std::string cling::printValue(TObject *val) {
1043 std::ostringstream strm;
1044 strm << "Name: " << val->GetName() << " Title: " << val->GetTitle();
1045 return strm.str();
1046}
1047
1048#ifdef R__PLACEMENTDELETE
1049////////////////////////////////////////////////////////////////////////////////
1050/// Only called by placement new when throwing an exception.
1051
1052void TObject::operator delete(void *ptr, void *vp)
1053{
1054 TStorage::ObjectDealloc(ptr, vp);
1055}
1056
1057////////////////////////////////////////////////////////////////////////////////
1058/// Only called by placement new[] when throwing an exception.
1059
1060void TObject::operator delete[](void *ptr, void *vp)
1061{
1062 TStorage::ObjectDealloc(ptr, vp);
1063}
1064#endif
void Class()
Definition: Class.C:29
#define R__unlikely(expr)
Definition: RConfig.hxx:604
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
unsigned short UShort_t
Definition: RtypesCore.h:38
int Int_t
Definition: RtypesCore.h:43
unsigned int UInt_t
Definition: RtypesCore.h:44
const Bool_t kFALSE
Definition: RtypesCore.h:90
unsigned long ULong_t
Definition: RtypesCore.h:53
long Long_t
Definition: RtypesCore.h:52
bool Bool_t
Definition: RtypesCore.h:61
float Float_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassImp(name)
Definition: Rtypes.h:361
#define gDirectory
Definition: TDirectory.h:229
const Int_t kError
Definition: TError.h:39
const Int_t kSysError
Definition: TError.h:41
void ErrorHandler(int level, const char *location, const char *fmt, va_list va)
General error handler function. It calls the user set error handler.
Definition: TError.cxx:202
const Int_t kFatal
Definition: TError.h:42
const Int_t kWarning
Definition: TError.h:38
const Int_t kInfo
Definition: TError.h:37
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
#define gInterpreter
Definition: TInterpreter.h:556
R__EXTERN TObjectTable * gObjectTable
Definition: TObjectTable.h:82
#define gROOT
Definition: TROOT.h:406
char * Form(const char *fmt,...)
char * StrDup(const char *str)
Duplicate the string str.
Definition: TString.cxx:2490
#define gPad
Definition: TVirtualPad.h:287
#define va_(arg)
Definition: Varargs.h:41
#define snprintf
Definition: civetweb.c:1540
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual void SkipVersion(const TClass *cl=0)=0
virtual TProcessID * ReadProcessID(UShort_t pidf)=0
Return the current Process-ID.
Definition: TBuffer.cxx:344
virtual UShort_t WriteProcessID(TProcessID *pid)=0
Always return 0 (current processID).
Definition: TBuffer.cxx:353
virtual UShort_t GetPidOffset() const =0
Bool_t IsReading() const
Definition: TBuffer.h:85
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
static Int_t AutoBrowse(TObject *obj, TBrowser *browser)
Browse external object inherited from TObject.
Definition: TClass.cxx:1946
virtual TInspectorImp * CreateInspectorImp(const TObject *obj, UInt_t width, UInt_t height)
Create a batch version of TInspectorImp.
Iterator of linked list.
Definition: TList.h:200
void SetOption(Option_t *option)
Sets the object option stored in the list.
Definition: TList.cxx:1152
Option_t * GetOption() const
Returns the object option stored in the list.
Definition: TList.cxx:1143
virtual void Add(TObject *obj)
Definition: TList.h:87
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
An array of TObjects.
Definition: TObjArray.h:37
static void AddObj(TObject *obj)
Add an object to the global object table gObjectTable.
void RemoveQuietly(TObject *obj)
Remove an object from the object table.
Mother of all ROOT objects.
Definition: TObject.h:37
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:933
virtual Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition: TObject.cxx:473
virtual void Inspect() const
Dump contents of this object in a graphics canvas.
Definition: TObject.cxx:464
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Computes distance from point (px,py) to the object.
Definition: TObject.cxx:186
static void SetObjectStat(Bool_t stat)
Turn on/off tracking of objects in the TObjectTable.
Definition: TObject.cxx:972
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition: TObject.cxx:506
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:796
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:483
@ kOverwrite
overwrite existing object with same name
Definition: TObject.h:88
@ kSingleKey
write collection with single key
Definition: TObject.h:87
@ kWriteDelete
write object, then delete previous key with same name
Definition: TObject.h:89
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual void Browse(TBrowser *b)
Browse object. May be overridden for another default action.
Definition: TObject.cxx:119
virtual void Dump() const
Dump contents of object on stdout.
Definition: TObject.cxx:266
UInt_t fUniqueID
object unique identifier
Definition: TObject.h:40
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:187
virtual const char * GetIconName() const
Returns mime type name of object.
Definition: TObject.cxx:367
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
Definition: TObject.cxx:572
virtual void DoError(int level, const char *location, const char *fmt, va_list va) const
Interface to ErrorHandler (protected).
Definition: TObject.cxx:852
virtual Bool_t HandleTimer(TTimer *timer)
Execute action in response of a timer timing out.
Definition: TObject.cxx:411
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:375
@ kIsOnHeap
object is on heap
Definition: TObject.h:77
UInt_t fBits
bit field status word
Definition: TObject.h:41
static Long_t GetDtorOnly()
Return destructor only flag.
Definition: TObject.cxx:980
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:277
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:905
R__ALWAYS_INLINE Bool_t IsOnHeap() const
Definition: TObject.h:148
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:128
virtual void UseCurrentStyle()
Set current style settings in this object This function is called when either TCanvas::UseCurrentStyl...
Definition: TObject.cxx:715
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:877
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:944
static Long_t fgDtorOnly
object for which to call dtor only (i.e. no delete)
Definition: TObject.h:43
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad...
Definition: TObject.cxx:219
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to an event at (px,py).
Definition: TObject.cxx:311
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:321
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
Definition: TObject.cxx:105
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:386
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:664
@ kOnlyPrepStep
Used to request that the class specific implementation of TObject::Write just prepare the objects to ...
Definition: TObject.h:102
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:599
virtual void Delete(Option_t *option="")
Delete this object.
Definition: TObject.cxx:169
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
static Bool_t GetObjectStat()
Get status of object stat flag.
Definition: TObject.cxx:965
virtual void Copy(TObject &object) const
Copy this to obj.
Definition: TObject.cxx:61
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TObject.cxx:677
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:919
static void SetDtorOnly(void *obj)
Set destructor only flag.
Definition: TObject.cxx:988
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:705
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
virtual void DrawClass() const
Draw class inheritance tree of the class to which this object belongs.
Definition: TObject.cxx:210
virtual Int_t Compare(const TObject *obj) const
Compare abstract method.
Definition: TObject.cxx:159
virtual ~TObject()
TObject destructor.
Definition: TObject.cxx:79
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition: TObject.cxx:519
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:550
virtual void Pop()
Pop on object drawn in a pad to the top of the display list.
Definition: TObject.cxx:528
virtual ULong_t Hash() const
Return hash value for this object.
Definition: TObject.cxx:433
virtual void ls(Option_t *option="") const
The ls function lists the contents of a class on stdout.
Definition: TObject.cxx:492
static Bool_t fgObjectStat
if true keep track of objects in TObjectTable
Definition: TObject.h:44
void ResetBit(UInt_t f)
Definition: TObject.h:186
@ kCanDelete
if object in a list can be deleted
Definition: TObject.h:58
@ kIsReferenced
if object is referenced by a TRef or TRefArray
Definition: TObject.h:61
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition: TObject.h:60
virtual Int_t Read(const char *name)
Read contents of object with specified name from the current directory.
Definition: TObject.cxx:562
static void AddToTObjectTable(TObject *)
Private helper function which will dispatch to TObjectTable::AddObj.
Definition: TObject.cxx:96
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:865
void Obsolete(const char *method, const char *asOfVers, const char *removedFromVers) const
Use this method to declare a method obsolete.
Definition: TObject.cxx:953
A TProcessID identifies a ROOT job in a unique way in time and space.
Definition: TProcessID.h:69
void PutObjectWithID(TObject *obj, UInt_t uid=0)
stores the object at the uid th slot in the table of objects The object uniqued is set as well as its...
Definition: TProcessID.cxx:381
static TProcessID * GetProcessWithUID(const TObject *obj)
static function returning a pointer to TProcessID with its pid encoded in the highest byte of obj->Ge...
Definition: TProcessID.cxx:295
static Bool_t Initialized()
Return kTRUE if the TROOT object has been initialized.
Definition: TROOT.cxx:2796
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2781
A TRefTable maintains the association between a referenced object and the parent object supporting th...
Definition: TRefTable.h:35
static TRefTable * GetRefTable()
Static function returning the current TRefTable.
Definition: TRefTable.cxx:287
virtual Int_t Add(Int_t uid, TProcessID *context=0)
Add a new uid to the table.
Definition: TRefTable.cxx:88
static void ObjectDealloc(void *vp)
Used to deallocate a TObject on the heap (via TObject::operator delete()).
Definition: TStorage.cxx:359
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:638
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2289
Handles synchronous and a-synchronous timer events.
Definition: TTimer.h:51
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:51
virtual void Modified(Bool_t flag=1)=0
virtual TList * GetListOfPrimitives() const =0
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
virtual void Update()=0
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
void CallRecursiveRemoveIfNeeded(TObject &obj)
call RecursiveRemove for obj if gROOT is valid and obj.TestBit(kMustCleanup) is true.
Definition: TROOT.h:395