ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonPhaseII
Event
xAOD
xAODMuonViews
xAODMuonViews
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
7
#include "
xAODCore/AuxContainerBase.h
"
8
#include "
AthContainers/DataVector.h
"
9
#include "
AthContainers/AuxElement.h
"
10
#include "GaudiKernel/MsgStream.h"
11
#include "
AthenaKernel/getMessageSvc.h
"
12
#include "GeoModelKernel/throwExcept.h"
13
#include "
StoreGate/WriteHandle.h
"
14
15
#include <concepts>
16
namespace
xAOD
{
17
22
namespace
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
37
template
<
detail::DataVectorConcept
Cont_t,
38
detail::AuxContainerConcept
AuxCont_t>
39
class
FillContainer
{
40
public
:
42
using
WriteHandle_t
=
SG::WriteHandle<Cont_t>
;
44
FillContainer
() {
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
53
FillContainer
(
FillContainer
&&
other
) =
default
;
55
FillContainer
&
operator=
(
FillContainer
&&
other
) =
default
;
57
Cont_t*
get
()
const
{
58
if
(!
hasHandle
()) {
59
return
m_cont
.get();
60
}
61
WriteHandle_t
& handle
ATLAS_THREAD_SAFE
{*
m_writeHandle
};
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
94
StatusCode
recordNonConst
(
const
SG::WriteHandleKey<Cont_t>
& key,
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
114
WriteHandle_t
&
getHandle
() {
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
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
AuxContainerBase.h
AuxElement.h
Base class for elements of a container that can have aux data.
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
WriteHandle.h
Handle class for recording to StoreGate.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition
StoreGate/StoreGate/WriteHandleKey.h:40
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
xAOD::FillContainer::hasHandle
bool hasHandle() const
Returns whether the record function has been called.
Definition
FillContainer.h:122
xAOD::FillContainer< xAOD::sTgcStripContainer, xAOD::sTgcStripAuxContainer >::m_auxCont
std::unique_ptr< AuxCont_t > m_auxCont
Definition
FillContainer.h:127
xAOD::FillContainer::recordNonConst
StatusCode recordNonConst(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
Definition
FillContainer.h:94
xAOD::FillContainer< xAOD::sTgcStripContainer, xAOD::sTgcStripAuxContainer >::WriteHandle_t
SG::WriteHandle< Cont_t > WriteHandle_t
Definition
FillContainer.h:42
xAOD::FillContainer::FillContainer
FillContainer(FillContainer &&other)=default
Move constructor.
xAOD::FillContainer::record
StatusCode record(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
Definition
FillContainer.h:72
xAOD::FillContainer::FillContainer
FillContainer()
default constructor
Definition
FillContainer.h:44
xAOD::FillContainer< xAOD::sTgcStripContainer, xAOD::sTgcStripAuxContainer >::m_cont
std::unique_ptr< Cont_t > m_cont
Definition
FillContainer.h:125
xAOD::FillContainer::operator=
FillContainer & operator=(FillContainer &&other)=default
Default move operator.
xAOD::FillContainer< xAOD::sTgcStripContainer, xAOD::sTgcStripAuxContainer >::m_writeHandle
std::unique_ptr< WriteHandle_t > m_writeHandle
Definition
FillContainer.h:129
xAOD::FillContainer::getHandle
WriteHandle_t & getHandle()
Returns the reference to the active write handle.
Definition
FillContainer.h:114
xAOD::FillContainer::operator->
Cont_t * operator->() const
Define the arrow operator.
Definition
FillContainer.h:65
xAOD::FillContainer::get
Cont_t * get() const
get operator
Definition
FillContainer.h:57
xAOD::FillContainer::operator*
Cont_t & operator*() const
Define the dereference operator.
Definition
FillContainer.h:67
xAOD::detail::AuxContainerConcept
Define that the templated class needs to inherit from the AuxContainerBase class.
Definition
FillContainer.h:24
xAOD::detail::DataVectorConcept
Define a data vector.
Definition
FillContainer.h:27
xAOD::detail::PrimaryContainerConcept
Define the primary container.
Definition
FillContainer.h:30
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition
getMessageSvc.cxx:20
xAOD::detail
Internal implementation details and type concepts for container merging.
Definition
ShallowCopy.h:138
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition
ICaloAffectedTool.h:24
xAOD::other
@ other
Definition
TrackingPrimitives.h:528
msg
MsgStream & msg
Definition
testRead.cxx:32
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition
throwExcept.h:10
Generated on
for ATLAS Offline Software by
1.17.0