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-2024 CERN for the benefit of the ATLAS collaboration.
4 */
11
12
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
30namespace SG::detail {
31
32
34template <class RANGE, class CONT>
36
37
44{
45public:
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:
91
92
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>
179 sgkey_t sgkey,
180 DataLinkBase_span& links,
181 IProxyDict* sg,
182 InitLinkFunc_t* initLinkFunc);
183
184
203 static bool updateLinksBase (IAuxTypeVector& linkedVec,
204 PackedLinkBase_span& links,
205 const const_DataLinkBase_span& srcDLinks,
206 IProxyDict* sg,
207 InitLinkFunc_t* initLinkFunc);
208
209
210#ifndef XAOD_STANDALONE
227 static bool applyThinningBase (IAuxTypeVector& linkedVec,
228 PackedLinkBase_span& links,
229 DataLinkBase_span& dlinks,
230 const SG::ThinningCache* tc,
231 IProxyDict* sg,
232 InitLinkFunc_t* initLinkFunc);
233#endif
234
235
236private:
244 static bool resizeLinks (LinkedVector& linkedVec, size_t sz);
245};
246
247
253template <class CONT>
256{
257public:
263
267
268
286 static std::pair<size_t, bool>
288 sgkey_t sgkey,
289 DataLinkBase_span& links,
290 IProxyDict* sg);
291
292
311 static bool updateLinks (IAuxTypeVector& linkedVec,
313 size_t n,
314 const const_DataLinkBase_span& srcDLinks,
315 IProxyDict* sg);
316
317
336 static bool updateLinks (IAuxTypeVector& linkedVec,
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
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
432private:
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
445 static void initLink (DataLinkBase& dl, sgkey_t sgkey, IProxyDict* sg);
446};
447
448
449} // namespace SG::detail
450
451
453
454
455#endif // not ATHCONTAINERS_PACKEDLINKVECTORHELPER_H
Wrapper for CurrentEventStore, to do the correct thing for both Athena and standalone builds.
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>.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
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.