ATLAS Offline Software
Loading...
Searching...
No Matches
AuxVariable.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2//
3// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4//
5#ifndef XAODCORE_TOOLS_AUXVARIABLE_H
6#define XAODCORE_TOOLS_AUXVARIABLE_H
7
8// EDM include(s).
11#include "CxxUtils/pputils.h"
12
23#define AUX_VARIABLE( VAR, ... ) \
24 do { \
25 static const auxid_t auxid = \
26 getAuxID( #VAR, VAR CXXUTILS_PP_FIRST( __VA_ARGS__ ) ); \
27 regAuxVar( auxid, #VAR, VAR ); \
28 } while( false )
29
30
31
55namespace xAOD { namespace detail {
56
57
58template <class VARTYPE, class AUXBASE>
59VARTYPE initAuxVar2( AUXBASE* auxcont,
60 std::true_type)
61{
62 return VARTYPE (auxcont->memResource());
63}
64
65
66template <class VARTYPE, class AUXBASE>
67VARTYPE initAuxVar2( AUXBASE* /*auxcont*/,
68 std::false_type)
69{
70 return VARTYPE();
71}
72
73
74template <class VARTYPE, class AUXBASE>
75VARTYPE initAuxVar1( AUXBASE* auxcont)
76{
77 return initAuxVar2<VARTYPE> ( auxcont, std::is_constructible<VARTYPE, std::pmr::memory_resource*>() );
78}
79
80
81template <const char* NAME, class AUXBASE, class VARTYPE>
82VARTYPE initAuxVar( AUXBASE* auxcont,
83 VARTYPE& var,
85{
86 static const SG::auxid_t auxid = auxcont->getAuxID( NAME, var, flags );
87 auxcont->regAuxVar (auxid, NAME, var);
88 return initAuxVar1<VARTYPE>( auxcont );
89}
90
91
92// Version to handle initializing a linked variable.
93// ELT is the type of the variable being linked to, LINKS is the type of the
94// member defined in the container for it. LINKED is the member type
95// for the linked variable, and AUXBASE is the container base class.
96template <class ELT, const char* NAME, class AUXBASE, class LINKS, class LINKED>
97LINKED initLinkedVar( AUXBASE* auxcont,
98 LINKS& links,
99 LINKED& linked )
100{
101 // Use the @c ConstAccessor specialization to get the variable
102 // declared properly.
103 static const SG::ConstAccessor<ELT> acc( NAME );
104 auxcont->regAuxVar( acc.linkedAuxid(), SG::AuxTypeRegistry::linkedName (NAME), linked );
105 auxcont->regAuxVar( acc.auxid(), NAME, links );
106 return xAOD::detail::initAuxVar1<LINKED>( auxcont );
107}
108
109
110}} // namespace xAOD::detail
111
112
113#define AUXVAR_DECL( TYPE, NAME, ... ) \
114 static constexpr const char NAME ## __name[] = #NAME; \
115 AuxVariable_t< TYPE AUXVAR_DECL_ALLOC_( TYPE, __VA_ARGS__ ) > NAME \
116 { xAOD::detail::initAuxVar< NAME ## __name >( this, NAME CXXUTILS_PP_SECOND( __VA_ARGS__ ) ) }
117#define AUXVAR_DECL_ALLOC_( TYPE, ... ) \
118 __VA_OPT__( CXXUTILS_PP_FIRST( __VA_ARGS__ )< TYPE > )
119
120
121#define AUXVAR_PACKEDCONTAINER_DECL( TYPE, NAME ) \
122 static constexpr const char NAME ## __name[] = #NAME; \
123 SG::PackedContainer< TYPE > NAME { xAOD::detail::initAuxVar< NAME ## __name >( this, NAME ) }
124
125
126#endif // XAODCORE_TOOLS_AUXVARIABLE_H
Handle mappings between names and auxid_t.
Helper class to provide constant type-safe access to aux data.
static std::string linkedName(const std::string &name)
Given a variable name, return the name of the corresponding linked variable.
Helper class to provide constant type-safe access to aux data.
AuxVarFlags
Additional flags to qualify an auxiliary variable.
Definition AuxTypes.h:58
@ None
No special flags set.
Definition AuxTypes.h:60
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
LINKED initLinkedVar(AUXBASE *auxcont, LINKS &links, LINKED &linked)
Definition AuxVariable.h:97
VARTYPE initAuxVar2(AUXBASE *auxcont, std::true_type)
Definition AuxVariable.h:59
VARTYPE initAuxVar(AUXBASE *auxcont, VARTYPE &var, SG::AuxVarFlags flags=SG::AuxVarFlags::None)
Definition AuxVariable.h:82
VARTYPE initAuxVar1(AUXBASE *auxcont)
Definition AuxVariable.h:75
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
Preprocessor utilities.