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