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