ATLAS Offline Software
TObjectManager.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 // Local include(s):
15 
16 namespace xAOD {
17 
19  ::Bool_t renewOnRead )
20  : m_branch( br ), m_holder( holder ), m_entry( -1 ), m_isSet( kTRUE ),
21  m_renewOnRead( renewOnRead ) {
22  }
23 
25  : TVirtualManager(), m_branch( parent.m_branch ),
26  m_holder( 0 ), m_entry( parent.m_entry ),
27  m_isSet( parent.m_isSet ), m_renewOnRead( parent.m_renewOnRead ) {
28 
29  if( parent.m_holder ) {
30  m_holder = new THolder( *parent.m_holder );
31  }
32  }
33 
35 
36  // Delete the holder object if we have one:
37  if( m_holder ) {
38  delete m_holder;
39  }
40  }
41 
43 
44  // Check if we need to do anything:
45  if( this == &parent ) {
46  return *this;
47  }
48 
49  m_branch = parent.m_branch;
50  if( m_holder ) {
51  delete m_holder;
52  m_holder = 0;
53  }
54  if( parent.m_holder ) {
55  m_holder = new THolder( *parent.m_holder );
56  }
57  m_entry = parent.m_entry;
58  m_isSet = parent.m_isSet;
59  m_renewOnRead = parent.m_renewOnRead;
60 
61  return *this;
62  }
63 
64  ::TBranch* TObjectManager::branch() {
65 
66  return m_branch;
67  }
68 
75  ::TBranch** TObjectManager::branchPtr() {
76 
77  return &m_branch;
78  }
79 
83 
84  return m_holder;
85  }
86 
90 
91  return m_holder;
92  }
93 
101  ::Int_t TObjectManager::getEntry( ::Int_t getall ) {
102 
103  // Make sure that the branch is associated to a tree
104  // as the entry to be read is retrieved from the tree
105  if (!m_branch->GetTree()){
106  Error("xAOD::TObjectManager::getEntry",
107  XAOD_MESSAGE("Branch=%s is not associated to any tree while reading of branches within this class relies on that"),
108  m_branch->GetName());
109  return -1;
110  }
111 
112  // Get the entry that should be read
113  // The entry to be read is set with TTree::LoadTree()
114  // NB: for a branch from a friend tree and if the friend tree has an index built,
115  // then the entry to read is found when calling the TTree::LoadTree() function
116  // that matches the major and minor values between the main tree and the friend tree
117  ::Long64_t entry = m_branch->GetTree()->GetReadEntry();
118 
119  if ( entry < 0 ){
120  // Raise error as it implies
121  // either that the TTree::LoadTree() function has not been called
122  // or
123  // the entry requested to be read by the user
124  // is not corresponding to any entry for the friend tree
125  Error("xAOD::TObjectManager::getEntry",
126  XAOD_MESSAGE( "Entry to read is not set for branch=%s from tree=%s. "
127  "It is either because TTree::LoadTree(entry) was not called "
128  "beforehand in the TEvent class OR "
129  "the entry requested to be read for the main tree is not corresponding to an event for the friend tree" ),
130  m_branch->GetName(),
131  m_branch->GetTree()->GetName());
132  return -1;
133  }
134 
135  // Check if anything needs to be done:
136  if( entry == m_entry ) return 0;
137 
138  // Make sure that the branch is not in "MakeClass mode":
139  if( m_branch->GetMakeClass() ) {
140  m_branch->SetMakeClass( 0 );
141  }
142 
143  // Renew the object in memory if we are in such a mode:
144  if( m_renewOnRead ) {
145  m_holder->renew();
146  }
147 
148  // Load the entry.
149  const ::Int_t nbytes = m_branch->GetEntry( entry, getall );
150 
151  // If the load was successful, remember that we loaded this entry.
152  if( nbytes >= 0 ) {
153  m_entry = entry;
154  }
155 
156  // This is a tricky thing... Parts of the code try to minimise some
157  // operations to only happen when an object is getting updated. But
158  // it can happen that an interface or auxiliary store object doesn't
159  // actually store any data itself. So TBranch::GetEntry will return 0.
160  // But we still need to tell the code looking at this return value
161  // that we did go to a new event. So we should never return 0 at
162  // this point...
163  if( nbytes ) {
164  return nbytes;
165  } else {
166  return 1;
167  }
168  }
169 
175  const void* TObjectManager::object() const {
176 
177  return std::as_const(*m_holder).get();
178  }
179 
181 
182  return m_holder->get();
183  }
184 
190 
191  m_holder->set( obj );
192  m_isSet = kTRUE;
193  return;
194  }
195 
199 
200  return m_isSet;
201  }
202 
206  ::Bool_t TObjectManager::isSet() const {
207 
208  return m_isSet;
209  }
210 
216 
217  m_isSet = kFALSE;
218  return;
219  }
220 
221 } // namespace xAOD
xAOD::TObjectManager::create
virtual ::Bool_t create() override
Create the object for the current event.
Definition: TObjectManager.cxx:198
xAOD::TObjectManager::m_branch
::TBranch * m_branch
Pointer keeping track of the branch.
Definition: TObjectManager.h:71
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::TObjectManager::branchPtr
::TBranch ** branchPtr()
Pointer to the branch's pointer.
Definition: TObjectManager.cxx:75
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TObjectManager::~TObjectManager
~TObjectManager()
Destructor.
Definition: TObjectManager.cxx:34
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::TObjectManager::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition: TObjectManager.h:75
xAOD::TObjectManager::operator=
TObjectManager & operator=(const TObjectManager &parent)
Assignment operator.
Definition: TObjectManager.cxx:42
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::TObjectManager::m_isSet
::Bool_t m_isSet
Was the object set for the current event?
Definition: TObjectManager.h:77
xAOD::TObjectManager::m_renewOnRead
::Bool_t m_renewOnRead
Should the object be recreated on each read?
Definition: TObjectManager.h:79
xAOD::TObjectManager::isSet
virtual ::Bool_t isSet() const override
Check if the object was set for the current event.
Definition: TObjectManager.cxx:206
TObjectManager.h
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TObjectManager
Manager for EDM objects created by ROOT.
Definition: TObjectManager.h:29
xAOD::TObjectManager::getEntry
virtual ::Int_t getEntry(::Int_t getall=0) override
Function for updating the object in memory if needed.
Definition: TObjectManager.cxx:101
xAOD::THolder::renew
void renew()
Renew the object in memory.
Definition: THolder.cxx:420
xAOD::TObjectManager::holder
const THolder * holder() const
Accessor to the Holder object.
Definition: TObjectManager.cxx:82
THolder.h
xAOD::TObjectManager::reset
virtual void reset() override
Reset the object at the end of processing of an event.
Definition: TObjectManager.cxx:215
xAOD::TObjectManager::TObjectManager
TObjectManager(::TBranch *br=0, THolder *holder=0, ::Bool_t renewOnRead=kFALSE)
Constructor, getting hold of the created objects.
Definition: TObjectManager.cxx:18
xAOD::TObjectManager::branch
::TBranch * branch()
Accessor to the branch.
Definition: TObjectManager.cxx:64
python.PyAthena.obj
obj
Definition: PyAthena.py:135
xAOD::TObjectManager::setObject
virtual void setObject(void *obj) override
Function replacing the object being handled.
Definition: TObjectManager.cxx:189
xAOD::TObjectManager::object
virtual const void * object() const override
Function getting a const pointer to the object being handled.
Definition: TObjectManager.cxx:175
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355
xAOD::TObjectManager::m_holder
THolder * m_holder
Holder object for the EDM object.
Definition: TObjectManager.h:73