ATLAS Offline Software
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();
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 }
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
getArrayFormat
IParticleWriterConfig::ArrayFormat getArrayFormat(const std::string &name)
Definition: AlgHelpers.cxx:37
IParticleWriterAlg::m_arrayFormat
Gaudi::Property< std::string > m_arrayFormat
Definition: IParticleWriterAlg.h:40
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
IParticleWriterAlg::finalize
virtual StatusCode finalize() override
Definition: IParticleWriterAlg.cxx:72
IParticleWriterAlg::m_writer
std::unique_ptr< IParticleWriter > m_writer
Definition: IParticleWriterAlg.h:48
Primitive
Definition: Primitive.h:10
IParticleWriterAlg::IParticleWriterAlg
IParticleWriterAlg(const std::string &name, ISvcLocator *loc)
Definition: IParticleWriterAlg.cxx:11
AlgHelpers.h
IParticleWriterAlg::m_output_svc
ServiceHandle< IH5GroupSvc > m_output_svc
Definition: IParticleWriterAlg.h:45
IParticleWriterAlg::m_dsName
Gaudi::Property< std::string > m_dsName
Definition: IParticleWriterAlg.h:34
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IParticleWriterAlg::m_primToType
Gaudi::Property< std::map< std::string, std::string > > m_primToType
Definition: IParticleWriterAlg.h:28
IParticleWriter
Definition: IParticleWriter.h:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IParticleWriterConfig
Definition: IParticleWriterConfig.h:21
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IParticleWriterAlg::m_primitives
Gaudi::Property< std::vector< std::string > > m_primitives
Definition: IParticleWriterAlg.h:25
IParticleWriterAlg::m_maxSize
Gaudi::Property< unsigned long long > m_maxSize
Definition: IParticleWriterAlg.h:37
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
IParticleWriterAlg::m_partKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_partKey
Definition: IParticleWriterAlg.h:43
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
IParticleWriterConfig.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
IParticleWriterAlg::initialize
virtual StatusCode initialize() override
Definition: IParticleWriterAlg.cxx:18
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
IParticleWriterAlg::m_primToAssociation
Gaudi::Property< std::map< std::string, std::string > > m_primToAssociation
Definition: IParticleWriterAlg.h:31
IParticleWriterAlg::execute
virtual StatusCode execute() override
Definition: IParticleWriterAlg.cxx:65
getPrimitiveType
Primitive::Type getPrimitiveType(const std::string &name)
Definition: AlgHelpers.cxx:10
IParticleWriterAlg.h