ATLAS Offline Software
Control/AthContainers/AthContainers/JaggedVec.h File Reference

Auxiliary variable type allowing storage as a jagged vector. That is, the payloads for all the DataVector elements are stored contiguously in a single vector. More...

#include "AthContainers/JaggedVecImpl.h"
#include "AthContainers/tools/JaggedVecVectorFactory.h"
#include "AthContainers/JaggedVecConstAccessor.h"
#include "AthContainers/JaggedVecAccessor.h"
#include "AthContainers/JaggedVecDecorator.h"
Include dependency graph for Control/AthContainers/AthContainers/JaggedVec.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Detailed Description

Auxiliary variable type allowing storage as a jagged vector. That is, the payloads for all the DataVector elements are stored contiguously in a single vector.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Mar, 2024 When we want to store an auxiliary variable with a variable number of data items per element, one usually uses a std::vector<T>. This means that the auxiliary variable itself is stored as a nested std::vector<std::vector<T> >. This tends to be somewhat inefficient in space, as well as being not so friendly if one wants to share the data with heterogenous resources such as GPUs.

A jagged vector flattens this structure. The variable itself contains simply a pair of indices into another, ‘linked’, variable, which holds the items for all container elements in a single contiguous block. Specialized accessor classes allow one to treat the data as if it were still a separate vector per element.

The usual way of declaring a jagged vector variable in an xAOD container class is to use the macro defined in xAODCore/JaggedVec.h:

...
class FooAuxContainer_v1 : public xAOD::AuxContainerBase {
...
private:
AUXVAR_JAGGEDVEC_DECL (int, intVec);
};

This will declare an auxiliary variable intVec of type SG::JaggedVecElt<int> containing the indices of the vector elements, as well as a variable intVec_linked of type int containing the actual vector data.

One does not usually interact directly with the linked variable or even with the SG::JaggedVecElt type. Rather, the usual Accessor classes provide a vector-like interface. So one can write, for example,

Foo& foo = ...;
static const SG::Accessor<SG::JaggedVecElt<int> > intVecAcc ("intVec");
size_t foo_sz = intVecAcc (foo).size();
int foo_elt = intVecAcc (foo).at(1);
for (int& ii : intVecElt (foo)) ... ;
intVecElt (foo).push_back (10);
intVecElt (foo).append_range (std::vector<int> {...});
std::vector<int> v = intVecElt (foo);

ConstAccessor and Decorator should work as expected. The accessors can also be used to create dynamic jagged vector variables. A jagged vector should be able to hold any type that can be put in a std::vector. In particular, std::string and ElementLink have been tested. However, if you are not using a primitive type, you may need to add dictionary entries in order to save the variable.

As mentioned above, you don't usually need to interact with the _linked variable holding the actual payload. However, you may need to name it if you are selecting individual variables to write.

Definition in file Control/AthContainers/AthContainers/JaggedVec.h.

Foo
Definition: FooBar.h:9
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
xAOD::AuxContainerBase
Common base class for the auxiliary containers.
Definition: AuxContainerBase.h:59
AUXVAR_JAGGEDVEC_DECL
#define AUXVAR_JAGGEDVEC_DECL(T, NAME,...)
Definition: Event/xAOD/xAODCore/xAODCore/JaggedVec.h:32
python.PyAthena.v
v
Definition: PyAthena.py:154