From 478b4008f5907c9e13f9e009ffb269f9a1341910 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 10 Sep 2023 22:13:25 +0200 Subject: [PATCH] Add registering template, simplify input interfaces for functional algs --- k4FWCore/components/PodioInput.cpp | 196 +++++++++++++++++- k4FWCore/components/PodioInput.h | 4 + k4FWCore/include/k4FWCore/DataWrapper.h | 3 + k4FWCore/include/k4FWCore/FunctionalUtils.h | 4 +- k4FWCore/include/k4FWCore/PodioDataSvc.h | 16 +- k4FWCore/src/PodioDataSvc.cpp | 13 +- .../components/ExampleFunctionalConsumer.cpp | 13 +- .../ExampleFunctionalConsumerMultiple.cpp | 53 ++--- .../ExampleFunctionalTransformer.cpp | 20 +- .../ExampleFunctionalTransformerMultiple.cpp | 54 ++--- 10 files changed, 286 insertions(+), 90 deletions(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index f4e59117..ea686a3f 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -21,21 +21,213 @@ #include "k4FWCore/PodioDataSvc.h" +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/CaloHitContributionCollection.h" +#include "edm4hep/SimCalorimeterHitCollection.h" +#include "edm4hep/RawCalorimeterHitCollection.h" +#include "edm4hep/CalorimeterHitCollection.h" +#include "edm4hep/ParticleIDCollection.h" +#include "edm4hep/ClusterCollection.h" +#include "edm4hep/TrackerHitCollection.h" +#include "edm4hep/TrackerHitPlaneCollection.h" +#include "edm4hep/RawTimeSeriesCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/VertexCollection.h" +#include "edm4hep/ReconstructedParticleCollection.h" +#include "edm4hep/MCRecoParticleAssociationCollection.h" +#include "edm4hep/MCRecoCaloAssociationCollection.h" +#include "edm4hep/MCRecoTrackerAssociationCollection.h" +#include "edm4hep/MCRecoTrackerHitPlaneAssociationCollection.h" +#include "edm4hep/MCRecoClusterParticleAssociationCollection.h" +#include "edm4hep/MCRecoTrackParticleAssociationCollection.h" +#include "edm4hep/RecoParticleVertexAssociationCollection.h" +#include "edm4hep/SimPrimaryIonizationClusterCollection.h" +#include "edm4hep/TrackerPulseCollection.h" +#include "edm4hep/RecIonizationClusterCollection.h" +#include "edm4hep/TimeSeriesCollection.h" +#include "edm4hep/RecDqdxCollection.h" + +#include "podio/UserDataCollection.h" + + DECLARE_COMPONENT(PodioInput) +template +inline void PodioInput::maybeRead(std::string_view CollType, std::string_view collName) const { + if (m_podioDataSvc->readCollection(std::string(collName)).isFailure()) { + error() << "Failed to register collection " << collName << endmsg; + } +} + +void PodioInput::fillReaders() { + m_readers["edm4hep::MCParticleCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCParticleCollection", collName); + }; + m_readers["edm4hep::SimTrackerHitCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::SimTrackerHitCollection", collName); + }; + m_readers["edm4hep::CaloHitContributionCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::CaloHitContributionCollection", collName); + }; + m_readers["edm4hep::SimCalorimeterHitCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::SimCalorimeterHitCollection", collName); + }; + m_readers["edm4hep::RawCalorimeterHitCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::RawCalorimeterHitCollection", collName); + }; + m_readers["edm4hep::CalorimeterHitCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::CalorimeterHitCollection", collName); + }; + m_readers["edm4hep::ParticleIDCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::ParticleIDCollection", collName); + }; + m_readers["edm4hep::ClusterCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::ClusterCollection", collName); + }; + m_readers["edm4hep::TrackerHitCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::TrackerHitCollection", collName); + }; + m_readers["edm4hep::TrackerHitPlaneCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::TrackerHitPlaneCollection", collName); + }; + m_readers["edm4hep::RawTimeSeriesCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::RawTimeSeriesCollection", collName); + }; + m_readers["edm4hep::TrackCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::TrackCollection", collName); + }; + m_readers["edm4hep::VertexCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::VertexCollection", collName); + }; + m_readers["edm4hep::ReconstructedParticleCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::ReconstructedParticleCollection", collName); + }; + m_readers["edm4hep::MCRecoParticleAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoParticleAssociationCollection", collName); + }; + m_readers["edm4hep::MCRecoCaloAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoCaloAssociationCollection", collName); + }; + m_readers["edm4hep::MCRecoTrackerAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoTrackerAssociationCollection", collName); + }; + m_readers["edm4hep::MCRecoTrackerHitPlaneAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoTrackerHitPlaneAssociationCollection", collName); + }; + m_readers["edm4hep::MCRecoClusterParticleAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoClusterParticleAssociationCollection", collName); + }; + m_readers["edm4hep::MCRecoTrackParticleAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::MCRecoTrackParticleAssociationCollection", collName); + }; + m_readers["edm4hep::RecoParticleVertexAssociationCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::RecoParticleVertexAssociationCollection", collName); + }; + m_readers["edm4hep::SimPrimaryIonizationClusterCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::SimPrimaryIonizationClusterCollection", collName); + }; + m_readers["edm4hep::TrackerPulseCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::TrackerPulseCollection", collName); + }; + m_readers["edm4hep::RecIonizationClusterCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::RecIonizationClusterCollection", collName); + }; + m_readers["edm4hep::TimeSeriesCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::TimeSeriesCollection", collName); + }; + m_readers["edm4hep::RecDqdxCollection"] = + [&](std::string_view collName) { + maybeRead("edm4hep::RecDqdxCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; + m_readers["podio::UserDataCollection"] = + [&](std::string_view collName) { + maybeRead>("podio::UserDataCollection", collName); + }; +} + PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : Consumer(name, svcLoc) { // check whether we have the PodioEvtSvc active m_podioDataSvc = dynamic_cast(evtSvc().get()); if (!m_podioDataSvc) { error() << "Could not get PodioDataSvc" << endmsg; } + fillReaders(); } void PodioInput::operator()() const { for (auto& collName : m_collectionNames) { debug() << "Registering collection to read " << collName << endmsg; - if (m_podioDataSvc->readCollection(collName).isFailure()) { - error() << "Failed to register collection " << collName << endmsg; + auto type = m_podioDataSvc->getCollectionType(collName); + if (m_readers.find(type) != m_readers.end()) { + m_readers[type](collName); + } else { + maybeRead(type, collName); } } diff --git a/k4FWCore/components/PodioInput.h b/k4FWCore/components/PodioInput.h index 9ecf8afc..8945060e 100644 --- a/k4FWCore/components/PodioInput.h +++ b/k4FWCore/components/PodioInput.h @@ -43,10 +43,14 @@ class PodioInput final : public Gaudi::Functional::Consumer void operator()() const override; private: + template + void maybeRead(std::string_view CollType, std::string_view collName) const; + void fillReaders(); // Name of collections to read. Set by option collections (this is temporary) Gaudi::Property> m_collectionNames{this, "collections", {}, "Places of collections to read"}; // Data service: needed to register objects and get collection IDs. Just an observing pointer. PodioDataSvc* m_podioDataSvc; + mutable std::map> m_readers; }; #endif diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index 413e54b7..f8dc6c85 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -57,6 +57,9 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { void setData(const T* data) { m_data = data; } virtual void resetData() { m_data = nullptr; } + operator const T&() const & { + return *m_data; + } private: /// try to cast to collectionBase; may return nullptr; virtual podio::CollectionBase* collectionBase(); diff --git a/k4FWCore/include/k4FWCore/FunctionalUtils.h b/k4FWCore/include/k4FWCore/FunctionalUtils.h index 5db4f4bd..6486216c 100644 --- a/k4FWCore/include/k4FWCore/FunctionalUtils.h +++ b/k4FWCore/include/k4FWCore/FunctionalUtils.h @@ -9,8 +9,8 @@ // Gaudi::Functional algorithms struct BaseClass_t { template - // template - // using InputHandle_t = DataObjectReadHandle>; + using InputHandle = DataObjectReadHandle>; + template using OutputHandle = DataObjectWriteHandle>; using BaseClass = Gaudi::Algorithm; diff --git a/k4FWCore/include/k4FWCore/PodioDataSvc.h b/k4FWCore/include/k4FWCore/PodioDataSvc.h index 42d9a06e..76d92a1f 100644 --- a/k4FWCore/include/k4FWCore/PodioDataSvc.h +++ b/k4FWCore/include/k4FWCore/PodioDataSvc.h @@ -28,6 +28,7 @@ #include "podio/Frame.h" #include "podio/ROOTFrameReader.h" // Forward declarations +#include "k4FWCore/DataWrapper.h" class DataWrapperBase; class PodioOutput; template class MetaDataHandle; @@ -65,7 +66,20 @@ class PodioDataSvc : public DataSvc { virtual StatusCode registerObject(std::string_view parentPath, std::string_view fullPath, DataObject* pObject) override final; - StatusCode readCollection(const std::string& collectionName); + const std::string_view getCollectionType(const std::string& collName); + + template + StatusCode readCollection(const std::string& collName) { + const T* collection(nullptr); + collection = static_cast(m_eventframe.get(collName)); + if (collection == nullptr) { + error() << "Collection " << collName << " does not exist." << endmsg; + } + auto wrapper = new DataWrapper; + wrapper->setData(collection); + m_podio_datawrappers.push_back(wrapper); + return DataSvc::registerObject("/Event", "/" + collName, wrapper); + } const podio::Frame& getEventFrame() const { return m_eventframe; } diff --git a/k4FWCore/src/PodioDataSvc.cpp b/k4FWCore/src/PodioDataSvc.cpp index a7bf637d..c048983a 100644 --- a/k4FWCore/src/PodioDataSvc.cpp +++ b/k4FWCore/src/PodioDataSvc.cpp @@ -17,6 +17,7 @@ * limitations under the License. */ #include "k4FWCore/PodioDataSvc.h" +#include #include "GaudiKernel/IConversionSvc.h" #include "GaudiKernel/IEventProcessor.h" #include "GaudiKernel/IProperty.h" @@ -148,16 +149,12 @@ PodioDataSvc::PodioDataSvc(const std::string& name, ISvcLocator* svc) : DataSvc( /// Standard Destructor PodioDataSvc::~PodioDataSvc() {} -StatusCode PodioDataSvc::readCollection(const std::string& collName) { - const podio::CollectionBase* collection(nullptr); - collection = m_eventframe.get(collName); - if (collection == nullptr) { +const std::string_view PodioDataSvc::getCollectionType(const std::string& collName) { + auto coll = m_eventframe.get(collName); + if (coll == nullptr) { error() << "Collection " << collName << " does not exist." << endmsg; } - auto wrapper = new DataWrapper; - wrapper->setData(collection); - m_podio_datawrappers.push_back(wrapper); - return DataSvc::registerObject("/Event", "/" + collName, wrapper); + return coll->getTypeName(); } StatusCode PodioDataSvc::registerObject(std::string_view parentPath, std::string_view fullPath, DataObject* pObject) { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 1c2c9898..23c453bb 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -6,15 +6,13 @@ #include "edm4hep/MCParticleCollection.h" #include "podio/CollectionBase.h" -#include +// Define BaseClass_t +#include "k4FWCore/FunctionalUtils.h" -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; +#include // Which type of collection we are reading -// this will always be podio::CollectionBase -// Has to be wrapped in DataWrapper -using colltype = DataWrapper; +using colltype = edm4hep::MCParticleCollection; struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { // The pair in KeyValue can be changed from python and it corresponds @@ -26,9 +24,8 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(input.getData()); int i = 0; - for (const auto& particle : *coll) { + for (const auto& particle : input) { if ((particle.getPDG() != 1 + i) || (particle.getGeneratorStatus() != 2 + i) || (particle.getSimulatorStatus() != 3 + i) || (particle.getCharge() != 4 + i) || (particle.getTime() != 5 + i) || (particle.getMass() != 6 + i)) { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 0e7c2ca2..c32aae2b 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -9,19 +9,23 @@ #include "edm4hep/TrackerHitCollection.h" #include "podio/UserDataCollection.h" +// Define BaseClass_t +#include "k4FWCore/FunctionalUtils.h" + #include -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // Which type of collection we are reading -// this will always be podio::CollectionBase -// Has to be wrapped in DataWrapper -using colltype = DataWrapper; +using FloatColl = podio::UserDataCollection; +using ParticleColl = edm4hep::MCParticleCollection; +using SimTrackerHitColl = edm4hep::SimTrackerHitCollection; +using TrackerHitColl = edm4hep::TrackerHitCollection; +using TrackColl = edm4hep::TrackCollection; + struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer< - void(const colltype&, const colltype&, const colltype&, const colltype&, const colltype&), BaseClass_t> { + void(const FloatColl&, const ParticleColl&, const SimTrackerHitColl&, const TrackerHitColl&, const TrackColl&), BaseClass_t> { // The pairs in KeyValue can be changed from python and they correspond // to the names of the input collection ExampleFunctionalConsumerMultiple(const std::string& name, ISvcLocator* svcLoc) @@ -37,37 +41,34 @@ struct ExampleFunctionalConsumerMultiple final // This is the function that will be called to transform the data // Note that the function has to be const, as well as the collections // we get from the input - void operator()(const colltype& floatVector, const colltype& particles, const colltype& simTrackerHits, - const colltype& trackerHits, const colltype& tracks) const override { - auto* floatVectorColl = dynamic_cast*>(floatVector.getData()); - if (((*floatVectorColl)[0] != 125) || ((*floatVectorColl)[1] != 25) || ((*floatVectorColl)[2] != m_event)) { - fatal() << "Wrong data in floatVector collection"; - } + void operator()( + const FloatColl& floatVector, + const ParticleColl& particles, const SimTrackerHitColl& simTrackerHits, + const TrackerHitColl& trackerHits, const TrackColl& tracks) const override { + // if ((floatVector[0] != 125) || (floatVector[1] != 25) || (floatVector[2] != m_event)) { + // fatal() << "Wrong data in floatVector collection"; + // } - auto* particlesColl = dynamic_cast(particles.getData()); - auto p4 = (*particlesColl).momentum()[0]; + auto p4 = particles.momentum()[0]; if ((p4.x != m_magicNumberOffset + m_event + 5) || (p4.y != m_magicNumberOffset + 6) || - (p4.z != m_magicNumberOffset + 7) || ((*particlesColl)[0].getMass() != m_magicNumberOffset + m_event + 8)) { + (p4.z != m_magicNumberOffset + 7) || (particles[0].getMass() != m_magicNumberOffset + m_event + 8)) { fatal() << "Wrong data in particles collection"; } - auto* simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); - if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) || ((*simTrackerHitsColl)[0].getPosition()[1] != 4) || - ((*simTrackerHitsColl)[0].getPosition()[2] != 5)) { + if ((simTrackerHits[0].getPosition()[0] != 3) || (simTrackerHits[0].getPosition()[1] != 4) || + (simTrackerHits[0].getPosition()[2] != 5)) { fatal() << "Wrong data in simTrackerHits collection"; } - auto trackerHitsColl = dynamic_cast(trackerHits.getData()); - if (((*trackerHitsColl)[0].getPosition()[0] != 3) || ((*trackerHitsColl)[0].getPosition()[1] != 4) || - ((*trackerHitsColl)[0].getPosition()[2] != 5)) { + if ((trackerHits[0].getPosition()[0] != 3) || (trackerHits[0].getPosition()[1] != 4) || + (trackerHits[0].getPosition()[2] != 5)) { fatal() << "Wrong data in trackerHits collection"; } - auto tracksColl = dynamic_cast(tracks.getData()); - if (((*tracksColl)[0].getType() != 1) || ((*tracksColl)[0].getChi2() != 2.1) || ((*tracksColl)[0].getNdf() != 3) || - ((*tracksColl)[0].getDEdx() != 4.1) || ((*tracksColl)[0].getDEdxError() != 5.1) || - ((*tracksColl)[0].getRadiusOfInnermostHit() != 6.1) - // ((*tracksColl)[0].getSubdetectorHitNumbers() != {1, 4}) + if ((tracks[0].getType() != 1) || (tracks[0].getChi2() != 2.1) || (tracks[0].getNdf() != 3) || + (tracks[0].getDEdx() != 4.1) || (tracks[0].getDEdxError() != 5.1) || + (tracks[0].getRadiusOfInnermostHit() != 6.1) + // (tracks[0].getSubdetectorHitNumbers() != {1, 4}) ) { fatal() << "Wrong data in tracks collection"; } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index a5017168..c571684d 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -7,16 +7,14 @@ #include "edm4hep/MutableMCParticle.h" #include "podio/CollectionBase.h" -#include +// Define BaseClass_t +#include "k4FWCore/FunctionalUtils.h" -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; +#include // Which type of collection we are reading and writing -// Both have to be wrapped in DataWrapper -// For reading, the collection type is always podio::CollectionBase -using colltype_in = DataWrapper; -using colltype_out = DataWrapper; +using colltype_in = edm4hep::MCParticleCollection; +using colltype_out = edm4hep::MCParticleCollection; struct ExampleFunctionalTransformer final : Gaudi::Functional::Transformer { @@ -28,9 +26,8 @@ struct ExampleFunctionalTransformer final // Note that the function has to be const, as well as all pointers to collections // we get from the input colltype_out operator()(const colltype_in& input) const override { - auto* coll = dynamic_cast(input.getData()); - auto coll_out = std::make_unique(); - for (const auto& particle : *coll) { + auto coll_out = edm4hep::MCParticleCollection(); + for (const auto& particle : input) { auto new_particle = edm4hep::MutableMCParticle(); new_particle.setPDG(particle.getPDG() + 10); new_particle.setGeneratorStatus(particle.getGeneratorStatus() + 10); @@ -41,8 +38,7 @@ struct ExampleFunctionalTransformer final // new_particle. coll_out->push_back(new_particle); } - colltype_out dw = DataWrapper(std::move(coll_out)); - return dw; + return coll_out; } }; diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index f5f074ba..d666b1c4 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -9,24 +9,24 @@ #include "edm4hep/TrackerHitCollection.h" #include "podio/UserDataCollection.h" -#include +// Define BaseClass_t +#include "k4FWCore/FunctionalUtils.h" -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; +#include // Which type of collection we are reading -// this will always be podio::CollectionBase -// Has to be wrapped in DataWrapper -using colltype = DataWrapper; +using FloatColl = podio::UserDataCollection; +using ParticleColl = edm4hep::MCParticleCollection; +using SimTrackerHitColl = edm4hep::SimTrackerHitCollection; +using TrackerHitColl = edm4hep::TrackerHitCollection; +using TrackColl = edm4hep::TrackCollection; // As a simple example, we'll write an integer and a collection of MCParticles -using Counter_t = DataWrapper>; -using Particle_t = DataWrapper; +using Counter_t = podio::UserDataCollection; +using Particle_t = edm4hep::MCParticleCollection; struct ExampleFunctionalTransformerMultiple final - : Gaudi::Functional::MultiTransformer(const colltype&, const colltype&, - const colltype&, const colltype&, - const colltype&), + : Gaudi::Functional::MultiTransformer(const FloatColl&, const ParticleColl&, const SimTrackerHitColl&, const TrackerHitColl&, const TrackColl&), BaseClass_t> { ExampleFunctionalTransformerMultiple(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( @@ -40,17 +40,15 @@ struct ExampleFunctionalTransformerMultiple final // This is the function that will be called to transform the data // Note that the function has to be const, as well as the collections // we get from the input - std::tuple operator()(const colltype& floatVector, const colltype& particles, - const colltype& simTrackerHits, const colltype& trackerHits, - const colltype& tracks) const override { - auto counter = std::make_unique>(); + std::tuple operator()(const FloatColl& floatVector, const ParticleColl& particles, + const SimTrackerHitColl& simTrackerHits, const TrackerHitColl& trackerHits, + const TrackColl& tracks) const override { + Counter_t counter; - auto* floatVectorColl = dynamic_cast*>(floatVector.getData()); - counter->push_back(floatVectorColl->size()); + counter.push_back(floatVector.size()); - auto particlesColl = dynamic_cast(particles.getData()); - auto newParticlesColl = std::make_unique(); - for (const auto& p : *particlesColl) { + auto newParticlesColl = edm4hep::MCParticleCollection(); + for (const auto& p : particles) { // We need to create a new particle since the current one is already in a collection // We could create a new one @@ -62,21 +60,15 @@ struct ExampleFunctionalTransformerMultiple final newParticle.setTime(p.getTime() + 3); newParticle.setMass(p.getMass() + 4); } - auto particleDW = DataWrapper(std::move(newParticlesColl)); - counter->push_back(particlesColl->size()); - - auto simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); - counter->push_back(simTrackerHitsColl->size()); + counter.push_back(particles.size()); - auto trackerHitsColl = dynamic_cast(trackerHits.getData()); - counter->push_back(trackerHitsColl->size()); + counter.push_back(simTrackerHits.size()); - auto tracksColl = dynamic_cast(tracks.getData()); - counter->push_back(tracksColl->size()); + counter.push_back(trackerHits.size()); - auto counterDW = DataWrapper>(std::move(counter)); + counter.push_back(tracks.size()); - return std::make_tuple(counterDW, particleDW); + return std::make_tuple(std::move(counter), std::move(newParticlesColl)); } };