ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
Athena::RootBranchAddress Class Reference

#include <RootBranchAddress.h>

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

Public Member Functions

 RootBranchAddress ()
 Default constructor: More...
 
 RootBranchAddress (const RootBranchAddress &rhs)
 Copy constructor: More...
 
RootBranchAddressoperator= (const RootBranchAddress &rhs)
 Assignment operator: More...
 
 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: More...
 
virtual ~RootBranchAddress ()
 Destructor: More...
 
void setBranchAddress (const RootType &t)
 setup the ROOT TTree internal address for the branch. More...
 
TTree * ttree ()
 the TTree whose branch we proxy More...
 

Public Attributes

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

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 {}

◆ 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) {
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 }

◆ 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:
Athena::RootBranchAddress::m_type
RootType m_type
the buffer for the TBranch
Definition: RootBranchAddress.h:88
Athena::RootBranchAddress::m_branch
TBranch * m_branch
the branch we are connected to.
Definition: RootBranchAddress.h:92
tree
TChain * tree
Definition: tile_monitor.h:30
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
Athena::RootBranchAddress::ttree
TTree * ttree()
the TTree whose branch we proxy
Definition: RootBranchAddress.cxx:217
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
columnar::operator=
AccessorTemplate & operator=(AccessorTemplate &&that)
Definition: VectorColumn.h:88
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
RootType
TTypeAdapter RootType
Definition: RootType.h:211
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:28
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
Athena::RootBranchAddress::m_ptr
void * m_ptr
Definition: RootBranchAddress.h:89
TScopeAdapter
Definition: RootType.h:119