Skip to content
Snippets Groups Projects
Commit 1b5c2b90 authored by Tadej Novak's avatar Tadej Novak
Browse files

Merge branch 'regvar.xAODCore-20240430' into 'main'

xAODCore+xAODTrigger: New method for registering auxiliary variables.

See merge request atlas/athena!71043
parents a4d4463b a5970f55
No related branches found
No related tags found
No related merge requests found
...@@ -178,7 +178,10 @@ namespace xAOD { ...@@ -178,7 +178,10 @@ namespace xAOD {
/// @} /// @}
protected: /// Declare how to wrap variables for this sort of base.
template <class T, class ALLOC = std::allocator<T> >
using AuxVariable_t = std::vector<T, ALLOC>;
/// Get the auxiliary ID for one of the persistent variables /// Get the auxiliary ID for one of the persistent variables
template< typename T, typename ALLOC > template< typename T, typename ALLOC >
auxid_t getAuxID( const std::string& name, auxid_t getAuxID( const std::string& name,
......
// Dear emacs, this is -*- c++ -*- // Dear emacs, this is -*- c++ -*-
/* /*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef XAODCORE_AUXINFOBASE_H #ifndef XAODCORE_AUXINFOBASE_H
#define XAODCORE_AUXINFOBASE_H #define XAODCORE_AUXINFOBASE_H
...@@ -162,7 +162,10 @@ namespace xAOD { ...@@ -162,7 +162,10 @@ namespace xAOD {
/// @} /// @}
protected: /// Declare how to wrap variables for this sort of base.
template <class T, class ALLOC = std::allocator<T> >
using AuxVariable_t = T;
/// Get the auxiliary ID for one of the persistent variables /// Get the auxiliary ID for one of the persistent variables
template< typename T > template< typename T >
auxid_t getAuxID( const std::string& name, auxid_t getAuxID( const std::string& name,
......
// Dear emacs, this is -*- c++ -*- // Dear emacs, this is -*- c++ -*-
// //
// Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
// //
#ifndef XAODCORE_TOOLS_AUXVARIABLE_H #ifndef XAODCORE_TOOLS_AUXVARIABLE_H
#define XAODCORE_TOOLS_AUXVARIABLE_H #define XAODCORE_TOOLS_AUXVARIABLE_H
// EDM include(s). // EDM include(s).
#include "AthContainers/AuxTypeRegistry.h" #include "AthContainers/AuxTypeRegistry.h"
#include "CxxUtils/pputils.h"
// System include(s).
#include <boost/preprocessor/facilities/overload.hpp>
/// Convenience macro for declaring an auxiliary variable /// Convenience macro for declaring an auxiliary variable
/// ///
...@@ -18,21 +16,92 @@ ...@@ -18,21 +16,92 @@
/// AUX_VARIABLE( RunNumber ); /// AUX_VARIABLE( RunNumber );
/// </code> /// </code>
/// ///
/// Can take a optional additional argument giving SG::AuxTypeRegistry::Flags /// Can take a optional additional argument giving SG::AuxVarFlags
/// to use for this variable. /// to use for this variable.
/// ///
#define AUX_VARIABLE(...) \ #define AUX_VARIABLE( VAR, ... ) \
BOOST_PP_OVERLOAD( AUX_VARIABLE_, __VA_ARGS__ )(__VA_ARGS__) do { \
#define AUX_VARIABLE_1( VAR ) \ static const auxid_t auxid = \
do { \ getAuxID( #VAR, VAR CXXUTILS_PP_FIRST( __VA_ARGS__ ) ); \
static const auxid_t auxid = getAuxID( #VAR, VAR ); \ regAuxVar( auxid, #VAR, VAR ); \
regAuxVar( auxid, #VAR, VAR ); \
} while( false )
#define AUX_VARIABLE_2( VAR, FLAGS ) \
do { \
static const auxid_t auxid = \
getAuxID( #VAR, VAR, FLAGS ); \
regAuxVar( auxid, #VAR, VAR ); \
} while( false ) } while( false )
/// Alternatively, an auxiliary variable may be declared using the AUXVAR_DECL
/// macro in the class definition. In this case, no explicit code
/// is required in the constructor. It takes two arguments: the type
/// of the variable and the variable name. Example:
/// <code>
/// AUXVAR_DECL( int32_t, RunNumber );
/// </code>
///
/// If AUXVAR_DECL is used with type T, the actual type of the member will
/// be given by the alias AuxVariable_t<T>. For AuxInfoBase, this will
/// be T, and for AuxContainerBase std::vector<T>. It may, however,
/// be overridden by derived classes to customize the container type used.
///
/// AuxVariable_t should actually take a second, defaultable, template
/// argument giving the allocator type to use for the container.
/// This may be provided as an optional third argument to AUXVAR_DECL.
/// AUXVAR_DECL may also take an optional fourth argument giving SG::AuxVarFlags
/// to use for the variable.
///
/// If an auxiliary variable declared with AUXVAR_DECL can be initialized
/// from a std::pmr::memory_resource*, then it will be initialized
/// with the resource associated with the AuxContainerBase/AuxInfoBase instance.
///
namespace xAOD { namespace detail {
template <class VARTYPE, class AUXBASE>
VARTYPE initAuxVar2( AUXBASE* auxcont,
std::true_type)
{
return VARTYPE (auxcont->memResource());
}
template <class VARTYPE, class AUXBASE>
VARTYPE initAuxVar2( AUXBASE* /*auxcont*/,
std::false_type)
{
return VARTYPE();
}
template <class VARTYPE, class AUXBASE>
VARTYPE initAuxVar1( AUXBASE* auxcont)
{
return initAuxVar2<VARTYPE> ( auxcont, std::is_constructible<VARTYPE, std::pmr::memory_resource*>() );
}
template <const char* NAME, class AUXBASE, class VARTYPE>
VARTYPE initAuxVar( AUXBASE* auxcont,
VARTYPE& var,
SG::AuxVarFlags flags = SG::AuxVarFlags::None )
{
static const SG::auxid_t auxid = auxcont->getAuxID( NAME, var, flags );
auxcont->regAuxVar (auxid, NAME, var);
return initAuxVar1<VARTYPE>( auxcont );
}
}} // namespace xAOD::detail
#define AUXVAR_DECL( TYPE, NAME, ... ) \
static constexpr const char NAME ## __name[] = #NAME; \
AuxVariable_t< TYPE AUXVAR_DECL_ALLOC_( TYPE, __VA_ARGS__ ) > NAME \
{ xAOD::detail::initAuxVar< NAME ## __name >( this, NAME CXXUTILS_PP_SECOND( __VA_ARGS__ ) ) }
#define AUXVAR_DECL_ALLOC_( TYPE, ... ) \
__VA_OPT__( CXXUTILS_PP_FIRST( __VA_ARGS__ )< TYPE > )
#define AUXVAR_PACKEDCONTAINER_DECL( TYPE, NAME ) \
static constexpr const char NAME ## __name[] = #NAME; \
SG::PackedContainer< TYPE > NAME { xAOD::detail::initAuxVar< NAME ## __name >( this, NAME ) }
#endif // XAODCORE_TOOLS_AUXVARIABLE_H #endif // XAODCORE_TOOLS_AUXVARIABLE_H
// Dear emacs, this is -*- c++ -*- // Dear emacs, this is -*- c++ -*-
/* /*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_H #ifndef XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_H
#define XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_H #define XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_H
...@@ -125,11 +125,16 @@ namespace xAOD { ...@@ -125,11 +125,16 @@ namespace xAOD {
/// @} /// @}
protected: /// Declare how to wrap variables for this sort of base.
template <class T, class ALLOC = std::allocator<T> >
using AuxVariable_t = std::vector<T, ALLOC>;
/// Get the auxiliary ID for one of the persistent variables /// Get the auxiliary ID for one of the persistent variables
template< typename T > template< typename T >
auxid_t getAuxID( const std::string& name, auxid_t getAuxID( const std::string& name,
std::vector< T >& /*vec*/ ); std::vector< T >& /*vec*/,
SG::AuxVarFlags flags =
SG::AuxVarFlags::None );
/// Register one of the user defined persistent variables internally /// Register one of the user defined persistent variables internally
template< typename T > template< typename T >
void regAuxVar( auxid_t auxid, const std::string& name, void regAuxVar( auxid_t auxid, const std::string& name,
......
// Dear emacs, this is -*- c++ -*- // Dear emacs, this is -*- c++ -*-
/* /*
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
*/ */
#ifndef XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_ICC #ifndef XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_ICC
#define XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_ICC #define XAODTRIGGER_VERSIONS_BYTESTREAMAUXCONTAINER_V1_ICC
...@@ -18,9 +18,10 @@ namespace xAOD { ...@@ -18,9 +18,10 @@ namespace xAOD {
template< typename T > template< typename T >
ByteStreamAuxContainer_v1::auxid_t ByteStreamAuxContainer_v1::auxid_t
ByteStreamAuxContainer_v1::getAuxID( const std::string& name, ByteStreamAuxContainer_v1::getAuxID( const std::string& name,
std::vector< T >& /*vec*/ ) { std::vector< T >& /*vec*/,
SG::AuxVarFlags flags) {
return SG::AuxTypeRegistry::instance().template getAuxID< T >( name ); return SG::AuxTypeRegistry::instance().template getAuxID< T >( name, "", flags );
} }
/// The user is expected to use this function inside the constructor of /// The user is expected to use this function inside the constructor of
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment