ATLAS Offline Software
Loading...
Searching...
No Matches
FillContainer.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef XAODMUONVIEWS_FILLCONTAINER_H
5#define XAODMUONVIEWS_FILLCONTAINER_H
6
10#include "GaudiKernel/MsgStream.h"
12#include "GeoModelKernel/throwExcept.h"
14
15#include <concepts>
16namespace xAOD {
17
22namespace detail{
24 template <typename AuxCont_t> concept AuxContainerConcept = std::is_base_of_v<xAOD::AuxContainerBase, AuxCont_t>
25 || std::is_same_v<AuxCont_t, void*>;
27 template<typename Cont_t> concept DataVectorConcept =
28 std::is_same_v<Cont_t, DataVector<typename Cont_t::base_value_type>>;
30 template <typename Cont_t> concept PrimaryContainerConcept = DataVectorConcept<Cont_t>
31 && requires(const Cont_t& container) {
32 requires std::is_base_of_v<SG::AuxElement, typename Cont_t::base_value_type>;
33 };
34}
35
36
37template <detail::DataVectorConcept Cont_t,
40 public:
45 static_assert( (detail::PrimaryContainerConcept<Cont_t> && !std::is_same_v<AuxCont_t, void*>) ||
46 (detail::DataVectorConcept<Cont_t> && std::is_same_v<AuxCont_t, void*>));
47 if constexpr(!std::is_same_v<AuxCont_t, void*>) {
48 m_cont->setStore(m_auxCont.get());
49 }
50 }
51
57 Cont_t* get() const {
58 if (!hasHandle()) {
59 return m_cont.get();
60 }
62 return handle.ptr();
63 }
64
65 Cont_t* operator->() const { return get(); }
67 Cont_t& operator*() const { return *get(); }
72 StatusCode record(const SG::WriteHandleKey<Cont_t>& key,
73 const EventContext& ctx) {
74 if (key.empty()) {
75 return StatusCode::SUCCESS;
76 }
77 if (hasHandle()) {
78 MsgStream msg{Athena::getMessageSvc(), "FillContainer"};
79 msg<<MSG::ERROR<<__func__<<"() - "<<__LINE__<<": Write handle under key "
80 <<m_writeHandle->key()<<" already exists."<<endmsg;
81 return StatusCode::FAILURE;
82 }
83 m_writeHandle = std::make_unique<WriteHandle_t>(key, ctx);
84 if constexpr(!std::is_same_v<AuxCont_t, void*>) {
85 return m_writeHandle->record(std::move(m_cont), std::move(m_auxCont));
86 } else {
87 return m_writeHandle->record(std::move(m_cont));
88 }
89 }
90
95 const EventContext& ctx) {
96 if (key.empty()) {
97 return StatusCode::SUCCESS;
98 }
99 if (hasHandle()) {
100 MsgStream msg{Athena::getMessageSvc(), "FillContainer"};
101 msg<<MSG::ERROR<<__func__<<"() - "<<__LINE__<<": Write handle under key "
102 <<m_writeHandle->key()<<" already exists."<<endmsg;
103 return StatusCode::FAILURE;
104 }
105 m_writeHandle = std::make_unique<WriteHandle_t>(key, ctx);
106 if constexpr(!std::is_same_v<AuxCont_t, void*>) {
107 return m_writeHandle->recordNonConst(std::move(m_cont), std::move(m_auxCont));
108 } else {
109 return m_writeHandle->recordNonConst(std::move(m_cont));
110 }
111 }
112
115 if (!hasHandle()) {
116 THROW_EXCEPTION("The write handle has not been initialized. Please call record or"
117 <<" recordNonConst before calling getHandle()");
118 }
119 return *m_writeHandle;
120 }
121
122 bool hasHandle() const { return m_writeHandle != nullptr; }
123 private:
125 std::unique_ptr<Cont_t> m_cont{std::make_unique<Cont_t>()};
127 std::unique_ptr<AuxCont_t> m_auxCont{std::make_unique<AuxCont_t>()};
129 std::unique_ptr<WriteHandle_t> m_writeHandle{};
130};
131
132}
133#endif
#define endmsg
Base class for elements of a container that can have aux data.
An STL vector of pointers that by default owns its pointed-to elements.
Handle class for recording to StoreGate.
#define ATLAS_THREAD_SAFE
Property holding a SG store/key/clid from which a WriteHandle is made.
bool hasHandle() const
Returns whether the record function has been called.
StatusCode recordNonConst(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
SG::WriteHandle< Cont_t > WriteHandle_t
Abrivation of the write handle type.
FillContainer(FillContainer &&other)=default
Move constructor.
StatusCode record(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
FillContainer()
default constructor
FillContainer & operator=(FillContainer &&other)=default
Default move operator.
WriteHandle_t & getHandle()
Returns the reference to the active write handle.
Cont_t * operator->() const
Define the arrow operator.
Cont_t * get() const
get operator
Cont_t & operator*() const
Define the dereference operator.
Define that the templated class needs to inherit from the AuxContainerBase class.
Define the primary container.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Auxiliary class to create a xAOD container together with its associated AuxContainer without manually...
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
MsgStream & msg
Definition testRead.cxx:32
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10