ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
xAODRootAccess
Root
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):
12
#include "
AthContainers/AuxTypeRegistry.h
"
13
14
// Local include(s):
15
#include "
xAODRootAccess/tools/TPrimitiveAuxBranchManager.h
"
16
#include "
xAODRootAccess/tools/THolder.h
"
17
#include "
xAODRootAccess/tools/Message.h
"
18
19
namespace
xAOD
{
20
21
TPrimitiveAuxBranchManager::TPrimitiveAuxBranchManager
(
auxid_t
auxid,
22
::TBranch* br,
23
THolder
*
holder
)
24
:
m_branch
( br ),
m_holder
(
holder
),
m_entry
( -1 ),
25
m_isSet
( kTRUE ),
m_auxId
( auxid ),
m_vector
( 0 ) {
26
}
27
28
TPrimitiveAuxBranchManager::
29
TPrimitiveAuxBranchManager
(
const
TPrimitiveAuxBranchManager
& parent )
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
43
TPrimitiveAuxBranchManager::~TPrimitiveAuxBranchManager
() {
44
45
if
(
m_holder
) {
46
delete
m_holder
;
47
}
48
if
(
m_vector
) {
49
delete
m_vector
;
50
}
51
}
52
53
TPrimitiveAuxBranchManager
&
54
TPrimitiveAuxBranchManager::
55
operator=
(
const
TPrimitiveAuxBranchManager
& rhs ) {
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
84
::TBranch*
TPrimitiveAuxBranchManager::branch
() {
85
86
return
m_branch
;
87
}
88
89
::TBranch**
TPrimitiveAuxBranchManager::branchPtr
() {
90
91
return
&
m_branch
;
92
}
93
94
const
THolder
*
TPrimitiveAuxBranchManager::holder
()
const
{
95
96
return
m_holder
;
97
}
98
99
THolder
*
TPrimitiveAuxBranchManager::holder
() {
100
101
return
m_holder
;
102
}
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
152
const
void
*
TPrimitiveAuxBranchManager::object
()
const
{
153
154
return
std::as_const(*m_holder).get();
155
}
156
157
void
*
TPrimitiveAuxBranchManager::object
() {
158
159
return
m_holder
->get();
160
}
161
162
void
TPrimitiveAuxBranchManager::setObject
(
void
* obj ) {
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
177
::Bool_t
TPrimitiveAuxBranchManager::create
() {
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
199
::Bool_t
TPrimitiveAuxBranchManager::isSet
()
const
{
200
201
return
m_isSet
;
202
}
203
204
void
TPrimitiveAuxBranchManager::reset
() {
205
206
m_isSet
= kFALSE;
207
return
;
208
}
209
210
}
// namespace xAOD
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
Message.h
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition
Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
THolder.h
TPrimitiveAuxBranchManager.h
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition
AuxTypeRegistry.cxx:640
SG::AuxTypeRegistry::makeVector
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.
Definition
AuxTypeRegistry.cxx:818
xAOD::THolder
This class takes care of holding EDM objects in memory.
Definition
THolder.h:35
xAOD::TPrimitiveAuxBranchManager
Manager for primitive auxiliary branches created dynamically.
Definition
TPrimitiveAuxBranchManager.h:35
xAOD::TPrimitiveAuxBranchManager::m_vector
SG::IAuxTypeVector * m_vector
Dummy auxiliary variable for the empty events.
Definition
TPrimitiveAuxBranchManager.h:93
xAOD::TPrimitiveAuxBranchManager::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition
TPrimitiveAuxBranchManager.h:86
xAOD::TPrimitiveAuxBranchManager::holder
const THolder * holder() const
Accessor to the Holder object (constant version).
Definition
TPrimitiveAuxBranchManager.cxx:94
xAOD::TPrimitiveAuxBranchManager::auxid_t
SG::auxid_t auxid_t
Definition of the auxiliary ID type.
Definition
TPrimitiveAuxBranchManager.h:39
xAOD::TPrimitiveAuxBranchManager::m_isSet
::Bool_t m_isSet
Was the variable set for the current event?
Definition
TPrimitiveAuxBranchManager.h:88
xAOD::TPrimitiveAuxBranchManager::branch
::TBranch * branch()
Accessor to the branch.
Definition
TPrimitiveAuxBranchManager.cxx:84
xAOD::TPrimitiveAuxBranchManager::~TPrimitiveAuxBranchManager
~TPrimitiveAuxBranchManager()
Destructor.
Definition
TPrimitiveAuxBranchManager.cxx:43
xAOD::TPrimitiveAuxBranchManager::setObject
virtual void setObject(void *obj) override
Function replacing the object being handled.
Definition
TPrimitiveAuxBranchManager.cxx:162
xAOD::TPrimitiveAuxBranchManager::m_branch
::TBranch * m_branch
Pointer keeping track of the branch.
Definition
TPrimitiveAuxBranchManager.h:82
xAOD::TPrimitiveAuxBranchManager::getEntry
virtual::Int_t getEntry(::Int_t getall=0) override
Function for updating the object in memory if needed.
Definition
TPrimitiveAuxBranchManager.cxx:104
xAOD::TPrimitiveAuxBranchManager::create
virtual::Bool_t create() override
Create the object for the current event.
Definition
TPrimitiveAuxBranchManager.cxx:177
xAOD::TPrimitiveAuxBranchManager::reset
virtual void reset() override
Reset the object at the end of processing of an event.
Definition
TPrimitiveAuxBranchManager.cxx:204
xAOD::TPrimitiveAuxBranchManager::m_holder
THolder * m_holder
Holder object for the EDM object.
Definition
TPrimitiveAuxBranchManager.h:84
xAOD::TPrimitiveAuxBranchManager::m_auxId
auxid_t m_auxId
Auxiliary variable type.
Definition
TPrimitiveAuxBranchManager.h:91
xAOD::TPrimitiveAuxBranchManager::branchPtr
::TBranch ** branchPtr()
Pointer to the branch's pointer.
Definition
TPrimitiveAuxBranchManager.cxx:89
xAOD::TPrimitiveAuxBranchManager::operator=
TPrimitiveAuxBranchManager & operator=(const TPrimitiveAuxBranchManager &rhs)
Assignment operator.
Definition
TPrimitiveAuxBranchManager.cxx:55
xAOD::TPrimitiveAuxBranchManager::object
virtual const void * object() const override
Function getting a const pointer to the object being handled.
Definition
TPrimitiveAuxBranchManager.cxx:152
xAOD::TPrimitiveAuxBranchManager::isSet
virtual::Bool_t isSet() const override
Check if the object was set for the current event.
Definition
TPrimitiveAuxBranchManager.cxx:199
xAOD::TPrimitiveAuxBranchManager::TPrimitiveAuxBranchManager
TPrimitiveAuxBranchManager(auxid_t auxid, ::TBranch *br=0, THolder *holder=0)
Constructor getting hold of a possible branch.
Definition
TPrimitiveAuxBranchManager.cxx:21
xAOD::TVirtualManager
Interface class for the "manager classes".
Definition
TVirtualManager.h:24
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
Generated on
for ATLAS Offline Software by
1.17.0