ATLAS Offline Software
Loading...
Searching...
No Matches
dataVectorAsELV.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id$
14
15
16#ifndef ATHCONTAINERS_DATAVECTORASELV_H
17#define ATHCONTAINERS_DATAVECTORASELV_H
18
19
25#include "AthLinks/ElementLink.h"
26#include <vector>
27
28
29namespace SG {
30
31
37template <class DV>
38void dataVectorViewAsELV (const std::true_type&,
39 const DV& v,
40 std::vector<ElementLink<DV> >& ret,
41 const EventContext& ctx)
42{
43 const DV* last_d = nullptr;
44 const SG::AuxVectorData* last_b = nullptr;
45 for (const typename DV::base_value_type* elt : v) {
46 const SG::AuxVectorData* cont_b = elt->container();
47 if (cont_b != last_b) {
48 last_b = cont_b;
49 last_d = dynamic_cast<const DV*>(cont_b);
50 }
51 if (!last_d)
52 throw SG::ExcDVToELV ("Element not in a container");
53 ret.emplace_back (*last_d, elt->index(), ctx);
54 }
55}
56
57
58
65template <class DV>
66void dataVectorViewAsELV (const std::false_type&,
67 const DV&,
68 std::vector<ElementLink<DV> >&,
69 const EventContext&)
70{
71 throw SG::ExcDVToELV ("Element in view container does not derive from AuxElement.");
72}
73
74
75
85template <class DV>
86std::vector<ElementLink<DV> >
87dataVectorAsELV (const DV& v, const EventContext& ctx = Gaudi::Hive::currentContext())
88{
89 std::vector<ElementLink<DV> > ret;
90 size_t sz = v.size();
91 ret.reserve (sz);
92
93 if (v.ownPolicy() == SG::OWN_ELEMENTS) {
94 // Could hoist the sgkey lookup.
95 // But this will probably not be a common case, so don't do that
96 // unless it's needed.
97 for (size_t i = 0; i < sz; i++)
98 ret.emplace_back (v, i, ctx);
99 }
100 else {
101 dataVectorViewAsELV (typename AuxStore_traits<DV>::flag(), v, ret, ctx);
102 }
103
104 return ret;
105}
106
107
108} // namespace SG
109
110
111#endif // not ATHCONTAINERS_DATAVECTORASELV_H
Associate AuxStore classes with EDM container classes.
Manage lookup of vectors of auxiliary data.
Exceptions that can be thrown from AthContainers.
static Double_t sz
Manage lookup of vectors of auxiliary data.
Exception — Can't convert DataVector to vector of ElementLinks.
Forward declaration.
void dataVectorViewAsELV(const std::true_type &, const DV &v, std::vector< ElementLink< DV > > &ret, const EventContext &ctx)
Helper for dataVectorViewAsELV.
std::vector< ElementLink< DV > > dataVectorAsELV(const DV &v, const EventContext &ctx=Gaudi::Hive::currentContext())
Helper to make a vector<EL> from a DataVector.
@ OWN_ELEMENTS
this data object owns its elements
Associate AuxStore classes with EDM container classes (default implementation).