ATLAS Offline Software
PackedLinkVectorHelper.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  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
14 #define ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
15 
16 
21 #include "AthLinks/ElementLink.h"
22 #include "AthLinks/DataLink.h"
23 #include "CxxUtils/span.h"
24 #include "CxxUtils/ranges.h"
25 #include <ranges>
26 #include <variant>
27 #include <utility>
28 
29 
30 namespace SG::detail {
31 
32 
34 template <class RANGE, class CONT>
35 concept ElementLinkRange = CxxUtils::InputRangeOverT<RANGE, ElementLink<CONT> >;
36 
37 
44 {
45 public:
46 #ifdef XAOD_STANDALONE
47  using IProxyDict = AthContainers::IProxyDict;
48 
49  // To reduce the number of template instantiations, we want to be able
50  // to treat the vectors of DataLinks as just vectors of DataLinkBase.
51  // That works fine in Athena, where all the data members are in
52  // DataLinkBase. But in AnalysisBase, DataLink<T> adds more
53  // data members. So for this case, use a dummy DataLink type
54  // rather than DataLinkBase.
56 #else
58 #endif
59 
61  typedef void InitLinkFunc_t (DataLinkBase& dl,
62  sgkey_t sgkey,
63  IProxyDict* sg);
64 
65 
71 
72 
84  {
85  public:
90  LinkedVector (IAuxTypeVector& linkedVector);
91 
92 
98  LinkedVector (AuxVectorData& container, SG::auxid_t auxid);
99 
100 
105 
106 
111 
112 
117 
118  private:
119  // Holds either a pointer to the @c IAuxTypeVector or a container, ID pair.
120  std::variant<IAuxTypeVector*,
121  std::pair<AuxVectorData*, SG::auxid_t> > m_data;
122  };
123 
124 
126  // Can't use std::span now because we want span::at(), which is C++26.
128 
129 
136 
137 
144 
145 
152 
153 
177  static std::pair<size_t, bool>
178  findCollectionBase (LinkedVector& linkedVec,
179  sgkey_t sgkey,
181  IProxyDict* sg,
182  InitLinkFunc_t* initLinkFunc);
183 
184 
203  static bool updateLinksBase (IAuxTypeVector& linkedVec,
205  const const_DataLinkBase_span& srcDLinks,
206  IProxyDict* sg,
207  InitLinkFunc_t* initLinkFunc);
208 
209 
210 #ifndef XAOD_STANDALONE
211 
227  static bool applyThinningBase (IAuxTypeVector& linkedVec,
229  DataLinkBase_span& dlinks,
230  const SG::ThinningCache* tc,
231  IProxyDict* sg,
232  InitLinkFunc_t* initLinkFunc);
233 #endif
234 
235 
236 private:
244  static bool resizeLinks (LinkedVector& linkedVec, size_t sz);
245 };
246 
247 
253 template <class CONT>
256 {
257 public:
263 
265  using PLink_t = PackedLink<CONT>;
267 
268 
286  static std::pair<size_t, bool>
288  sgkey_t sgkey,
290  IProxyDict* sg);
291 
292 
311  static bool updateLinks (IAuxTypeVector& linkedVec,
312  SG::PackedLink<CONT>* ptr,
313  size_t n,
314  const const_DataLinkBase_span& srcDLinks,
315  IProxyDict* sg);
316 
317 
336  static bool updateLinks (IAuxTypeVector& linkedVec,
337  SG::PackedLink<CONT>* ptr,
338  size_t n,
339  const IAuxTypeVector& srclv,
340  IProxyDict* sg);
341 
342 
361  template <class VALLOC>
362  static bool updateLinks (IAuxTypeVector& linkedVec,
363  std::vector<SG::PackedLink<CONT>, VALLOC>* ptr,
364  size_t n,
365  const IAuxTypeVector& srclv,
366  IProxyDict* sg);
367 
368 
380  template <class VALLOC, ElementLinkRange<CONT> RANGE>
381  static bool assignVElt (std::vector<PLink_t, VALLOC>& velt,
382  IAuxTypeVector& linkedVec,
383  DataLinkBase_span& dlinks,
384  const RANGE& x);
385 
386 
399  template <class VALLOC, ElementLinkRange<CONT> RANGE>
400  static bool insertVElt (std::vector<PLink_t, VALLOC>& velt,
401  size_t pos,
402  IAuxTypeVector& linkedVec,
403  DataLinkBase_span& dlinks,
404  const RANGE& x);
405 
406 
407 #ifndef XAOD_STANDALONE
408 
423  static bool applyThinning (IAuxTypeVector& linkedVec,
424  PackedLink<CONT>* ptr,
425  size_t n,
426  DataLinkBase_span& dlinks,
427  const SG::ThinningCache* tc,
428  IProxyDict* sg);
429 #endif
430 
431 
432 private:
433  // We want to be able to deal with spans over the base classes.
434  static_assert (sizeof (PLink_t) == sizeof(PackedLinkBase));
435  static_assert (sizeof (DLink_t) == sizeof(DataLinkBase));
436 
437 
446 };
447 
448 
449 } // namespace SG::detail
450 
451 
453 
454 
455 #endif // not ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG::detail
Definition: DataVectorWithAllocFwd.h:22
SG::detail::PackedLinkVectorHelperBase::LinkedVector::LinkedVector
LinkedVector(AuxVectorData &container, SG::auxid_t auxid)
Constructor from a container and aux ID.
TestSUSYToolsAlg.dl
dl
Definition: TestSUSYToolsAlg.py:81
fitman.sz
sz
Definition: fitman.py:527
SG::detail::PackedLinkVectorHelperBase::LinkedVector::get
IAuxTypeVector * get()
Return the IAuxTypeVector.
SG::detail::PackedLinkVectorHelperBase::InitLinkFunc_t
void InitLinkFunc_t(DataLinkBase &dl, sgkey_t sgkey, IProxyDict *sg)
Function to initialize a DataLink to a given hashed key.
Definition: PackedLinkVectorHelper.h:61
SG::detail::PackedLinkVectorHelperBase::getLinkBaseSpan
static const_DataLinkBase_span getLinkBaseSpan(const IAuxTypeVector &linkedVec)
Return a span over all the linked DataLinks.
SG::detail::PackedLinkVectorHelper::findCollection
static std::pair< size_t, bool > findCollection(LinkedVector &linkedVec, sgkey_t sgkey, DataLinkBase_span &links, IProxyDict *sg)
Find the collection index in the linked DataLinks for a sgkey.
SG::detail::ElementLinkRange
concept ElementLinkRange
Concept for a range of things that can convert to ElementLink<CONT>.
Definition: PackedLinkVectorHelper.h:35
SG::detail::PackedLinkVectorHelperBase::resizeLinks
static bool resizeLinks(LinkedVector &linkedVec, size_t sz)
Resize a linked vector of DataLinks.
Definition: PackedLinkVectorHelper.cxx:171
SG::detail::PackedLinkVectorHelperBase::LinkedVector
Helper to access the IAuxTypeVector for an aux variable.
Definition: PackedLinkVectorHelper.h:84
SG::detail::PackedLinkVectorHelperBase::findCollectionBase
static std::pair< size_t, bool > findCollectionBase(LinkedVector &linkedVec, sgkey_t sgkey, DataLinkBase_span &links, IProxyDict *sg, InitLinkFunc_t *initLinkFunc)
Find the collection index in the linked DataLinks for a sgkey.
Definition: PackedLinkVectorHelper.cxx:42
SG::detail::PackedLinkVectorHelper::updateLinks
static bool updateLinks(IAuxTypeVector &linkedVec, SG::PackedLink< CONT > *ptr, size_t n, const IAuxTypeVector &srclv, IProxyDict *sg)
Update collection index of a collection of PackedLink.
SG::detail::AuxDataSpan
Auxiliary variable span wrapper.
Definition: AuxDataSpan.h:71
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
x
#define x
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
CxxUtils::span
Simplified version of the C++20 std::span.
Definition: span.h:67
IAuxTypeVector.h
Abstract interface for manipulating vectors of arbitrary types.
SG::detail::PackedLinkVectorHelper::PLink_t
PackedLink< CONT > PLink_t
The PackedLinks.
Definition: PackedLinkVectorHelper.h:265
SG::detail::PackedLinkVectorHelperBase::LinkedVector::LinkedVector
LinkedVector(IAuxTypeVector &linkedVector)
Constructor from an IAuxTypeVector directly.
SG::detail::PackedLinkVectorHelper
Helper functions for managing PackedLink variables.
Definition: PackedLinkVectorHelper.h:256
SG::detail::PackedLinkVectorHelperBase::LinkedVector::m_data
std::variant< IAuxTypeVector *, std::pair< AuxVectorData *, SG::auxid_t > > m_data
Definition: PackedLinkVectorHelper.h:121
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::detail::PackedLinkVectorHelperBase::applyThinningBase
static bool applyThinningBase(IAuxTypeVector &linkedVec, PackedLinkBase_span &links, DataLinkBase_span &dlinks, const SG::ThinningCache *tc, IProxyDict *sg, InitLinkFunc_t *initLinkFunc)
Apply thinning to packed links, to prepare them for output.
Definition: PackedLinkVectorHelper.cxx:130
SG::detail::PackedLinkVectorHelper::assignVElt
static bool assignVElt(std::vector< PLink_t, VALLOC > &velt, IAuxTypeVector &linkedVec, DataLinkBase_span &dlinks, const RANGE &x)
Assign a range of ElementLink to a vector of Packedlink.
SG::detail::AuxDataConstSpan
Auxiliary variable span wrapper (const).
Definition: AuxDataSpan.h:185
span.h
Simplified version of the C++20 std::span.
beamspotman.n
n
Definition: beamspotman.py:731
DMTest::links
links
Definition: CLinks_v1.cxx:22
PackedLinkImpl.h
Definition of PackedLink type.
CurrentEventStore.h
Wrapper for CurrentEventStore, to do the correct thing for both Athena and standalone builds.
SG::detail::PackedLinkVectorHelper::initLink
static void initLink(DataLinkBase &dl, sgkey_t sgkey, IProxyDict *sg)
Initialize a DataLink.
AuxVectorData.h
Manage lookup of vectors of auxiliary data.
SG::detail::PackedLinkVectorHelper::updateLinks
static bool updateLinks(IAuxTypeVector &linkedVec, std::vector< SG::PackedLink< CONT >, VALLOC > *ptr, size_t n, const IAuxTypeVector &srclv, IProxyDict *sg)
Update collection index of a collection of PackedLink vectors.
SG::detail::PackedLinkVectorHelper::updateLinks
static bool updateLinks(IAuxTypeVector &linkedVec, SG::PackedLink< CONT > *ptr, size_t n, const const_DataLinkBase_span &srcDLinks, IProxyDict *sg)
Update collection index of a collection of PackedLink.
SG::detail::PackedLinkVectorHelperBase::LinkedVector::operator->
IAuxTypeVector * operator->()
Return the IAuxTypeVector.
SG::detail::PackedLinkVectorHelperBase::DataLinkBase
::DataLinkBase DataLinkBase
Definition: PackedLinkVectorHelper.h:57
SG::detail::PackedLinkVectorHelperBase::updateLinksBase
static bool updateLinksBase(IAuxTypeVector &linkedVec, PackedLinkBase_span &links, const const_DataLinkBase_span &srcDLinks, IProxyDict *sg, InitLinkFunc_t *initLinkFunc)
Update collection index of a collection of PackedLink.
Definition: PackedLinkVectorHelper.cxx:87
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
SG::detail::PackedLinkVectorHelper::applyThinning
static bool applyThinning(IAuxTypeVector &linkedVec, PackedLink< CONT > *ptr, size_t n, DataLinkBase_span &dlinks, const SG::ThinningCache *tc, IProxyDict *sg)
Apply thinning to packed links, to prepare them for output.
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::detail::PackedLinkVectorHelperBase::LinkedVector::operator*
IAuxTypeVector & operator*()
Return the IAuxTypeVector.
SG::detail::PackedLinkVectorHelper::insertVElt
static bool insertVElt(std::vector< PLink_t, VALLOC > &velt, size_t pos, IAuxTypeVector &linkedVec, DataLinkBase_span &dlinks, const RANGE &x)
Insert a range of ElementLink into a vector of Packedlink.
SG::detail::PackedLinkVectorHelperBase
Helper functions for managing PackedLink variables.
Definition: PackedLinkVectorHelper.h:44
SG::PackedLinkBase
A packed version of ElementLink.
Definition: PackedLinkImpl.h:47
SG::IAuxTypeVector
Abstract interface for manipulating vectors of arbitrary types.
Definition: IAuxTypeVector.h:42
SG::detail::PackedLinkVectorHelperBase::getLinkBaseSpan
static DataLinkBase_span getLinkBaseSpan(IAuxTypeVector &linkedVec)
Return a span over all the linked DataLinkBase's, from the linked vector.
SG::detail::PackedLinkVectorHelperBase::storeFromSpan
static IProxyDict * storeFromSpan(DataLinkBase_span &links)
Return the current store from the first valid link in the span.
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
ranges.h
C++20 range helpers.
SG::ThinningCache
Cache thinning decisions for converters.
Definition: ThinningCache.h:48
DataLinkBase
Type-independent part of DataLink; holds the persistent state.
Definition: AthLinks/DataLinkBase.h:37
PackedLinkVectorHelper.icc