ATLAS Offline Software
Loading...
Searching...
No Matches
ToolColumnVectorMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8//
9// includes
10//
11
13
16#include <algorithm>
17#include <stdexcept>
18
19//
20// method implementations
21//
22
23namespace columnar
24{
25 ToolColumnVectorMap ::
26 ToolColumnVectorMap (ColumnVectorHeader& val_columnHeader, IColumnarTool& val_tool)
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 }
57
58
59
60 std::vector<std::string> ToolColumnVectorMap ::
61 getColumnNames () const
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 }
69
70
71
72 [[nodiscard]] std::size_t ToolColumnVectorMap ::
73 getColumnIndex (const std::string& name) const
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 }
80}
the header information for the entire columnar data vector
an interface for tools that operate on columnar data
virtual void setColumnIndex(const std::string &name, std::size_t index)=0
set the index for the column
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
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
my cached information for the various columns needed