ATLAS Offline Software
Loading...
Searching...
No Matches
IParticleWriterAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
6
7#include "AlgHelpers.h"
8
9#include "H5Cpp.h"
10
12 ISvcLocator* loc):
13 AthAlgorithm(name, loc),
14 m_writer(nullptr)
15{
16}
17
19 ATH_CHECK(m_partKey.initialize());
20 ATH_CHECK(m_output_svc.retrieve());
21
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
67 std::vector<const xAOD::IParticle*> parts(ipc->begin(), ipc->end());
68 m_writer->fill(parts);
69 return StatusCode::SUCCESS;
70}
71
73 m_writer->flush();
74 return StatusCode::SUCCESS;
75}
Primitive::Type getPrimitiveType(const std::string &name)
IParticleWriterConfig::ArrayFormat getArrayFormat(const std::string &name)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Property< std::map< std::string, std::string > > m_primToType
virtual StatusCode execute() override
virtual StatusCode finalize() override
Gaudi::Property< std::string > m_arrayFormat
Gaudi::Property< std::string > m_dsName
Gaudi::Property< unsigned long long > m_maxSize
Gaudi::Property< std::map< std::string, std::string > > m_primToAssociation
std::unique_ptr< IParticleWriter > m_writer
IParticleWriterAlg(const std::string &name, ISvcLocator *loc)
SG::ReadHandleKey< xAOD::IParticleContainer > m_partKey
virtual StatusCode initialize() override
ServiceHandle< IH5GroupSvc > m_output_svc
Gaudi::Property< std::vector< std::string > > m_primitives