ATLAS Offline Software
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 
16 namespace 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 =
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
xAOD::TAuxBranchManager::getEntry
virtual ::Int_t getEntry(::Int_t getall=0) override
Function for updating the object in memory if needed.
Definition: TAuxBranchManager.cxx:102
xAOD::TAuxBranchManager::m_isSet
::Bool_t m_isSet
Was the object set for the current event?
Definition: TAuxBranchManager.h:85
xAOD::TAuxBranchManager::m_holder
THolder * m_holder
Holder object for the EDM object.
Definition: TAuxBranchManager.h:81
xAOD::TAuxBranchManager::create
virtual ::Bool_t create() override
Create the object for the current event.
Definition: TAuxBranchManager.cxx:168
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
xAOD::TAuxBranchManager
Manager for auxiliary branches created dynamically.
Definition: TAuxBranchManager.h:34
TAuxBranchManager.h
xAOD::THolder::setOwner
void setOwner(::Bool_t state=kTRUE)
Set whether the holder should own its object.
Definition: THolder.cxx:257
xAOD::THolder
This class takes care of holding EDM objects in memory.
Definition: THolder.h:35
xAOD::THolder::get
const void * get() const
Return a typeless const pointer to the held object.
Definition: THolder.cxx:215
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TAuxBranchManager::isSet
virtual ::Bool_t isSet() const override
Check if the object was set for the current event.
Definition: TAuxBranchManager.cxx:189
xAOD::TVirtualManager
Interface class for the "manager classes".
Definition: TVirtualManager.h:24
xAOD::TAuxBranchManager::setObject
virtual void setObject(void *obj) override
Function replacing the object being handled.
Definition: TAuxBranchManager.cxx:160
xAOD::TAuxBranchManager::reset
virtual void reset() override
Reset the object at the end of processing of an event.
Definition: TAuxBranchManager.cxx:193
xAOD::TAuxBranchManager::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition: TAuxBranchManager.h:83
xAOD::TAuxBranchManager::~TAuxBranchManager
~TAuxBranchManager()
Destructor.
Definition: TAuxBranchManager.cxx:40
xAOD::TAuxBranchManager::branch
::TBranch * branch()
Accessor to the branch.
Definition: TAuxBranchManager.cxx:82
xAOD::TAuxBranchManager::TAuxBranchManager
TAuxBranchManager(auxid_t auxid, ::TBranch *br=0, THolder *holder=0)
Constructor getting hold of a possible branch.
Definition: TAuxBranchManager.cxx:18
xAOD::TAuxBranchManager::object
virtual const void * object() const override
Function getting a const pointer to the object being handled.
Definition: TAuxBranchManager.cxx:150
Message.h
xAOD::THolder::set
virtual void set(void *obj)
Replace the managed object.
Definition: THolder.cxx:230
xAOD::TAuxBranchManager::auxid_t
SG::auxid_t auxid_t
Definition of the auxiliary ID type.
Definition: TAuxBranchManager.h:38
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SG::IAuxTypeVector::toVector
virtual void * toVector()=0
Return a pointer to the STL vector itself.
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
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::TAuxBranchManager::m_auxId
auxid_t m_auxId
Auxiliary variable type.
Definition: TAuxBranchManager.h:88
xAOD::TAuxBranchManager::m_vector
SG::IAuxTypeVector * m_vector
Dummy auxiliary variable for the empty events.
Definition: TAuxBranchManager.h:90
THolder.h
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
xAOD::TAuxBranchManager::branchPtr
::TBranch ** branchPtr()
Pointer to the branch's pointer.
Definition: TAuxBranchManager.cxx:87
xAOD::TAuxBranchManager::m_branch
::TBranch * m_branch
Pointer keeping track of the branch.
Definition: TAuxBranchManager.h:79
xAOD::TAuxBranchManager::operator=
TAuxBranchManager & operator=(const TAuxBranchManager &rhs)
Assignment operator.
Definition: TAuxBranchManager.cxx:51
python.PyAthena.obj
obj
Definition: PyAthena.py:132
xAOD::TAuxBranchManager::holder
const THolder * holder() const
Accessor to the Holder object (constant version)
Definition: TAuxBranchManager.cxx:92
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355