ATLAS Offline Software
Loading...
Searching...
No Matches
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-2026 CERN for the benefit of the ATLAS collaboration.
4 */
11
12
13#ifndef ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
14#define ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
15
16
20#include "AthLinks/ElementLink.h"
21#include "AthLinks/DataLink.h"
22#include "CxxUtils/span.h"
23#include "CxxUtils/ranges.h"
24#include <ranges>
25#include <variant>
26#include <utility>
27
28
29#ifdef XAOD_STANDALONE
32
33namespace AthContainers {
34using IProxyDict = xAOD::TVirtualEvent;
35}
36#else
38#endif
39
40
41namespace SG::detail {
42
43
45template <class RANGE, class CONT>
47
48
55{
56public:
57#ifdef XAOD_STANDALONE
58 using IProxyDict = AthContainers::IProxyDict;
59
60 // To reduce the number of template instantiations, we want to be able
61 // to treat the vectors of DataLinks as just vectors of DataLinkBase.
62 // That works fine in Athena, where all the data members are in
63 // DataLinkBase. But in AnalysisBase, DataLink<T> adds more
64 // data members. So for this case, use a dummy DataLink type
65 // rather than DataLinkBase.
67#else
69#endif
70
72 typedef void InitLinkFunc_t (DataLinkBase& dl,
73 sgkey_t sgkey,
74 IProxyDict* sg);
75
76
82
83
95 {
96 public:
102
103
110
111
116
117
122
123
128
129 private:
130 // Holds either a pointer to the @c IAuxTypeVector or a container, ID pair.
131 std::variant<IAuxTypeVector*,
132 std::pair<AuxVectorData*, SG::auxid_t> > m_data;
133 };
134
135
137 // Can't use std::span now because we want span::at(), which is C++26.
139
140
147
148
155
156
163
164
188 static std::pair<size_t, bool>
190 sgkey_t sgkey,
191 DataLinkBase_span& links,
192 IProxyDict* sg,
193 InitLinkFunc_t* initLinkFunc);
194
195
214 static bool updateLinksBase (IAuxTypeVector& linkedVec,
215 PackedLinkBase_span& links,
216 const const_DataLinkBase_span& srcDLinks,
217 IProxyDict* sg,
218 InitLinkFunc_t* initLinkFunc);
219
220
221#ifndef XAOD_STANDALONE
238 static bool applyThinningBase (IAuxTypeVector& linkedVec,
239 PackedLinkBase_span& links,
240 DataLinkBase_span& dlinks,
241 const SG::ThinningCache* tc,
242 IProxyDict* sg,
243 InitLinkFunc_t* initLinkFunc);
244#endif
245
246
247private:
255 static bool resizeLinks (LinkedVector& linkedVec, size_t sz);
256};
257
258
264template <class CONT>
267{
268public:
274
278
279
297 static std::pair<size_t, bool>
299 sgkey_t sgkey,
300 DataLinkBase_span& links,
301 IProxyDict* sg);
302
303
322 static bool updateLinks (IAuxTypeVector& linkedVec,
324 size_t n,
325 const const_DataLinkBase_span& srcDLinks,
326 IProxyDict* sg);
327
328
347 static bool updateLinks (IAuxTypeVector& linkedVec,
349 size_t n,
350 const IAuxTypeVector& srclv,
351 IProxyDict* sg);
352
353
372 template <class VALLOC>
373 static bool updateLinks (IAuxTypeVector& linkedVec,
374 std::vector<SG::PackedLink<CONT>, VALLOC>* ptr,
375 size_t n,
376 const IAuxTypeVector& srclv,
377 IProxyDict* sg);
378
379
391 template <class VALLOC, ElementLinkRange<CONT> RANGE>
392 static bool assignVElt (std::vector<PLink_t, VALLOC>& velt,
393 IAuxTypeVector& linkedVec,
394 DataLinkBase_span& dlinks,
395 const RANGE& x);
396
397
410 template <class VALLOC, ElementLinkRange<CONT> RANGE>
411 static bool insertVElt (std::vector<PLink_t, VALLOC>& velt,
412 size_t pos,
413 IAuxTypeVector& linkedVec,
414 DataLinkBase_span& dlinks,
415 const RANGE& x);
416
417
418#ifndef XAOD_STANDALONE
434 static bool applyThinning (IAuxTypeVector& linkedVec,
435 PackedLink<CONT>* ptr,
436 size_t n,
437 DataLinkBase_span& dlinks,
438 const SG::ThinningCache* tc,
439 IProxyDict* sg);
440#endif
441
442
443private:
444 // We want to be able to deal with spans over the base classes.
445 static_assert (sizeof (PLink_t) == sizeof(PackedLinkBase));
446 static_assert (sizeof (DLink_t) == sizeof(DataLinkBase));
447
448
456 static void initLink (DataLinkBase& dl, sgkey_t sgkey, IProxyDict* sg);
457};
458
459
460} // namespace SG::detail
461
462
464
465
466#endif // not ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
Manage lookup of vectors of auxiliary data.
Abstract interface for manipulating vectors of arbitrary types.
static Double_t sz
static Double_t tc
Definition of PackedLink type.
#define x
Simplified version of the C++20 std::span.
Definition span.h:61
Manage lookup of vectors of auxiliary data.
Abstract interface for manipulating vectors of arbitrary types.
Cache thinning decisions for converters.
Auxiliary variable span wrapper (const).
Auxiliary variable span wrapper.
Definition AuxDataSpan.h:73
Helper to access the IAuxTypeVector for an aux variable.
IAuxTypeVector * operator->()
Return the IAuxTypeVector.
IAuxTypeVector & operator*()
Return the IAuxTypeVector.
LinkedVector(IAuxTypeVector &linkedVector)
Constructor from an IAuxTypeVector directly.
IAuxTypeVector * get()
Return the IAuxTypeVector.
LinkedVector(AuxVectorData &container, SG::auxid_t auxid)
Constructor from a container and aux ID.
std::variant< IAuxTypeVector *, std::pair< AuxVectorData *, SG::auxid_t > > m_data
Helper functions for managing PackedLink variables.
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.
detail::AuxDataSpan< DataLinkBase > DataLinkBase_span
Spans over the linked DataLinks.
detail::AuxDataConstSpan< DataLinkBase > const_DataLinkBase_span
CxxUtils::span< PackedLinkBase > PackedLinkBase_span
Span over links.
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.
static DataLinkBase_span getLinkBaseSpan(IAuxTypeVector &linkedVec)
Return a span over all the linked DataLinkBase's, from the linked vector.
void InitLinkFunc_t(DataLinkBase &dl, sgkey_t sgkey, IProxyDict *sg)
Function to initialize a DataLink to a given hashed key.
static IProxyDict * storeFromSpan(DataLinkBase_span &links)
Return the current store from the first valid link in the span.
static const_DataLinkBase_span getLinkBaseSpan(const IAuxTypeVector &linkedVec)
Return a span over all the linked DataLinks.
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.
static bool resizeLinks(LinkedVector &linkedVec, size_t sz)
Resize a linked vector of DataLinks.
Helper functions for managing PackedLink variables.
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.
detail::AuxDataConstSpan< DataLink< CONT > > const_DataLink_span
static void initLink(DataLinkBase &dl, sgkey_t sgkey, IProxyDict *sg)
Initialize a DataLink.
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.
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.
ElementLink< CONT > Link_t
The (linked) data links.
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.
detail::AuxDataSpan< DataLink< CONT > > DataLink_span
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.
PackedLink< CONT > PLink_t
The PackedLinks.
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.
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.
Concept for an input range over a given type.
Definition ranges.h:27
Concept for a range of things that can convert to ElementLink<CONT>.
SG::auxid_t auxid() const
Return the aux id for this variable.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
const SG::AuxVectorData * container() const
Return the container holding this element.
virtual IAuxTypeVector * linkedVector(SG::auxid_t auxid) override
Return interface for a linked variable.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
C++20 range helpers.
Simplified version of the C++20 std::span.
A packed version of ElementLink.