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