ATLAS Offline Software
ViewVectorBase.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-2022 CERN for the benefit of the ATLAS collaboration
5 */
14 #ifndef ATHCONTAINERS_VIEWVECTORBASE_H
15 #define ATHCONTAINERS_VIEWVECTORBASE_H
16 
17 
20 #include "AthLinks/ElementLinkBase.h"
21 #include "CxxUtils/sgkey_t.h"
22 #include <vector>
23 #include <cstdint>
24 
25 
26 class ViewVectorBaseTest;
27 
28 
29 namespace SG {
30 
31 
38 {
39 public:
41  virtual ~ViewVectorBase() = default;
42 
43 
47  virtual void toPersistent() = 0;
48 
49 
53  virtual void toTransient() = 0;
54 
55 
60 
61 
70 
71 
72 protected:
79  template <class DV>
80  void doToPersistent1 (DV& v, const std::true_type&);
81 
82 
90  template <class DV>
91  void doToPersistent1 (DV&, const std::false_type&);
92 
93 
100  template <class DV>
101  void doToPersistent (DV& v);
102 
103 
110  template <class DV>
111  void doToTransient2 (DV& v, const std::true_type&);
112 
113 
120  template <class DV>
121  void doToTransient2 (DV&, const std::false_type&) {}
122 
123 
130  template <class DV>
131  void doToTransient1 (DV& v, const std::true_type&)
132  {
133  doToTransient2 (v, std::is_same<DV, typename DV::base_data_vector>());
134  }
135 
136 
146  template <class DV>
147  void doToTransient1 (DV&, const std::false_type&) {}
148 
149 
156  template <class DV>
157  void doToTransient (DV& v)
158  {
159 #ifdef XAOD_STANDALONE
160  doToTransient1 (v, std::true_type());
161 #else
163 #endif
164  }
165 
166 
167 private:
168  // For unit testing.
169  friend class ::ViewVectorBaseTest;
170 
172  std::vector<sgkey_t> m_persKey;
173  std::vector<unsigned int> m_persIndex;
174 
176  bool m_clearOnPersistent = false;
177 };
178 
179 
180 } // namespace SG
181 
182 
184 
185 
186 #endif // not ATHCONTAINERS_VIEWVECTORBASE_H
SG::ViewVectorBase::toTransient
virtual void toTransient()=0
Convert the vector to transient form.
SG::ViewVectorBase::doToTransient1
void doToTransient1(DV &v, const std::true_type &)
Convert to persistent form.
Definition: ViewVectorBase.h:131
SG::ViewVectorBase::doToTransient1
void doToTransient1(DV &, const std::false_type &)
Convert to transient form.
Definition: ViewVectorBase.h:147
SG::ViewVectorBase::doToTransient2
void doToTransient2(DV &v, const std::true_type &)
Convert to transient form.
SG::ViewVectorBase::doToTransient2
void doToTransient2(DV &, const std::false_type &)
Convert to transient form.
Definition: ViewVectorBase.h:121
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::ViewVectorBase::clearPersistent
void clearPersistent()
Clear the persistent data.
SG::ViewVectorBase::doToPersistent1
void doToPersistent1(DV &, const std::false_type &)
Convert to persistent form.
SG::ViewVectorBase::doToPersistent1
void doToPersistent1(DV &v, const std::true_type &)
Convert to persistent form.
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
ViewVectorBase.icc
CurrentEventStore.h
Wrapper for CurrentEventStore, to do the correct thing for both Athena and standalone builds.
SG::ViewVectorBase
Hold the persistent representation for a ViewVector.
Definition: ViewVectorBase.h:38
SG::ViewVectorBase::~ViewVectorBase
virtual ~ViewVectorBase()=default
Destructor.
dataVectorAsELV.h
Helper to make a vector<EL> from a DataVector.
SG::ViewVectorBase::doToPersistent
void doToPersistent(DV &v)
Convert to persistent form.
SG::ViewVectorBase::doToTransient
void doToTransient(DV &v)
Convert to persistent form.
Definition: ViewVectorBase.h:157
SG::ViewVectorBase::toPersistent
virtual void toPersistent()=0
Convert the vector to persistent form.
python.PyAthena.v
v
Definition: PyAthena.py:154
sgkey_t.h
Define the type used for hashed StoreGate key+CLID pairs.
SG::ViewVectorBase::setClearOnPersistent
void setClearOnPersistent()
Set a flag to declare that the vector should be cleared on the next call to toPersistent().
SG::ViewVectorBase::m_persIndex
std::vector< unsigned int > m_persIndex
Definition: ViewVectorBase.h:173
SG::ViewVectorBase::m_persKey
std::vector< sgkey_t > m_persKey
The persistent form. (sgkey, index)
Definition: ViewVectorBase.h:172
SG::ViewVectorBase::m_clearOnPersistent
bool m_clearOnPersistent
If true, the vector should be cleared when doPersistent is called.
Definition: ViewVectorBase.h:176