ATLAS Offline Software
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$
16 #ifndef ATHCONTAINERS_DATAVECTORASELV_H
17 #define ATHCONTAINERS_DATAVECTORASELV_H
18 
19 
25 #include "AthLinks/ElementLink.h"
26 #include <vector>
27 
28 
29 namespace SG {
30 
31 
32 #ifdef XAOD_STANDALONE
33 using AthContainers::IProxyDict;
34 #endif // XAOD_STANDALONE
35 
36 
42 template <class DV>
43 void dataVectorViewAsELV (const std::true_type&,
44  const DV& v,
45  std::vector<ElementLink<DV> >& ret,
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 
70 template <class DV>
71 void dataVectorViewAsELV (const std::false_type&,
72  const DV&,
73  std::vector<ElementLink<DV> >&,
74  IProxyDict*)
75 {
76  throw SG::ExcDVToELV ("Element in view container does not derive from AuxElement.");
77 }
78 
79 
80 
90 template <class DV>
91 std::vector<ElementLink<DV> >
92 dataVectorAsELV (const DV& v, IProxyDict* store = 0)
93 {
94  std::vector<ElementLink<DV> > ret;
95  size_t sz = v.size();
96  ret.reserve (sz);
97 
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 {
109  }
110 
111  return ret;
112 }
113 
114 
115 } // namespace SG
116 
117 
118 #endif // not ATHCONTAINERS_DATAVECTORASELV_H
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
SG::ExcDVToELV
Exception — Can't convert DataVector to vector of ElementLinks.
Definition: Control/AthContainers/AthContainers/exceptions.h:268
fitman.sz
sz
Definition: fitman.py:527
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxStore_traits
Associate AuxStore classes with EDM container classes (default implementation).
Definition: AuxStore_traits.h:138
exceptions.h
Exceptions that can be thrown from AthContainers.
SG::CurrentEventStore::store
static IProxyDict * store()
Fetch the current store.
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
SG::dataVectorViewAsELV
void dataVectorViewAsELV(const std::true_type &, const DV &v, std::vector< ElementLink< DV > > &ret, IProxyDict *store)
Helper for dataVectorViewAsELV.
Definition: dataVectorAsELV.h:43
lumiFormat.i
int i
Definition: lumiFormat.py:92
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
ret
T ret(T t)
Definition: rootspy.cxx:260
CurrentEventStore.h
Wrapper for CurrentEventStore, to do the correct thing for both Athena and standalone builds.
OwnershipPolicy.h
AuxVectorData.h
Manage lookup of vectors of auxiliary data.
AuxStore_traits.h
Associate AuxStore classes with EDM container classes.
python.PyAthena.v
v
Definition: PyAthena.py:157
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:167
SG::dataVectorAsELV
std::vector< ElementLink< DV > > dataVectorAsELV(const DV &v, IProxyDict *store=0)
Helper to make a vector<EL> from a DataVector.
Definition: dataVectorAsELV.h:92