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-2020 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
32#ifdef XAOD_STANDALONE
33using AthContainers::IProxyDict;
34#endif // XAOD_STANDALONE
35
36
42template <class DV>
43void dataVectorViewAsELV (const std::true_type&,
44 const DV& v,
45 std::vector<ElementLink<DV> >& ret,
46 IProxyDict* store)
47{
48 const DV* last_d = nullptr;
49 const SG::AuxVectorData* last_b = nullptr;
50 for (const typename DV::base_value_type* elt : v) {
51 const SG::AuxVectorData* cont_b = elt->container();
52 if (cont_b != last_b) {
53 last_b = cont_b;
54 last_d = dynamic_cast<const DV*>(cont_b);
55 }
56 if (!last_d)
57 throw SG::ExcDVToELV ("Element not in a container");
58 ret.emplace_back (*last_d, elt->index(), store);
59 }
60}
61
62
63
70template <class DV>
71void dataVectorViewAsELV (const std::false_type&,
72 const DV&,
73 std::vector<ElementLink<DV> >&,
75{
76 throw SG::ExcDVToELV ("Element in view container does not derive from AuxElement.");
77}
78
79
80
90template <class DV>
91std::vector<ElementLink<DV> >
92dataVectorAsELV (const DV& v, IProxyDict* store = 0)
93{
94 std::vector<ElementLink<DV> > ret;
95 size_t sz = v.size();
96 ret.reserve (sz);
97
98 if (!store) store = SG::CurrentEventStore::store();
99
100 if (v.ownPolicy() == SG::OWN_ELEMENTS) {
101 // Could hoist the sgkey lookup.
102 // But this will probably not be a common case, so don't do that
103 // unless it's needed.
104 for (size_t i = 0; i < sz; i++)
105 ret.emplace_back (v, i, store);
106 }
107 else {
108 dataVectorViewAsELV (typename AuxStore_traits<DV>::flag(), v, ret, store);
109 }
110
111 return ret;
112}
113
114
115} // namespace SG
116
117
118#endif // not ATHCONTAINERS_DATAVECTORASELV_H
Wrapper for CurrentEventStore, to do the correct thing for both Athena and standalone builds.
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.
static IProxyDict * store()
Fetch the current store.
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, IProxyDict *store)
Helper for dataVectorViewAsELV.
std::vector< ElementLink< DV > > dataVectorAsELV(const DV &v, IProxyDict *store=0)
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).