Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ObjectColumnXAOD.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /// @author Nils Krumnack
6 
7 
8 #include <ColumnarCore/ColumnarTool.h>
9 #include <ColumnarCore/ObjectId.h>
10 #include <ColumnarCore/ObjectRange.h>
11 #include <ColumnarCore/ContainerId.h>
12 #include <cassert>
13 
14 namespace columnar
15 {
16  template<ContainerId CI>
17  class AccessorTemplate<CI,ObjectColumn,ColumnAccessMode::input,ColumnarModeXAOD> final
18  {
19  /// Common Public Members
20  /// =====================
21  public:
22 
23  static_assert (ContainerIdTraits<CI>::isDefined, "ContainerId not defined, include the appropriate header");
24 
25  using CM = ColumnarModeXAOD;
26 
27  AccessorTemplate (ColumnarTool<CM>& columnBase,
28  const std::string& name)
29  : m_columnBase (&columnBase), m_key (name)
30  {
31  }
32 
33  ObjectRange<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> /*eventId*/) const
34  requires (ContainerIdTraits<CI>::perEventRange)
35  {
36  return ObjectRange<CI,CM> (retrieveObject ());
37  }
38 
39  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> /*eventRange*/) const
40  requires (ContainerIdTraits<CI>::perEventRange)
41  {
42  return ObjectRange<CI,CM> (retrieveObject ());
43  }
44 
45  ObjectId<CI,CM> operator() (ObjectId<ContainerId::eventContext,CM> /*eventId*/) const
46  requires (ContainerIdTraits<CI>::perEventId)
47  {
48  return ObjectId<CI,CM> (retrieveObject ());
49  }
50 
51  ObjectRange<CI,CM> operator() (ObjectRange<ContainerId::eventContext,CM> /*eventRange*/) const
52  requires (ContainerIdTraits<CI>::perEventId)
53  {
54  return ObjectRange<CI,CM> (retrieveObject ());
55  }
56 
57 
58 
59  /// Private Members
60  /// ===============
61  private:
62 
63  ColumnarTool<CM> *m_columnBase = nullptr;
64  std::string m_key;
65 
66  // retrieve the object from the event store. there is probably
67  // something clever that could be done with `SG::ReadHandleKey`, but
68  // in practice all CP tools converted so far (25 Feb 25) do not
69  // actually retrieve objects in XAOD mode. so for simplicity and to
70  // avoid some of the bookkeeping issues with "subtool" objects
71  // holding accessors, I use this "non-tracking" version.
72  auto& retrieveObject () const
73  {
74  typename ContainerIdTraits<CI>::xAODObjectRangeType *container = nullptr;
75  if (!m_columnBase->eventStore().retrieve (container, m_key).isSuccess())
76  throw std::runtime_error ("failed to retrieve " + m_key);
77  return *container;
78  }
79  };
80 }