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 36 of file RootBranchAddress.cxx.

36  :
37  GenericAddress(),
38  m_ptr (),
39  m_branch (NULL)
40 {}

◆ RootBranchAddress() [2/3]

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

Copy constructor:

Definition at line 43 of file RootBranchAddress.cxx.

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

◆ 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 62 of file RootBranchAddress.cxx.

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

◆ ~RootBranchAddress()

Athena::RootBranchAddress::~RootBranchAddress ( )
virtual

Destructor:

Definition at line 77 of file RootBranchAddress.cxx.

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

Member Function Documentation

◆ operator=()

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

Assignment operator:

Definition at line 51 of file RootBranchAddress.cxx.

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

◆ 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 93 of file RootBranchAddress.cxx.

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

◆ ttree()

TTree * Athena::RootBranchAddress::ttree ( )

the TTree whose branch we proxy

Definition at line 218 of file RootBranchAddress.cxx.

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

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:218
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
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:29
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
Athena::RootBranchAddress::m_ptr
void * m_ptr
Definition: RootBranchAddress.h:89
TScopeAdapter
Definition: RootType.h:119