Skip to content

Commit 72ce715

Browse files
committed
[Tree] Delete virtual copy and copy assignment methods in TTree
The `TTree` class already deletes the copy constructor and the copy assignment, but users might still be tempted to use the virtual copy constructor or copy assignment provided by `TObject::Clone()` and `TObject::Copy()`. But these implementations also make no sense to the TTree. To avoid user confusion, this commit suggests to override these methods in TTree such that they thow an exception and tell you what to use instead. Prevents reports this one in the future: * https://its.cern.ch/jira/browse/ROOT-9111
1 parent 0ba8001 commit 72ce715

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tree/tree/inc/TTree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker
340340
TTree(const TTree& tt) = delete;
341341
TTree& operator=(const TTree& tt) = delete;
342342

343+
TObject *Clone(const char *newname="") const override;
344+
void Copy(TObject &object) const override;
345+
343346
virtual Int_t AddBranchToCache(const char *bname, bool subbranches = false);
344347
virtual Int_t AddBranchToCache(TBranch *branch, bool subbranches = false);
345348
virtual Int_t DropBranchFromCache(const char *bname, bool subbranches = false);

tree/tree/src/TTree.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ End_Macro
466466
#include <climits>
467467
#include <algorithm>
468468
#include <set>
469+
#include <stdexcept>
469470

470471
#ifdef R__USE_IMT
471472
#include "ROOT/TThreadExecutor.hxx"
@@ -1060,6 +1061,17 @@ TTree::~TTree()
10601061
}
10611062
}
10621063

1064+
TObject *TTree::Clone(const char *) const
1065+
{
1066+
throw std::runtime_error("TObject::Clone() is not supported by TTree! Use TTree::CloneTree().");
1067+
}
1068+
1069+
void TTree::Copy(TObject &) const
1070+
{
1071+
throw std::runtime_error(
1072+
"TObject::Copy() is not supported by TTree! Use TTree::CopyTree() or TTree::CopyEntries().");
1073+
}
1074+
10631075
////////////////////////////////////////////////////////////////////////////////
10641076
/// Returns the transient buffer currently used by this TTree for reading/writing baskets.
10651077

0 commit comments

Comments
 (0)