ATLAS Offline Software
LinkColumn.h
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 #ifndef COLUMNAR_CORE_LINK_COLUMN_H
9 #define COLUMNAR_CORE_LINK_COLUMN_H
10 
11 #include <AthLinks/ElementLink.h>
14 
15 namespace columnar
16 {
24  template<ContainerIdConcept LT,typename ELT>
25  struct LinkCastColumn {};
26 
27 
28 
29  // in xAOD mode we can do a straightforward conversion from
30  // ElementLink to OptObjectId, as ElementLink contains all the
31  // information about the object
32  template<ContainerIdConcept LT>
34  {
38  static constexpr bool isNativeType = false;
39  static constexpr bool useConvertInput = true;
40  static constexpr bool useConvertWithDataInput = false;
41  static ColumnInfo& updateColumnInfo (ColumnarTool<CM>& /*columnarTool*/, ColumnInfo& info) {return info;}
42 
44  {
45  if (link.isValid())
46  {
47  typename LT::xAODObjectIdType *ptr = *link.cptr();
48  return OptObjectId<LT,CM> (ptr);
49  } else
50  {
51  return OptObjectId<LT,CM> ();
52  }
53  }
54  };
55 
56 
57  template<ContainerIdConcept LT,typename ELT>
59  {
63  static constexpr bool isNativeType = false;
64  static constexpr bool useConvertInput = true;
65  static constexpr bool useConvertWithDataInput = false;
66  static ColumnInfo& updateColumnInfo (ColumnarTool<CM>& /*columnarTool*/, ColumnInfo& info) {return info;}
67 
69  {
70  if (link.isValid())
71  {
72  auto *ptr = *link.cptr();
73  if (!ptr) return OptObjectId<LT,CM> ();
74  auto *ptr2 = dynamic_cast<typename LT::xAODObjectIdType*>(ptr);
75  if (!ptr2) throw std::runtime_error ("link not of expected type");
76  return OptObjectId<LT,CM> (ptr2);
77  } else
78  {
79  return OptObjectId<LT,CM> ();
80  }
81  }
82  };
83 
84 
85 
86 
87 
88  // in Array mode we take an index from the underlying column and
89  // combine it with the data vector from the input to get the new
90  // OptObjectId
91  template<ContainerIdConcept LT>
93  {
95  using ColumnType = typename CM::LinkIndexType;
97  using DataType = void **;
98  static constexpr bool isNativeType = false;
99  static constexpr bool useConvertInput = false;
100  static constexpr bool useConvertWithDataInput = true;
102  {
103  info.linkTargetNames = {columnarTool.containerStoreName(LT::idName)};
104  return info;
105  }
106 
107  static OptObjectId<LT> convertInput (void **data, typename CM::LinkIndexType link)
108  {
109  if (link == invalidObjectIndex)
110  return OptObjectId<LT,CM> ();
111  return OptObjectId<LT,CM> (data, link);
112  }
113  };
114  // I'm just inheriting the ColumnTypeTraits from OptObjectId, as the
115  // behavior is exactly the same.
116  template<ContainerIdConcept LT,typename ELT>
117  struct ColumnTypeTraits<LinkCastColumn<LT,ELT>,ColumnarModeArray> : ColumnTypeTraits<OptObjectId<LT>,ColumnarModeArray> {};
118 }
119 
120 #endif
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeArray >::ColumnType
typename CM::LinkIndexType ColumnType
Definition: LinkColumn.h:95
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
OptObjectId.h
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeArray >::updateColumnInfo
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &columnarTool, ColumnInfo &info)
Definition: LinkColumn.h:101
columnar::ColumnTypeTraits::useConvertWithDataInput
static constexpr bool useConvertWithDataInput
Definition: ColumnAccessor.h:99
columnar::ColumnTypeTraits::useConvertInput
static constexpr bool useConvertInput
Definition: ColumnAccessor.h:98
columnar::OptObjectId
a class representing a single optional object (electron, muons, etc.)
Definition: ContainerId.h:179
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeXAOD >::updateColumnInfo
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &, ColumnInfo &info)
Definition: LinkColumn.h:41
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeArray >::convertInput
static OptObjectId< LT > convertInput(void **data, typename CM::LinkIndexType link)
Definition: LinkColumn.h:107
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeXAOD >::convertInput
static OptObjectId< LT > convertInput(const ElementLink< typename LT::xAODElementLinkType > &link)
Definition: LinkColumn.h:43
columnar::ColumnInfo
a struct that contains meta-information about each column that's needed to interface the column with ...
Definition: ColumnInfo.h:35
columnar::ColumnarModeArray::LinkIndexType
std::size_t LinkIndexType
the type used for columns that represent element links
Definition: ColumnarDef.h:68
ColumnAccessor.h
columnar::ColumnTypeTraits< OptObjectId< LT >, ColumnarModeArray >::DataType
void ** DataType
Definition: LinkColumn.h:97
columnar::ColumnTypeTraits::isNativeType
static constexpr bool isNativeType
Definition: ColumnAccessor.h:97
columnar::final
CM final
Definition: ColumnAccessor.h:106
SignEnum::LT
@ LT
Definition: SignEnums.h:19
columnar::NativeColumn
a type wrapper to force AccessorTemplate to treat the type as native
Definition: ColumnAccessor.h:120
columnar::invalidObjectIndex
constexpr ColumnarOffsetType invalidObjectIndex
the value for an invalid element index
Definition: IColumnarTool.h:25
columnar::ColumnTypeTraits< LinkCastColumn< LT, ELT >, ColumnarModeXAOD >::convertInput
static OptObjectId< LT > convertInput(const ElementLink< ELT > &link)
Definition: LinkColumn.h:68
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:193
columnar::ColumnarModeArray
Definition: ColumnarDef.h:33
columnar::ColumnTypeTraits
a trait class to provide information about the column type
Definition: ColumnAccessor.h:96
columnar
Definition: ClusterDef.h:16
columnar::ColumnarTool
the base class for all columnar components
Definition: ColumnAccessorDataArray.h:17
columnar::ColumnarModeXAOD
Definition: ColumnarDef.h:18
columnar::ColumnTypeTraits< LinkCastColumn< LT, ELT >, ColumnarModeXAOD >::updateColumnInfo
static ColumnInfo & updateColumnInfo(ColumnarTool< CM > &, ColumnInfo &info)
Definition: LinkColumn.h:66
columnar::LinkCastColumn
a special column type that behaves like an OptObjectId, but applies an internal cast in xAOD mode
Definition: LinkColumn.h:25
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87