ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
columnar::TestUtils::BranchReader< T > Class Template Referencefinal
Collaboration diagram for columnar::TestUtils::BranchReader< T >:

Public Member Functions

 BranchReader (const std::string &val_branchName)
 
 ~BranchReader () noexcept
 
 BranchReader (const BranchReader &)=delete
 
BranchReaderoperator= (const BranchReader &)=delete
 
void setIsStatic (bool isStatic)
 
const std::string & branchName () const
 
std::string columnName () const
 
std::string containerName () const
 
void connectTree (TTree *tree)
 
const T & getEntry (Long64_t entry)
 
const T & getCachedEntry () const
 

Private Attributes

std::string m_branchName
 
TBranch * m_branch = nullptr
 
bool m_isStatic = std::is_pod_v<T>
 
T * m_data {new T()}
 

Detailed Description

template<typename T>
class columnar::TestUtils::BranchReader< T >

Definition at line 123 of file ColumnarPhysliteTest.cxx.

Constructor & Destructor Documentation

◆ BranchReader() [1/2]

template<typename T >
columnar::TestUtils::BranchReader< T >::BranchReader ( const std::string &  val_branchName)
inline

Definition at line 131 of file ColumnarPhysliteTest.cxx.

132  : m_branchName (val_branchName)
133  {
134  if (m_branchName.find ("Aux.") != std::string::npos)
135  m_isStatic = true;
136  }

◆ ~BranchReader()

template<typename T >
columnar::TestUtils::BranchReader< T >::~BranchReader ( )
inlinenoexcept

Definition at line 138 of file ColumnarPhysliteTest.cxx.

139  {
140  delete m_data;
141  }

◆ BranchReader() [2/2]

template<typename T >
columnar::TestUtils::BranchReader< T >::BranchReader ( const BranchReader< T > &  )
delete

Member Function Documentation

◆ branchName()

template<typename T >
const std::string& columnar::TestUtils::BranchReader< T >::branchName ( ) const
inline

Definition at line 151 of file ColumnarPhysliteTest.cxx.

152  {
153  return m_branchName;
154  }

◆ columnName()

template<typename T >
std::string columnar::TestUtils::BranchReader< T >::columnName ( ) const
inline

Definition at line 156 of file ColumnarPhysliteTest.cxx.

157  {
158  std::string columnName = m_branchName;
159  if (auto index = columnName.find ("AuxDyn."); index != std::string::npos)
160  columnName.replace (index, 6, "");
161  else if (auto index = columnName.find ("Aux."); index != std::string::npos)
162  columnName.replace (index, 3, "");
163  else if (columnName.find (".") != std::string::npos)
164  throw std::runtime_error ("branch name does not contain AuxDyn or Aux: " + m_branchName);
165  return columnName;
166  }

◆ connectTree()

template<typename T >
void columnar::TestUtils::BranchReader< T >::connectTree ( TTree *  tree)
inline

Definition at line 180 of file ColumnarPhysliteTest.cxx.

181  {
182  m_branch = tree->GetBranch (m_branchName.c_str());
183  if (!m_branch)
184  throw std::runtime_error ("failed to get branch: " + m_branchName);
185  m_branch->SetMakeClass (1);
186  if (m_isStatic)
187  m_branch->SetAddress (m_data);
188  else
189  m_branch->SetAddress (&m_data);
190  }

◆ containerName()

template<typename T >
std::string columnar::TestUtils::BranchReader< T >::containerName ( ) const
inline

Definition at line 168 of file ColumnarPhysliteTest.cxx.

169  {
170  if (auto index = m_branchName.find ("AuxDyn."); index != std::string::npos)
171  return m_branchName.substr (0, index);
172  else if (auto index = m_branchName.find ("Aux."); index != std::string::npos)
173  return m_branchName.substr (0, index);
174  else if (m_branchName.find (".") == std::string::npos)
175  return m_branchName;
176  else
177  throw std::runtime_error ("branch name does not contain AuxDyn or Aux: " + m_branchName);
178  }

◆ getCachedEntry()

template<typename T >
const T& columnar::TestUtils::BranchReader< T >::getCachedEntry ( ) const
inline

Definition at line 203 of file ColumnarPhysliteTest.cxx.

204  {
205  return *m_data;
206  }

◆ getEntry()

template<typename T >
const T& columnar::TestUtils::BranchReader< T >::getEntry ( Long64_t  entry)
inline

Definition at line 192 of file ColumnarPhysliteTest.cxx.

193  {
194  if (!m_branch)
195  throw std::runtime_error ("branch not connected: " + m_branchName);
196  if (m_branch->GetEntry (entry) <= 0)
197  throw std::runtime_error ("failed to get entry " + std::to_string (entry) + " for branch: " + m_branchName);
198  if (m_data == nullptr)
199  throw std::runtime_error ("got nullptr reading data for branch: " + m_branchName);
200  return *m_data;
201  }

◆ operator=()

template<typename T >
BranchReader& columnar::TestUtils::BranchReader< T >::operator= ( const BranchReader< T > &  )
delete

◆ setIsStatic()

template<typename T >
void columnar::TestUtils::BranchReader< T >::setIsStatic ( bool  isStatic)
inline

Definition at line 146 of file ColumnarPhysliteTest.cxx.

147  {
148  m_isStatic = isStatic;
149  }

Member Data Documentation

◆ m_branch

template<typename T >
TBranch* columnar::TestUtils::BranchReader< T >::m_branch = nullptr
private

Definition at line 126 of file ColumnarPhysliteTest.cxx.

◆ m_branchName

template<typename T >
std::string columnar::TestUtils::BranchReader< T >::m_branchName
private

Definition at line 125 of file ColumnarPhysliteTest.cxx.

◆ m_data

template<typename T >
T* columnar::TestUtils::BranchReader< T >::m_data {new T()}
private

Definition at line 128 of file ColumnarPhysliteTest.cxx.

◆ m_isStatic

template<typename T >
bool columnar::TestUtils::BranchReader< T >::m_isStatic = std::is_pod_v<T>
private

Definition at line 127 of file ColumnarPhysliteTest.cxx.


The documentation for this class was generated from the following file:
columnar::TestUtils::BranchReader::m_data
T * m_data
Definition: ColumnarPhysliteTest.cxx:128
index
Definition: index.py:1
columnar::TestUtils::BranchReader::m_branch
TBranch * m_branch
Definition: ColumnarPhysliteTest.cxx:126
tree
TChain * tree
Definition: tile_monitor.h:30
columnar::TestUtils::BranchReader::m_branchName
std::string m_branchName
Definition: ColumnarPhysliteTest.cxx:125
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
columnar::TestUtils::BranchReader::m_isStatic
bool m_isStatic
Definition: ColumnarPhysliteTest.cxx:127
columnar::TestUtils::BranchReader::columnName
std::string columnName() const
Definition: ColumnarPhysliteTest.cxx:156