ATLAS Offline Software
Loading...
Searching...
No Matches
ManualColumnData.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
14#include <cstdint>
15#include <stdexcept>
16
17//
18// method implementations
19//
20
21namespace columnar
22{
23 namespace TestUtils
24 {
25 namespace
26 {
27 template<typename T>
28 T castGetAny (const std::string& columnName, const std::any& value)
29 {
30 if (value.type() == typeid(float))
31 return std::any_cast<float> (value);
32 if (value.type() == typeid(double))
33 return std::any_cast<double> (value);
34 if (value.type() == typeid(char))
35 return std::any_cast<char> (value);
36 if (value.type() == typeid(int))
37 return std::any_cast<int> (value);
38 if (value.type() == typeid(unsigned))
39 return std::any_cast<unsigned> (value);
40 if (value.type() == typeid(std::size_t))
41 return std::any_cast<std::size_t> (value);
42 throw std::logic_error (columnName + ": received unsupported input type " + boost::core::demangle(value.type().name()) + ", cast value or extend test handler to support it");
43 }
44 template<typename T>
45 std::vector<T> castGetAnyVector (const std::string& columnName, const std::vector<std::any>& value)
46 {
47 std::vector<T> result;
48 result.reserve (value.size());
49 for (auto& v : value)
50 result.push_back (castGetAny<T> (columnName, v));
51 return result;
52 }
53 template<typename T>
54 std::shared_ptr<void> castGetAnyColumn (const std::string& columnName, const std::vector<std::any>& value)
55 {
56 auto vec = std::make_shared<std::vector<T>> (castGetAnyVector<T> (columnName, value));
57 return std::shared_ptr<void> (vec, vec->data());
58 }
59 }
60
61
62
63 ManualColumnData ::
64 ManualColumnData (std::vector<std::any>&& data)
65 : m_data (std::move (data))
66 {
67 }
68
69
70
71 void ManualColumnData ::
72 configureType (const std::string& columnName, const std::type_info& type)
73 {
74 // I could check whether the type matches an already configured
75 // type, but by not doing so I allow the user to reset the column
76 // data if it got overwritten by the tool.
77
78 if (type == typeid(float))
79 {
80 m_column = castGetAnyColumn<float> (columnName, m_data);
81 } else if (type == typeid(char))
82 {
83 m_column = castGetAnyColumn<char> (columnName, m_data);
84 } else if (type == typeid(int))
85 {
86 m_column = castGetAnyColumn<int> (columnName, m_data);
87 } else if (type == typeid(std::uint8_t))
88 {
89 m_column = castGetAnyColumn<std::uint8_t> (columnName, m_data);
90 } else if (type == typeid(std::uint16_t))
91 {
92 m_column = castGetAnyColumn<std::uint16_t> (columnName, m_data);
93 } else if (type == typeid(std::uint32_t))
94 {
95 m_column = castGetAnyColumn<std::uint32_t> (columnName, m_data);
96 } else if (type == typeid(std::uint64_t))
97 {
98 m_column = castGetAnyColumn<std::uint64_t> (columnName, m_data);
99 } else
100 throw std::runtime_error (
101 columnName + ": column has unsupported type " +
102 boost::core::demangle(type.name()) +
103 ", extend test handler to support it");
104 m_type = &type;
105 }
106 }
107}
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::shared_ptr< void > m_column
the column created from m_data
const std::type_info * type() const noexcept
get the type we are configured for
const std::type_info * m_type
the actual type for the column
std::vector< std::any > m_data
a vector of untyped data provided by the user
unsigned long long T
STL namespace.