ATLAS Offline Software
Loading...
Searching...
No Matches
columnar::ToolColumnVectorMap Class Referencefinal

a class that interfaces an IColumnarTool to a ColumnVectorHeader More...

#include <ToolColumnVectorMap.h>

Collaboration diagram for columnar::ToolColumnVectorMap:

Classes

struct  MyColumnInfo
 my cached information for the various columns needed More...

Public Member Functions

 ToolColumnVectorMap (ColumnVectorHeader &val_columnHeader, IColumnarTool &val_tool)
 standard constructor
const IColumnarToolgetTool () const
 get the wrapped tool
const ColumnVectorHeadergetColumnHeader () const
 get the header information for the various columns needed
std::vector< std::string > getColumnNames () const
 get the list of all defined columns
std::size_t getColumnIndex (const std::string &name) const
 get the index for the column with the given name
template<typename CT>
void setColumn (ColumnVectorData &columnData, const std::string &name, std::size_t size, CT *dataPtr) const
 set the data for the given column picking up the type via a template
void setColumnVoid (ColumnVectorData &columnData, const std::string &name, std::size_t size, const void *dataPtr, const std::type_info &type, bool isConst) const
 set the data for the given column with the user passing in the type
template<typename CT>
std::pair< std::size_t, CT * > getColumn (ColumnVectorData &columnData, const std::string &name) const
 get the data for the given column picking up the type via a template
std::pair< std::size_t, const void * > getColumnVoid (ColumnVectorData &columnData, const std::string &name, const std::type_info *type, bool isConst) const
 get the data for the given column in a type-erased manner

Private Attributes

const IColumnarToolm_tool = nullptr
 the wrapped tool
ColumnVectorHeaderm_columnHeader = nullptr
 the header information for the various columns needed
std::unordered_map< std::string, MyColumnInfom_columns

Detailed Description

a class that interfaces an IColumnarTool to a ColumnVectorHeader

This takes care of registering all the columns needed by the tool, storing the name-index map, and setting the column indices in the tool.

This class does not try to take care of any tool management, or working with the ColumnVectorData. It does provide some helpers implemented using its own public interface, but this is just for convenience.

Definition at line 29 of file ToolColumnVectorMap.h.

Constructor & Destructor Documentation

◆ ToolColumnVectorMap()

columnar::ToolColumnVectorMap::ToolColumnVectorMap ( ColumnVectorHeader & val_columnHeader,
IColumnarTool & val_tool )
explicit

standard constructor

Public Members

This will extract the column information from the tool, configure all the columns for it, and set the proper column indices in the tool.

Definition at line 25 of file ToolColumnVectorMap.cxx.

27 : m_tool (&val_tool), m_columnHeader (&val_columnHeader)
28 {
29 auto toolColumns = m_tool->getColumnInfo();
30 for (auto& column : toolColumns)
31 {
32 const std::size_t columnIndex = m_columnHeader->addColumn (column);
33
34 MyColumnInfo myinfo;
35 myinfo.index = columnIndex;
36 val_tool.setColumnIndex (column.name, myinfo.index);
37
38 auto [iter, success] = m_columns.emplace (column.name, std::move (myinfo));
39 if (!success)
40 throw std::runtime_error ("column name already registered: " + column.name);
41 }
42
43 for (auto& column : toolColumns)
44 {
45 if (!column.offsetName.empty())
46 {
47 auto offsetIter = m_columns.find (column.offsetName);
48 if (offsetIter == m_columns.end())
49 throw std::runtime_error ("offset column name not found: " + column.offsetName);
50 m_columnHeader->setOffsetColumn (m_columns.at (column.name).index, offsetIter->second.index);
51 }
52 }
53
54 // final consistency check
55 m_columnHeader->checkSelf ();
56 }
ColumnVectorHeader * m_columnHeader
the header information for the various columns needed
std::unordered_map< std::string, MyColumnInfo > m_columns
const IColumnarTool * m_tool
the wrapped tool
my cached information for the various columns needed

Member Function Documentation

◆ getColumn()

