ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlattenEvent.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FlattenEvent.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <vector>
12 
16 
18  : BareAlgorithm("FlattenEvent", lvl), m_cfg(cfg) {
19  if (m_cfg.inputEvent.empty()) {
20  throw std::invalid_argument("Missing input event collection");
21  }
22  if (m_cfg.outputParticles.empty()) {
23  throw std::invalid_argument("Missing output particles collection");
24  }
25 }
26 
28  // setup input and output containers
29  const auto& event =
30  ctx.eventStore.get<std::vector<SimVertex>>(m_cfg.inputEvent);
31  SimParticleContainer::sequence_type unsortedParticles;
32 
33  // extract particles
34  for (const auto& vertex : event) {
35  for (const auto& particle : vertex.outgoing) {
36  unsortedParticles.emplace_back(particle);
37  }
38  }
39  unsortedParticles.shrink_to_fit();
40 
41  // re-establish ordering by barcode
42  SimParticleContainer particles;
43  particles.adopt_sequence(std::move(unsortedParticles));
44 
45  ctx.eventStore.add(m_cfg.outputParticles, std::move(particles));
46  return ProcessCode::SUCCESS;
47 }