ATLAS Offline Software
Loading...
Searching...
No Matches
Athena::RootBranchAddress Class Reference

A simple class to hold the buffer of a TBranch from a TTree. More...

#include <RootBranchAddress.h>

Inheritance diagram for Athena::RootBranchAddress:
Collaboration diagram for Athena::RootBranchAddress:

Public Member Functions

 RootBranchAddress ()
 Default constructor:
 RootBranchAddress (const RootBranchAddress &rhs)
 Copy constructor:
RootBranchAddressoperator= (const RootBranchAddress &rhs)
 Assignment operator:
 RootBranchAddress (long svc, const CLID &clid, const std::string &p1="", const std::string &p2="", unsigned long ip1=0, unsigned long ip2=0)
 Constructor with parameters:
virtual ~RootBranchAddress ()
 Destructor:
void setBranchAddress (const RootType &t)
 setup the ROOT TTree internal address for the branch.
TTree * ttree ()
 the TTree whose branch we proxy

Public Attributes

RootType m_type
 the buffer for the TBranch
void * m_ptr
TBranch * m_branch
 the branch we are connected to.

Detailed Description

A simple class to hold the buffer of a TBranch from a TTree.

Definition at line 31 of file RootBranchAddress.h.

Constructor & Destructor Documentation

◆ RootBranchAddress() [1/3]

Athena::RootBranchAddress::RootBranchAddress ( )

Default constructor:

Definition at line 35 of file RootBranchAddress.cxx.

35 :
36 GenericAddress(),
37 m_ptr (),
38 m_branch (NULL)
39{}
TBranch * m_branch
the branch we are connected to.

◆ RootBranchAddress() [2/3]

Athena::RootBranchAddress::RootBranchAddress ( const RootBranchAddress & rhs)

Copy constructor:

Definition at line 42 of file RootBranchAddress.cxx.

42 :
43 GenericAddress(rhs),
44 m_ptr (rhs.m_ptr),
45 m_branch (rhs.m_branch)
46{}

◆ RootBranchAddress() [3/3]

Athena::RootBranchAddress::RootBranchAddress ( long svc,
const CLID & clid,
const std::string & p1 = "",
const std::string & p2 = "",
unsigned long ip1 = 0,
unsigned long ip2 = 0 )

Constructor with parameters:

Definition at line 61 of file RootBranchAddress.cxx.

66 :
67 GenericAddress(svc, clid, p1, p2, ip1, ip2),
68 m_ptr (),
69 m_branch (NULL)
70{
71 // std::cerr << "::RBA::+RBA... (this=" << this << ") br=["
72 // << this->par()[1] << "]\n";
73}

◆ ~RootBranchAddress()

Athena::RootBranchAddress::~RootBranchAddress ( )
virtual

Destructor:

Definition at line 76 of file RootBranchAddress.cxx.

77{
78 // std::cerr << "::RBA::~RBA... (this=" << this << ") br=["
79 // << this->par()[1] << "]\n";
80}

Member Function Documentation

◆ operator=()

RootBranchAddress & Athena::RootBranchAddress::operator= ( const RootBranchAddress & rhs)

Assignment operator:

Definition at line 50 of file RootBranchAddress.cxx.

51{
52 if (this != &rhs) {
53 GenericAddress::operator=(rhs);
54 m_ptr = rhs.m_ptr;
55 m_branch = rhs.m_branch;
56 }
57 return *this;
58}

◆ setBranchAddress()

void Athena::RootBranchAddress::setBranchAddress ( const RootType & t)

setup the ROOT TTree internal address for the branch.

as a side-effect, this will load the data from the tree for this branch and entry.

Parameters
tadditional RootType hint (we check the consistency) FIXME: should the TBranch::GetEntry be lifted into its own method ? for the moment, that doesn't seem necessary, as setBranchAddress is only used in one place (LeafCnv) where the intent is to load the data anyway...

Definition at line 92 of file RootBranchAddress.cxx.