template<typename CT>
std::pair< std::size_t, CT * > columnar::ToolColumnVectorMap::getColumn ( ColumnVectorData & columnData,
const std::string & name ) const
inlinenodiscard

get the data for the given column picking up the type via a template

Definition at line 94 of file ToolColumnVectorMap.h.

94 {
95 return columnData.getColumn<CT> (getColumnIndex(name));
96 }
std::size_t getColumnIndex(const std::string &name) const
get the index for the column with the given name

◆ getColumnHeader()

const ColumnVectorHeader & columnar::ToolColumnVectorMap::getColumnHeader ( ) const
inlinenodiscard

get the header information for the various columns needed

Definition at line 49 of file ToolColumnVectorMap.h.

49 {
50 return *m_columnHeader; }

◆ getColumnIndex()

std::size_t columnar::ToolColumnVectorMap::getColumnIndex ( const std::string & name) const
nodiscard

get the index for the column with the given name

This is mostly to share the lookup code, as well as the proper error handling.

Definition at line 72 of file ToolColumnVectorMap.cxx.

74 {
75 auto column = m_columns.find (name);
76 if (column == m_columns.end())
77 throw std::runtime_error ("trying to access unknown column " + name + " on tool");
78 return column->second.index;
79 }

◆ getColumnNames()

std::vector< std::string > columnar::ToolColumnVectorMap::getColumnNames ( ) const
nodiscard

get the list of all defined columns

This is mostly to make it easy for the caller to know which columns are defined. For more complete information ask the tool directly for the vector of ColumnInfo.

Definition at line 60 of file ToolColumnVectorMap.cxx.

62 {
63 std::vector<std::string> result;
64 for (auto& column : m_columns)
65 result.push_back (column.first);
66 std::sort (result.begin(), result.end());
67 return result;
68 }
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ getColumnVoid()

std::pair< std::size_t, const void * > columnar::ToolColumnVectorMap::getColumnVoid ( ColumnVectorData & columnData,
const std::string & name,
const std::type_info * type,
bool isConst ) const
inlinenodiscard

get the data for the given column in a type-erased manner

Definition at line 100 of file ToolColumnVectorMap.h.

100 {
101 return columnData.getColumnVoid (getColumnIndex(name), type, isConst);
102 }

◆ getTool()

const IColumnarTool & columnar::ToolColumnVectorMap::getTool ( ) const
inlinenodiscard

get the wrapped tool

Definition at line 45 of file ToolColumnVectorMap.h.

45 {
46 return *m_tool; }

◆ setColumn()

template<typename CT>
void columnar::ToolColumnVectorMap::setColumn ( ColumnVectorData & columnData,
const std::string & name,
std::size_t size,
CT * dataPtr ) const
inline

set the data for the given column picking up the type via a template

Forwarding MemberFunctions

These function are just forwarding to ColumnVectorHeader and ColumnVectorData. These are just here to make use easier and insulate the user from changes (Law of Demeter).

Definition at line 79 of file ToolColumnVectorMap.h.

79 {
80 columnData.setColumn (getColumnIndex(name), size, dataPtr);
81 }

◆ setColumnVoid()

void columnar::ToolColumnVectorMap::setColumnVoid ( ColumnVectorData & columnData,
const std::string & name,
std::size_t size,
const void * dataPtr,
const std::type_info & type,
bool isConst ) const
inline

set the data for the given column with the user passing in the type

Definition at line 85 of file ToolColumnVectorMap.h.

85 {
86 columnData.setColumnVoid (getColumnIndex(name), size, dataPtr, type, isConst);
87 }

Member Data Documentation

◆ m_columnHeader

ColumnVectorHeader* columnar::ToolColumnVectorMap::m_columnHeader = nullptr
private

the header information for the various columns needed

Definition at line 115 of file ToolColumnVectorMap.h.

◆ m_columns

std::unordered_map<std::string,MyColumnInfo> columnar::ToolColumnVectorMap::m_columns
private

Definition at line 122 of file ToolColumnVectorMap.h.

◆ m_tool

const IColumnarTool* columnar::ToolColumnVectorMap::m_tool = nullptr
private

the wrapped tool

Private Members

Definition at line 112 of file ToolColumnVectorMap.h.


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