ATLAS Offline Software
Loading...
Searching...
No Matches
TAuxBranchManager.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3// ROOT include(s):
4#include <TBranch.h>
5#include <TTree.h>
6#include <TError.h>
7
8// EDM include(s):
10
11// Local include(s):
15
16namespace xAOD {
17
19 ::TBranch* br, THolder* holder )
20 : m_branch( br ), m_holder( holder ), m_entry( -1 ),
21 m_isSet( kTRUE ), m_auxId( auxid ), m_vector( nullptr ) {
22 }
23
25 : TVirtualManager(), m_branch( parent.m_branch ), m_holder( nullptr ),
26 m_entry( parent.m_entry ), m_isSet( parent.m_isSet ),
27 m_auxId( parent.m_auxId ), m_vector( nullptr ) {
28
29 if( parent.m_holder ) {
30 m_holder = new THolder( *parent.m_holder );
31 }
32 if( parent.m_vector ) {
33 m_vector =
34 SG::AuxTypeRegistry::instance().makeVector( m_auxId,
35 ( size_t ) 0,
36 ( size_t ) 0 ).release();
37 }
38 }
39
41
42 if( m_holder ) {
43 delete m_holder;
44 }
45 if( m_vector ) {
46 delete m_vector;
47 }
48 }
49
52
53 // Check if anything needs to be done:
54 if( this == &rhs ) {
55 return *this;
56 }
57
58 m_branch = rhs.m_branch;
59 if( m_holder ) delete m_holder;
60 if( rhs.m_holder ) {
61 m_holder = new THolder( *rhs.m_holder );
62 } else {
63 m_holder = 0;
64 }
65 m_entry = rhs.m_entry;
66 m_isSet = rhs.m_isSet;
67 m_auxId = rhs.m_auxId;
68 if( m_vector ) delete m_vector;
69 if( rhs.m_vector ) {
70 m_vector =
72 ( size_t ) 0,
73 ( size_t ) 0 ).release();
74 } else {
75 m_vector = 0;
76 }
77
78 // Return this same object:
79 return *this;
80 }
81
83
84 return m_branch;
85 }
86
88
89 return &m_branch;
90 }
91
93
94 return m_holder;
95 }
96
98
99 return m_holder;
100 }
101
102 ::Int_t TAuxBranchManager::getEntry( ::Int_t getall ) {
103
104 // Make sure that the branch is associated to a tree
105 // as the entry to be read is retrieved from the tree
106 if (!m_branch->GetTree()){
107 Error("xAOD::TAuxBranchManager::getEntry",
108 XAOD_MESSAGE("Branch=%s is not associated to any tree while reading of branches within this class relies on that"),
109 m_branch->GetName());
110 return -1;
111 }
112
113 // Get the entry that should be read
114 // The entry to be read is set with TTree::LoadTree()
115 // NB: for a branch from a friend tree and if the friend tree has an index built,
116 // then the entry to read is found when calling the TTree::LoadTree() function
117 // that matches the major and minor values between the main tree and the friend tree
118 ::Long64_t entry = m_branch->GetTree()->GetReadEntry();
119
120 if ( entry < 0 ){
121 // Raise error as it implies
122 // either that the TTree::LoadTree() function has not been called
123 // or
124 // the entry requested to be read by the user
125 // is not corresponding to any entry for the friend tree
126 Error("xAOD::TAuxBranchManager::getEntry",
127 XAOD_MESSAGE( "Entry to read is not set for branch=%s from tree=%s. "
128 "It is either because TTree::LoadTree(entry) was not called "
129 "beforehand in the TEvent class OR "
130 "the entry requested to be read for the main tree is not corresponding to an event for the friend tree"),
131 m_branch->GetName(),
132 m_branch->GetTree()->GetName());
133 return -1;
134 }
135
136 // Check if anything needs to be done:
137 if( entry == m_entry ) return 0;
138
139 // Load the entry.
140 const ::Int_t nbytes = m_branch->GetEntry( entry, getall );
141
142 // If the load was successful, remember that we loaded this entry.
143 if( nbytes >= 0 ) {
144 m_entry = entry;
145 }
146
147 return nbytes;
148 }
149
150 const void* TAuxBranchManager::object() const {
151
152 return std::as_const(*m_holder).get();
153 }
154
156
157 return m_holder->get();
158 }
159
161
162 m_holder->setOwner( kFALSE );
163 m_holder->set( obj );
164 m_isSet = kTRUE;
165 return;
166 }
167
169
170 // If we already have it set, let's stop here:
171 if( m_isSet ) return kTRUE;
172
173 // Otherwise let's create a default object:
174 m_isSet = kTRUE;
175 if( ! m_vector ) {
176 m_vector =
178 ( size_t ) 0,
179 ( size_t ) 0 ).release();
180 }
181 // ...and use it to fill the current event:
182 m_holder->setOwner( kFALSE );
183 m_holder->set( m_vector->toVector() );
184
185 // We are now "set":
186 return kTRUE;
187 }
188
189 ::Bool_t TAuxBranchManager::isSet() const {
190 return m_isSet;
191 }
192
194
195 m_isSet = kFALSE;
196 return;
197 }
198
199} // namespace xAOD
Handle mappings between names and auxid_t.
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
std::unique_ptr< IAuxTypeVector > makeVector(SG::auxid_t auxid, size_t size, size_t capacity) const
Construct a new vector to hold an aux item.
Manager for auxiliary branches created dynamically.
virtual void setObject(void *obj) override
Function replacing the object being handled.
::Bool_t m_isSet
Was the object set for the current event?
TAuxBranchManager(auxid_t auxid, ::TBranch *br=0, THolder *holder=0)
Constructor getting hold of a possible branch.
SG::auxid_t auxid_t
Definition of the auxiliary ID type.
::TBranch * m_branch
Pointer keeping track of the branch.
virtual void reset() override
Reset the object at the end of processing of an event.
TAuxBranchManager & operator=(const TAuxBranchManager &rhs)
Assignment operator.
const THolder * holder() const
Accessor to the Holder object (constant version)
virtual const void * object() const override
Function getting a const pointer to the object being handled.
virtual::Bool_t isSet() const override
Check if the object was set for the current event.
THolder * m_holder
Holder object for the EDM object.
SG::IAuxTypeVector * m_vector
Dummy auxiliary variable for the empty events.
virtual::Int_t getEntry(::Int_t getall=0) override
Function for updating the object in memory if needed.
::TBranch * branch()
Accessor to the branch.
virtual::Bool_t create() override
Create the object for the current event.
::Long64_t m_entry
The last entry that was loaded for this branch.
auxid_t m_auxId
Auxiliary variable type.
::TBranch ** branchPtr()
Pointer to the branch's pointer.
This class takes care of holding EDM objects in memory.
Definition THolder.h:35
Interface class for the "manager classes".
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.