ATLAS Offline Software
Loading...
Searching...
No Matches
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
BranchReader & operator= (const BranchReader &)=delete
void setIsStatic (bool isStatic)
const std::string & branchName () const
std::string columnName () const
std::string containerName () const
void connectTree (TTree *tree)
void connectTree (const Backend &b)
const T & getEntry (Long64_t entry)
const T & getCachedEntry () const
std::optional< float > entrySize () const
std::optional< float > uncompressedSize () const
std::optional< unsigned > numBaskets ()

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 28 of file ColumnReaderTTree.cxx.

Constructor & Destructor Documentation

◆ BranchReader() [1/2]

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

◆ ~BranchReader()

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

Definition at line 43 of file ColumnReaderTTree.cxx.

◆ 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
inlinenodiscard

Definition at line 56 of file ColumnReaderTTree.cxx.

57 {
58 return m_branchName;
59 }

◆ columnName()

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

Definition at line 61 of file ColumnReaderTTree.cxx.

62 {
64 if (auto index = columnName.find("AuxDyn."); index != std::string::npos)
65 columnName.replace(index, 6, "");
66 else if (auto index = columnName.find("Aux."); index != std::string::npos)
67 columnName.replace(index, 3, "");
68 else if (columnName.find(".") != std::string::npos)
69 throw std::runtime_error("branch name does not contain AuxDyn or Aux: " +m_branchName);
70 return columnName;
71 }

◆ connectTree() [1/2]

template<typename T>
void columnar::TestUtils::BranchReader< T >::connectTree ( const Backend & b)
inline

Definition at line 97 of file ColumnReaderTTree.cxx.

98 {
99 auto* tree = std::get<TTree*>(b); // throws if wrong backend
101 }

◆ connectTree() [2/2]

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

Definition at line 85 of file ColumnReaderTTree.cxx.

86 {
87 m_branch = tree->GetBranch(m_branchName.c_str());
88 if (!m_branch)
89 throw std::runtime_error("failed to get branch: " + m_branchName);
90 m_branch->SetMakeClass(1);
91 if (m_isStatic)
92 m_branch->SetAddress(m_data);
93 else
94 m_branch->SetAddress(&m_data);
95 }

◆ containerName()

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

Definition at line 73 of file ColumnReaderTTree.cxx.

74 {
75 if (auto index = m_branchName.find("AuxDyn."); index != std::string::npos)
76 return m_branchName.substr(0, index);
77 else if (auto index = m_branchName.find("Aux."); index != std::string::npos)
78 return m_branchName.substr(0, index);
79 else if (m_branchName.find(".") == std::string::npos)
80 return m_branchName;
81 else
82 throw std::runtime_error("branch name does not contain AuxDyn or Aux: " +m_branchName);
83 }

◆ entrySize()

template<typename T>
std::optional< float > columnar::TestUtils::BranchReader< T >::entrySize ( ) const
inline

Definition at line 119 of file ColumnReaderTTree.cxx.

120 {
121 if (!m_branch)
122 return std::nullopt;
123 return static_cast<float>(m_branch->GetZipBytes()) / m_branch->GetEntries();
124 }

◆ getCachedEntry()

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

Definition at line 114 of file ColumnReaderTTree.cxx.

115 {
116 return *m_data;
117 }

◆ getEntry()

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

Definition at line 103 of file ColumnReaderTTree.cxx.

104 {
105 if (!m_branch)
106 throw std::runtime_error("branch not connected: " + m_branchName);
107 if (m_branch->GetEntry(entry) <= 0)
108 throw std::runtime_error("failed to get entry " + std::to_string(entry) + " for branch: " + m_branchName);
109 if (m_data == nullptr)
110 throw std::runtime_error("got nullptr reading data for branch: " + m_branchName);
111 return *m_data;
112 }

◆ numBaskets()

template<typename T>
std::optional< unsigned > columnar::TestUtils::BranchReader< T >::numBaskets ( )
inline

Definition at line 135 of file ColumnReaderTTree.cxx.

136 {
137 if (!m_branch)
138 return std::nullopt;
139 return m_branch->GetListOfBaskets()->GetSize();
140 }

◆ 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 51 of file ColumnReaderTTree.cxx.

52 {
54 }

◆ uncompressedSize()

template<typename T>
std::optional< float > columnar::TestUtils::BranchReader< T >::uncompressedSize ( ) const
inline

Definition at line 126 of file ColumnReaderTTree.cxx.

127 {
128 if (!m_branch)
129 return std::nullopt;
130 return static_cast<float>(m_branch->GetTotBytes()) / m_branch->GetEntries();
131 }

Member Data Documentation

◆ m_branch

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

Definition at line 31 of file ColumnReaderTTree.cxx.

◆ m_branchName

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

Definition at line 30 of file ColumnReaderTTree.cxx.

◆ m_data

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

Definition at line 33 of file ColumnReaderTTree.cxx.

33{new T()};

◆ m_isStatic

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

Definition at line 32 of file ColumnReaderTTree.cxx.


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