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  std::unique_ptr<THolder> holder,
20  ::Bool_t renewOnRead )
21  : IObjectManager(std::move(holder)),
22  m_branch( br ), m_entry( -1 ), m_isSet( kTRUE ),
23  m_renewOnRead( renewOnRead ) {
24  }
25 
27  : IObjectManager(parent),
28  m_branch( parent.m_branch ), m_entry( parent.m_entry ),
29  m_isSet( parent.m_isSet ), m_renewOnRead( parent.m_renewOnRead ) {
30 
31  }
32 
34 
36 
37  // Check if we need to do anything:
38  if( this == &parent ) {
39  return *this;
40  }
41 
42  m_branch = parent.m_branch;
44  m_entry = parent.m_entry;
45  m_isSet = parent.m_isSet;
46  m_renewOnRead = parent.m_renewOnRead;
47 
48  return *this;
49  }
50 
51  ::TBranch* TObjectManager::branch() {
52 
53  return m_branch;
54  }
55 
62  ::TBranch** TObjectManager::branchPtr() {
63 
64  return &m_branch;
65  }
66 
74  ::Int_t TObjectManager::getEntry( ::Int_t getall ) {
75 
76  // Make sure that the branch is associated to a tree
77  // as the entry to be read is retrieved from the tree
78  if (!m_branch->GetTree()){
79  Error("xAOD::TObjectManager::getEntry",
80  XAOD_MESSAGE("Branch=%s is not associated to any tree while reading of branches within this class relies on that"),
81  m_branch->GetName());
82  return -1;
83  }
84 
85  // Get the entry that should be read
86  // The entry to be read is set with TTree::LoadTree()
87  // NB: for a branch from a friend tree and if the friend tree has an index built,
88  // then the entry to read is found when calling the TTree::LoadTree() function
89  // that matches the major and minor values between the main tree and the friend tree
90  ::Long64_t entry = m_branch->GetTree()->GetReadEntry();
91 
92  if ( entry < 0 ){
93  // Raise error as it implies
94  // either that the TTree::LoadTree() function has not been called
95  // or
96  // the entry requested to be read by the user
97  // is not corresponding to any entry for the friend tree
98  Error("xAOD::TObjectManager::getEntry",
99  XAOD_MESSAGE( "Entry to read is not set for branch=%s from tree=%s. "
100  "It is either because TTree::LoadTree(entry) was not called "
101  "beforehand in the TEvent class OR "
102  "the entry requested to be read for the main tree is not corresponding to an event for the friend tree" ),
103  m_branch->GetName(),
104  m_branch->GetTree()->GetName());
105  return -1;
106  }
107 
108  // Check if anything needs to be done:
109  if( entry == m_entry ) return 0;
110 
111  // Make sure that the branch is not in "MakeClass mode":
112  if( m_branch->GetMakeClass() ) {
113  m_branch->SetMakeClass( 0 );
114  }
115 
116  // Renew the object in memory if we are in such a mode:
117  if( m_renewOnRead ) {
118  holder()->renew();
119  }
120 
121  // Load the entry.
122  const ::Int_t nbytes = m_branch->GetEntry( entry, getall );
123 
124  // If the load was successful, remember that we loaded this entry.
125  if( nbytes >= 0 ) {
126  m_entry = entry;
127  }
128 
129  // This is a tricky thing... Parts of the code try to minimise some
130  // operations to only happen when an object is getting updated. But
131  // it can happen that an interface or auxiliary store object doesn't
132  // actually store any data itself. So TBranch::GetEntry will return 0.
133  // But we still need to tell the code looking at this return value
134  // that we did go to a new event. So we should never return 0 at
135  // this point...
136  if( nbytes ) {
137  return nbytes;
138  } else {
139  return 1;
140  }
141  }
142 
148  const void* TObjectManager::object() const {
149 
150  return holder()->get();
151  }
152 
154 
155  return holder()->get();
156  }
157 
163 
164  holder()->set( obj );
165  m_isSet = kTRUE;
166  return;
167  }
168 
172 
173  return m_isSet;
174  }
175 
179  ::Bool_t TObjectManager::isSet() const {
180 
181  return m_isSet;
182  }
183 
189 
190  m_isSet = kFALSE;
191  return;
192  }
193 
194 } // namespace xAOD
xAOD::TObjectManager::create
virtual ::Bool_t create() override
Create the object for the current event.
Definition: TObjectManager.cxx:171
xAOD::TObjectManager::m_branch
::TBranch * m_branch
Pointer keeping track of the branch.
Definition: TObjectManager.h:68
xAOD::Details::IObjectManager::holder
const THolder * holder() const
Accessor to the Holder object.
Definition: IObjectManager.cxx:43
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:62
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.
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
xAOD::TObjectManager::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition: TObjectManager.h:70
xAOD::TObjectManager::operator=
TObjectManager & operator=(const TObjectManager &parent)
Assignment operator.
Definition: TObjectManager.cxx:35
xAOD::TObjectManager::TObjectManager
TObjectManager(::TBranch *br=0, std::unique_ptr< THolder > holder=nullptr, ::Bool_t renewOnRead=kFALSE)
Constructor, getting hold of the created objects.
Definition: TObjectManager.cxx:18
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:72
xAOD::TObjectManager::m_renewOnRead
::Bool_t m_renewOnRead
Should the object be recreated on each read?
Definition: TObjectManager.h:74
xAOD::TObjectManager::isSet
virtual ::Bool_t isSet() const override
Check if the object was set for the current event.
Definition: TObjectManager.cxx:179
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:74
xAOD::THolder::renew
void renew()
Renew the object in memory.
Definition: THolder.cxx:420
THolder.h
xAOD::TObjectManager::reset
virtual void reset() override
Reset the object at the end of processing of an event.
Definition: TObjectManager.cxx:188
xAOD::TObjectManager::branch
::TBranch * branch()
Accessor to the branch.
Definition: TObjectManager.cxx:51
python.PyAthena.obj
obj
Definition: PyAthena.py:132
xAOD::TObjectManager::setObject
virtual void setObject(void *obj) override
Function replacing the object being handled.
Definition: TObjectManager.cxx:162
xAOD::TObjectManager::object
virtual const void * object() const override
Function getting a const pointer to the object being handled.
Definition: TObjectManager.cxx:148
PlotCalibFromCool.br
br
Definition: PlotCalibFromCool.py:355