Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ColumnarMemoryTest.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 
15 
16 #ifdef XAOD_STANDALONE
18 #endif
19 
20 //
21 // method implementations
22 //
23 
24 namespace columnar
25 {
28  {
29 #ifdef XAOD_STANDALONE
30  static std::once_flag flag;
31  std::call_once (flag, [] ()
32  {
33  // Preload the component factories: Alternately this could be
34  // loaded and executed via a dictionary, but I had some technical
35  // issue with that, and this seems to be working.
37  });
38 #endif
39  }
40 
41 
42 
45  {
46  static std::atomic<unsigned> index = 0;
47  return "UniqueMemoryTestTool" + std::to_string(++index);
48  }
49 
50 
51 
53  checkMode ()
54  {
55  return std::is_same_v<ColumnarModeDefault,ColumnarModeArray>;
56  }
57 
58 
59 
62  {
63  m_tool = dynamic_cast<IColumnarTool*> (&val_tool);
64  if (m_tool == nullptr)
65  throw std::runtime_error ("tool does not implement IColumnarTool");
66  m_systTool = dynamic_cast<CP::ISystematicsTool*> (m_tool);
67  }
68 
69 
70 
72  renameContainers (const std::vector<std::pair<std::string,std::string>>& renames)
73  {
75  if (m_toolWrapper)
76  {
77  m_toolWrapper = std::make_shared<ColumnarToolWrapper> (m_tool);
78  }
79  }
80 
81 
82 
84  initialize ()
85  {
86  m_toolWrapper = std::make_shared<ColumnarToolWrapper> (m_tool);
87  }
88 
89 
90 
92  applySystematicVariation (const std::string& sysName)
93  {
94  // by convention setting a systematic on a non-systematics tool
95  // will do nothing
96  if (m_systTool == nullptr)
97  return;
98  if (!m_systTool->applySystematicVariation (CP::SystematicSet (sysName)).isSuccess())
99  throw std::runtime_error ("failed to apply systematic variation");
100  }
101 
102 
103 
104  [[nodiscard]] std::vector<ColumnInfo> ColumnarMemoryTest::ColumnarTestToolHandle ::
105  getColumnInfo () const
106  {
107  if (!m_toolWrapper)
108  throw std::runtime_error ("tool not initialized");
109  return m_toolWrapper->getColumnInfo ();
110  }
111 
112 
113 
115  getColumnNames () const
116  {
117  if (!m_toolWrapper)
118  throw std::runtime_error ("tool not initialized");
119  return m_toolWrapper->getColumnNames ();
120  }
121 
122 
123 
126  {
127  if (!m_systTool)
128  return {""};
129  std::vector<std::string> result;
130  for (auto& sys : CP::make_systematics_vector (m_systTool->recommendedSystematics()))
131  result.push_back (sys.name());
132  return result;
133  }
134 
135 
136 
138  getToolWrapper () const
139  {
140  if (!m_toolWrapper)
141  throw std::runtime_error ("tool not initialized");
142  return *m_toolWrapper;
143  }
144 
145 
146 
148  getTool ()
149  {
150  return m_tool;
151  }
152 
153 
154 
156  ColumnMapType (ColumnarTestToolHandle& val_toolHandle)
157  : m_toolHandle (&val_toolHandle), m_columnData (std::make_unique<ColumnarToolWrapperData> (&val_toolHandle.getToolWrapper()))
158  {
159  for (auto& column : m_toolHandle->getColumnInfo())
160  {
161  auto [iter, success] = m_columnMap.emplace (column.name, ColumnInfo {column});
162  if (!success)
163  throw std::runtime_error ("column already exists: " + column.name);
164  }
165  }
166 
167 
168 
170  addColumn (const std::string& name, std::vector<std::any> data)
171  {
172  auto column = m_columnMap.find (name);
173  if (column == m_columnMap.end())
174  throw std::runtime_error ("adding unknown column: " + name);
175  if (m_inputs.contains (name))
176  throw std::runtime_error ("column added twice: " + name);
177  if (column->second.type == &typeid(float))
178  addInputTyped<float> (name, data);
179  else if (column->second.type == &typeid(char))
180  addInputTyped<char> (name, data);
181  else if (column->second.type == &typeid(int))
182  addInputTyped<int> (name, data);
183  else if (column->second.type == &typeid(std::uint8_t))
184  addInputTyped<std::uint8_t> (name, data);
185  else if (column->second.type == &typeid(std::uint16_t))
186  addInputTyped<std::uint16_t> (name, data);
187  else if (column->second.type == &typeid(std::uint32_t))
188  addInputTyped<std::uint32_t> (name, data);
189  else if (column->second.type == &typeid(std::uint64_t))
190  addInputTyped<std::uint64_t> (name, data);
191  else
192  throw std::logic_error ("column name " + name + " has unsupported type " + column->second.type->name() + ", extend test handler to support it");
193  }
194 
195 
196 
198  setExpectation (const std::string& name, const std::vector<std::any> & values)
199  {
200  auto column = m_columnMap.find (name);
201  if (column == m_columnMap.end())
202  throw std::runtime_error ("adding unknown column: " + name);
203  if (m_expectations.contains (name))
204  throw std::runtime_error ("column added twice: " + name);
205  if (column->second.type == &typeid(float))
206  addExpectationTyped<float> (name, values);
207  else if (column->second.type == &typeid(char))
208  addExpectationTyped<char> (name, values);
209  else if (column->second.type == &typeid(int))
210  addExpectationTyped<int> (name, values);
211  else if (column->second.type == &typeid(std::uint8_t))
212  addExpectationTyped<std::uint8_t> (name, values);
213  else if (column->second.type == &typeid(std::uint16_t))
214  addExpectationTyped<std::uint16_t> (name, values);
215  else if (column->second.type == &typeid(std::uint32_t))
216  addExpectationTyped<std::uint32_t> (name, values);
217  else if (column->second.type == &typeid(std::uint64_t))
218  addExpectationTyped<std::uint64_t> (name, values);
219  else
220  throw std::logic_error ("column name " + name + " has unsupported type " + column->second.type->name() + ", extend test handler to support it");
221  }
222 
223 
224 
226  columnSize (const std::string& name)
227  {
228  auto iter = m_inputs.find (name);
229  if (iter == m_inputs.end())
230  throw std::runtime_error ("column not found: " + name);
231  return std::visit ([] (const auto& data) { return data.size(); }, iter->second);
232  }
233 
234 
235 
238  {
239  for (auto& [name, columnInfo] : m_columnMap)
240  {
241  if (auto iter = m_inputs.find (columnInfo.name); iter != m_inputs.end())
242  {
243  switch (columnInfo.accessMode)
244  {
246  std::visit ([&] (const auto& data)
247  {
248  m_columnData->setColumn (iter->first, data.size(), data.data());
249  }, iter->second);
250  break;
253  std::visit ([&] (auto& data)
254  {
255  m_columnData->setColumn (iter->first, data.size(), data.data());
256  }, m_activeColumns[iter->first] = iter->second);
257  break;
258  default:
259  throw std::runtime_error ("column mode unknown: " + columnInfo.name);
260  }
261  }
262  }
263  }
264 
265 
266 
268  call ()
269  {
270  m_columnData->call ();
271  }
272 
273 
274 
277  {
278  for (auto& [name, info] : m_columnMap)
279  {
280  if (info.accessMode == ColumnAccessMode::input)
281  continue;
282 
283  auto iter = m_activeColumns.find (name);
284  if (iter == m_activeColumns.end())
285  continue;
286 
287  if (info.type == &typeid(float))
288  checkExpectationTyped<float> (name);
289  else if (info.type == &typeid(char))
290  checkExpectationTyped<char> (name);
291  else if (info.type == &typeid(int))
292  checkExpectationTyped<int> (name);
293  else if (info.type == &typeid(std::uint8_t))
294  checkExpectationTyped<std::uint8_t> (name);
295  else if (info.type == &typeid(std::uint16_t))
296  checkExpectationTyped<std::uint16_t> (name);
297  else if (info.type == &typeid(std::uint32_t))
298  checkExpectationTyped<std::uint32_t> (name);
299  else if (info.type == &typeid(std::uint64_t))
300  checkExpectationTyped<std::uint64_t> (name);
301  else
302  throw std::logic_error ("column name " + name + " has unsupported type " + info.type->name() + ", extend test handler to support it");
303  }
304  }
305 }
grepfile.info
info
Definition: grepfile.py:38
CaloCondBlobAlgs_fillNoiseFromASCII.sysName
sysName
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:93
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
columnar::ColumnarMemoryTest::ColumnMapType::connectColumnsToTool
void connectColumnsToTool()
add the columns we have to the tool
Definition: ColumnarMemoryTest.cxx:237
columnar::IColumnarTool
an interface for tools that operate on columnar data
Definition: IColumnarTool.h:214
columnar::ColumnAccessMode::input
@ input
an input column
get_generator_info.result
result
Definition: get_generator_info.py:21
CP::make_systematics_vector
std::vector< CP::SystematicSet > make_systematics_vector(const SystematicSet &systematics)
utility functions for working with systematics
Definition: SystematicsUtil.cxx:25
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
columnar::ColumnarMemoryTest::ColumnMapType::ColumnMapType
ColumnMapType(ColumnarTestToolHandle &val_toolHandle)
Definition: ColumnarMemoryTest.cxx:156
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
columnar::ColumnarMemoryTest::ColumnMapType::checkExpectations
void checkExpectations()
Definition: ColumnarMemoryTest.cxx:276
columnar::ColumnarMemoryTest::ColumnMapType::m_toolHandle
ColumnarTestToolHandle * m_toolHandle
Definition: ColumnarMemoryTest.h:213
index
Definition: index.py:1
CP::preloadComponentFactories
bool preloadComponentFactories()
Definition: ComponentFactoryPreloader.cxx:406
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::m_systTool
CP::ISystematicsTool * m_systTool
Definition: ColumnarMemoryTest.h:87
columnar::ColumnarMemoryTest::ColumnMapType::columnSize
ColumnarOffsetType columnSize(const std::string &name)
Definition: ColumnarMemoryTest.cxx:226
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::ColumnarTestToolHandle
ColumnarTestToolHandle(asg::AsgTool &val_tool)
Definition: ColumnarMemoryTest.cxx:61
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::m_tool
IColumnarTool * m_tool
Definition: ColumnarMemoryTest.h:86
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::renameContainers
void renameContainers(const std::vector< std::pair< std::string, std::string >> &renames)
rename the columns the tool uses
Definition: ColumnarMemoryTest.cxx:72
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
columnar::ColumnAccessMode::output
@ output
an output column
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::getColumnNames
std::vector< std::string > getColumnNames() const
get the expected column names
Definition: ColumnarMemoryTest.cxx:115
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::applySystematicVariation
void applySystematicVariation(const std::string &sysName)
set the tool to apply the given systematic variation
Definition: ColumnarMemoryTest.cxx:92
columnar::ColumnarMemoryTest::ColumnMapType::call
void call()
Definition: ColumnarMemoryTest.cxx:268
columnar::ColumnInfo
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition: ColumnInfo.h:35
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
columnar::ColumnarMemoryTest::ColumnMapType::addColumn
void addColumn(const std::string &name, std::vector< std::any > data)
Definition: ColumnarMemoryTest.cxx:170
columnar::ColumnarToolWrapperData
a class that holds the columnar data for a single call to ColumnarToolWrapper
Definition: ColumnarToolWrapper.h:136
master.flag
bool flag
Definition: master.py:29
columnar::ColumnarMemoryTest::makeUniqueName
std::string makeUniqueName()
make a unique tool name to be used in unit tests
Definition: ColumnarMemoryTest.cxx:44
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::getToolWrapper
const ColumnarToolWrapper & getToolWrapper() const
get the tool wrapper
Definition: ColumnarMemoryTest.cxx:138
columnar::ColumnarMemoryTest::ColumnMapType::m_columnMap
std::unordered_map< std::string, const ColumnInfo > m_columnMap
Definition: ColumnarMemoryTest.h:217
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::getColumnInfo
std::vector< ColumnInfo > getColumnInfo() const
get the expected column info
Definition: ColumnarMemoryTest.cxx:105
ColumnarDef.h
columnar::renameContainers
void renameContainers(IColumnarTool &tool, const std::vector< std::pair< std::string, std::string >> &renames)
rename containers in the columnar tool
Definition: ColumnarToolHelpers.cxx:23
columnar::ColumnarMemoryTest::ColumnarMemoryTest
ColumnarMemoryTest()
Definition: ColumnarMemoryTest.cxx:27
columnar::ColumnAccessMode::update
@ update
an updateable column
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::getRecommendedSystematics
std::vector< std::string > getRecommendedSystematics() const
get the recommended systematics
Definition: ColumnarMemoryTest.cxx:125
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
columnar::ColumnarToolWrapper
a class that wraps an IColumnarTool for use in Python
Definition: ColumnarToolWrapper.h:36
ComponentFactoryPreloader.h
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::initialize
void initialize()
initialize the tool
Definition: ColumnarMemoryTest.cxx:84
CP::ISystematicsTool
Interface for all CP tools supporting systematic variations.
Definition: ISystematicsTool.h:32
ColumnarMemoryTest.h
columnar
Definition: ClusterDef.h:16
columnar::ColumnarMemoryTest::checkMode
static bool checkMode()
check whether we have the right mode
Definition: ColumnarMemoryTest.cxx:53
columnar::ColumnarOffsetType
std::size_t ColumnarOffsetType
the type used for the size and offsets in the columnar data
Definition: IColumnarTool.h:20
python.difftuple.renames
dictionary renames
Definition: difftuple.py:25
columnar::ColumnarMemoryTest::ColumnMapType::setExpectation
void setExpectation(const std::string &name, const std::vector< std::any > &values)
Definition: ColumnarMemoryTest.cxx:198
columnar::ColumnarMemoryTest::ColumnarTestToolHandle
a handle to a columnar tool for running tests
Definition: ColumnarMemoryTest.h:47
columnar::ColumnarMemoryTest::ColumnarTestToolHandle::getTool
IColumnarTool * getTool()
get the contained tool
Definition: ColumnarMemoryTest.cxx:148