Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TObjectHolder.cxx
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
10
11#include "TROOT.h"
12#include <sstream>
13
14using namespace ROOT::Browsable;
15
16///////////////////////////////////////////////////////////////////////////
17/// Check if object is not registered in some global lists
18/// Prevent double deletion
19
21{
22 if (obj && obj->InheritsFrom("TH1")) {
23 std::stringstream cmd;
24 cmd << "((TH1 *) " << std::hex << std::showbase << (size_t)obj << ")->SetDirectory(nullptr);";
25 gROOT->ProcessLine(cmd.str().c_str());
26 } else if (obj && obj->InheritsFrom("TF1")) {
27 std::stringstream cmd;
28 cmd << "((TF1 *) " << std::hex << std::showbase << (size_t)obj << ")->AddToGlobalList(kFALSE);";
29 gROOT->ProcessLine(cmd.str().c_str());
30 }
31}
32
33///////////////////////////////////////////////////////////////////////////
34/// Return TObject instance with ownership
35/// If object is not owned by the holder, it will be cloned (except TDirectory or TTree classes)
36
38{
39 auto res = fObj;
40
41 if (fOwner) {
42 fObj = nullptr;
43 fOwner = false;
44 } else if (fObj && !fObj->IsA()->InheritsFrom("TDirectory") && !fObj->IsA()->InheritsFrom("TTree")) {
45 res = fObj->Clone();
47 } else {
48 res = nullptr;
49 }
50
51 return res;
52}
#define gROOT
Definition TROOT.h:406
TObject * fObj
! plain holder without IO
void ClearROOTOwnership(TObject *obj)
Check if object is not registered in some global lists Prevent double deletion.
void * TakeObject() final
Return TObject instance with ownership If object is not owned by the holder, it will be cloned (excep...
bool fOwner
! is TObject owner
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4943
Mother of all ROOT objects.
Definition TObject.h:41
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:241
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
virtual TClass * IsA() const
Definition TObject.h:243