ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
JetH5Writer
src
IParticleWriterAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
src/IParticleWriterAlg.h
"
5
#include "
JetH5Writer/IParticleWriterConfig.h
"
6
7
#include "
AlgHelpers.h
"
8
9
#include "H5Cpp.h"
10
11
IParticleWriterAlg::IParticleWriterAlg
(
const
std::string& name,
12
ISvcLocator* loc):
13
AthAlgorithm
(name, loc),
14
m_writer
(nullptr)
15
{
16
}
17
18
StatusCode
IParticleWriterAlg::initialize
() {
19
ATH_CHECK
(
m_partKey
.initialize());
20
ATH_CHECK
(
m_output_svc
.retrieve());
21
22
IParticleWriterConfig
cfg;
23
cfg.name =
m_dsName
.value();
24
cfg.maximum_size =
m_maxSize
.value();
25
cfg.format =
getArrayFormat
(
m_arrayFormat
);
26
if
(cfg.name.empty()) {
27
ATH_MSG_ERROR
(
"datasetName isn't specified in particle writer"
);
28
return
StatusCode::FAILURE;
29
}
30
for
(
const
std::string& prim:
m_primitives
) {
31
if
(!
m_primToType
.value().count(prim)) {
32
ATH_MSG_ERROR
(prim <<
" not specified in type mapping"
);
33
return
StatusCode::FAILURE;
34
}
35
auto
type
=
getPrimitiveType
(
m_primToType
.value().at(prim));
36
if
(
m_primToAssociation
.value().count(prim)) {
37
std::string path =
m_primToAssociation
.value().at(prim);
38
size_t
pos = path.find(
'/'
);
39
if
(pos == std::string::npos) {
40
ATH_MSG_ERROR
(
"no '/' in "
<< path);
41
return
StatusCode::FAILURE;
42
}
43
std::string link_name = path.substr(0, pos);
44
std::string source_name = path.substr(pos+1);
45
Primitive
newprim {
46
type
,
47
std::move(source_name),
48
prim
49
};
50
cfg.inputs.emplace_back(std::move(link_name), std::move(newprim));
51
}
else
{
52
Primitive
newprim {
53
type
,
54
prim,
55
prim
56
};
57
cfg.inputs.emplace_back(
""
,std::move(newprim));
58
}
59
}
60
m_writer
.reset(
new
IParticleWriter
(*
m_output_svc
->group(), cfg));
61
62
return
StatusCode::SUCCESS;
63
}
64
65
StatusCode
IParticleWriterAlg::execute
(
const
EventContext& ctx) {
66
SG::ReadHandle
ipc(
m_partKey
, ctx);
67
std::vector<const xAOD::IParticle*> parts(ipc->begin(), ipc->end());
68
m_writer
->fill(parts);
69
return
StatusCode::SUCCESS;
70
}
71
72
StatusCode
IParticleWriterAlg::finalize
() {
73
m_writer
->flush();
74
return
StatusCode::SUCCESS;
75
}
getPrimitiveType
Primitive::Type getPrimitiveType(const std::string &name)
Definition
AlgHelpers.cxx:10
getArrayFormat
IParticleWriterConfig::ArrayFormat getArrayFormat(const std::string &name)
Definition
AlgHelpers.cxx:37
AlgHelpers.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
IParticleWriterAlg.h
IParticleWriterConfig.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
IParticleWriterAlg::m_primToType
Gaudi::Property< std::map< std::string, std::string > > m_primToType
Definition
IParticleWriterAlg.h:28
IParticleWriterAlg::finalize
virtual StatusCode finalize() override
Definition
IParticleWriterAlg.cxx:72
IParticleWriterAlg::m_arrayFormat
Gaudi::Property< std::string > m_arrayFormat
Definition
IParticleWriterAlg.h:40
IParticleWriterAlg::m_dsName
Gaudi::Property< std::string > m_dsName
Definition
IParticleWriterAlg.h:34
IParticleWriterAlg::m_maxSize
Gaudi::Property< unsigned long long > m_maxSize
Definition
IParticleWriterAlg.h:37
IParticleWriterAlg::m_primToAssociation
Gaudi::Property< std::map< std::string, std::string > > m_primToAssociation
Definition
IParticleWriterAlg.h:31
IParticleWriterAlg::m_writer
std::unique_ptr< IParticleWriter > m_writer
Definition
IParticleWriterAlg.h:48
IParticleWriterAlg::IParticleWriterAlg
IParticleWriterAlg(const std::string &name, ISvcLocator *loc)
Definition
IParticleWriterAlg.cxx:11
IParticleWriterAlg::m_partKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_partKey
Definition
IParticleWriterAlg.h:43
IParticleWriterAlg::initialize
virtual StatusCode initialize() override
Definition
IParticleWriterAlg.cxx:18
IParticleWriterAlg::m_output_svc
ServiceHandle< IH5GroupSvc > m_output_svc
Definition
IParticleWriterAlg.h:45
IParticleWriterAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
IParticleWriterAlg.cxx:65
IParticleWriterAlg::m_primitives
Gaudi::Property< std::vector< std::string > > m_primitives
Definition
IParticleWriterAlg.h:25
IParticleWriter
Definition
IParticleWriter.h:26
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
type
IParticleWriterConfig
Definition
IParticleWriterConfig.h:21
Primitive
Definition
Primitive.h:10
Generated on
for ATLAS Offline Software by
1.17.0