File indexing completed on 2025-07-14 09:12:41
0001
0002
0003
0004
0005 #include "Gaudi/Property.h"
0006 #include "Gaudi/Algorithm.h"
0007
0008 #include <k4FWCore/DataHandle.h>
0009
0010
0011 #include "edm4eic/ReconstructedParticleCollection.h"
0012
0013 namespace Jug::Reco {
0014
0015
0016
0017
0018
0019
0020
0021
0022 class ParticleCollector : public Gaudi::Algorithm {
0023 private:
0024 Gaudi::Property<std::vector<std::string>> m_inputParticles{this, "inputParticles", {}, "Particles to be aggregated"};
0025 mutable DataHandle<edm4eic::ReconstructedParticleCollection> m_outputParticles{"outputParticles", Gaudi::DataHandle::Writer,
0026 this};
0027
0028 std::vector<DataHandle<edm4eic::ReconstructedParticleCollection>*> m_particleCollections;
0029
0030 public:
0031 ParticleCollector(const std::string& name, ISvcLocator* svcLoc) : Gaudi::Algorithm(name, svcLoc) {
0032 declareProperty("outputParticles", m_outputParticles, "output particles combined into single collection");
0033 }
0034 ~ParticleCollector() {
0035 for (auto* col : m_particleCollections) {
0036 delete col;
0037 }
0038 }
0039
0040 StatusCode initialize() override {
0041 if (Gaudi::Algorithm::initialize().isFailure()) {
0042 return StatusCode::FAILURE;
0043 }
0044 for (auto colname : m_inputParticles) {
0045 debug() << "initializing collection: " << colname << endmsg;
0046 m_particleCollections.push_back(
0047 new DataHandle<edm4eic::ReconstructedParticleCollection>{colname, Gaudi::DataHandle::Reader, this});
0048 }
0049 return StatusCode::SUCCESS;
0050 }
0051
0052 StatusCode execute(const EventContext&) const override {
0053 auto* output = m_outputParticles.createAndPut();
0054 if (msgLevel(MSG::DEBUG)) {
0055 debug() << "execute collector" << endmsg;
0056 }
0057 for (const auto& list : m_particleCollections) {
0058 const auto& parts = *(list->get());
0059 if (msgLevel(MSG::DEBUG)) {
0060 debug() << "col n particles: " << parts.size() << endmsg;
0061 }
0062 for (const auto& part : parts) {
0063 output->push_back(part.clone());
0064 }
0065 }
0066
0067 return StatusCode::SUCCESS;
0068 }
0069 };
0070
0071 DECLARE_COMPONENT(ParticleCollector)
0072
0073 }