93{
94 const std::string& br_name = this->par()[1];
95 //const unsigned long* ipar = this->ipar();
96 TTree *tree = this->ttree();
97 Long64_t ientry = tree->GetReadEntry();
98
99 // std::cerr << "::RBA::setBA(" << this << ") -- tree_nbr=" << tree_nbr << "|"
100 // << " ientry=" << ientry
101 // << "\tname=[" << br_name << "]"
102 // << " addr=" << m_ptr
103 // << "\n";
104 if (m_branch && m_ptr != 0) {
105 m_branch->GetEntry(ientry);
106 return;
107 }
108
109 // activate branch...
110 tree->SetBranchStatus(br_name.c_str(), 1);
111
112 // --- inspired from pyroot/src/Pythonize.cxx ---
113 // search for branch first (typical for objects)
114 TBranch *branch = tree->GetBranch(br_name.c_str());
115 if (!branch) {
116 //ATH_MSG_INFO("-- branch [" << br_name << "] =0 -> trying a subbranch");
117 // for benefit of naming of sub-branches,
118 // the actual name may have a trailing '.'
119 branch = tree->GetBranch((br_name+".").c_str());
120 }
121
122 m_branch = branch;
123 if (branch) {
124 Long64_t bentry = branch->GetReadEntry();
125 if ( bentry != ientry || ientry < 0) {
126 // std::cerr << "::RBA:: -- ientry=" << ientry << " bentry="
127 // << bentry
128 // << "\tname=[" << br_name << "]"
129 // << "\n";
130 /*Long64_t nnn =*/ branch->GetEntry(ientry);
131 bentry = branch->GetReadEntry();
132 // std::cerr << "::RBA:: -- ientry=" << ientry << " bentry="
133 // << bentry
134 // << "\tname=[" << br_name << "]"
135 // << " --> " << nnn
136 // << "\n";
137
138 }
139
140 //ATH_MSG_INFO("-- branch [" << br_name << "] = OK");
141 // found a branched object, wrap its address for the object it represents
142 TClass *cls = TClass::GetClass(branch->GetClassName());
143 if (cls) {
144 if (!branch->GetAddress()) {
145 branch->GetEntry(ientry);
146 }
147 if (branch->GetAddress()) {
148 //ATH_MSG_INFO("-- branch [" << br_name << "] cls: [" << cls->GetName() << "]");
149 void* addr = *(char**)branch->GetAddress();
150 RootType t = RootType(*cls->GetTypeInfo());
151 if (t != rflx_type && !t.Id()) {
152 t = rflx_type;
153 }
154 m_type = std::move(t);
155 m_ptr = addr;
156 return;
157
158 } else {
159 //ATH_MSG_INFO("-- branch [" << br_name << "] cls: [" << cls << "]");
160 }
161 } else {
162 //ATH_MSG_INFO("-- branch [" << br_name << "] cls: [" << cls << "]");
163 }
164
165 }
166
167 // if not, try a leaf
168 TLeaf *leaf = tree->GetLeaf(br_name.c_str());
169 //ATH_MSG_INFO("-- leaf [" << br_name << "] ??");
170 if (branch && !leaf) {
171 leaf = branch->GetLeaf(br_name.c_str());
172 if (!leaf) {
173 TObjArray *leaves = branch->GetListOfLeaves();
174 if (leaves->GetSize() && (leaves->First() == leaves->Last())) {
175 // i.e., if unambiguously only this one
176 leaf = (TLeaf*)leaves->At(0);
177 }
178 }
179 }
180
181 if (leaf) {
182 //ATH_MSG_INFO("-- leaf [" << br_name << "] = OK");
183 // found a leaf, extract value and wrap
184 if ( 1 < leaf->GetLenStatic() || leaf->GetLeafCount() ) {
185 // array types --- FIXME
186 //ATH_MSG_INFO("-- leaf [" << br_name << "] => array...");
187 std::string tname = leaf->GetTypeName();
188 void *addr = (void*)leaf->GetValuePointer();
189 RootType t = RootType(tname+"*");
190 if (t != rflx_type && !t.Id()) {
191 t = rflx_type;
192 }
193 m_type = std::move(t);
194 m_ptr = &addr;
195 return;
196
197 } else {
198 // value types
199 std::string tname = leaf->GetTypeName();
200 // std::cerr << "-- leaf [" << br_name << "] => value-type("
201 // << tname << ")...\n";
202 void *addr = (void*)leaf->GetValuePointer();
203 RootType t = RootType(tname);
204 if (t != rflx_type && !t.Id()) {
205 t = rflx_type;
206 }
207 m_type = std::move(t);
208 m_ptr = addr;
209 // std::cerr << "-->ptr: [" << m_type.Name() << "]\n";
210 }
211 }
212
213}
TTypeAdapter RootType
Definition RootType.h:211
RootType m_type
the buffer for the TBranch
TTree * ttree()
the TTree whose branch we proxy
TChain * tree

◆ ttree()

TTree * Athena::RootBranchAddress::ttree ( )

the TTree whose branch we proxy

Definition at line 217 of file RootBranchAddress.cxx.

218{
219 return reinterpret_cast<TTree*>(reinterpret_cast<unsigned long*>(this->ipar()[0]));
220}

Member Data Documentation

◆ m_branch

TBranch* Athena::RootBranchAddress::m_branch

the branch we are connected to.

Definition at line 92 of file RootBranchAddress.h.

◆ m_ptr

void* Athena::RootBranchAddress::m_ptr

Definition at line 89 of file RootBranchAddress.h.

◆ m_type

RootType Athena::RootBranchAddress::m_type

the buffer for the TBranch

Definition at line 88 of file RootBranchAddress.h.


The documentation for this class was generated from the following files: