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