ATLAS Offline Software
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 
19 namespace xAOD {
20 
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 
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 
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 
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
xAOD::TPrimitiveAuxBranchManager::m_branch
::TBranch * m_branch
Pointer keeping track of the branch.
Definition: TPrimitiveAuxBranchManager.h:82
xAOD::TPrimitiveAuxBranchManager::branchPtr
::TBranch ** branchPtr()
Pointer to the branch's pointer.
Definition: TPrimitiveAuxBranchManager.cxx:89
xAOD::TPrimitiveAuxBranchManager::~TPrimitiveAuxBranchManager
~TPrimitiveAuxBranchManager()
Destructor.
Definition: TPrimitiveAuxBranchManager.cxx:43
xAOD::TPrimitiveAuxBranchManager::m_vector
SG::IAuxTypeVector * m_vector
Dummy auxiliary variable for the empty events.
Definition: TPrimitiveAuxBranchManager.h:93
TPrimitiveAuxBranchManager.h
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
xAOD::THolder::setOwner
void setOwner(::Bool_t state=kTRUE)
Set whether the holder should own its object.
Definition: THolder.cxx:257
xAOD::TPrimitiveAuxBranchManager::m_auxId
auxid_t m_auxId
Auxiliary variable type.
Definition: TPrimitiveAuxBranchManager.h:91
xAOD::THolder
This class takes care of holding EDM objects in memory.
Definition: THolder.h:35
xAOD::TPrimitiveAuxBranchManager::operator=
TPrimitiveAuxBranchManager & operator=(const TPrimitiveAuxBranchManager &rhs)
Assignment operator.
Definition: TPrimitiveAuxBranchManager.cxx:55
xAOD::THolder::get
const void * get() const
Return a typeless const pointer to the held object.
Definition: THolder.cxx:215
xAOD::TPrimitiveAuxBranchManager::m_holder
THolder * m_holder
Holder object for the EDM object.
Definition: TPrimitiveAuxBranchManager.h:84
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
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TPrimitiveAuxBranchManager::setObject
virtual void setObject(void *obj) override
Function replacing the object being handled.
Definition: TPrimitiveAuxBranchManager.cxx:162
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TVirtualManager
Interface class for the "manager classes".
Definition: TVirtualManager.h:24
xAOD::TPrimitiveAuxBranchManager
Manager for primitive auxiliary branches created dynamically.
Definition: TPrimitiveAuxBranchManager.h:35
xAOD::TPrimitiveAuxBranchManager::object
virtual const void * object() const override
Function getting a const pointer to the object being handled.
Definition: TPrimitiveAuxBranchManager.cxx:152
Message.h
xAOD::THolder::set
virtual void set(void *obj)
Replace the managed object.
Definition: THolder.cxx:230
test_pyathena.parent
parent
Definition: test_pyathena.py:15
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::m_isSet
::Bool_t m_isSet
Was the variable set for the current event?
Definition: TPrimitiveAuxBranchManager.h:88
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
SG::IAuxTypeVector::resize
virtual bool resize(size_t sz)=0
Change the size of the vector.
xAOD::TPrimitiveAuxBranchManager::auxid_t
SG::auxid_t auxid_t
Definition of the auxiliary ID type.
Definition: TPrimitiveAuxBranchManager.h:39
THolder.h
AuxTypeRegistry.h
Handle mappings between names and auxid_t.
xAOD::TPrimitiveAuxBranchManager::branch
::TBranch * branch()
Accessor to the branch.
Definition: TPrimitiveAuxBranchManager.cxx:84
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::TPrimitiveAuxBranchManager::create
virtual ::Bool_t create() override
Create the object for the current event.
Definition: TPrimitiveAuxBranchManager.cxx:177
python.PyAthena.obj
obj
Definition: PyAthena.py:132
xAOD::TPrimitiveAuxBranchManager::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition: TPrimitiveAuxBranchManager.h:86
xAOD::TPrimitiveAuxBranchManager::reset
virtual void reset() override
Reset the object at the end of processing of an event.
Definition: TPrimitiveAuxBranchManager.cxx:204
SG::IAuxTypeVector::toPtr
virtual void * toPtr()=0
Return a pointer to the start of the vector's data.
xAOD::TPrimitiveAuxBranchManager::holder
const THolder * holder() const
Accessor to the Holder object (constant version)
Definition: TPrimitiveAuxBranchManager.cxx:94
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355