From dbc48089b0ada0d24646f7af87dff9d11e945637 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 4 Sep 2023 21:02:51 +0200 Subject: [PATCH 01/68] Add example producer --- test/k4FWCoreTest/CMakeLists.txt | 5 ++++ .../options/runExampleProducer.py | 13 ++++++++++ .../src/components/ExampleProducer.cpp | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/k4FWCoreTest/options/runExampleProducer.py create mode 100644 test/k4FWCoreTest/src/components/ExampleProducer.cpp diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index a536490f..b991d528 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -32,6 +32,7 @@ set(k4fwcoretest_plugin_sources src/components/k4FWCoreTest_cellID_reader.cpp src/components/k4FWCoreTest_cellID_writer.cpp src/components/k4FWCoreTest_CheckExampleEventData.cpp + src/components/ExampleProducer.cpp ) gaudi_add_module(k4FWCoreTestPlugins @@ -198,3 +199,7 @@ add_test(NAME TestExec WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} --dry-run options/TestExec.py) set_test_env(TestExec) +add_test(NAME ExampleProducer + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN}) +set_test_env(ExampleProducer) diff --git a/test/k4FWCoreTest/options/runExampleProducer.py b/test/k4FWCoreTest/options/runExampleProducer.py new file mode 100644 index 00000000..d86e1065 --- /dev/null +++ b/test/k4FWCoreTest/options/runExampleProducer.py @@ -0,0 +1,13 @@ +from Gaudi.Configuration import * +from Configurables import ExampleProducer +from Configurables import EvtStoreSvc +from Configurables import ApplicationMgr + +producer = ExampleProducer("ExampleProducer", OutputLocation="/ExampleInt", ExampleInt=5) + +ApplicationMgr( TopAlg=[producer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[EvtStoreSvc("EventDataSvc")], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/src/components/ExampleProducer.cpp b/test/k4FWCoreTest/src/components/ExampleProducer.cpp new file mode 100644 index 00000000..da6d902b --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleProducer.cpp @@ -0,0 +1,24 @@ +#include "Gaudi/Property.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiAlg/Producer.h" + +#include + +using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; + +struct ExampleProducer final : Gaudi::Functional::Producer { + + ExampleProducer( const std::string& name, ISvcLocator* svcLoc ) + : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} + + int operator()() const override { + info() << "Producing " << m_exampleInt << endmsg; + return m_exampleInt; + } + + Gaudi::Property m_exampleInt{this, "ExampleInt", 3, + "Example int to be produced"}; + +}; + +DECLARE_COMPONENT(ExampleProducer) From dbfe99993a4e95466dd8054b2c478da516db39ce Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 9 Jul 2023 17:32:18 +0200 Subject: [PATCH 02/68] Up --- test/k4FWCoreTest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index b991d528..4d2e9e2d 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -201,5 +201,5 @@ add_test(NAME TestExec set_test_env(TestExec) add_test(NAME ExampleProducer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN}) + COMMAND ${K4RUN} options/runExampleProducer.py) set_test_env(ExampleProducer) From 3c40628efae99fda472b3ffe3af88661693c9938 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 9 Jul 2023 17:38:38 +0200 Subject: [PATCH 03/68] Up --- test/k4FWCoreTest/options/runExampleProducer.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleProducer.py b/test/k4FWCoreTest/options/runExampleProducer.py index d86e1065..92cafa33 100644 --- a/test/k4FWCoreTest/options/runExampleProducer.py +++ b/test/k4FWCoreTest/options/runExampleProducer.py @@ -3,11 +3,20 @@ from Configurables import EvtStoreSvc from Configurables import ApplicationMgr +from Configurables import k4DataSvc +podioevent = k4DataSvc("EventDataSvc") +ApplicationMgr().ExtSvc += [podioevent] + +from Configurables import PodioOutput +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_twoproducer.root" +out.outputCommands = ["keep *"] + producer = ExampleProducer("ExampleProducer", OutputLocation="/ExampleInt", ExampleInt=5) -ApplicationMgr( TopAlg=[producer], +ApplicationMgr( TopAlg=[producer, out], EvtSel="NONE", EvtMax=10, - ExtSvc=[EvtStoreSvc("EventDataSvc")], + ExtSvc=[k4DataSvc("EventDataSvc")], OutputLevel=INFO, ) From f74c86522b80d7a8bd5c93704de2fb1c06048adb Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 9 Jul 2023 17:40:09 +0200 Subject: [PATCH 04/68] Up --- test/k4FWCoreTest/options/runExampleProducer.py | 4 ++-- test/k4FWCoreTest/src/components/ExampleProducer.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleProducer.py b/test/k4FWCoreTest/options/runExampleProducer.py index 92cafa33..4b2b9767 100644 --- a/test/k4FWCoreTest/options/runExampleProducer.py +++ b/test/k4FWCoreTest/options/runExampleProducer.py @@ -1,5 +1,5 @@ from Gaudi.Configuration import * -from Configurables import ExampleProducer +from Configurables import FunctionalProducer from Configurables import EvtStoreSvc from Configurables import ApplicationMgr @@ -12,7 +12,7 @@ out.filename = "output_k4test_exampledata_twoproducer.root" out.outputCommands = ["keep *"] -producer = ExampleProducer("ExampleProducer", OutputLocation="/ExampleInt", ExampleInt=5) +producer = FunctionalProducer("FunctionalProducer", OutputLocation="/ExampleInt", ExampleInt=5) ApplicationMgr( TopAlg=[producer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/src/components/ExampleProducer.cpp b/test/k4FWCoreTest/src/components/ExampleProducer.cpp index da6d902b..93eef89b 100644 --- a/test/k4FWCoreTest/src/components/ExampleProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleProducer.cpp @@ -6,9 +6,9 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; -struct ExampleProducer final : Gaudi::Functional::Producer { +struct FunctionalProducer final : Gaudi::Functional::Producer { - ExampleProducer( const std::string& name, ISvcLocator* svcLoc ) + FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} int operator()() const override { @@ -21,4 +21,4 @@ struct ExampleProducer final : Gaudi::Functional::Producer { }; -DECLARE_COMPONENT(ExampleProducer) +DECLARE_COMPONENT(FunctionalProducer) From 28a35c171d9d0928185e07960a586cf176dc7987 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jul 2023 21:28:00 +0200 Subject: [PATCH 05/68] Update the example producer --- .../options/runExampleProducer.py | 18 ++++---- .../src/components/ExampleProducer.cpp | 46 +++++++++++++++++-- 2 files changed, 51 insertions(+), 13 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleProducer.py b/test/k4FWCoreTest/options/runExampleProducer.py index 4b2b9767..1463315e 100644 --- a/test/k4FWCoreTest/options/runExampleProducer.py +++ b/test/k4FWCoreTest/options/runExampleProducer.py @@ -5,18 +5,18 @@ from Configurables import k4DataSvc podioevent = k4DataSvc("EventDataSvc") -ApplicationMgr().ExtSvc += [podioevent] from Configurables import PodioOutput out = PodioOutput("out") -out.filename = "output_k4test_exampledata_twoproducer.root" +out.filename = "output_k4test_exampledata_producer.root" out.outputCommands = ["keep *"] -producer = FunctionalProducer("FunctionalProducer", OutputLocation="/ExampleInt", ExampleInt=5) +producer = FunctionalProducer("FunctionalProducer", + OutputLocation="ExampleInt", ExampleInt=5) -ApplicationMgr( TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) +ApplicationMgr(TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/src/components/ExampleProducer.cpp b/test/k4FWCoreTest/src/components/ExampleProducer.cpp index 93eef89b..8832a31f 100644 --- a/test/k4FWCoreTest/src/components/ExampleProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleProducer.cpp @@ -1,21 +1,59 @@ #include "Gaudi/Property.h" #include "GaudiAlg/GaudiAlgorithm.h" #include "GaudiAlg/Producer.h" +#include "edm4hep/MCParticleCollection.h" +#include "podio/UserDataCollection.h" +#include "k4FWCore/DataHandle.h" #include using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; -struct FunctionalProducer final : Gaudi::Functional::Producer { + +using colltype = DataWrapper>; + +struct FunctionalProducer final : Gaudi::Functional::Producer { + + mutable DataHandle m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Writer, this}; FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} - int operator()() const override { - info() << "Producing " << m_exampleInt << endmsg; - return m_exampleInt; + colltype operator()() const override { + // auto* res = m_vectorFloatHandle.createAndPut(); + // res{}; + + auto coll = new podio::UserDataCollection(); + coll->push_back(1.5); + colltype* dw = new DataWrapper>(); + dw->setData(coll); + return *dw; + // return m_exampleInt; } +// using colltype = podio::UserDataCollection; + +// struct FunctionalProducer final : Gaudi::Functional::Producer { + +// mutable DataHandle m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Writer, this}; + +// FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) +// : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} + +// colltype operator()() const override { +// // auto* res = m_vectorFloatHandle.createAndPut(); +// // res{}; + +// // auto coll = new podio::UserDataCollection(); +// // coll->push_back(1.0); +// auto coll = podio::UserDataCollection(); +// coll.push_back(2.5); +// // colltype* dw = new DataWrapper>(); +// // dw->setData(coll); +// return coll; +// // return m_exampleInt; +// } + Gaudi::Property m_exampleInt{this, "ExampleInt", 3, "Example int to be produced"}; From bdbcf7381cf5d9ffb56c2419089cbe16ce70da82 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 26 Jul 2023 21:30:39 +0200 Subject: [PATCH 06/68] Change to Functional Producer --- ...pleProducer.cpp => FunctionalProducer.cpp} | 29 +------------------ 1 file changed, 1 insertion(+), 28 deletions(-) rename test/k4FWCoreTest/src/components/{ExampleProducer.cpp => FunctionalProducer.cpp} (53%) diff --git a/test/k4FWCoreTest/src/components/ExampleProducer.cpp b/test/k4FWCoreTest/src/components/FunctionalProducer.cpp similarity index 53% rename from test/k4FWCoreTest/src/components/ExampleProducer.cpp rename to test/k4FWCoreTest/src/components/FunctionalProducer.cpp index 8832a31f..413539be 100644 --- a/test/k4FWCoreTest/src/components/ExampleProducer.cpp +++ b/test/k4FWCoreTest/src/components/FunctionalProducer.cpp @@ -9,7 +9,6 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; - using colltype = DataWrapper>; struct FunctionalProducer final : Gaudi::Functional::Producer { @@ -20,40 +19,14 @@ struct FunctionalProducer final : Gaudi::Functional::Producer(); coll->push_back(1.5); + coll->push_back(2.5); colltype* dw = new DataWrapper>(); dw->setData(coll); return *dw; - // return m_exampleInt; } -// using colltype = podio::UserDataCollection; - -// struct FunctionalProducer final : Gaudi::Functional::Producer { - -// mutable DataHandle m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Writer, this}; - -// FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) -// : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} - -// colltype operator()() const override { -// // auto* res = m_vectorFloatHandle.createAndPut(); -// // res{}; - -// // auto coll = new podio::UserDataCollection(); -// // coll->push_back(1.0); -// auto coll = podio::UserDataCollection(); -// coll.push_back(2.5); -// // colltype* dw = new DataWrapper>(); -// // dw->setData(coll); -// return coll; -// // return m_exampleInt; -// } - Gaudi::Property m_exampleInt{this, "ExampleInt", 3, "Example int to be produced"}; From ae4f679bad271c179347f600ad76c884d82cb1a6 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 09:42:42 +0200 Subject: [PATCH 07/68] Add a consumer, producer and transformer --- .../options/runFunctionalConsumer.py | 26 ++++++++++++++ .../options/runFunctionalProducer.py | 22 ++++++++++++ .../options/runFunctionalTransformer.py | 31 ++++++++++++++++ .../src/components/FunctionalConsumer.cpp | 30 ++++++++++++++++ .../src/components/FunctionalTransformer.cpp | 35 +++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 test/k4FWCoreTest/options/runFunctionalConsumer.py create mode 100644 test/k4FWCoreTest/options/runFunctionalProducer.py create mode 100644 test/k4FWCoreTest/options/runFunctionalTransformer.py create mode 100644 test/k4FWCoreTest/src/components/FunctionalConsumer.cpp create mode 100644 test/k4FWCoreTest/src/components/FunctionalTransformer.cpp diff --git a/test/k4FWCoreTest/options/runFunctionalConsumer.py b/test/k4FWCoreTest/options/runFunctionalConsumer.py new file mode 100644 index 00000000..2a2d204f --- /dev/null +++ b/test/k4FWCoreTest/options/runFunctionalConsumer.py @@ -0,0 +1,26 @@ +from Gaudi.Configuration import * +from Configurables import FunctionalConsumer +from Configurables import EvtStoreSvc +from Configurables import ApplicationMgr + +from Configurables import k4DataSvc +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer.root" + +from Configurables import PodioInput + +inp = PodioInput() +inp.collections = [ + "ExampleInt", +] + +consumer = FunctionalConsumer("FunctionalConsumer", + InputLocation="/Event/ExampleInt", + ) + +ApplicationMgr(TopAlg=[inp, consumer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/options/runFunctionalProducer.py b/test/k4FWCoreTest/options/runFunctionalProducer.py new file mode 100644 index 00000000..1463315e --- /dev/null +++ b/test/k4FWCoreTest/options/runFunctionalProducer.py @@ -0,0 +1,22 @@ +from Gaudi.Configuration import * +from Configurables import FunctionalProducer +from Configurables import EvtStoreSvc +from Configurables import ApplicationMgr + +from Configurables import k4DataSvc +podioevent = k4DataSvc("EventDataSvc") + +from Configurables import PodioOutput +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_producer.root" +out.outputCommands = ["keep *"] + +producer = FunctionalProducer("FunctionalProducer", + OutputLocation="ExampleInt", ExampleInt=5) + +ApplicationMgr(TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/options/runFunctionalTransformer.py b/test/k4FWCoreTest/options/runFunctionalTransformer.py new file mode 100644 index 00000000..b1ba4e5d --- /dev/null +++ b/test/k4FWCoreTest/options/runFunctionalTransformer.py @@ -0,0 +1,31 @@ +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import FunctionalTransformer +from Configurables import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import PodioOutput +from Configurables import PodioInput + +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer.root" + +inp = PodioInput() +inp.collections = [ + "ExampleInt", +] + +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_transformer.root" +# Use this to keep all the existing collections in the input file +out.outputCommands = ["drop ExampleInt"] + +transformer = FunctionalTransformer("FunctionalTransformer", + InputLocation="ExampleInt", + OutputLocation="ExampleDoubles") + +ApplicationMgr(TopAlg=[inp, transformer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp new file mode 100644 index 00000000..29efd460 --- /dev/null +++ b/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp @@ -0,0 +1,30 @@ +#include "Gaudi/Property.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiAlg/Consumer.h" +#include "edm4hep/MCParticleCollection.h" +#include "podio/UserDataCollection.h" +#include "k4FWCore/DataHandle.h" + +#include + +using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; + +using colltype = DataWrapper; + +struct FunctionalConsumer final : Gaudi::Functional::Consumer { + + FunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) + : Consumer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt")) {} + + void operator()(const colltype& input) const override { + std::cout << "FunctionalConsumer: " << input << std::endl; + const auto* coll = input.getData(); + const auto* ptr = reinterpret_cast*>(coll); + for (const auto& val : *ptr) { + std::cout << val << std::endl; + } + } + +}; + +DECLARE_COMPONENT(FunctionalConsumer) diff --git a/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp new file mode 100644 index 00000000..211178a3 --- /dev/null +++ b/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp @@ -0,0 +1,35 @@ +#include "Gaudi/Property.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiAlg/Transformer.h" +#include "edm4hep/MCParticleCollection.h" +#include "podio/UserDataCollection.h" +#include "k4FWCore/DataHandle.h" + +#include + +using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; + +using colltype_in = DataWrapper; +using colltype_out = DataWrapper>; + +struct FunctionalTransformer final : Gaudi::Functional::Transformer { + + FunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) + : Transformer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt"), + KeyValue( "OutputLocation", "/ExampleDouble" ) ) {} + + colltype_out operator()(const colltype_in& input) const override { + const auto* coll = input.getData(); + const auto* ptr = reinterpret_cast*>(coll); + auto coll_out = new podio::UserDataCollection(); + for (auto& val : *ptr) { + coll_out->push_back(val); + } + colltype_out* dw = new DataWrapper>(); + dw->setData(coll_out); + return *dw; + } + +}; + +DECLARE_COMPONENT(FunctionalTransformer) From 3d8808144ec751125de71f5af1adce405dafc4d8 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 10:29:22 +0200 Subject: [PATCH 08/68] Remove deleted file --- .../options/runExampleProducer.py | 22 ------------------- .../src/components/FunctionalProducer.cpp | 2 -- 2 files changed, 24 deletions(-) delete mode 100644 test/k4FWCoreTest/options/runExampleProducer.py diff --git a/test/k4FWCoreTest/options/runExampleProducer.py b/test/k4FWCoreTest/options/runExampleProducer.py deleted file mode 100644 index 1463315e..00000000 --- a/test/k4FWCoreTest/options/runExampleProducer.py +++ /dev/null @@ -1,22 +0,0 @@ -from Gaudi.Configuration import * -from Configurables import FunctionalProducer -from Configurables import EvtStoreSvc -from Configurables import ApplicationMgr - -from Configurables import k4DataSvc -podioevent = k4DataSvc("EventDataSvc") - -from Configurables import PodioOutput -out = PodioOutput("out") -out.filename = "output_k4test_exampledata_producer.root" -out.outputCommands = ["keep *"] - -producer = FunctionalProducer("FunctionalProducer", - OutputLocation="ExampleInt", ExampleInt=5) - -ApplicationMgr(TopAlg=[producer, out], - EvtSel="NONE", - EvtMax=10, - ExtSvc=[k4DataSvc("EventDataSvc")], - OutputLevel=INFO, - ) diff --git a/test/k4FWCoreTest/src/components/FunctionalProducer.cpp b/test/k4FWCoreTest/src/components/FunctionalProducer.cpp index 413539be..79c26fe6 100644 --- a/test/k4FWCoreTest/src/components/FunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/FunctionalProducer.cpp @@ -13,8 +13,6 @@ using colltype = DataWrapper>; struct FunctionalProducer final : Gaudi::Functional::Producer { - mutable DataHandle m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Writer, this}; - FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} From 26e08e8ac5e61f1521a371d2f5f8e748e8b76063 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 11:04:32 +0200 Subject: [PATCH 09/68] Add some information in the README about Gaudi::Functional --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b8a1cf64..a01b9719 100644 --- a/README.md +++ b/README.md @@ -61,12 +61,26 @@ print(my_opts[0].foo) k4FWCore is a CMake project. After setting up the dependencies (use for example `source /cvmfs/sw.hsf.org/key4hep/setup.sh`) - -``` -mkdir build install -cd build; +``` bash +mkdir build +cd build cmake .. make install ``` - +## Implementing algorithms +k4FWCore uses (or will use) `Gaudi::Functional` for executing algorithms. In +`Gaudi::Functional` we have three different base classes that we will use +depending on how may input and output types they take: +- The `Consumer` takes inputs but no outputs; can be used for reading +- The `Producer` takes outputs but no inputs; can be used for generating + collections or events +- The `Transformer` is the more general one (both the `Consumer` and the + `Producer` are a particular case of this one) and takes both inputs and + outputs + +In all cases the implementation process is the same, we'll create a new class +that will implement `operator()`, that is where our algorithm will be. Simple +examples can be found in the test folder for each one of these three. + +`GaudiAlg` is deprecated and will be removed in future versions of Gaudi. From b2b50da9c380191e76464f9ed85085dfdf0533c6 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 4 Sep 2023 21:03:27 +0200 Subject: [PATCH 10/68] Add the functional code and tests --- test/k4FWCoreTest/CMakeLists.txt | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 4d2e9e2d..59356d3b 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -32,7 +32,9 @@ set(k4fwcoretest_plugin_sources src/components/k4FWCoreTest_cellID_reader.cpp src/components/k4FWCoreTest_cellID_writer.cpp src/components/k4FWCoreTest_CheckExampleEventData.cpp - src/components/ExampleProducer.cpp + src/components/FunctionalProducer.cpp + src/components/FunctionalConsumer.cpp + src/components/FunctionalTransformer.cpp ) gaudi_add_module(k4FWCoreTestPlugins @@ -199,7 +201,19 @@ add_test(NAME TestExec WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} --dry-run options/TestExec.py) set_test_env(TestExec) -add_test(NAME ExampleProducer +add_test(NAME FunctionalProducer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runExampleProducer.py) -set_test_env(ExampleProducer) + COMMAND ${K4RUN} options/runFunctionalProducer.py) +set_test_env(FunctionalProducer) + +add_test(NAME FunctionalConsumer + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runFunctionalProducer.py) +set_test_env(FunctionalConsumer) +set_tests_properties(FunctionalConsumer PROPERTIES DEPENDS FunctionalProducer) + +add_test(NAME FunctionalTransformer + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runFunctionalTransformer.py) +set_test_env(FunctionalTransformer) +set_tests_properties(FunctionalTransformer PROPERTIES DEPENDS FunctionalProducer) From 40a9af33b92d43b3a09bd4860fd379327ba6ffe3 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 11:22:19 +0200 Subject: [PATCH 11/68] Add comments and cleanup to the functional algorithms --- .../src/components/FunctionalConsumer.cpp | 23 +++++++++----- .../src/components/FunctionalProducer.cpp | 30 ++++++++++--------- .../src/components/FunctionalTransformer.cpp | 29 +++++++++++------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp index 29efd460..74aad8f2 100644 --- a/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp @@ -1,23 +1,32 @@ #include "Gaudi/Property.h" -#include "GaudiAlg/GaudiAlgorithm.h" +#include "Gaudi/Algorithm.h" #include "GaudiAlg/Consumer.h" -#include "edm4hep/MCParticleCollection.h" +#include "k4FWCore/DataWrapper.h" + +#include "podio/CollectionBase.h" #include "podio/UserDataCollection.h" -#include "k4FWCore/DataHandle.h" +#include "edm4hep/MCParticleCollection.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; -struct FunctionalConsumer final : Gaudi::Functional::Consumer { +struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { - FunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) + ExampleFunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) : Consumer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt")) {} + // This is the function that will be called to transform the data + // Note that the function has to be const, as well as all pointers to collections + // we get from the input void operator()(const colltype& input) const override { - std::cout << "FunctionalConsumer: " << input << std::endl; + std::cout << "ExampleFunctionalConsumer: " << input << std::endl; const auto* coll = input.getData(); const auto* ptr = reinterpret_cast*>(coll); for (const auto& val : *ptr) { @@ -27,4 +36,4 @@ struct FunctionalConsumer final : Gaudi::Functional::Consumer +// This will always be Gaudi::Algorithm using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; -using colltype = DataWrapper>; +// Which type of collection we are producing +// Has to be wrapped in DataWrapper +using colltype = DataWrapper; -struct FunctionalProducer final : Gaudi::Functional::Producer { +struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { - FunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) + ExampleFunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} + // This is the function that will be called to produce the data colltype operator()() const override { - auto coll = new podio::UserDataCollection(); - coll->push_back(1.5); - coll->push_back(2.5); - colltype* dw = new DataWrapper>(); - dw->setData(coll); - return *dw; + auto coll = std::make_unique(); + coll->push_back({1, 2, 3, 4, 5, 6, {}, {}, {}, {}, {}, {}}); + coll->push_back({2, 3, 4, 5, 6, 7, {}, {}, {}, {}, {}, {}}); + colltype dw = DataWrapper(std::move(coll)); + return dw; } Gaudi::Property m_exampleInt{this, "ExampleInt", 3, "Example int to be produced"}; - }; -DECLARE_COMPONENT(FunctionalProducer) +DECLARE_COMPONENT(ExampleFunctionalProducer) diff --git a/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp index 211178a3..6513b92c 100644 --- a/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp @@ -1,35 +1,44 @@ #include "Gaudi/Property.h" -#include "GaudiAlg/GaudiAlgorithm.h" +#include "Gaudi/Algorithm.h" #include "GaudiAlg/Transformer.h" -#include "edm4hep/MCParticleCollection.h" +#include "k4FWCore/DataWrapper.h" + +#include "podio/CollectionBase.h" #include "podio/UserDataCollection.h" -#include "k4FWCore/DataHandle.h" +#include "edm4hep/MCParticleCollection.h" #include +// This will always be Gaudi::Algorithm using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; +// 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>; -struct FunctionalTransformer final : Gaudi::Functional::Transformer { +struct ExampleFunctionalTransformer final : + Gaudi::Functional::Transformer { - FunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) + ExampleFunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) : Transformer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt"), KeyValue( "OutputLocation", "/ExampleDouble" ) ) {} + // This is the function that will be called to transform the data + // 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 { const auto* coll = input.getData(); const auto* ptr = reinterpret_cast*>(coll); - auto coll_out = new podio::UserDataCollection(); + auto coll_out = std::make_unique>(); for (auto& val : *ptr) { coll_out->push_back(val); } - colltype_out* dw = new DataWrapper>(); - dw->setData(coll_out); - return *dw; + colltype_out dw = DataWrapper>(std::move(coll_out)); + return dw; } }; -DECLARE_COMPONENT(FunctionalTransformer) +DECLARE_COMPONENT(ExampleFunctionalTransformer) From a03296a3c26d2da3e9d5ae0329ba1e5a25c7447c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 11:24:04 +0200 Subject: [PATCH 12/68] Rename some some files --- .../{FunctionalConsumer.cpp => ExampleFunctionalConsumer.cpp} | 0 .../{FunctionalProducer.cpp => ExampleFunctionalProducer.cpp} | 0 ...FunctionalTransformer.cpp => ExampleFunctionalTransformer.cpp} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename test/k4FWCoreTest/src/components/{FunctionalConsumer.cpp => ExampleFunctionalConsumer.cpp} (100%) rename test/k4FWCoreTest/src/components/{FunctionalProducer.cpp => ExampleFunctionalProducer.cpp} (100%) rename test/k4FWCoreTest/src/components/{FunctionalTransformer.cpp => ExampleFunctionalTransformer.cpp} (100%) diff --git a/test/k4FWCoreTest/src/components/FunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp similarity index 100% rename from test/k4FWCoreTest/src/components/FunctionalConsumer.cpp rename to test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp diff --git a/test/k4FWCoreTest/src/components/FunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp similarity index 100% rename from test/k4FWCoreTest/src/components/FunctionalProducer.cpp rename to test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp diff --git a/test/k4FWCoreTest/src/components/FunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp similarity index 100% rename from test/k4FWCoreTest/src/components/FunctionalTransformer.cpp rename to test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp From 66b454eb398033594b5e968e7c84b75a00e6f0a6 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 13:16:52 +0200 Subject: [PATCH 13/68] Rename to ExampleFunctional --- .../{runFunctionalConsumer.py => runExampleFunctionalConsumer.py} | 0 .../{runFunctionalProducer.py => runExampleFunctionalProducer.py} | 0 ...unctionalTransformer.py => runExampleFunctionalTransformer.py} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename test/k4FWCoreTest/options/{runFunctionalConsumer.py => runExampleFunctionalConsumer.py} (100%) rename test/k4FWCoreTest/options/{runFunctionalProducer.py => runExampleFunctionalProducer.py} (100%) rename test/k4FWCoreTest/options/{runFunctionalTransformer.py => runExampleFunctionalTransformer.py} (100%) diff --git a/test/k4FWCoreTest/options/runFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py similarity index 100% rename from test/k4FWCoreTest/options/runFunctionalConsumer.py rename to test/k4FWCoreTest/options/runExampleFunctionalConsumer.py diff --git a/test/k4FWCoreTest/options/runFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py similarity index 100% rename from test/k4FWCoreTest/options/runFunctionalProducer.py rename to test/k4FWCoreTest/options/runExampleFunctionalProducer.py diff --git a/test/k4FWCoreTest/options/runFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py similarity index 100% rename from test/k4FWCoreTest/options/runFunctionalTransformer.py rename to test/k4FWCoreTest/options/runExampleFunctionalTransformer.py From a3d616db6fede6218eab6ad89fff9bfbed1d1277 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 13:22:51 +0200 Subject: [PATCH 14/68] Update the option files and a producer with multiple outputs --- .../options/runExampleFunctionalConsumer.py | 15 +-- .../options/runExampleFunctionalProducer.py | 12 ++- .../runExampleFunctionalProducerMultiple.py | 22 +++++ .../runExampleFunctionalTransformer.py | 8 +- .../components/ExampleFunctionalConsumer.cpp | 14 ++- .../ExampleFunctionalProducerMultiple.cpp | 96 +++++++++++++++++++ 6 files changed, 147 insertions(+), 20 deletions(-) create mode 100644 test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index 2a2d204f..f01d8eb6 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -1,9 +1,10 @@ -from Gaudi.Configuration import * -from Configurables import FunctionalConsumer -from Configurables import EvtStoreSvc +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import ExampleFunctionalConsumer from Configurables import ApplicationMgr - from Configurables import k4DataSvc +from Configurables import PodioInput + podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata_producer.root" @@ -14,9 +15,9 @@ "ExampleInt", ] -consumer = FunctionalConsumer("FunctionalConsumer", - InputLocation="/Event/ExampleInt", - ) +consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", + InputLocation="/Event/ExampleInt", + ) ApplicationMgr(TopAlg=[inp, consumer], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index 1463315e..41589f9b 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -1,7 +1,8 @@ -from Gaudi.Configuration import * -from Configurables import FunctionalProducer -from Configurables import EvtStoreSvc +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import ExampleFunctionalProducer from Configurables import ApplicationMgr +from Configurables import k4DataSvc from Configurables import k4DataSvc podioevent = k4DataSvc("EventDataSvc") @@ -11,8 +12,9 @@ out.filename = "output_k4test_exampledata_producer.root" out.outputCommands = ["keep *"] -producer = FunctionalProducer("FunctionalProducer", - OutputLocation="ExampleInt", ExampleInt=5) +producer = ExampleFunctionalProducer("ExampleFunctionalProducer", + OutputLocation="ExampleInt", + ExampleInt=5) ApplicationMgr(TopAlg=[producer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py new file mode 100644 index 00000000..43ac5d42 --- /dev/null +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -0,0 +1,22 @@ +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import ExampleFunctionalProducerMultiple +from Configurables import ApplicationMgr +from Configurables import k4DataSvc + +from Configurables import k4DataSvc +podioevent = k4DataSvc("EventDataSvc") + +from Configurables import PodioOutput +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_producer_multiple.root" +out.outputCommands = ["keep *"] + +producer = ExampleFunctionalProducerMultiple("ExampleFunctionalProducerMultiple") + +ApplicationMgr(TopAlg=[producer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index b1ba4e5d..8f5ac01e 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -1,6 +1,6 @@ from Gaudi.Configuration import INFO from Gaudi import Configurables -from Configurables import FunctionalTransformer +from Configurables import ExampleFunctionalTransformer from Configurables import ApplicationMgr from Configurables import k4DataSvc from Configurables import PodioOutput @@ -19,9 +19,9 @@ # Use this to keep all the existing collections in the input file out.outputCommands = ["drop ExampleInt"] -transformer = FunctionalTransformer("FunctionalTransformer", - InputLocation="ExampleInt", - OutputLocation="ExampleDoubles") +transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", + InputLocation="ExampleInt", + OutputLocation="ExampleDoubles") ApplicationMgr(TopAlg=[inp, transformer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 74aad8f2..02dcde77 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -4,7 +4,6 @@ #include "k4FWCore/DataWrapper.h" #include "podio/CollectionBase.h" -#include "podio/UserDataCollection.h" #include "edm4hep/MCParticleCollection.h" #include @@ -28,9 +27,16 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer*>(coll); - for (const auto& val : *ptr) { - std::cout << val << std::endl; + const auto* ptr = reinterpret_cast(coll); + int i = 0; + for (const auto& p : *ptr) { + assert(p.getPDG() == 1 + i); + assert(p.getGeneratorStatus() == 2 + i); + assert(p.getSimulatorStatus() == 3 + i); + assert(p.getCharge() == 4 + i); + assert(p.getTime() == 5 + i); + assert(p.getMass() == 6 + i); + i++; } } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp new file mode 100644 index 00000000..da7ea9e5 --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -0,0 +1,96 @@ +#include "Gaudi/Property.h" +#include "Gaudi/Algorithm.h" +#include "GaudiAlg/Producer.h" +#include "k4FWCore/DataWrapper.h" + +#include "podio/UserDataCollection.h" +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/TrackerHitCollection.h" + +#include + +// This will always be Gaudi::Algorithm +using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; + +// Which type of collections we are producing +// They have to be wrapped in DataWrapper +using Float_t = DataWrapper>; +using Particle_t = DataWrapper; +using SimTrackerHit_t = DataWrapper; +using TrackerHit_t = DataWrapper; +using Track_t = DataWrapper; + +struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(), BaseClass_t> { + + ExampleFunctionalProducerMultiple( const std::string& name, ISvcLocator* svcLoc ) + : Producer( name, svcLoc, + { + KeyValue( "OutputLocationFloat", "VectorFloat" ), + KeyValue( "OutputLocationParticles", "MCParticles" ), + KeyValue( "OutputLocation1", "SimTrackerHits" ), + KeyValue( "OutputLocation1", "TrackerHits" ), + KeyValue( "OutputLocation1", "Tracks" ) + } + ) {} + + // This is the function that will be called to produce the data + std::tuple operator()() const override { + // The following was copied and adapted from the + // k4FWCoreTest_CreateExampleEventData test + + auto floatVector = std::make_unique>(); + floatVector->push_back(125.); + floatVector->push_back(25.); + floatVector->push_back(m_event); + Float_t floatVector_dw = DataWrapper>(std::move(floatVector)); + + auto particles = std::make_unique(); + auto particle = particles->create(); + auto& p4 = particle.momentum(); + p4.x = m_magicNumberOffset + m_event + 5; + p4.y = m_magicNumberOffset + 6; + p4.z = m_magicNumberOffset + 7; + particle.setMass(m_magicNumberOffset + m_event + 8); + Particle_t particle_dw = DataWrapper(std::move(particles)); + + auto simTrackerHits = std::make_unique(); + auto hit = simTrackerHits->create(); + hit.setPosition({3, 4, 5}); + SimTrackerHit_t simTrackerHit_dw = DataWrapper(std::move(simTrackerHits)); + + auto trackerHits = std::make_unique(); + auto trackerHit = trackerHits->create(); + trackerHit.setPosition({3, 4, 5}); + TrackerHit_t trackerHit_dw = DataWrapper(std::move(trackerHits)); + + auto tracks = std::make_unique(); + auto track = tracks->create(); + auto track2 = tracks->create(); + // set members + track.setType(1); + track.setChi2(2.1); + track.setNdf(3); + track.setDEdx(4.1); + track.setDEdxError(5.1); + track.setRadiusOfInnermostHit(6.1); + track.addToSubdetectorHitNumbers(1); + track.addToSubdetectorHitNumbers(4); + track.addToTrackStates(edm4hep::TrackState()); + // set associatons + track.addToTrackerHits(trackerHit); + track.addToTracks(track2); + Track_t track_dw = DataWrapper(std::move(tracks)); + + return std::make_tuple(floatVector_dw, particle_dw, simTrackerHit_dw, trackerHit_dw, track_dw); + } + +private: + // integer to add to the dummy values written to the edm + Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, + "Integer to add to the dummy values written to the edm"}; + int m_event{0}; +}; + +DECLARE_COMPONENT(ExampleFunctionalProducerMultiple) From a9b050fd5451df2f9799f845e54e28d2dd4d8b08 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 4 Sep 2023 21:03:45 +0200 Subject: [PATCH 15/68] Rename also in CMakeLists.txt --- test/k4FWCoreTest/CMakeLists.txt | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 59356d3b..5e89b05c 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -32,9 +32,10 @@ set(k4fwcoretest_plugin_sources src/components/k4FWCoreTest_cellID_reader.cpp src/components/k4FWCoreTest_cellID_writer.cpp src/components/k4FWCoreTest_CheckExampleEventData.cpp - src/components/FunctionalProducer.cpp - src/components/FunctionalConsumer.cpp - src/components/FunctionalTransformer.cpp + src/components/ExampleFunctionalProducer.cpp + src/components/ExampleFunctionalConsumer.cpp + src/components/ExampleFunctionalTransformer.cpp + src/components/ExampleFunctionalProducerMultiple.cpp ) gaudi_add_module(k4FWCoreTestPlugins @@ -201,19 +202,24 @@ add_test(NAME TestExec WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} --dry-run options/TestExec.py) set_test_env(TestExec) -add_test(NAME FunctionalProducer +add_test(NAME ExampleFunctionalProducer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runFunctionalProducer.py) -set_test_env(FunctionalProducer) + COMMAND ${K4RUN} options/runExampleFunctionalProducer.py) +set_test_env(ExampleFunctionalProducer) -add_test(NAME FunctionalConsumer +add_test(NAME ExampleFunctionalConsumer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runFunctionalProducer.py) -set_test_env(FunctionalConsumer) -set_tests_properties(FunctionalConsumer PROPERTIES DEPENDS FunctionalProducer) + COMMAND ${K4RUN} options/runExampleFunctionalProducer.py) +set_test_env(ExampleFunctionalConsumer) +set_tests_properties(ExampleFunctionalConsumer PROPERTIES DEPENDS ExampleFunctionalProducer) -add_test(NAME FunctionalTransformer +add_test(NAME ExampleFunctionalTransformer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runFunctionalTransformer.py) -set_test_env(FunctionalTransformer) -set_tests_properties(FunctionalTransformer PROPERTIES DEPENDS FunctionalProducer) + COMMAND ${K4RUN} options/runExampleFunctionalTransformer.py) +set_test_env(ExampleFunctionalTransformer) +set_tests_properties(ExampleFunctionalTransformer PROPERTIES DEPENDS ExampleFunctionalProducer) + +add_test(NAME ExampleFunctionalProducerMultiple + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runExampleFunctionalProducerMultiple.py) +set_test_env(ExampleFunctionalProducerMultiple) From 2db8c79fc8cd41c900939bae7927d9c7b531f0da Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 13:24:11 +0200 Subject: [PATCH 16/68] Add missing include --- k4FWCore/src/PodioDataSvc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/k4FWCore/src/PodioDataSvc.cpp b/k4FWCore/src/PodioDataSvc.cpp index 16e0950e..0fdee29c 100644 --- a/k4FWCore/src/PodioDataSvc.cpp +++ b/k4FWCore/src/PodioDataSvc.cpp @@ -17,12 +17,13 @@ * limitations under the License. */ #include "k4FWCore/PodioDataSvc.h" +#include "k4FWCore/DataWrapper.h" #include "GaudiKernel/IConversionSvc.h" #include "GaudiKernel/IEventProcessor.h" #include "GaudiKernel/IProperty.h" #include "GaudiKernel/ISvcLocator.h" -#include "k4FWCore/DataWrapper.h" +#include "podio/CollectionBase.h" #include "TTree.h" From a8ef4805074f5534fede13a12c4dc803edef344f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 13:27:51 +0200 Subject: [PATCH 17/68] Add more information in the README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a01b9719..a2400414 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,9 @@ depending on how may input and output types they take: In all cases the implementation process is the same, we'll create a new class that will implement `operator()`, that is where our algorithm will be. Simple -examples can be found in the test folder for each one of these three. +examples can be found in the test folder for each one of these three. In +addition, there are tests that have either multiple inputs and / or multiple +outputs (like `ExampleFunctionalProducerMultiple`) that can be used as a +template for the more typical case when working with multiple inputs or outputs. `GaudiAlg` is deprecated and will be removed in future versions of Gaudi. From 673044a1dbe83842145f2ea5aa34f0f5248413ff Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 13:54:17 +0200 Subject: [PATCH 18/68] Fix ExampleFunctionalTransformer --- .../ExampleFunctionalTransformer.cpp | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 6513b92c..67309ff6 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -4,8 +4,8 @@ #include "k4FWCore/DataWrapper.h" #include "podio/CollectionBase.h" -#include "podio/UserDataCollection.h" #include "edm4hep/MCParticleCollection.h" +#include "edm4hep/MutableMCParticle.h" #include @@ -16,7 +16,7 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // 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_out = DataWrapper; struct ExampleFunctionalTransformer final : Gaudi::Functional::Transformer { @@ -30,12 +30,20 @@ struct ExampleFunctionalTransformer final : // we get from the input colltype_out operator()(const colltype_in& input) const override { const auto* coll = input.getData(); - const auto* ptr = reinterpret_cast*>(coll); - auto coll_out = std::make_unique>(); - for (auto& val : *ptr) { - coll_out->push_back(val); + const auto* ptr = reinterpret_cast(coll); + auto coll_out = std::make_unique(); + for (const auto& p : *ptr) { + auto new_particle = edm4hep::MutableMCParticle(); + new_particle.setPDG(p.getPDG() + 10); + new_particle.setGeneratorStatus(p.getGeneratorStatus() + 10); + new_particle.setSimulatorStatus(p.getSimulatorStatus() + 10); + new_particle.setCharge(p.getCharge() + 10); + new_particle.setTime(p.getTime() + 10); + new_particle.setMass(p.getMass() + 10); + // new_particle. + coll_out->push_back(new_particle); } - colltype_out dw = DataWrapper>(std::move(coll_out)); + colltype_out dw = DataWrapper(std::move(coll_out)); return dw; } From 30578ab456da61efd226bacaa4b3ee403a6a3874 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 14:08:03 +0200 Subject: [PATCH 19/68] Add a constructor for unique_ptrs and change getData to const --- k4FWCore/include/k4FWCore/DataWrapper.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index b172c058..154a4da7 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -43,9 +43,12 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { public: DataWrapper() : m_data(nullptr){}; + DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()){ + uptr.release(); + }; virtual ~DataWrapper(); - const T* getData() { return m_data; } + const T* getData() const { return m_data; } void setData(const T* data) { m_data = data; } virtual void resetData() { m_data = nullptr; } From 6f8910e1cdc9e124a4f644440e2e4579cc0f6382 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 14:30:32 +0200 Subject: [PATCH 20/68] Move PodioInput to use Gaudi::Functional --- k4FWCore/components/PodioInput.cpp | 34 ++++++------------------------ k4FWCore/components/PodioInput.h | 26 ++++++++++------------- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index b58bc0ec..d307a0e7 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -17,49 +17,29 @@ * limitations under the License. */ #include "PodioInput.h" +#include "GaudiAlg/Consumer.h" -#include "TFile.h" -#include "TROOT.h" - -#include "k4FWCore/DataWrapper.h" #include "k4FWCore/PodioDataSvc.h" DECLARE_COMPONENT(PodioInput) -PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : GaudiAlgorithm(name, svcLoc) {} - -StatusCode PodioInput::initialize() { - if (GaudiAlgorithm::initialize().isFailure()) - return StatusCode::FAILURE; - +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 (nullptr == m_podioDataSvc) - return StatusCode::FAILURE; - - // TODO: add an upfront check for existence of data products - - return StatusCode::SUCCESS; + if (!m_podioDataSvc) { + error() << "Could not get PodioDataSvc" << endmsg; + } } -StatusCode PodioInput::execute() { - size_t cntr = 0; - // Re-create the collections from ROOT file +void PodioInput::operator()() const { for (auto& collName : m_collectionNames) { debug() << "Registering collection to read " << collName << endmsg; if (m_podioDataSvc->readCollection(collName).isFailure()) { - return StatusCode::FAILURE; + error() << "Failed to register collection " << collName << endmsg; } } // Tell data service that we are done with requested collections m_podioDataSvc->endOfRead(); - return StatusCode::SUCCESS; -} - -StatusCode PodioInput::finalize() { - if (GaudiAlgorithm::finalize().isFailure()) - return StatusCode::FAILURE; - return StatusCode::SUCCESS; } diff --git a/k4FWCore/components/PodioInput.h b/k4FWCore/components/PodioInput.h index 4f61caa8..84ab6f20 100644 --- a/k4FWCore/components/PodioInput.h +++ b/k4FWCore/components/PodioInput.h @@ -18,15 +18,14 @@ */ #ifndef FWCORE_PODIOINPUT_H #define FWCORE_PODIOINPUT_H -// Gaaudi -#include "GaudiAlg/GaudiAlgorithm.h" +// Gaudi +#include "GaudiAlg/Consumer.h" +#include "Gaudi/Property.h" // STL #include #include -// forward declarations -// from k4FWCore: class PodioDataSvc; /** @class PodioInput @@ -36,21 +35,18 @@ class PodioDataSvc; * @author J. Lingemann */ -class PodioInput : public GaudiAlgorithm { +using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; + +class PodioInput final : public Gaudi::Functional::Consumer { public: - /// Constructor. - PodioInput(const std::string& name, ISvcLocator* svcLoc); - /// Initialization of PodioInput. Acquires the data service, opens root file and creates trees. - virtual StatusCode initialize(); - /// Execute. Re-creates collections that are specified to be read and sets references. - virtual StatusCode execute(); - /// Finalize. Closes ROOT file. - virtual StatusCode finalize(); + + PodioInput( const std::string& name, ISvcLocator* svcLoc ); + void operator()() const override; private: - /// Name of collections to read. Set by option collections (this is temporary) + // 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. + // Data service: needed to register objects and get collection IDs. Just an observing pointer. PodioDataSvc* m_podioDataSvc; }; From 5d7fa0c2dde1e2e9bcf8231d7575dbb12bad63b9 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 14:48:54 +0200 Subject: [PATCH 21/68] Allow not being the owner in DataWrapper.h --- k4FWCore/include/k4FWCore/DataWrapper.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index 154a4da7..daecf266 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -45,6 +45,7 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { DataWrapper() : m_data(nullptr){}; DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()){ uptr.release(); + is_owner = false; }; virtual ~DataWrapper(); @@ -58,10 +59,11 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { private: const T* m_data; + bool is_owner{true}; }; template DataWrapper::~DataWrapper() { - if (m_data != nullptr) + if (is_owner && !m_data) delete m_data; } From 4ce096c59e866f488f70f99a8d665c5b3244b029 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 14:49:34 +0200 Subject: [PATCH 22/68] Fix some collection names --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc new file mode 100644 index 00000000..e69de29b From 31e58552910ca4aeed577b917a7f90791ffc2969 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 15:30:11 +0200 Subject: [PATCH 23/68] Rename the collections --- test/k4FWCoreTest/options/runExampleFunctionalConsumer.py | 4 ++-- test/k4FWCoreTest/options/runExampleFunctionalProducer.py | 2 +- .../options/runExampleFunctionalTransformer.py | 8 ++++---- .../src/components/ExampleFunctionalConsumer.cc | 0 .../src/components/ExampleFunctionalConsumer.cpp | 2 +- .../src/components/ExampleFunctionalProducer.cpp | 2 +- .../src/components/ExampleFunctionalTransformer.cpp | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index f01d8eb6..409e11f1 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -12,11 +12,11 @@ inp = PodioInput() inp.collections = [ - "ExampleInt", + "MCParticles", ] consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", - InputLocation="/Event/ExampleInt", + InputLocation="MCParticles", ) ApplicationMgr(TopAlg=[inp, consumer], diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index 41589f9b..66f07859 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -13,7 +13,7 @@ out.outputCommands = ["keep *"] producer = ExampleFunctionalProducer("ExampleFunctionalProducer", - OutputLocation="ExampleInt", + OutputLocation="MCParticles", ExampleInt=5) ApplicationMgr(TopAlg=[producer, out], diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index 8f5ac01e..53d29223 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -11,17 +11,17 @@ inp = PodioInput() inp.collections = [ - "ExampleInt", + "MCParticles", ] out = PodioOutput("out") out.filename = "output_k4test_exampledata_transformer.root" # Use this to keep all the existing collections in the input file -out.outputCommands = ["drop ExampleInt"] +out.outputCommands = ["drop MCParticles"] transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", - InputLocation="ExampleInt", - OutputLocation="ExampleDoubles") + InputLocation="MCParticles", + OutputLocation="NewMCParticles") ApplicationMgr(TopAlg=[inp, transformer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cc deleted file mode 100644 index e69de29b..00000000 diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 02dcde77..a20dd803 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -19,7 +19,7 @@ using colltype = DataWrapper; struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { ExampleFunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) - : Consumer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt")) {} + : Consumer( name, svcLoc, KeyValue("InputLocation", "MCParticles")) {} // This is the function that will be called to transform the data // Note that the function has to be const, as well as all pointers to collections diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index 5ebcc678..8d05e9c9 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -17,7 +17,7 @@ using colltype = DataWrapper; struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { ExampleFunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) - : Producer( name, svcLoc, KeyValue( "OutputLocation", "/ExampleInt" ) ) {} + : Producer( name, svcLoc, KeyValue( "OutputLocation", "MCParticles" ) ) {} // This is the function that will be called to produce the data colltype operator()() const override { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 67309ff6..9450bab1 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -22,8 +22,8 @@ struct ExampleFunctionalTransformer final : Gaudi::Functional::Transformer { ExampleFunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) - : Transformer( name, svcLoc, KeyValue("InputLocation", "/ExampleInt"), - KeyValue( "OutputLocation", "/ExampleDouble" ) ) {} + : Transformer( name, svcLoc, KeyValue("InputLocation", "MCParticles"), + KeyValue( "OutputLocation", "NewMCParticles" ) ) {} // This is the function that will be called to transform the data // Note that the function has to be const, as well as all pointers to collections From 38cb3b1a3f5326e85ae9e4aca579a9c6053d30a0 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 16:09:00 +0200 Subject: [PATCH 24/68] Remove cout --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index a20dd803..7f2774fb 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -25,7 +25,6 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(coll); int i = 0; From ac42a85641f1dfef4aa9a998f471ed204457613a Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 16:11:18 +0200 Subject: [PATCH 25/68] Change to dynamic_cast --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 2 +- .../src/components/ExampleFunctionalTransformer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 7f2774fb..214620c3 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -26,7 +26,7 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(coll); + const auto* ptr = dynamic_cast(coll); int i = 0; for (const auto& p : *ptr) { assert(p.getPDG() == 1 + i); diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 9450bab1..b8555f32 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -30,7 +30,7 @@ struct ExampleFunctionalTransformer final : // we get from the input colltype_out operator()(const colltype_in& input) const override { const auto* coll = input.getData(); - const auto* ptr = reinterpret_cast(coll); + const auto* ptr = dynamic_cast(coll); auto coll_out = std::make_unique(); for (const auto& p : *ptr) { auto new_particle = edm4hep::MutableMCParticle(); From 06b611d1e52f4480181b522de066dd41834bbbd1 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 16:12:49 +0200 Subject: [PATCH 26/68] Improve slightly the interface for reading --- .../src/components/ExampleFunctionalConsumer.cpp | 5 ++--- .../src/components/ExampleFunctionalTransformer.cpp | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 214620c3..f1a2f3a6 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -22,11 +22,10 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(coll); + auto* ptr = dynamic_cast(input.getData()); int i = 0; for (const auto& p : *ptr) { assert(p.getPDG() == 1 + i); diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index b8555f32..a46b1274 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -29,8 +29,7 @@ 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 { - const auto* coll = input.getData(); - const auto* ptr = dynamic_cast(coll); + auto* ptr = dynamic_cast(input.getData()); auto coll_out = std::make_unique(); for (const auto& p : *ptr) { auto new_particle = edm4hep::MutableMCParticle(); From 1fc6d10ea698917e186252e6cc30543894d3210b Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 16:25:32 +0200 Subject: [PATCH 27/68] Rename a couple of variables --- .../src/components/ExampleFunctionalConsumer.cpp | 16 ++++++++-------- .../components/ExampleFunctionalTransformer.cpp | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index f1a2f3a6..b0a6b702 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -25,15 +25,15 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(input.getData()); + auto* coll = dynamic_cast(input.getData()); int i = 0; - for (const auto& p : *ptr) { - assert(p.getPDG() == 1 + i); - assert(p.getGeneratorStatus() == 2 + i); - assert(p.getSimulatorStatus() == 3 + i); - assert(p.getCharge() == 4 + i); - assert(p.getTime() == 5 + i); - assert(p.getMass() == 6 + i); + for (const auto& particle : *coll) { + assert(particle.getPDG() == 1 + i); + assert(particle.getGeneratorStatus() == 2 + i); + assert(particle.getSimulatorStatus() == 3 + i); + assert(particle.getCharge() == 4 + i); + assert(particle.getTime() == 5 + i); + assert(particle.getMass() == 6 + i); i++; } } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index a46b1274..0aa63a50 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -29,16 +29,16 @@ 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* ptr = dynamic_cast(input.getData()); + auto* coll = dynamic_cast(input.getData()); auto coll_out = std::make_unique(); - for (const auto& p : *ptr) { + for (const auto& particle : *coll) { auto new_particle = edm4hep::MutableMCParticle(); - new_particle.setPDG(p.getPDG() + 10); - new_particle.setGeneratorStatus(p.getGeneratorStatus() + 10); - new_particle.setSimulatorStatus(p.getSimulatorStatus() + 10); - new_particle.setCharge(p.getCharge() + 10); - new_particle.setTime(p.getTime() + 10); - new_particle.setMass(p.getMass() + 10); + new_particle.setPDG(particle.getPDG() + 10); + new_particle.setGeneratorStatus(particle.getGeneratorStatus() + 10); + new_particle.setSimulatorStatus(particle.getSimulatorStatus() + 10); + new_particle.setCharge(particle.getCharge() + 10); + new_particle.setTime(particle.getTime() + 10); + new_particle.setMass(particle.getMass() + 10); // new_particle. coll_out->push_back(new_particle); } From 45a2080e0102ce5a49e6481e2296d4738e069485 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 22:24:37 +0200 Subject: [PATCH 28/68] Add a Consumer with multiple inputs --- test/k4FWCoreTest/CMakeLists.txt | 7 ++ .../runExampleFunctionalConsumerMultiple.py | 30 ++++++++ .../ExampleFunctionalConsumerMultiple.cpp | 75 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 5e89b05c..31a86de8 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -36,6 +36,7 @@ set(k4fwcoretest_plugin_sources src/components/ExampleFunctionalConsumer.cpp src/components/ExampleFunctionalTransformer.cpp src/components/ExampleFunctionalProducerMultiple.cpp + src/components/ExampleFunctionalConsumerMultiple.cpp ) gaudi_add_module(k4FWCoreTestPlugins @@ -223,3 +224,9 @@ add_test(NAME ExampleFunctionalProducerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalProducerMultiple.py) set_test_env(ExampleFunctionalProducerMultiple) + +add_test(NAME ExampleFunctionalConsumerMultiple + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runExampleFunctionalProducerMultiple.py) +set_test_env(ExampleFunctionalConsumerMultiple) +set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py new file mode 100644 index 00000000..0052bdd8 --- /dev/null +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -0,0 +1,30 @@ +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import ExampleFunctionalConsumerMultiple +from Configurables import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import PodioInput + +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer_multiple.root" + +from Configurables import PodioInput + +inp = PodioInput() +inp.collections = [ + "VectorFloat", + "MCParticles", + "SimTrackerHits", + "TrackerHits", + "Tracks", +] + +consumer = ExampleFunctionalConsumerMultiple("ExampleFunctionalConsumerMultiple", + ) + +ApplicationMgr(TopAlg=[inp, consumer], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp new file mode 100644 index 00000000..19483644 --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -0,0 +1,75 @@ +#include "Gaudi/Property.h" +#include "Gaudi/Algorithm.h" +#include "GaudiAlg/Consumer.h" +#include "k4FWCore/DataWrapper.h" + +#include "podio/UserDataCollection.h" +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/TrackerHitCollection.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; + +struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer { + + ExampleFunctionalConsumerMultiple( const std::string& name, ISvcLocator* svcLoc ) + : Consumer( name, svcLoc, + { + KeyValue("InputLocationFloat", "VectorFloat"), + KeyValue("InputLocationParticles", "MCParticles"), + KeyValue("InputLocationSimTrackerHits", "SimTrackerHits"), + KeyValue("InputLocationTrackerHits", "TrackerHits"), + KeyValue("InputLocationTracks", "Tracks"), + } + ) {} + + // 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()); + // assert(*floatVectorColl[0] == 125); + // assert(*floatVectorColl[1] == 25); + // assert(*floatVectorColl[2] == m_event); + + // auto particlesColl = dynamic_cast(particles.getData()); + // auto p4 = particlesColl[0].momentum(); + // assert(p4.x == m_magicNumberOffset + m_event + 5); + // assert(p4.y == m_magicNumberOffset + 6); + // assert(p4.z == m_magicNumberOffset + 7); + // assert(particlesColl[0].getMass() == m_magicNumberOffset + m_event + 8); + + // auto simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); + // assert(simTrackerHitsColl[0].getPosition()[0] == 3); + // assert(simTrackerHitsColl[0].getPosition()[1] == 4); + // assert(simTrackerHitsColl[0].getPosition()[2] == 5); + + // auto trackerHitsColl = dynamic_cast(trackerHits.getData()); + // assert(trackerHitsColl[0].getPosition()[0] == 3); + // assert(trackerHitsColl[0].getPosition()[1] == 4); + // assert(trackerHitsColl[0].getPosition()[2] == 5); + + // auto tracksColl = dynamic_cast(tracks.getData()); + + } + +}; + +DECLARE_COMPONENT(ExampleFunctionalConsumerMultiple) From f703cc813b86c90dee2ad9dcafa3183c257bc0ea Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 27 Jul 2023 22:26:32 +0200 Subject: [PATCH 29/68] Rename output keys --- .../src/components/ExampleFunctionalProducerMultiple.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index da7ea9e5..f2dcdba2 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -29,9 +29,9 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer Date: Tue, 1 Aug 2023 10:07:06 +0200 Subject: [PATCH 30/68] Fix the ExampleFunctionalTransformer test --- test/k4FWCoreTest/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 31a86de8..76286399 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -218,7 +218,9 @@ add_test(NAME ExampleFunctionalTransformer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalTransformer.py) set_test_env(ExampleFunctionalTransformer) -set_tests_properties(ExampleFunctionalTransformer PROPERTIES DEPENDS ExampleFunctionalProducer) +set_tests_properties(ExampleFunctionalTransformer PROPERTIES + PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" + DEPENDS ExampleFunctionalProducer) add_test(NAME ExampleFunctionalProducerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} From 69d1bf2d2bf017c227bd581f29d6432b138ff5d4 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 11:20:11 +0200 Subject: [PATCH 31/68] Improve the FunctionalConsumerMultiple test --- .../ExampleFunctionalConsumerMultiple.cpp | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 19483644..fa5989be 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -44,31 +44,54 @@ struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer*>(floatVector.getData()); - // assert(*floatVectorColl[0] == 125); - // assert(*floatVectorColl[1] == 25); - // assert(*floatVectorColl[2] == m_event); + auto* floatVectorColl = dynamic_cast*>(floatVector.getData()); + if (((*floatVectorColl)[0] != 125) || + ((*floatVectorColl)[1] != 25) || + ((*floatVectorColl)[2] != m_event)) { + fatal() << "Wrong data in floatVector collection"; + } - // auto particlesColl = dynamic_cast(particles.getData()); - // auto p4 = particlesColl[0].momentum(); - // assert(p4.x == m_magicNumberOffset + m_event + 5); - // assert(p4.y == m_magicNumberOffset + 6); - // assert(p4.z == m_magicNumberOffset + 7); - // assert(particlesColl[0].getMass() == m_magicNumberOffset + m_event + 8); + auto* particlesColl = dynamic_cast(particles.getData()); + auto p4 = (*particlesColl).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)) { + fatal() << "Wrong data in particles collection"; + } - // auto simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); - // assert(simTrackerHitsColl[0].getPosition()[0] == 3); - // assert(simTrackerHitsColl[0].getPosition()[1] == 4); - // assert(simTrackerHitsColl[0].getPosition()[2] == 5); + auto* simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); + if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) || + ((*simTrackerHitsColl)[0].getPosition()[1] != 4) || + ((*simTrackerHitsColl)[0].getPosition()[2] != 5)) { + fatal() << "Wrong data in simTrackerHits collection"; + } - // auto trackerHitsColl = dynamic_cast(trackerHits.getData()); - // assert(trackerHitsColl[0].getPosition()[0] == 3); - // assert(trackerHitsColl[0].getPosition()[1] == 4); - // assert(trackerHitsColl[0].getPosition()[2] == 5); + auto trackerHitsColl = dynamic_cast(trackerHits.getData()); + if (((*trackerHitsColl)[0].getPosition()[0] != 3) || + ((*trackerHitsColl)[0].getPosition()[1] != 4) || + ((*trackerHitsColl)[0].getPosition()[2] != 5)) { + fatal() << "Wrong data in trackerHits collection"; + } - // auto tracksColl = dynamic_cast(tracks.getData()); + 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}) + ) { + fatal() << "Wrong data in tracks collection"; + } } +private: + // integer to add to the dummy values written to the edm + Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, + "Integer to add to the dummy values written to the edm"}; + int m_event{0}; }; From a7235df2bec7adc3f33de2829d2aeb11e2a1ad50 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 11:23:38 +0200 Subject: [PATCH 32/68] Change from asserts to ifs --- .../src/components/ExampleFunctionalConsumer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index b0a6b702..629dd2d3 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -28,12 +28,14 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer(input.getData()); int i = 0; for (const auto& particle : *coll) { - assert(particle.getPDG() == 1 + i); - assert(particle.getGeneratorStatus() == 2 + i); - assert(particle.getSimulatorStatus() == 3 + i); - assert(particle.getCharge() == 4 + i); - assert(particle.getTime() == 5 + i); - assert(particle.getMass() == 6 + i); + 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)) { + fatal() << "Wrong data in MCParticle collection"; + } i++; } } From f462c8ca9c2441666ee5f2e6e8ef248d2a03ef23 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 11:34:19 +0200 Subject: [PATCH 33/68] Add a functional test from many to many --- test/k4FWCoreTest/CMakeLists.txt | 7 ++ .../ExampleFunctionalTransformerMultiple.cpp | 87 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 76286399..4a43af28 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -37,6 +37,7 @@ set(k4fwcoretest_plugin_sources src/components/ExampleFunctionalTransformer.cpp src/components/ExampleFunctionalProducerMultiple.cpp src/components/ExampleFunctionalConsumerMultiple.cpp + src/components/ExampleFunctionalTransformerMultiple.cpp ) gaudi_add_module(k4FWCoreTestPlugins @@ -232,3 +233,9 @@ add_test(NAME ExampleFunctionalConsumerMultiple COMMAND ${K4RUN} options/runExampleFunctionalProducerMultiple.py) set_test_env(ExampleFunctionalConsumerMultiple) set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) + +add_test(NAME ExampleFunctionalTransformerMultiple + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runExampleFunctionalTransformerMultiple.py) +set_test_env(ExampleFunctionalTransformerMultiple) +set_tests_properties(ExampleFunctionalTransformerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp new file mode 100644 index 00000000..0edcc08e --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -0,0 +1,87 @@ +#include "Gaudi/Property.h" +#include "Gaudi/Algorithm.h" +#include "GaudiAlg/Transformer.h" +#include "k4FWCore/DataWrapper.h" + +#include "podio/UserDataCollection.h" +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/TrackerHitCollection.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 Counter_t = DataWrapper>; +using Particle_t = DataWrapper; + +// As a simple example, we'll write an integer and a collection of MCParticles +struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTransformer(const colltype&, + const colltype&, + const colltype&, + const colltype&, + const colltype&), BaseClass_t> { + + ExampleFunctionalTransformerMultiple( const std::string& name, ISvcLocator* svcLoc ) + : MultiTransformer( name, svcLoc, + { + KeyValue("InputLocationFloat", "VectorFloat"), + KeyValue("InputLocationParticles", "MCParticles"), + KeyValue("InputLocationSimTrackerHits", "SimTrackerHits"), + KeyValue("InputLocationTrackerHits", "TrackerHits"), + KeyValue("InputLocationTracks", "Tracks") + }, + { + KeyValue("OutputLocationFloat", "VectorFloat"), + KeyValue("InputLocationParticles", "MCParticles") + } + ) {} + + // 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>(); + + auto* floatVectorColl = dynamic_cast*>(floatVector.getData()); + counter->push_back(floatVectorColl->size()); + + + auto particlesColl = dynamic_cast(particles.getData()); + auto newParticlesColl = std::make_unique(); + for (const auto& p : *particlesColl) { + newParticlesColl->push_back(p); + } + auto particle_dw = DataWrapper(std::move(newParticlesColl)); + counter->push_back(particlesColl->size()); + + + auto simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); + counter->push_back(simTrackerHitsColl->size()); + + auto trackerHitsColl = dynamic_cast(trackerHits.getData()); + counter->push_back(trackerHitsColl->size()); + + auto tracksColl = dynamic_cast(tracks.getData()); + counter->push_back(tracksColl->size()); + + auto counter_dw = DataWrapper>(std::move(counter)); + + return std::make_tuple(counter_dw, particle_dw); + + } + +}; + +DECLARE_COMPONENT(ExampleFunctionalTransformerMultiple) From 3774a902fb62e68da2e956ef48eb3ff6aade9bd8 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 11:40:04 +0200 Subject: [PATCH 34/68] Rename handlers --- .../components/ExampleFunctionalProducerMultiple.cpp | 12 ++++++------ .../ExampleFunctionalTransformerMultiple.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index f2dcdba2..b4f4f632 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -44,7 +44,7 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producerpush_back(125.); floatVector->push_back(25.); floatVector->push_back(m_event); - Float_t floatVector_dw = DataWrapper>(std::move(floatVector)); + Float_t floatVectorDW = DataWrapper>(std::move(floatVector)); auto particles = std::make_unique(); auto particle = particles->create(); @@ -53,17 +53,17 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(std::move(particles)); + Particle_t particleDW = DataWrapper(std::move(particles)); auto simTrackerHits = std::make_unique(); auto hit = simTrackerHits->create(); hit.setPosition({3, 4, 5}); - SimTrackerHit_t simTrackerHit_dw = DataWrapper(std::move(simTrackerHits)); + SimTrackerHit_t simTrackerHitDW = DataWrapper(std::move(simTrackerHits)); auto trackerHits = std::make_unique(); auto trackerHit = trackerHits->create(); trackerHit.setPosition({3, 4, 5}); - TrackerHit_t trackerHit_dw = DataWrapper(std::move(trackerHits)); + TrackerHit_t trackerHitDW = DataWrapper(std::move(trackerHits)); auto tracks = std::make_unique(); auto track = tracks->create(); @@ -81,9 +81,9 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(std::move(tracks)); + Track_t trackDW = DataWrapper(std::move(tracks)); - return std::make_tuple(floatVector_dw, particle_dw, simTrackerHit_dw, trackerHit_dw, track_dw); + return std::make_tuple(floatVectorDW, particleDW, simTrackerHitDW, trackerHitDW, trackDW); } private: diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 0edcc08e..bd86e1a9 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -19,10 +19,10 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // Has to be wrapped in DataWrapper using colltype = DataWrapper; +// As a simple example, we'll write an integer and a collection of MCParticles using Counter_t = DataWrapper>; using Particle_t = DataWrapper; -// As a simple example, we'll write an integer and a collection of MCParticles struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTransformer(const colltype&, const colltype&, const colltype&, @@ -63,7 +63,7 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran for (const auto& p : *particlesColl) { newParticlesColl->push_back(p); } - auto particle_dw = DataWrapper(std::move(newParticlesColl)); + auto particleDW = DataWrapper(std::move(newParticlesColl)); counter->push_back(particlesColl->size()); @@ -76,9 +76,9 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran auto tracksColl = dynamic_cast(tracks.getData()); counter->push_back(tracksColl->size()); - auto counter_dw = DataWrapper>(std::move(counter)); + auto counterDW = DataWrapper>(std::move(counter)); - return std::make_tuple(counter_dw, particle_dw); + return std::make_tuple(counterDW, particleDW); } From acf7d5367c808152eb74c20b0f3e73b030aeb127 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 11:44:17 +0200 Subject: [PATCH 35/68] Add an options file to run the TransformerMultiple --- ...runExampleFunctionalTransformerMultiple.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py new file mode 100644 index 00000000..b6405439 --- /dev/null +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -0,0 +1,33 @@ +from Gaudi.Configuration import INFO +from Gaudi import Configurables +from Configurables import ExampleFunctionalTransformerMultiple +from Configurables import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import PodioOutput +from Configurables import PodioInput + +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer_multiple.root" + +inp = PodioInput() +inp.collections = [ + "VectorFloat", + "MCParticles", + "SimTrackerHits", + "TrackerHits", + "Tracks", +] + +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_transformer_multiple.root" +# Use this to keep all the existing collections in the input file +out.outputCommands = ["drop MCParticles"] + +transformer = ExampleFunctionalTransformerMultiple("ExampleFunctionalTransformerMultiple") + +ApplicationMgr(TopAlg=[inp, transformer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[k4DataSvc("EventDataSvc")], + OutputLevel=INFO, + ) From 26d8281e59de7d723404b201a3875dd76d3f6191 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 17:35:44 +0200 Subject: [PATCH 36/68] Fix tests in parallel and fix the transformer multiple test --- test/k4FWCoreTest/CMakeLists.txt | 6 ++++-- .../ExampleFunctionalTransformerMultiple.cpp | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 4a43af28..ded56df7 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -221,7 +221,7 @@ add_test(NAME ExampleFunctionalTransformer set_test_env(ExampleFunctionalTransformer) set_tests_properties(ExampleFunctionalTransformer PROPERTIES PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" - DEPENDS ExampleFunctionalProducer) + DEPENDS "ExampleFunctionalProducer;ExampleFunctionalConsumer") add_test(NAME ExampleFunctionalProducerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} @@ -238,4 +238,6 @@ add_test(NAME ExampleFunctionalTransformerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalTransformerMultiple.py) set_test_env(ExampleFunctionalTransformerMultiple) -set_tests_properties(ExampleFunctionalTransformerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) +set_tests_properties(ExampleFunctionalTransformerMultiple PROPERTIES + PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" + DEPENDS "ExampleFunctionalProducerMultiple;ExampleFunctionalConsumerMultiple") diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index bd86e1a9..55337ea9 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -39,8 +39,8 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran KeyValue("InputLocationTracks", "Tracks") }, { - KeyValue("OutputLocationFloat", "VectorFloat"), - KeyValue("InputLocationParticles", "MCParticles") + KeyValue("OutputLocationCounter", "Counter"), + KeyValue("OutputLocationParticles", "MCParticles_out") } ) {} @@ -61,12 +61,21 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran auto particlesColl = dynamic_cast(particles.getData()); auto newParticlesColl = std::make_unique(); for (const auto& p : *particlesColl) { - newParticlesColl->push_back(p); + // We need to create a new particle since the current one is already in a collection + + // We could create a new one + auto newParticle = newParticlesColl->create(); + newParticle.setPDG(p.getPDG()); + newParticle.setGeneratorStatus(p.getGeneratorStatus() + 1); + newParticle.setSimulatorStatus(p.getSimulatorStatus() + 1); + newParticle.setCharge(p.getCharge() + 2); + 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()); @@ -79,7 +88,6 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran auto counterDW = DataWrapper>(std::move(counter)); return std::make_tuple(counterDW, particleDW); - } }; From e86829d0e590cda25c0458fcebc2efa29109a7e0 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 1 Aug 2023 18:27:17 +0200 Subject: [PATCH 37/68] Improve documentation and rename the input and output collections --- .../options/runExampleFunctionalConsumer.py | 2 +- .../options/runExampleFunctionalProducer.py | 8 ++++---- .../runExampleFunctionalProducerMultiple.py | 11 +++++++++-- .../options/runExampleFunctionalTransformer.py | 6 +++--- .../runExampleFunctionalTransformerMultiple.py | 16 +++++++++++++--- .../components/ExampleFunctionalConsumer.cpp | 4 +++- .../ExampleFunctionalConsumerMultiple.cpp | 12 +++++++----- .../components/ExampleFunctionalProducer.cpp | 9 +++++++-- .../ExampleFunctionalProducerMultiple.cpp | 17 ++++++++++++----- .../components/ExampleFunctionalTransformer.cpp | 4 ++-- .../ExampleFunctionalTransformerMultiple.cpp | 14 +++++++------- 11 files changed, 68 insertions(+), 35 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index 409e11f1..ca3d578c 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -16,7 +16,7 @@ ] consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", - InputLocation="MCParticles", + InputCollection="MCParticles", ) ApplicationMgr(TopAlg=[inp, consumer], diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index 66f07859..74f50ea7 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -10,11 +10,11 @@ from Configurables import PodioOutput out = PodioOutput("out") out.filename = "output_k4test_exampledata_producer.root" -out.outputCommands = ["keep *"] +# Collections can be dropped +# out.outputCommands = ["drop *"] -producer = ExampleFunctionalProducer("ExampleFunctionalProducer", - OutputLocation="MCParticles", - ExampleInt=5) + +producer = ExampleFunctionalProducer("ExampleFunctionalProducer") ApplicationMgr(TopAlg=[producer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index 43ac5d42..2dfc438b 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -10,9 +10,16 @@ from Configurables import PodioOutput out = PodioOutput("out") out.filename = "output_k4test_exampledata_producer_multiple.root" -out.outputCommands = ["keep *"] +# Collections can be dropped +# out.outputCommands = ["drop *"] -producer = ExampleFunctionalProducerMultiple("ExampleFunctionalProducerMultiple") +producer = ExampleFunctionalProducerMultiple("ExampleFunctionalProducerMultiple", + OutputCollectionFloat="VectorFloat", + OutputCollectionParticles="MCParticles", + OutputCollectionSimTrackerHits="SimTrackerHits", + OutputCollectionTrackerHits="TrackerHits", + OutputCollectionTracks="Tracks", + ExampleInt=5) ApplicationMgr(TopAlg=[producer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index 53d29223..eebf40ef 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -16,12 +16,12 @@ out = PodioOutput("out") out.filename = "output_k4test_exampledata_transformer.root" -# Use this to keep all the existing collections in the input file +# The collections that we don't drop will also be present in the output file out.outputCommands = ["drop MCParticles"] transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", - InputLocation="MCParticles", - OutputLocation="NewMCParticles") + InputCollection="MCParticles", + OutputCollection="NewMCParticles") ApplicationMgr(TopAlg=[inp, transformer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py index b6405439..32db6b4c 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -20,10 +20,20 @@ out = PodioOutput("out") out.filename = "output_k4test_exampledata_transformer_multiple.root" -# Use this to keep all the existing collections in the input file -out.outputCommands = ["drop MCParticles"] +# The collections that we don't drop will also be present in the output file +out.outputCommands = ["drop VectorFloat", "drop MCParticles", + "drop SimTrackerHits", "drop TrackerHits", + "drop Tracks"] -transformer = ExampleFunctionalTransformerMultiple("ExampleFunctionalTransformerMultiple") +transformer = ExampleFunctionalTransformerMultiple("ExampleFunctionalTransformerMultiple", + InputCollectionFloat="VectorFloat", + InputCollectionParticles="MCParticles", + InputCollectionSimTrackerHits="SimTrackerHits", + InputCollectionTrackerHits="TrackerHits", + InputCollectionTracks="Tracks", + OutputCollectionCounter="Counter", + OutputCollectionParticles="NewMCParticles", + ) ApplicationMgr(TopAlg=[inp, transformer, out], EvtSel="NONE", diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 629dd2d3..2fffd04a 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -18,8 +18,10 @@ using colltype = DataWrapper; struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { + // The pair in KeyValue can be changed from python and it corresponds + // to the name of the input collection ExampleFunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) - : Consumer( name, svcLoc, KeyValue("InputLocation", "MCParticles")) {} + : Consumer( name, svcLoc, KeyValue("InputCollection", "MCParticles")) {} // 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 diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index fa5989be..76eadbac 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -25,14 +25,16 @@ struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer { + // 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 ) : Consumer( name, svcLoc, { - KeyValue("InputLocationFloat", "VectorFloat"), - KeyValue("InputLocationParticles", "MCParticles"), - KeyValue("InputLocationSimTrackerHits", "SimTrackerHits"), - KeyValue("InputLocationTrackerHits", "TrackerHits"), - KeyValue("InputLocationTracks", "Tracks"), + KeyValue("InputCollectionFloat", "VectorFloat"), + KeyValue("InputCollectionParticles", "MCParticles"), + KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), + KeyValue("InputCollectionTrackerHits", "TrackerHits"), + KeyValue("InputCollectionTracks", "Tracks"), } ) {} diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index 8d05e9c9..22cc0ade 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -16,8 +16,10 @@ using colltype = DataWrapper; struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { + // The pair in KeyValue can be changed from python and it corresponds + // to the name of the output collection ExampleFunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) - : Producer( name, svcLoc, KeyValue( "OutputLocation", "MCParticles" ) ) {} + : Producer( name, svcLoc, KeyValue( "OutputCollection", "MCParticles" ) ) {} // This is the function that will be called to produce the data colltype operator()() const override { @@ -28,8 +30,11 @@ struct ExampleFunctionalProducer final : Gaudi::Functional::Producer m_exampleInt{this, "ExampleInt", 3, - "Example int to be produced"}; + "Example int that can be used in the algorithm"}; }; DECLARE_COMPONENT(ExampleFunctionalProducer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index b4f4f632..4725fa38 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -24,14 +24,16 @@ using Track_t = DataWrapper; struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(), BaseClass_t> { + // The pairs in KeyValue can be changed from python and they correspond + // to the names of the output collections ExampleFunctionalProducerMultiple( const std::string& name, ISvcLocator* svcLoc ) : Producer( name, svcLoc, { - KeyValue( "OutputLocationFloat", "VectorFloat" ), - KeyValue( "OutputLocationParticles", "MCParticles" ), - KeyValue( "OutputLocationSimTrackerHits", "SimTrackerHits" ), - KeyValue( "OutputLocationTrackerHits", "TrackerHits" ), - KeyValue( "OutputLocationTracks", "Tracks" ) + KeyValue( "OutputCollectionFloat", "VectorFloat" ), + KeyValue( "OutputCollectionParticles", "MCParticles" ), + KeyValue( "OutputCollectionSimTrackerHits", "SimTrackerHits" ), + KeyValue( "OutputCollectionTrackerHits", "TrackerHits" ), + KeyValue( "OutputCollectionTracks", "Tracks" ) } ) {} @@ -87,10 +89,15 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer m_exampleInt{this, "ExampleInt", 3, + "Example int that can be used in the algorithm"}; // integer to add to the dummy values written to the edm Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; int m_event{0}; + }; DECLARE_COMPONENT(ExampleFunctionalProducerMultiple) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 0aa63a50..6aa9433e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -22,8 +22,8 @@ struct ExampleFunctionalTransformer final : Gaudi::Functional::Transformer { ExampleFunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) - : Transformer( name, svcLoc, KeyValue("InputLocation", "MCParticles"), - KeyValue( "OutputLocation", "NewMCParticles" ) ) {} + : Transformer( name, svcLoc, KeyValue("InputCollection", "MCParticles"), + KeyValue( "OutputCollection", "NewMCParticles" ) ) {} // This is the function that will be called to transform the data // Note that the function has to be const, as well as all pointers to collections diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 55337ea9..4e290a7e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -32,15 +32,15 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran ExampleFunctionalTransformerMultiple( const std::string& name, ISvcLocator* svcLoc ) : MultiTransformer( name, svcLoc, { - KeyValue("InputLocationFloat", "VectorFloat"), - KeyValue("InputLocationParticles", "MCParticles"), - KeyValue("InputLocationSimTrackerHits", "SimTrackerHits"), - KeyValue("InputLocationTrackerHits", "TrackerHits"), - KeyValue("InputLocationTracks", "Tracks") + KeyValue("InputCollectionFloat", "VectorFloat"), + KeyValue("InputCollectionParticles", "MCParticles"), + KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), + KeyValue("InputCollectionTrackerHits", "TrackerHits"), + KeyValue("InputCollectionTracks", "Tracks") }, { - KeyValue("OutputLocationCounter", "Counter"), - KeyValue("OutputLocationParticles", "MCParticles_out") + KeyValue("OutputCollectionCounter", "Counter"), + KeyValue("OutputCollectionParticles", "NewMCParticles") } ) {} From fe718e7e4378c1b3b392b0af5384bac0bd5d1680 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 2 Aug 2023 08:27:08 +0200 Subject: [PATCH 38/68] Run clang-format --- k4FWCore/components/PodioInput.cpp | 1 - .../components/ExampleFunctionalConsumer.cpp | 23 +++--- .../ExampleFunctionalConsumerMultiple.cpp | 75 +++++++------------ .../components/ExampleFunctionalProducer.cpp | 12 ++- .../ExampleFunctionalProducerMultiple.cpp | 59 +++++++-------- .../ExampleFunctionalTransformer.cpp | 24 +++--- .../ExampleFunctionalTransformerMultiple.cpp | 54 ++++++------- 7 files changed, 102 insertions(+), 146 deletions(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index d307a0e7..f4e59117 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -32,7 +32,6 @@ PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : Consumer( } void PodioInput::operator()() const { - for (auto& collName : m_collectionNames) { debug() << "Registering collection to read " << collName << endmsg; if (m_podioDataSvc->readCollection(collName).isFailure()) { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 2fffd04a..1c2c9898 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -1,10 +1,10 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" #include "k4FWCore/DataWrapper.h" -#include "podio/CollectionBase.h" #include "edm4hep/MCParticleCollection.h" +#include "podio/CollectionBase.h" #include @@ -17,31 +17,26 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; using colltype = DataWrapper; struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { - // The pair in KeyValue can be changed from python and it corresponds // to the name of the input collection - ExampleFunctionalConsumer( const std::string& name, ISvcLocator* svcLoc ) - : Consumer( name, svcLoc, KeyValue("InputCollection", "MCParticles")) {} + ExampleFunctionalConsumer(const std::string& name, ISvcLocator* svcLoc) + : Consumer(name, svcLoc, KeyValue("InputCollection", "MCParticles")) {} // 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& input) const override { auto* coll = dynamic_cast(input.getData()); - int i = 0; + int i = 0; for (const auto& particle : *coll) { - 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)) { + 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)) { fatal() << "Wrong data in MCParticle collection"; } i++; } } - }; - + DECLARE_COMPONENT(ExampleFunctionalConsumer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 76eadbac..0e7c2ca2 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -1,13 +1,13 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" #include "k4FWCore/DataWrapper.h" -#include "podio/UserDataCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" #include "edm4hep/TrackCollection.h" #include "edm4hep/TrackerHitCollection.h" +#include "podio/UserDataCollection.h" #include @@ -19,82 +19,65 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // Has to be wrapped in DataWrapper using colltype = DataWrapper; -struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer { - +struct ExampleFunctionalConsumerMultiple final + : Gaudi::Functional::Consumer< + void(const colltype&, const colltype&, const colltype&, const colltype&, const colltype&), 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 ) - : Consumer( name, svcLoc, - { - KeyValue("InputCollectionFloat", "VectorFloat"), - KeyValue("InputCollectionParticles", "MCParticles"), - KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("InputCollectionTrackerHits", "TrackerHits"), - KeyValue("InputCollectionTracks", "Tracks"), - } - ) {} + ExampleFunctionalConsumerMultiple(const std::string& name, ISvcLocator* svcLoc) + : Consumer(name, svcLoc, + { + KeyValue("InputCollectionFloat", "VectorFloat"), + KeyValue("InputCollectionParticles", "MCParticles"), + KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), + KeyValue("InputCollectionTrackerHits", "TrackerHits"), + KeyValue("InputCollectionTracks", "Tracks"), + }) {} // 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 { + 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)) { + if (((*floatVectorColl)[0] != 125) || ((*floatVectorColl)[1] != 25) || ((*floatVectorColl)[2] != m_event)) { fatal() << "Wrong data in floatVector collection"; } auto* particlesColl = dynamic_cast(particles.getData()); - auto p4 = (*particlesColl).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)) { + auto p4 = (*particlesColl).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)) { fatal() << "Wrong data in particles collection"; } auto* simTrackerHitsColl = dynamic_cast(simTrackerHits.getData()); - if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) || - ((*simTrackerHitsColl)[0].getPosition()[1] != 4) || + if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) || ((*simTrackerHitsColl)[0].getPosition()[1] != 4) || ((*simTrackerHitsColl)[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) || + if (((*trackerHitsColl)[0].getPosition()[0] != 3) || ((*trackerHitsColl)[0].getPosition()[1] != 4) || ((*trackerHitsColl)[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) + 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}) - ) { + ) { fatal() << "Wrong data in tracks collection"; } - } + private: // integer to add to the dummy values written to the edm Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; - int m_event{0}; - + int m_event{0}; }; - + DECLARE_COMPONENT(ExampleFunctionalConsumerMultiple) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index 22cc0ade..bb5cbc88 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,5 +1,5 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/DataWrapper.h" @@ -15,11 +15,10 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; using colltype = DataWrapper; struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { - // The pair in KeyValue can be changed from python and it corresponds // to the name of the output collection - ExampleFunctionalProducer( const std::string& name, ISvcLocator* svcLoc ) - : Producer( name, svcLoc, KeyValue( "OutputCollection", "MCParticles" ) ) {} + ExampleFunctionalProducer(const std::string& name, ISvcLocator* svcLoc) + : Producer(name, svcLoc, KeyValue("OutputCollection", "MCParticles")) {} // This is the function that will be called to produce the data colltype operator()() const override { @@ -33,8 +32,7 @@ struct ExampleFunctionalProducer final : Gaudi::Functional::Producer m_exampleInt{this, "ExampleInt", 3, - "Example int that can be used in the algorithm"}; + Gaudi::Property m_exampleInt{this, "ExampleInt", 3, "Example int that can be used in the algorithm"}; }; - + DECLARE_COMPONENT(ExampleFunctionalProducer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index 4725fa38..d61ce935 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -1,13 +1,13 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/DataWrapper.h" -#include "podio/UserDataCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" #include "edm4hep/TrackCollection.h" #include "edm4hep/TrackerHitCollection.h" +#include "podio/UserDataCollection.h" #include @@ -16,26 +16,23 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // Which type of collections we are producing // They have to be wrapped in DataWrapper -using Float_t = DataWrapper>; -using Particle_t = DataWrapper; +using Float_t = DataWrapper>; +using Particle_t = DataWrapper; using SimTrackerHit_t = DataWrapper; -using TrackerHit_t = DataWrapper; -using Track_t = DataWrapper; - -struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(), BaseClass_t> { +using TrackerHit_t = DataWrapper; +using Track_t = DataWrapper; +struct ExampleFunctionalProducerMultiple final + : Gaudi::Functional::Producer(), + BaseClass_t> { // The pairs in KeyValue can be changed from python and they correspond // to the names of the output collections - ExampleFunctionalProducerMultiple( const std::string& name, ISvcLocator* svcLoc ) - : Producer( name, svcLoc, - { - KeyValue( "OutputCollectionFloat", "VectorFloat" ), - KeyValue( "OutputCollectionParticles", "MCParticles" ), - KeyValue( "OutputCollectionSimTrackerHits", "SimTrackerHits" ), - KeyValue( "OutputCollectionTrackerHits", "TrackerHits" ), - KeyValue( "OutputCollectionTracks", "Tracks" ) - } - ) {} + ExampleFunctionalProducerMultiple(const std::string& name, ISvcLocator* svcLoc) + : Producer( + name, svcLoc, + {KeyValue("OutputCollectionFloat", "VectorFloat"), KeyValue("OutputCollectionParticles", "MCParticles"), + KeyValue("OutputCollectionSimTrackerHits", "SimTrackerHits"), + KeyValue("OutputCollectionTrackerHits", "TrackerHits"), KeyValue("OutputCollectionTracks", "Tracks")}) {} // This is the function that will be called to produce the data std::tuple operator()() const override { @@ -48,22 +45,22 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producerpush_back(m_event); Float_t floatVectorDW = DataWrapper>(std::move(floatVector)); - auto particles = std::make_unique(); - auto particle = particles->create(); - auto& p4 = particle.momentum(); - p4.x = m_magicNumberOffset + m_event + 5; - p4.y = m_magicNumberOffset + 6; - p4.z = m_magicNumberOffset + 7; + auto particles = std::make_unique(); + auto particle = particles->create(); + auto& p4 = particle.momentum(); + p4.x = m_magicNumberOffset + m_event + 5; + p4.y = m_magicNumberOffset + 6; + p4.z = m_magicNumberOffset + 7; particle.setMass(m_magicNumberOffset + m_event + 8); Particle_t particleDW = DataWrapper(std::move(particles)); auto simTrackerHits = std::make_unique(); - auto hit = simTrackerHits->create(); + auto hit = simTrackerHits->create(); hit.setPosition({3, 4, 5}); - SimTrackerHit_t simTrackerHitDW = DataWrapper(std::move(simTrackerHits)); + SimTrackerHit_t simTrackerHitDW = DataWrapper(std::move(simTrackerHits)); auto trackerHits = std::make_unique(); - auto trackerHit = trackerHits->create(); + auto trackerHit = trackerHits->create(); trackerHit.setPosition({3, 4, 5}); TrackerHit_t trackerHitDW = DataWrapper(std::move(trackerHits)); @@ -91,13 +88,11 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer m_exampleInt{this, "ExampleInt", 3, - "Example int that can be used in the algorithm"}; + Gaudi::Property m_exampleInt{this, "ExampleInt", 3, "Example int that can be used in the algorithm"}; // integer to add to the dummy values written to the edm Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; - int m_event{0}; - + int m_event{0}; }; - + DECLARE_COMPONENT(ExampleFunctionalProducerMultiple) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 6aa9433e..a5017168 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -1,11 +1,11 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" #include "k4FWCore/DataWrapper.h" -#include "podio/CollectionBase.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/MutableMCParticle.h" +#include "podio/CollectionBase.h" #include @@ -15,22 +15,21 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; // 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_in = DataWrapper; using colltype_out = DataWrapper; -struct ExampleFunctionalTransformer final : - Gaudi::Functional::Transformer { - - ExampleFunctionalTransformer( const std::string& name, ISvcLocator* svcLoc ) - : Transformer( name, svcLoc, KeyValue("InputCollection", "MCParticles"), - KeyValue( "OutputCollection", "NewMCParticles" ) ) {} +struct ExampleFunctionalTransformer final + : Gaudi::Functional::Transformer { + ExampleFunctionalTransformer(const std::string& name, ISvcLocator* svcLoc) + : Transformer(name, svcLoc, KeyValue("InputCollection", "MCParticles"), + KeyValue("OutputCollection", "NewMCParticles")) {} // This is the function that will be called to transform the data // 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(); + auto* coll = dynamic_cast(input.getData()); + auto coll_out = std::make_unique(); for (const auto& particle : *coll) { auto new_particle = edm4hep::MutableMCParticle(); new_particle.setPDG(particle.getPDG() + 10); @@ -45,7 +44,6 @@ struct ExampleFunctionalTransformer final : colltype_out dw = DataWrapper(std::move(coll_out)); return dw; } - }; - + DECLARE_COMPONENT(ExampleFunctionalTransformer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 4e290a7e..f5f074ba 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -1,13 +1,13 @@ -#include "Gaudi/Property.h" #include "Gaudi/Algorithm.h" +#include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" #include "k4FWCore/DataWrapper.h" -#include "podio/UserDataCollection.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" #include "edm4hep/TrackCollection.h" #include "edm4hep/TrackerHitCollection.h" +#include "podio/UserDataCollection.h" #include @@ -20,45 +20,35 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; using colltype = DataWrapper; // As a simple example, we'll write an integer and a collection of MCParticles -using Counter_t = DataWrapper>; +using Counter_t = DataWrapper>; using Particle_t = DataWrapper; -struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTransformer(const colltype&, - const colltype&, - const colltype&, - const colltype&, - const colltype&), BaseClass_t> { - - ExampleFunctionalTransformerMultiple( const std::string& name, ISvcLocator* svcLoc ) - : MultiTransformer( name, svcLoc, - { - KeyValue("InputCollectionFloat", "VectorFloat"), - KeyValue("InputCollectionParticles", "MCParticles"), - KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("InputCollectionTrackerHits", "TrackerHits"), - KeyValue("InputCollectionTracks", "Tracks") - }, - { - KeyValue("OutputCollectionCounter", "Counter"), - KeyValue("OutputCollectionParticles", "NewMCParticles") - } - ) {} +struct ExampleFunctionalTransformerMultiple final + : Gaudi::Functional::MultiTransformer(const colltype&, const colltype&, + const colltype&, const colltype&, + const colltype&), + BaseClass_t> { + ExampleFunctionalTransformerMultiple(const std::string& name, ISvcLocator* svcLoc) + : MultiTransformer( + name, svcLoc, + {KeyValue("InputCollectionFloat", "VectorFloat"), KeyValue("InputCollectionParticles", "MCParticles"), + KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), + KeyValue("InputCollectionTrackerHits", "TrackerHits"), KeyValue("InputCollectionTracks", "Tracks")}, + {KeyValue("OutputCollectionCounter", "Counter"), KeyValue("OutputCollectionParticles", "NewMCParticles")}) { + } // 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 { + 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>(); auto* floatVectorColl = dynamic_cast*>(floatVector.getData()); counter->push_back(floatVectorColl->size()); - - auto particlesColl = dynamic_cast(particles.getData()); + auto particlesColl = dynamic_cast(particles.getData()); auto newParticlesColl = std::make_unique(); for (const auto& p : *particlesColl) { // We need to create a new particle since the current one is already in a collection @@ -71,7 +61,6 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran newParticle.setCharge(p.getCharge() + 2); newParticle.setTime(p.getTime() + 3); newParticle.setMass(p.getMass() + 4); - } auto particleDW = DataWrapper(std::move(newParticlesColl)); counter->push_back(particlesColl->size()); @@ -89,7 +78,6 @@ struct ExampleFunctionalTransformerMultiple final : Gaudi::Functional::MultiTran return std::make_tuple(counterDW, particleDW); } - }; - + DECLARE_COMPONENT(ExampleFunctionalTransformerMultiple) From d6d0331223bbf9f07b4866e0797e3a4531c1ff2c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 2 Aug 2023 08:27:47 +0200 Subject: [PATCH 39/68] Run clang-format --- k4FWCore/components/PodioInput.h | 5 ++--- k4FWCore/include/k4FWCore/DataWrapper.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/k4FWCore/components/PodioInput.h b/k4FWCore/components/PodioInput.h index 84ab6f20..9ecf8afc 100644 --- a/k4FWCore/components/PodioInput.h +++ b/k4FWCore/components/PodioInput.h @@ -19,8 +19,8 @@ #ifndef FWCORE_PODIOINPUT_H #define FWCORE_PODIOINPUT_H // Gaudi -#include "GaudiAlg/Consumer.h" #include "Gaudi/Property.h" +#include "GaudiAlg/Consumer.h" // STL #include @@ -39,8 +39,7 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; class PodioInput final : public Gaudi::Functional::Consumer { public: - - PodioInput( const std::string& name, ISvcLocator* svcLoc ); + PodioInput(const std::string& name, ISvcLocator* svcLoc); void operator()() const override; private: diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index daecf266..803b594a 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -43,7 +43,7 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { public: DataWrapper() : m_data(nullptr){}; - DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()){ + DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()) { uptr.release(); is_owner = false; }; @@ -59,7 +59,7 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { private: const T* m_data; - bool is_owner{true}; + bool is_owner{true}; }; template DataWrapper::~DataWrapper() { From 64df3c129b9e3b71d9c69ae195bcdc44e66bd88c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 2 Aug 2023 08:32:33 +0200 Subject: [PATCH 40/68] Run clang-format --- k4FWCore/src/PodioDataSvc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k4FWCore/src/PodioDataSvc.cpp b/k4FWCore/src/PodioDataSvc.cpp index 0fdee29c..a7bf637d 100644 --- a/k4FWCore/src/PodioDataSvc.cpp +++ b/k4FWCore/src/PodioDataSvc.cpp @@ -17,11 +17,11 @@ * limitations under the License. */ #include "k4FWCore/PodioDataSvc.h" -#include "k4FWCore/DataWrapper.h" #include "GaudiKernel/IConversionSvc.h" #include "GaudiKernel/IEventProcessor.h" #include "GaudiKernel/IProperty.h" #include "GaudiKernel/ISvcLocator.h" +#include "k4FWCore/DataWrapper.h" #include "podio/CollectionBase.h" From 65a25738258014b44c21cb8f1ccd0654f7cf0b37 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 4 Sep 2023 21:04:22 +0200 Subject: [PATCH 41/68] Add root files to the gitignore --- .gitignore | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 656d0058..6ae3efea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -### File copied from https://github.com/key4hep/key4hep-dev-utils -### DO NOT EDIT, CHANGES WILL BE OVERWRITTEN - ### C++ ### # Prerequisites *.d @@ -241,8 +238,8 @@ podio_generated_files.cmake /python/edm4hep/__version__.py edm4hep/edm4hep/ edm4hep/src/ -## k4FWCore -test/k4FWCoreTest/**/*.root +# k4FWCore +test/k4FWCoreTest/*.root ## k4MarlinWrapper test/inputFiles/*.slcio test/gaudi_opts/testConverterConstants.py From 545a75b91bf646b917104f9b67b93168f1560990 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 2 Aug 2023 08:45:54 +0200 Subject: [PATCH 42/68] Fix gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6ae3efea..e485c349 100644 --- a/.gitignore +++ b/.gitignore @@ -239,7 +239,7 @@ podio_generated_files.cmake edm4hep/edm4hep/ edm4hep/src/ # k4FWCore -test/k4FWCoreTest/*.root +test/k4FWCoreTest/**/*.root ## k4MarlinWrapper test/inputFiles/*.slcio test/gaudi_opts/testConverterConstants.py From 80f48c81ca2231d04a714d0b7bd66992c8f0747b Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 8 Aug 2023 18:02:16 +0200 Subject: [PATCH 43/68] Improve the interface for producers --- k4FWCore/include/k4FWCore/FunctionalUtils.h | 19 +++++++ .../components/ExampleFunctionalProducer.cpp | 23 ++++----- .../ExampleFunctionalProducerMultiple.cpp | 50 ++++++++----------- 3 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 k4FWCore/include/k4FWCore/FunctionalUtils.h diff --git a/k4FWCore/include/k4FWCore/FunctionalUtils.h b/k4FWCore/include/k4FWCore/FunctionalUtils.h new file mode 100644 index 00000000..2b9bc271 --- /dev/null +++ b/k4FWCore/include/k4FWCore/FunctionalUtils.h @@ -0,0 +1,19 @@ +#ifndef K4FWCORE_FUNCTIONALUTILS_H +#define K4FWCORE_FUNCTIONALUTILS_H + +#include "GaudiAlg/GaudiAlgorithm.h" +#include "GaudiKernel/DataObjectHandle.h" +#include "k4FWCore/DataWrapper.h" + +// Base class used for the Traits template argument of the +// Gaudi::Functional algorithms +struct BaseClass_t { + template + using OutputHandle = DataObjectWriteHandle>; + // template + // using InputHandle = DataObjectReadHandle>; + + using BaseClass = Gaudi::Algorithm; +}; + +#endif diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index bb5cbc88..bf344b34 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,18 +1,16 @@ +#include #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" -#include "k4FWCore/DataWrapper.h" +#include "GaudiKernel/DataObjectHandle.h" +#include "k4FWCore/FunctionalUtils.h" #include "edm4hep/MCParticleCollection.h" #include -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; - -// Which type of collection we are producing -// Has to be wrapped in DataWrapper -using colltype = DataWrapper; +// Which collection we are producing +using colltype = edm4hep::MCParticleCollection; struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { // The pair in KeyValue can be changed from python and it corresponds @@ -22,11 +20,12 @@ struct ExampleFunctionalProducer final : Gaudi::Functional::Producer(); - coll->push_back({1, 2, 3, 4, 5, 6, {}, {}, {}, {}, {}, {}}); - coll->push_back({2, 3, 4, 5, 6, 7, {}, {}, {}, {}, {}, {}}); - colltype dw = DataWrapper(std::move(coll)); - return dw; + auto coll = edm4hep::MCParticleCollection(); + coll.push_back({1, 2, 3, 4, 5, 6, {}, {}, {}, {}, {}, {}}); + coll.push_back({2, 3, 4, 5, 6, 7, {}, {}, {}, {}, {}, {}}); + // We have to return whatever collection type we specified in the + // template argument + return coll; } private: diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index d61ce935..49e891ed 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -1,7 +1,7 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" -#include "k4FWCore/DataWrapper.h" +#include "k4FWCore/FunctionalUtils.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" @@ -11,16 +11,12 @@ #include -// This will always be Gaudi::Algorithm -using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t; - // Which type of collections we are producing -// They have to be wrapped in DataWrapper -using Float_t = DataWrapper>; -using Particle_t = DataWrapper; -using SimTrackerHit_t = DataWrapper; -using TrackerHit_t = DataWrapper; -using Track_t = DataWrapper; +using Float_t = podio::UserDataCollection; +using Particle_t = edm4hep::MCParticleCollection; +using SimTrackerHit_t = edm4hep::SimTrackerHitCollection; +using TrackerHit_t = edm4hep::TrackerHitCollection; +using Track_t = edm4hep::TrackCollection; struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer(), @@ -39,34 +35,30 @@ struct ExampleFunctionalProducerMultiple final // The following was copied and adapted from the // k4FWCoreTest_CreateExampleEventData test - auto floatVector = std::make_unique>(); - floatVector->push_back(125.); - floatVector->push_back(25.); - floatVector->push_back(m_event); - Float_t floatVectorDW = DataWrapper>(std::move(floatVector)); + auto floatVector = podio::UserDataCollection(); + floatVector.push_back(125.); + floatVector.push_back(25.); + floatVector.push_back(m_event); - auto particles = std::make_unique(); - auto particle = particles->create(); + auto particles = edm4hep::MCParticleCollection(); + auto particle = particles.create(); auto& p4 = particle.momentum(); p4.x = m_magicNumberOffset + m_event + 5; p4.y = m_magicNumberOffset + 6; p4.z = m_magicNumberOffset + 7; particle.setMass(m_magicNumberOffset + m_event + 8); - Particle_t particleDW = DataWrapper(std::move(particles)); - auto simTrackerHits = std::make_unique(); - auto hit = simTrackerHits->create(); + auto simTrackerHits = edm4hep::SimTrackerHitCollection(); + auto hit = simTrackerHits.create(); hit.setPosition({3, 4, 5}); - SimTrackerHit_t simTrackerHitDW = DataWrapper(std::move(simTrackerHits)); - auto trackerHits = std::make_unique(); - auto trackerHit = trackerHits->create(); + auto trackerHits = edm4hep::TrackerHitCollection(); + auto trackerHit = trackerHits.create(); trackerHit.setPosition({3, 4, 5}); - TrackerHit_t trackerHitDW = DataWrapper(std::move(trackerHits)); - auto tracks = std::make_unique(); - auto track = tracks->create(); - auto track2 = tracks->create(); + auto tracks = edm4hep::TrackCollection(); + auto track = tracks.create(); + auto track2 = tracks.create(); // set members track.setType(1); track.setChi2(2.1); @@ -80,9 +72,9 @@ struct ExampleFunctionalProducerMultiple final // set associatons track.addToTrackerHits(trackerHit); track.addToTracks(track2); - Track_t trackDW = DataWrapper(std::move(tracks)); - return std::make_tuple(floatVectorDW, particleDW, simTrackerHitDW, trackerHitDW, trackDW); + return std::make_tuple(std::move(floatVector), std::move(particles), std::move(simTrackerHits), + std::move(trackerHits), std::move(tracks)); } private: From 638f7e5b948d0956bb0b93bf73dc7407e6674b24 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sat, 19 Aug 2023 18:34:57 +0200 Subject: [PATCH 44/68] Fix name --- k4FWCore/include/k4FWCore/FunctionalUtils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/k4FWCore/include/k4FWCore/FunctionalUtils.h b/k4FWCore/include/k4FWCore/FunctionalUtils.h index 2b9bc271..51265400 100644 --- a/k4FWCore/include/k4FWCore/FunctionalUtils.h +++ b/k4FWCore/include/k4FWCore/FunctionalUtils.h @@ -9,9 +9,9 @@ // Gaudi::Functional algorithms struct BaseClass_t { template - using OutputHandle = DataObjectWriteHandle>; + using OutputHandle_t = DataObjectWriteHandle>; // template - // using InputHandle = DataObjectReadHandle>; + // using InputHandle_t = DataObjectReadHandle>; using BaseClass = Gaudi::Algorithm; }; From cb6139f3fdc928d42b4c400e002319b20bda20a0 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 21 Aug 2023 13:38:49 +0200 Subject: [PATCH 45/68] Fix the producers --- k4FWCore/include/k4FWCore/DataWrapper.h | 4 ++++ k4FWCore/include/k4FWCore/FunctionalUtils.h | 2 +- .../k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index 803b594a..413e54b7 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -43,6 +43,10 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { public: DataWrapper() : m_data(nullptr){}; + DataWrapper(T&& coll) { + m_data = new T(std::move(coll)); + is_owner = true; + } DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()) { uptr.release(); is_owner = false; diff --git a/k4FWCore/include/k4FWCore/FunctionalUtils.h b/k4FWCore/include/k4FWCore/FunctionalUtils.h index 51265400..5db4f4bd 100644 --- a/k4FWCore/include/k4FWCore/FunctionalUtils.h +++ b/k4FWCore/include/k4FWCore/FunctionalUtils.h @@ -9,9 +9,9 @@ // Gaudi::Functional algorithms struct BaseClass_t { template - using OutputHandle_t = DataObjectWriteHandle>; // template // using InputHandle_t = DataObjectReadHandle>; + using OutputHandle = DataObjectWriteHandle>; using BaseClass = Gaudi::Algorithm; }; diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index bf344b34..16dcdcf0 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,8 +1,6 @@ -#include #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" -#include "GaudiKernel/DataObjectHandle.h" #include "k4FWCore/FunctionalUtils.h" #include "edm4hep/MCParticleCollection.h" From 57f7c2b5c69e95ca1595f3a20a0a0641c5883a0e Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 21 Aug 2023 19:55:17 +0200 Subject: [PATCH 46/68] Fix tests --- test/k4FWCoreTest/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index ded56df7..a40aef5a 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -211,7 +211,7 @@ set_test_env(ExampleFunctionalProducer) add_test(NAME ExampleFunctionalConsumer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runExampleFunctionalProducer.py) + COMMAND ${K4RUN} options/runExampleFunctionalConsumer.py) set_test_env(ExampleFunctionalConsumer) set_tests_properties(ExampleFunctionalConsumer PROPERTIES DEPENDS ExampleFunctionalProducer) @@ -230,7 +230,7 @@ set_test_env(ExampleFunctionalProducerMultiple) add_test(NAME ExampleFunctionalConsumerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - COMMAND ${K4RUN} options/runExampleFunctionalProducerMultiple.py) + COMMAND ${K4RUN} options/runExampleFunctionalConsumerMultiple.py) set_test_env(ExampleFunctionalConsumerMultiple) set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) From da2107eae582f8a25dc27fb9e09103c514e69d80 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 22 Aug 2023 09:05:18 +0200 Subject: [PATCH 47/68] Fix the consumer tests --- test/k4FWCoreTest/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index a40aef5a..dec71877 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -213,7 +213,9 @@ add_test(NAME ExampleFunctionalConsumer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalConsumer.py) set_test_env(ExampleFunctionalConsumer) -set_tests_properties(ExampleFunctionalConsumer PROPERTIES DEPENDS ExampleFunctionalProducer) +set_tests_properties(ExampleFunctionalConsumer PROPERTIES + PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" + DEPENDS ExampleFunctionalProducer) add_test(NAME ExampleFunctionalTransformer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} @@ -232,7 +234,9 @@ add_test(NAME ExampleFunctionalConsumerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalConsumerMultiple.py) set_test_env(ExampleFunctionalConsumerMultiple) -set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) +set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES + PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" + DEPENDS ExampleFunctionalProducerMultiple) add_test(NAME ExampleFunctionalTransformerMultiple WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} From 5294aabb742baba593eed6a5a751fbe21584ead1 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Mon, 4 Sep 2023 21:10:07 +0200 Subject: [PATCH 48/68] Fix tests --- test/k4FWCoreTest/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index dec71877..3b0438d9 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -214,7 +214,6 @@ add_test(NAME ExampleFunctionalConsumer COMMAND ${K4RUN} options/runExampleFunctionalConsumer.py) set_test_env(ExampleFunctionalConsumer) set_tests_properties(ExampleFunctionalConsumer PROPERTIES - PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" DEPENDS ExampleFunctionalProducer) add_test(NAME ExampleFunctionalTransformer @@ -222,7 +221,6 @@ add_test(NAME ExampleFunctionalTransformer COMMAND ${K4RUN} options/runExampleFunctionalTransformer.py) set_test_env(ExampleFunctionalTransformer) set_tests_properties(ExampleFunctionalTransformer PROPERTIES - PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" DEPENDS "ExampleFunctionalProducer;ExampleFunctionalConsumer") add_test(NAME ExampleFunctionalProducerMultiple @@ -235,7 +233,6 @@ add_test(NAME ExampleFunctionalConsumerMultiple COMMAND ${K4RUN} options/runExampleFunctionalConsumerMultiple.py) set_test_env(ExampleFunctionalConsumerMultiple) set_tests_properties(ExampleFunctionalConsumerMultiple PROPERTIES - PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" DEPENDS ExampleFunctionalProducerMultiple) add_test(NAME ExampleFunctionalTransformerMultiple @@ -243,5 +240,4 @@ add_test(NAME ExampleFunctionalTransformerMultiple COMMAND ${K4RUN} options/runExampleFunctionalTransformerMultiple.py) set_test_env(ExampleFunctionalTransformerMultiple) set_tests_properties(ExampleFunctionalTransformerMultiple PROPERTIES - PASS_REGULAR_EXPRESSION "Application Manager Terminated successfully with a user requested ScheduledStop" DEPENDS "ExampleFunctionalProducerMultiple;ExampleFunctionalConsumerMultiple") From 51890e0c40e52c6c77ef37764530a8822ae3c1b0 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 10 Sep 2023 22:13:25 +0200 Subject: [PATCH 49/68] 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)); } }; From f58bc210394294a21c1c928a3628634e345c99bd Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 13 Sep 2023 10:12:03 +0200 Subject: [PATCH 50/68] Rename FunctionalUtils.h to BaseClass.h --- k4FWCore/include/k4FWCore/{FunctionalUtils.h => BaseClass.h} | 0 test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 2 +- .../src/components/ExampleFunctionalConsumerMultiple.cpp | 2 +- test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp | 2 +- .../src/components/ExampleFunctionalProducerMultiple.cpp | 2 +- .../src/components/ExampleFunctionalTransformer.cpp | 2 +- .../src/components/ExampleFunctionalTransformerMultiple.cpp | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename k4FWCore/include/k4FWCore/{FunctionalUtils.h => BaseClass.h} (100%) diff --git a/k4FWCore/include/k4FWCore/FunctionalUtils.h b/k4FWCore/include/k4FWCore/BaseClass.h similarity index 100% rename from k4FWCore/include/k4FWCore/FunctionalUtils.h rename to k4FWCore/include/k4FWCore/BaseClass.h diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 23c453bb..6c8dacd0 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -7,7 +7,7 @@ #include "podio/CollectionBase.h" // Define BaseClass_t -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index c32aae2b..bf81e86d 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -10,7 +10,7 @@ #include "podio/UserDataCollection.h" // Define BaseClass_t -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index 16dcdcf0..0980b2e8 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,7 +1,7 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include "edm4hep/MCParticleCollection.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index 49e891ed..88f96abd 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -1,7 +1,7 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index c571684d..2b363edd 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -8,7 +8,7 @@ #include "podio/CollectionBase.h" // Define BaseClass_t -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index d666b1c4..20712450 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -10,7 +10,7 @@ #include "podio/UserDataCollection.h" // Define BaseClass_t -#include "k4FWCore/FunctionalUtils.h" +#include "k4FWCore/BaseClass.h" #include From 5b0d0220a9478e35f14da363c5d915150dcf6ab2 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 14 Sep 2023 16:01:44 +0200 Subject: [PATCH 51/68] Don't include the datawrappers --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 1 - .../src/components/ExampleFunctionalConsumerMultiple.cpp | 1 - .../k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp | 1 - .../src/components/ExampleFunctionalTransformerMultiple.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 6c8dacd0..3ca49636 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -1,7 +1,6 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" -#include "k4FWCore/DataWrapper.h" #include "edm4hep/MCParticleCollection.h" #include "podio/CollectionBase.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index bf81e86d..6ce0cac9 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -1,7 +1,6 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" -#include "k4FWCore/DataWrapper.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 2b363edd..a597374a 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -1,7 +1,6 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" -#include "k4FWCore/DataWrapper.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/MutableMCParticle.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 20712450..5dbe69f9 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -1,7 +1,6 @@ #include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" -#include "k4FWCore/DataWrapper.h" #include "edm4hep/MCParticleCollection.h" #include "edm4hep/SimTrackerHitCollection.h" From 9e79c83e098adbbe16d4e449c30e444957fb2542 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 19 Sep 2023 08:51:01 +0200 Subject: [PATCH 52/68] Reorganize imports --- test/k4FWCoreTest/options/runExampleFunctionalConsumer.py | 3 --- .../options/runExampleFunctionalConsumerMultiple.py | 3 --- test/k4FWCoreTest/options/runExampleFunctionalProducer.py | 4 +--- .../options/runExampleFunctionalProducerMultiple.py | 4 +--- test/k4FWCoreTest/options/runExampleFunctionalTransformer.py | 1 - .../options/runExampleFunctionalTransformerMultiple.py | 1 - 6 files changed, 2 insertions(+), 14 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index ca3d578c..35667450 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -1,5 +1,4 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalConsumer from Configurables import ApplicationMgr from Configurables import k4DataSvc @@ -8,8 +7,6 @@ podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata_producer.root" -from Configurables import PodioInput - inp = PodioInput() inp.collections = [ "MCParticles", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py index 0052bdd8..0f9e7977 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -1,5 +1,4 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalConsumerMultiple from Configurables import ApplicationMgr from Configurables import k4DataSvc @@ -8,8 +7,6 @@ podioevent = k4DataSvc("EventDataSvc") podioevent.input = "output_k4test_exampledata_producer_multiple.root" -from Configurables import PodioInput - inp = PodioInput() inp.collections = [ "VectorFloat", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index 74f50ea7..efc30fc1 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -1,13 +1,11 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalProducer from Configurables import ApplicationMgr from Configurables import k4DataSvc +from Configurables import PodioOutput -from Configurables import k4DataSvc podioevent = k4DataSvc("EventDataSvc") -from Configurables import PodioOutput out = PodioOutput("out") out.filename = "output_k4test_exampledata_producer.root" # Collections can be dropped diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index 2dfc438b..6e6acde4 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -1,13 +1,11 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalProducerMultiple from Configurables import ApplicationMgr from Configurables import k4DataSvc +from Configurables import PodioOutput -from Configurables import k4DataSvc podioevent = k4DataSvc("EventDataSvc") -from Configurables import PodioOutput out = PodioOutput("out") out.filename = "output_k4test_exampledata_producer_multiple.root" # Collections can be dropped diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index eebf40ef..50195e27 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -1,5 +1,4 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalTransformer from Configurables import ApplicationMgr from Configurables import k4DataSvc diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py index 32db6b4c..323727cb 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -1,5 +1,4 @@ from Gaudi.Configuration import INFO -from Gaudi import Configurables from Configurables import ExampleFunctionalTransformerMultiple from Configurables import ApplicationMgr from Configurables import k4DataSvc From 8ae87a38091d4f822da685752928a842f2f5b13d Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 08:05:35 +0200 Subject: [PATCH 53/68] Remove CollName from the arguments of maybeRead --- k4FWCore/components/PodioInput.cpp | 76 +++++++++++++++--------------- k4FWCore/components/PodioInput.h | 2 +- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index ea686a3f..4c17b44c 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -54,7 +54,7 @@ DECLARE_COMPONENT(PodioInput) template -inline void PodioInput::maybeRead(std::string_view CollType, std::string_view collName) const { +inline void PodioInput::maybeRead(std::string_view collName) const { if (m_podioDataSvc->readCollection(std::string(collName)).isFailure()) { error() << "Failed to register collection " << collName << endmsg; } @@ -63,151 +63,151 @@ inline void PodioInput::maybeRead(std::string_view CollType, std::string_view co void PodioInput::fillReaders() { m_readers["edm4hep::MCParticleCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCParticleCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::SimTrackerHitCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::SimTrackerHitCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::CaloHitContributionCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::CaloHitContributionCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::SimCalorimeterHitCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::SimCalorimeterHitCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::RawCalorimeterHitCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::RawCalorimeterHitCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::CalorimeterHitCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::CalorimeterHitCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::ParticleIDCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::ParticleIDCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::ClusterCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::ClusterCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::TrackerHitCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::TrackerHitCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::TrackerHitPlaneCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::TrackerHitPlaneCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::RawTimeSeriesCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::RawTimeSeriesCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::TrackCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::TrackCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::VertexCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::VertexCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::ReconstructedParticleCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::ReconstructedParticleCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoParticleAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoParticleAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoCaloAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoCaloAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoTrackerAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoTrackerAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoTrackerHitPlaneAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoTrackerHitPlaneAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoClusterParticleAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoClusterParticleAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::MCRecoTrackParticleAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::MCRecoTrackParticleAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::RecoParticleVertexAssociationCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::RecoParticleVertexAssociationCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::SimPrimaryIonizationClusterCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::SimPrimaryIonizationClusterCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::TrackerPulseCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::TrackerPulseCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::RecIonizationClusterCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::RecIonizationClusterCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::TimeSeriesCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::TimeSeriesCollection", collName); + maybeRead(collName); }; m_readers["edm4hep::RecDqdxCollection"] = [&](std::string_view collName) { - maybeRead("edm4hep::RecDqdxCollection", collName); + maybeRead(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { - maybeRead>("podio::UserDataCollection", collName); + maybeRead>(collName); }; } diff --git a/k4FWCore/components/PodioInput.h b/k4FWCore/components/PodioInput.h index 8945060e..00f7542d 100644 --- a/k4FWCore/components/PodioInput.h +++ b/k4FWCore/components/PodioInput.h @@ -44,7 +44,7 @@ class PodioInput final : public Gaudi::Functional::Consumer private: template - void maybeRead(std::string_view CollType, std::string_view collName) const; + void maybeRead(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"}; From b5840e8b69060323243711ed41132ac2239f54a6 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 12:43:09 +0200 Subject: [PATCH 54/68] Produce an empty MCParticleCollection in the exampleFunctionalProducerMultiple --- .../options/runExampleFunctionalProducerMultiple.py | 3 ++- .../ExampleFunctionalProducerMultiple.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index 6e6acde4..ed51bd5d 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -13,7 +13,8 @@ producer = ExampleFunctionalProducerMultiple("ExampleFunctionalProducerMultiple", OutputCollectionFloat="VectorFloat", - OutputCollectionParticles="MCParticles", + OutputCollectionParticles1="MCParticles1", + OutputCollectionParticles2="MCParticles2", OutputCollectionSimTrackerHits="SimTrackerHits", OutputCollectionTrackerHits="TrackerHits", OutputCollectionTracks="Tracks", diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index 88f96abd..2911843e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -19,19 +19,22 @@ using TrackerHit_t = edm4hep::TrackerHitCollection; using Track_t = edm4hep::TrackCollection; struct ExampleFunctionalProducerMultiple final - : Gaudi::Functional::Producer(), + : Gaudi::Functional::Producer(), BaseClass_t> { // The pairs in KeyValue can be changed from python and they correspond // to the names of the output collections ExampleFunctionalProducerMultiple(const std::string& name, ISvcLocator* svcLoc) : Producer( name, svcLoc, - {KeyValue("OutputCollectionFloat", "VectorFloat"), KeyValue("OutputCollectionParticles", "MCParticles"), + {KeyValue("OutputCollectionFloat", "VectorFloat"), + KeyValue("OutputCollectionParticles1", "MCParticles1"), + KeyValue("OutputCollectionParticles2", "MCParticles2"), KeyValue("OutputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("OutputCollectionTrackerHits", "TrackerHits"), KeyValue("OutputCollectionTracks", "Tracks")}) {} + KeyValue("OutputCollectionTrackerHits", "TrackerHits"), + KeyValue("OutputCollectionTracks", "Tracks")}) {} // This is the function that will be called to produce the data - std::tuple operator()() const override { + std::tuple operator()() const override { // The following was copied and adapted from the // k4FWCoreTest_CreateExampleEventData test @@ -73,7 +76,7 @@ struct ExampleFunctionalProducerMultiple final track.addToTrackerHits(trackerHit); track.addToTracks(track2); - return std::make_tuple(std::move(floatVector), std::move(particles), std::move(simTrackerHits), + return std::make_tuple(std::move(floatVector), std::move(particles), Particle_t(), std::move(simTrackerHits), std::move(trackerHits), std::move(tracks)); } From 89b29ee17911b6a2a50db26e4d88812c4129c786 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 12:47:22 +0200 Subject: [PATCH 55/68] Fix a maybeRead call since type was removed in a previous commit --- k4FWCore/components/PodioInput.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index 4c17b44c..a2d8dab5 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -227,7 +227,7 @@ void PodioInput::operator()() const { if (m_readers.find(type) != m_readers.end()) { m_readers[type](collName); } else { - maybeRead(type, collName); + maybeRead(collName); } } From f5a504008e5e56d879283ba89bacaac7c2d963cd Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 12:58:09 +0200 Subject: [PATCH 56/68] Fix the tests after the producer multiple outputs two MCParticleCollection --- .../options/runExampleFunctionalConsumerMultiple.py | 3 ++- .../options/runExampleFunctionalTransformerMultiple.py | 6 +++--- .../src/components/ExampleFunctionalConsumerMultiple.cpp | 2 +- .../src/components/ExampleFunctionalTransformerMultiple.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py index 0f9e7977..6b81081b 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -10,7 +10,8 @@ inp = PodioInput() inp.collections = [ "VectorFloat", - "MCParticles", + "MCParticles1", + "MCParticles2", "SimTrackerHits", "TrackerHits", "Tracks", diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py index 323727cb..1a55c947 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -11,7 +11,7 @@ inp = PodioInput() inp.collections = [ "VectorFloat", - "MCParticles", + "MCParticles1", "SimTrackerHits", "TrackerHits", "Tracks", @@ -20,13 +20,13 @@ out = PodioOutput("out") out.filename = "output_k4test_exampledata_transformer_multiple.root" # The collections that we don't drop will also be present in the output file -out.outputCommands = ["drop VectorFloat", "drop MCParticles", +out.outputCommands = ["drop VectorFloat", "drop MCParticles1", "drop SimTrackerHits", "drop TrackerHits", "drop Tracks"] transformer = ExampleFunctionalTransformerMultiple("ExampleFunctionalTransformerMultiple", InputCollectionFloat="VectorFloat", - InputCollectionParticles="MCParticles", + InputCollectionParticles="MCParticles1", InputCollectionSimTrackerHits="SimTrackerHits", InputCollectionTrackerHits="TrackerHits", InputCollectionTracks="Tracks", diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 6ce0cac9..453f16dd 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -31,7 +31,7 @@ struct ExampleFunctionalConsumerMultiple final : Consumer(name, svcLoc, { KeyValue("InputCollectionFloat", "VectorFloat"), - KeyValue("InputCollectionParticles", "MCParticles"), + KeyValue("InputCollectionParticles", "MCParticles1"), KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), KeyValue("InputCollectionTrackerHits", "TrackerHits"), KeyValue("InputCollectionTracks", "Tracks"), diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 5dbe69f9..0832c2b6 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -30,9 +30,11 @@ struct ExampleFunctionalTransformerMultiple final ExampleFunctionalTransformerMultiple(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( name, svcLoc, - {KeyValue("InputCollectionFloat", "VectorFloat"), KeyValue("InputCollectionParticles", "MCParticles"), + {KeyValue("InputCollectionFloat", "VectorFloat"), + KeyValue("InputCollectionParticles", "MCParticles1"), KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("InputCollectionTrackerHits", "TrackerHits"), KeyValue("InputCollectionTracks", "Tracks")}, + KeyValue("InputCollectionTrackerHits", "TrackerHits"), + KeyValue("InputCollectionTracks", "Tracks")}, {KeyValue("OutputCollectionCounter", "Counter"), KeyValue("OutputCollectionParticles", "NewMCParticles")}) { } From f185ca33b2c14b0facf3c0b202d44589e4ea4a7a Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 12:59:26 +0200 Subject: [PATCH 57/68] Add a comment explaining a test dependency --- test/k4FWCoreTest/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 3b0438d9..ec33ee94 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -216,6 +216,8 @@ set_test_env(ExampleFunctionalConsumer) set_tests_properties(ExampleFunctionalConsumer PROPERTIES DEPENDS ExampleFunctionalProducer) +# A dependency on the ExampleFunctionalConsumer is added to make sure +# they don't run at the same time add_test(NAME ExampleFunctionalTransformer WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runExampleFunctionalTransformer.py) From 4e3ee36b38828748f81f8eab617af3efafb4ea91 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 20 Sep 2023 13:07:09 +0200 Subject: [PATCH 58/68] Remove the podio/CollectionBase.h include --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 1 - .../k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 3ca49636..e7d94e59 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -3,7 +3,6 @@ #include "GaudiAlg/Consumer.h" #include "edm4hep/MCParticleCollection.h" -#include "podio/CollectionBase.h" // Define BaseClass_t #include "k4FWCore/BaseClass.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index a597374a..86403094 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -4,7 +4,6 @@ #include "edm4hep/MCParticleCollection.h" #include "edm4hep/MutableMCParticle.h" -#include "podio/CollectionBase.h" // Define BaseClass_t #include "k4FWCore/BaseClass.h" From cbf99879ccdaf6f002e489f14a0396fb9dd2235c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sat, 30 Sep 2023 08:27:53 +0200 Subject: [PATCH 59/68] Adress comments from PR --- README.md | 24 ++++++++++++------- k4FWCore/src/PodioDataSvc.cpp | 2 +- .../ExampleFunctionalConsumerMultiple.cpp | 6 ++--- .../ExampleFunctionalTransformer.cpp | 1 - 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a2400414..b2f41dd7 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,8 @@ make install ``` ## Implementing algorithms -k4FWCore uses (or will use) `Gaudi::Functional` for executing algorithms. In -`Gaudi::Functional` we have three different base classes that we will use -depending on how may input and output types they take: +k4FWCore uses `Gaudi::Functional` for executing algorithms. There are several +types of algorithms, depending on your use case: - The `Consumer` takes inputs but no outputs; can be used for reading - The `Producer` takes outputs but no inputs; can be used for generating collections or events @@ -79,11 +78,18 @@ depending on how may input and output types they take: `Producer` are a particular case of this one) and takes both inputs and outputs -In all cases the implementation process is the same, we'll create a new class -that will implement `operator()`, that is where our algorithm will be. Simple -examples can be found in the test folder for each one of these three. In -addition, there are tests that have either multiple inputs and / or multiple -outputs (like `ExampleFunctionalProducerMultiple`) that can be used as a -template for the more typical case when working with multiple inputs or outputs. +A more complete list of algorithms can be found in +https://lhcb.github.io/DevelopKit/03a-gaudi/, in the `Gaudi::Functional` +section. + +In all cases the implementation process is the same: we'll create a new class +that will inherit from one of the previous algorithms. Then, we implement +`operator()`, where our algorithm will be. This `operator()` will return either +a single type (including `void`) or a tuple with multiple types. It will take +one parameter per input. Simple examples can be found in the test folder for +each one of the above-mentioned algorithms. In addition, there are tests that +have either multiple inputs and / or multiple outputs (like +`ExampleFunctionalProducerMultiple`) that can be used as a template for the more +typical case when working with multiple inputs or outputs. `GaudiAlg` is deprecated and will be removed in future versions of Gaudi. diff --git a/k4FWCore/src/PodioDataSvc.cpp b/k4FWCore/src/PodioDataSvc.cpp index c048983a..956ab2da 100644 --- a/k4FWCore/src/PodioDataSvc.cpp +++ b/k4FWCore/src/PodioDataSvc.cpp @@ -150,7 +150,7 @@ PodioDataSvc::PodioDataSvc(const std::string& name, ISvcLocator* svc) : DataSvc( PodioDataSvc::~PodioDataSvc() {} const std::string_view PodioDataSvc::getCollectionType(const std::string& collName) { - auto coll = m_eventframe.get(collName); + const auto coll = m_eventframe.get(collName); if (coll == nullptr) { error() << "Collection " << collName << " does not exist." << endmsg; } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 453f16dd..23e6309e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -44,9 +44,9 @@ struct ExampleFunctionalConsumerMultiple final 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"; - // } + if ((floatVector[0] != 125) || (floatVector[1] != 25) || (floatVector[2] != m_event)) { + fatal() << "Wrong data in floatVector collection"; + } auto p4 = particles.momentum()[0]; if ((p4.x != m_magicNumberOffset + m_event + 5) || (p4.y != m_magicNumberOffset + 6) || diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index 86403094..d26c55cd 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -33,7 +33,6 @@ struct ExampleFunctionalTransformer final new_particle.setCharge(particle.getCharge() + 10); new_particle.setTime(particle.getTime() + 10); new_particle.setMass(particle.getMass() + 10); - // new_particle. coll_out->push_back(new_particle); } return coll_out; From 716c5c4e7e294d3e9159f77b516474ce8cde401a Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 1 Oct 2023 08:43:26 +0200 Subject: [PATCH 60/68] Add header explaining each functional test --- test/k4FWCoreTest/options/runExampleFunctionalConsumer.py | 3 +++ .../options/runExampleFunctionalConsumerMultiple.py | 3 +++ test/k4FWCoreTest/options/runExampleFunctionalProducer.py | 2 ++ .../options/runExampleFunctionalProducerMultiple.py | 2 ++ test/k4FWCoreTest/options/runExampleFunctionalTransformer.py | 3 +++ 5 files changed, 13 insertions(+) diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index 35667450..42db984f 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -1,3 +1,6 @@ +# This is an example reading from a file and using a consumer with a single input +# to check that the contents of the file are the expected ones + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalConsumer from Configurables import ApplicationMgr diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py index 6b81081b..5d2c0379 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -1,3 +1,6 @@ +# This is an example reading from a file and using a consumer with several inputs +# to check that the contents of the file are the expected ones + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalConsumerMultiple from Configurables import ApplicationMgr diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index efc30fc1..26e8fbfa 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -1,3 +1,5 @@ +# This is an example using a producer with a single output and saving that to a file + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalProducer from Configurables import ApplicationMgr diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index ed51bd5d..768fe217 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -1,3 +1,5 @@ +# This is an example using a producer with a multiple outputs and saving that to a file + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalProducerMultiple from Configurables import ApplicationMgr diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index 50195e27..2e0970e5 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -1,3 +1,6 @@ +# This is an example reading from a file and using a consumer with several inputs +# to check that the contents of the file are the expected ones + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalTransformer from Configurables import ApplicationMgr From 6849e50fdbbdb8b5c7669dd659e87b35a26de2cc Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Sun, 1 Oct 2023 08:48:59 +0200 Subject: [PATCH 61/68] Add tests chaining functional algorithms and mixing them with the old algorithms --- test/k4FWCoreTest/CMakeLists.txt | 12 +++ .../options/runFunctionalChain.py | 36 ++++++++ test/k4FWCoreTest/options/runFunctionalMix.py | 91 +++++++++++++++++++ .../components/ExampleFunctionalConsumer.cpp | 16 +++- .../ExampleFunctionalConsumerMultiple.cpp | 42 ++++++--- .../k4FWCoreTest_CheckExampleEventData.cpp | 12 ++- .../k4FWCoreTest_CheckExampleEventData.h | 2 + 7 files changed, 189 insertions(+), 22 deletions(-) create mode 100644 test/k4FWCoreTest/options/runFunctionalChain.py create mode 100644 test/k4FWCoreTest/options/runFunctionalMix.py diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index ec33ee94..75473504 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -243,3 +243,15 @@ add_test(NAME ExampleFunctionalTransformerMultiple set_test_env(ExampleFunctionalTransformerMultiple) set_tests_properties(ExampleFunctionalTransformerMultiple PROPERTIES DEPENDS "ExampleFunctionalProducerMultiple;ExampleFunctionalConsumerMultiple") + +add_test(NAME FunctionalChain + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runFunctionalChain.py) +set_test_env(FunctionalChain) + +add_test(NAME FunctionalMix + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMAND ${K4RUN} options/runFunctionalMix.py) +set_test_env(FunctionalChain) +set_tests_properties(FunctionalMix PROPERTIES + DEPENDS "ExampleFunctionalProducerMultiple") diff --git a/test/k4FWCoreTest/options/runFunctionalChain.py b/test/k4FWCoreTest/options/runFunctionalChain.py new file mode 100644 index 00000000..cf512b27 --- /dev/null +++ b/test/k4FWCoreTest/options/runFunctionalChain.py @@ -0,0 +1,36 @@ +# This is an example of how to run several functional algorithms in a chain +# The producer produces a collection, the first consumer checks that the collection +# is the expected one, the transformer transforms the collection and creates a new +# and the second consumer checks that the new collection is the expected one + +from Gaudi.Configuration import INFO +from Configurables import ExampleFunctionalProducer +from Configurables import ExampleFunctionalConsumer +from Configurables import ExampleFunctionalTransformer +from Configurables import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import PodioOutput + +event_data_svc = k4DataSvc("EventDataSvc") + +out = PodioOutput("out") +out.filename = "functional_chain.root" + +producer = ExampleFunctionalProducer("ExampleFunctionalProducer") +consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer", + InputCollection="MCParticles", + ) +transformer = ExampleFunctionalTransformer("ExampleFunctionalTransformer", + InputCollection="MCParticles", + OutputCollection="NewMCParticles") +new_consumer = ExampleFunctionalConsumer("ExampleFunctionalConsumer2", + InputCollection="NewMCParticles", + ) +new_consumer.PossibleOffset = 10 + +ApplicationMgr(TopAlg=[producer, consumer, transformer, new_consumer, out], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[event_data_svc], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/options/runFunctionalMix.py b/test/k4FWCoreTest/options/runFunctionalMix.py new file mode 100644 index 00000000..9bf528c6 --- /dev/null +++ b/test/k4FWCoreTest/options/runFunctionalMix.py @@ -0,0 +1,91 @@ +# This is an example mixing functional and non-functional algorithms +# + +from Gaudi.Configuration import INFO +from Configurables import ExampleFunctionalConsumerMultiple, ExampleFunctionalTransformerMultiple +from Configurables import ExampleFunctionalProducerMultiple, k4FWCoreTest_CreateExampleEventData +from Configurables import k4FWCoreTest_CheckExampleEventData +from Configurables import ApplicationMgr +from Configurables import k4DataSvc +from Configurables import PodioInput, PodioOutput + +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer_multiple.root" + +inp = PodioInput() +inp.collections = [ + "VectorFloat", + "MCParticles1", + "MCParticles2", + "SimTrackerHits", + "TrackerHits", + "Tracks", +] + +consumer_input_functional = ExampleFunctionalConsumerMultiple("ExampleFunctionalConsumerMultiple") +consumer_input_algorithm = k4FWCoreTest_CheckExampleEventData("CheckExampleEventData") +consumer_input_algorithm.mcparticles = 'MCParticles1' +consumer_input_algorithm.keepEventNumberZero = True + +# We only care about the new FunctionalMCParticles collection in this example +producer_functional = ExampleFunctionalProducerMultiple("ProducerFunctional", + OutputCollectionFloat="VectorFloat_", + OutputCollectionParticles1="FunctionalMCParticles", + OutputCollectionParticles2="MCParticles2_", + OutputCollectionSimTrackerHits="SimTrackerHits_", + OutputCollectionTrackerHits="TrackerHits_", + OutputCollectionTracks="Tracks_", + ExampleInt=5) + +consumer_producerfun_functional = ExampleFunctionalConsumerMultiple("FunctionalConsumerFunctional", + InputCollectionParticles="FunctionalMCParticles", + ) +consumer_producerfun_algorithm = k4FWCoreTest_CheckExampleEventData("CheckFunctional") +consumer_producerfun_algorithm.mcparticles = 'FunctionalMCParticles' +consumer_producerfun_algorithm.keepEventNumberZero = True + +producer_algorithm = k4FWCoreTest_CreateExampleEventData("CreateExampleEventData") +# We only care about the MCParticles collection +producer_algorithm.mcparticles = 'AlgorithmMCParticles' +producer_algorithm.simtrackhits = 'SimTrackerHits__' +producer_algorithm.trackhits = 'TrackerHits__' +producer_algorithm.tracks = 'Tracks__' +producer_algorithm.vectorfloat = 'VectorFloat__' + +consumer_produceralg_functional = ExampleFunctionalConsumerMultiple("FunctionalConsumerAlgorithm") +consumer_produceralg_algorithm = k4FWCoreTest_CheckExampleEventData("CheckAlgorithm") +consumer_produceralg_algorithm.mcparticles = 'FunctionalMCParticles' +consumer_produceralg_algorithm.keepEventNumberZero = True + +# Let's also run the transformer, why not +transformer_functional = ExampleFunctionalTransformerMultiple("FunctionalTransformerMultiple") + +out = PodioOutput("out") +out.filename = "output_k4test_exampledata_functional_mix.root" + +ApplicationMgr(TopAlg=[inp, + # Check we can read input + consumer_input_functional, + consumer_input_algorithm, + + producer_functional, + + # Check we can read what's produced by a functional + consumer_producerfun_functional, + consumer_producerfun_algorithm, + + producer_algorithm, + + # Check we can read what's produced by an algorithm + consumer_produceralg_functional, + consumer_produceralg_algorithm, + + transformer_functional, + + out + ], + EvtSel="NONE", + EvtMax=10, + ExtSvc=[podioevent], + OutputLevel=INFO, + ) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index e7d94e59..03801bf8 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -7,6 +7,7 @@ // Define BaseClass_t #include "k4FWCore/BaseClass.h" +#include #include // Which type of collection we are reading @@ -24,14 +25,21 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer m_possibleOffset{this, "PossibleOffset", 0, "Possible offset in the values data"}; }; DECLARE_COMPONENT(ExampleFunctionalConsumer) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 23e6309e..d6de3c8a 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -11,7 +11,9 @@ // Define BaseClass_t #include "k4FWCore/BaseClass.h" +#include #include +#include // Which type of collection we are reading @@ -44,32 +46,47 @@ struct ExampleFunctionalConsumerMultiple final 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"; + if (floatVector.size() != 3) { + throw std::runtime_error("Wrong size of floatVector collection, expected 3, got " + std::to_string(floatVector.size()) + ""); + } + if ((floatVector[0] != 125) || (floatVector[1] != 25) || (floatVector[2] != 0)) { + std::stringstream error; + error << "Wrong data in floatVector collection, expected 125, 25, " << 0 << " got " << floatVector[0] << ", " << floatVector[1] << ", " << floatVector[2] << ""; + throw std::runtime_error(error.str()); } auto p4 = particles.momentum()[0]; - if ((p4.x != m_magicNumberOffset + m_event + 5) || (p4.y != m_magicNumberOffset + 6) || - (p4.z != m_magicNumberOffset + 7) || (particles[0].getMass() != m_magicNumberOffset + m_event + 8)) { - fatal() << "Wrong data in particles collection"; + if ((p4.x != m_magicNumberOffset + 5) || (p4.y != m_magicNumberOffset + 6) || + (p4.z != m_magicNumberOffset + 7) || (particles[0].getMass() != m_magicNumberOffset + 8)) { + std::stringstream error; + error << "Wrong data in particles collection, expected " << m_magicNumberOffset + 5 << ", " + << m_magicNumberOffset + 6 << ", " << m_magicNumberOffset + 7 << ", " << + m_magicNumberOffset + 8 << " got " << p4.x << ", " << p4.y << ", " << + p4.z << ", " << particles[0].getMass() << ""; + throw std::runtime_error(error.str()); } if ((simTrackerHits[0].getPosition()[0] != 3) || (simTrackerHits[0].getPosition()[1] != 4) || (simTrackerHits[0].getPosition()[2] != 5)) { - fatal() << "Wrong data in simTrackerHits collection"; + std::stringstream error; + error << "Wrong data in simTrackerHits collection, expected 3, 4, 5 got " << simTrackerHits[0].getPosition()[0] << ", " << simTrackerHits[0].getPosition()[1] << ", " << simTrackerHits[0].getPosition()[2] << ""; + throw std::runtime_error(error.str()); } if ((trackerHits[0].getPosition()[0] != 3) || (trackerHits[0].getPosition()[1] != 4) || (trackerHits[0].getPosition()[2] != 5)) { - fatal() << "Wrong data in trackerHits collection"; + std::stringstream error; + error << "Wrong data in trackerHits collection, expected 3, 4, 5 got " << trackerHits[0].getPosition()[0] << ", " << trackerHits[0].getPosition()[1] << ", " << trackerHits[0].getPosition()[2] << ""; + throw std::runtime_error(error.str()); } - 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}) + if ((tracks[0].getType() != 1) || (std::abs(tracks[0].getChi2() - 2.1) > 1e-6) || (tracks[0].getNdf() != 3) || + (std::abs(tracks[0].getDEdx() - 4.1) > 1e-6) || (std::abs(tracks[0].getDEdxError() - 5.1) > 1e-6) || + (std::abs(tracks[0].getRadiusOfInnermostHit() - 6.1) > 1e-6) ) { - fatal() << "Wrong data in tracks collection"; + std::stringstream error; + error << "Wrong data in tracks collection, expected 1, 2.1, 3, 4.1, 5.1, 6.1 got " << tracks[0].getType() << ", " << tracks[0].getChi2() << ", " << tracks[0].getNdf() << ", " << tracks[0].getDEdx() << ", " << tracks[0].getDEdxError() << ", " << tracks[0].getRadiusOfInnermostHit() << ""; + throw std::runtime_error(error.str()); } } @@ -77,7 +94,6 @@ struct ExampleFunctionalConsumerMultiple final // integer to add to the dummy values written to the edm Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; - int m_event{0}; }; DECLARE_COMPONENT(ExampleFunctionalConsumerMultiple) diff --git a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp index 4614989d..bff6483f 100644 --- a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp +++ b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp @@ -40,8 +40,8 @@ StatusCode k4FWCoreTest_CheckExampleEventData::execute() { if (floatVector->size() != 3 || (*floatVector)[2] != m_event) { fatal() << "Contents of vectorfloat collection is not as expected: size = " << floatVector->size() << " (expected 3), contents = " << *floatVector << " (expected [125., 25., " << m_event << "]) " - << std::endl; - return StatusCode::FAILURE; + << endmsg; + // return StatusCode::FAILURE; } auto particles = m_mcParticleHandle.get(); @@ -50,11 +50,13 @@ StatusCode k4FWCoreTest_CheckExampleEventData::execute() { (particle.getMass() != m_magicNumberOffset + m_event + 8)) { fatal() << "Contents of mcparticles collection is not as expected: momentum.x = " << particle.getMomentum().x << " (expected " << m_magicNumberOffset + m_event + 5 << "), mass = " << particle.getMass() << " (expected " - << m_magicNumberOffset + m_event + 8 << ")" << std::endl; - return StatusCode::FAILURE; + << m_magicNumberOffset + m_event + 8 << ")" << endmsg; + // return StatusCode::FAILURE; } - m_event++; + if (!m_keepEventNumberZero) { + m_event++; + } return StatusCode::SUCCESS; } diff --git a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h index a28b1cb6..7f788bf5 100644 --- a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h +++ b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h @@ -56,6 +56,8 @@ class k4FWCoreTest_CheckExampleEventData : public GaudiAlgorithm { /// integer to add to the dummy values written to the edm Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; + Gaudi::Property m_keepEventNumberZero{this, "keepEventNumberZero", false, + "Don't add the event number to the dummy values written"}; /// Handle for the MCParticles to be written DataHandle m_mcParticleHandle{"MCParticles", Gaudi::DataHandle::Reader, this}; DataHandle> m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Reader, this}; From 8baed4b8304fe07661656915911b7e78b0c276a8 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 3 Oct 2023 19:27:02 +0200 Subject: [PATCH 62/68] Remove some unneeded includes --- test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp | 1 - .../src/components/ExampleFunctionalConsumerMultiple.cpp | 1 - test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp | 1 - .../src/components/ExampleFunctionalProducerMultiple.cpp | 1 - .../k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp | 1 - .../src/components/ExampleFunctionalTransformerMultiple.cpp | 1 - 6 files changed, 6 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 03801bf8..45c9983f 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index d6de3c8a..8a351e74 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index 0980b2e8..f1a066b3 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/BaseClass.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index 2911843e..c3476283 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/BaseClass.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index d26c55cd..b63a6950 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 0832c2b6..328fc459 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -1,4 +1,3 @@ -#include "Gaudi/Algorithm.h" #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" From 39d560c77aaeca5c4a62dff2f5073a8e613c0a18 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 3 Oct 2023 20:29:43 +0200 Subject: [PATCH 63/68] Fix the wrong name of a test --- test/k4FWCoreTest/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 75473504..b487fa34 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -252,6 +252,6 @@ set_test_env(FunctionalChain) add_test(NAME FunctionalMix WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND ${K4RUN} options/runFunctionalMix.py) -set_test_env(FunctionalChain) +set_test_env(FunctionalMix) set_tests_properties(FunctionalMix PROPERTIES DEPENDS "ExampleFunctionalProducerMultiple") From b80a6cbe23b43066a6433855ea061f5cfd89478c Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 3 Oct 2023 20:51:15 +0200 Subject: [PATCH 64/68] Run clang-format --- k4FWCore/components/PodioInput.cpp | 297 ++++++++---------- k4FWCore/components/PodioInput.h | 7 +- k4FWCore/include/k4FWCore/BaseClass.h | 8 +- k4FWCore/include/k4FWCore/DataWrapper.h | 7 +- k4FWCore/include/k4FWCore/PodioDataSvc.h | 21 +- .../components/ExampleFunctionalConsumer.cpp | 19 +- .../ExampleFunctionalConsumerMultiple.cpp | 53 ++-- .../ExampleFunctionalProducerMultiple.cpp | 8 +- .../ExampleFunctionalTransformer.cpp | 2 +- .../ExampleFunctionalTransformerMultiple.cpp | 23 +- .../k4FWCoreTest_CheckExampleEventData.cpp | 3 +- .../k4FWCoreTest_CheckExampleEventData.h | 4 +- 12 files changed, 205 insertions(+), 247 deletions(-) diff --git a/k4FWCore/components/PodioInput.cpp b/k4FWCore/components/PodioInput.cpp index a2d8dab5..9bd0e8ff 100644 --- a/k4FWCore/components/PodioInput.cpp +++ b/k4FWCore/components/PodioInput.cpp @@ -21,194 +21,155 @@ #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/MCParticleCollection.h" #include "edm4hep/MCRecoCaloAssociationCollection.h" -#include "edm4hep/MCRecoTrackerAssociationCollection.h" -#include "edm4hep/MCRecoTrackerHitPlaneAssociationCollection.h" #include "edm4hep/MCRecoClusterParticleAssociationCollection.h" +#include "edm4hep/MCRecoParticleAssociationCollection.h" #include "edm4hep/MCRecoTrackParticleAssociationCollection.h" +#include "edm4hep/MCRecoTrackerAssociationCollection.h" +#include "edm4hep/MCRecoTrackerHitPlaneAssociationCollection.h" +#include "edm4hep/ParticleIDCollection.h" +#include "edm4hep/RawCalorimeterHitCollection.h" +#include "edm4hep/RawTimeSeriesCollection.h" +#include "edm4hep/RecDqdxCollection.h" +#include "edm4hep/RecIonizationClusterCollection.h" #include "edm4hep/RecoParticleVertexAssociationCollection.h" +#include "edm4hep/ReconstructedParticleCollection.h" +#include "edm4hep/SimCalorimeterHitCollection.h" #include "edm4hep/SimPrimaryIonizationClusterCollection.h" -#include "edm4hep/TrackerPulseCollection.h" -#include "edm4hep/RecIonizationClusterCollection.h" +#include "edm4hep/SimTrackerHitCollection.h" #include "edm4hep/TimeSeriesCollection.h" -#include "edm4hep/RecDqdxCollection.h" +#include "edm4hep/TrackCollection.h" +#include "edm4hep/TrackerHitCollection.h" +#include "edm4hep/TrackerHitPlaneCollection.h" +#include "edm4hep/TrackerPulseCollection.h" +#include "edm4hep/VertexCollection.h" #include "podio/UserDataCollection.h" - DECLARE_COMPONENT(PodioInput) -template -inline void PodioInput::maybeRead(std::string_view collName) const { +template inline void PodioInput::maybeRead(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(collName); - }; - m_readers["edm4hep::SimTrackerHitCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::CaloHitContributionCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::SimCalorimeterHitCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::RawCalorimeterHitCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::CalorimeterHitCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::ParticleIDCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::ClusterCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::TrackerHitCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::TrackerHitPlaneCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::RawTimeSeriesCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::TrackCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::VertexCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::ReconstructedParticleCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoParticleAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoCaloAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoTrackerAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoTrackerHitPlaneAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoClusterParticleAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::MCRecoTrackParticleAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::RecoParticleVertexAssociationCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::SimPrimaryIonizationClusterCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::TrackerPulseCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::RecIonizationClusterCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::TimeSeriesCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["edm4hep::RecDqdxCollection"] = - [&](std::string_view collName) { - maybeRead(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; - m_readers["podio::UserDataCollection"] = - [&](std::string_view collName) { - maybeRead>(collName); - }; + m_readers["edm4hep::MCParticleCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::SimTrackerHitCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::CaloHitContributionCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::SimCalorimeterHitCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::RawCalorimeterHitCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::CalorimeterHitCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::ParticleIDCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::ClusterCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::TrackerHitCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::TrackerHitPlaneCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::RawTimeSeriesCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::TrackCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::VertexCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::ReconstructedParticleCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoParticleAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoCaloAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoTrackerAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoTrackerHitPlaneAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoClusterParticleAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::MCRecoTrackParticleAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::RecoParticleVertexAssociationCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::SimPrimaryIonizationClusterCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::TrackerPulseCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::RecIonizationClusterCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::TimeSeriesCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["edm4hep::RecDqdxCollection"] = [&](std::string_view collName) { + maybeRead(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; + m_readers["podio::UserDataCollection"] = [&](std::string_view collName) { + maybeRead>(collName); + }; } PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : Consumer(name, svcLoc) { diff --git a/k4FWCore/components/PodioInput.h b/k4FWCore/components/PodioInput.h index 00f7542d..3a41afc6 100644 --- a/k4FWCore/components/PodioInput.h +++ b/k4FWCore/components/PodioInput.h @@ -43,13 +43,12 @@ class PodioInput final : public Gaudi::Functional::Consumer void operator()() const override; private: - template - void maybeRead(std::string_view collName) const; - void fillReaders(); + template void maybeRead(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; + PodioDataSvc* m_podioDataSvc; mutable std::map> m_readers; }; diff --git a/k4FWCore/include/k4FWCore/BaseClass.h b/k4FWCore/include/k4FWCore/BaseClass.h index 6486216c..3a74a8df 100644 --- a/k4FWCore/include/k4FWCore/BaseClass.h +++ b/k4FWCore/include/k4FWCore/BaseClass.h @@ -8,11 +8,9 @@ // Base class used for the Traits template argument of the // Gaudi::Functional algorithms struct BaseClass_t { - template - using InputHandle = DataObjectReadHandle>; - template - using OutputHandle = DataObjectWriteHandle>; - + template using InputHandle = DataObjectReadHandle>; + template using OutputHandle = DataObjectWriteHandle>; + using BaseClass = Gaudi::Algorithm; }; diff --git a/k4FWCore/include/k4FWCore/DataWrapper.h b/k4FWCore/include/k4FWCore/DataWrapper.h index f8dc6c85..3167bb64 100644 --- a/k4FWCore/include/k4FWCore/DataWrapper.h +++ b/k4FWCore/include/k4FWCore/DataWrapper.h @@ -44,7 +44,7 @@ template class GAUDI_API DataWrapper : public DataWrapperBase { public: DataWrapper() : m_data(nullptr){}; DataWrapper(T&& coll) { - m_data = new T(std::move(coll)); + m_data = new T(std::move(coll)); is_owner = true; } DataWrapper(std::unique_ptr uptr) : m_data(uptr.get()) { @@ -57,9 +57,8 @@ 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; - } + 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/PodioDataSvc.h b/k4FWCore/include/k4FWCore/PodioDataSvc.h index 76d92a1f..5343a034 100644 --- a/k4FWCore/include/k4FWCore/PodioDataSvc.h +++ b/k4FWCore/include/k4FWCore/PodioDataSvc.h @@ -68,17 +68,16 @@ class PodioDataSvc : public DataSvc { 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); + 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/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 45c9983f..bd935840 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -22,16 +22,19 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer #include #include -#include - // Which type of collection we are reading -using FloatColl = podio::UserDataCollection; -using ParticleColl = edm4hep::MCParticleCollection; +using FloatColl = podio::UserDataCollection; +using ParticleColl = edm4hep::MCParticleCollection; using SimTrackerHitColl = edm4hep::SimTrackerHitCollection; -using TrackerHitColl = edm4hep::TrackerHitCollection; -using TrackColl = edm4hep::TrackCollection; - +using TrackerHitColl = edm4hep::TrackerHitCollection; +using TrackColl = edm4hep::TrackCollection; struct ExampleFunctionalConsumerMultiple final - : Gaudi::Functional::Consumer< - void(const FloatColl&, const ParticleColl&, const SimTrackerHitColl&, const TrackerHitColl&, const TrackColl&), BaseClass_t> { + : Gaudi::Functional::Consumer { // 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) @@ -41,50 +40,52 @@ 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 FloatColl& floatVector, - const ParticleColl& particles, const SimTrackerHitColl& simTrackerHits, - const TrackerHitColl& trackerHits, const TrackColl& tracks) const override { + void operator()(const FloatColl& floatVector, const ParticleColl& particles, const SimTrackerHitColl& simTrackerHits, + const TrackerHitColl& trackerHits, const TrackColl& tracks) const override { if (floatVector.size() != 3) { - throw std::runtime_error("Wrong size of floatVector collection, expected 3, got " + std::to_string(floatVector.size()) + ""); + throw std::runtime_error("Wrong size of floatVector collection, expected 3, got " + + std::to_string(floatVector.size()) + ""); } if ((floatVector[0] != 125) || (floatVector[1] != 25) || (floatVector[2] != 0)) { std::stringstream error; - error << "Wrong data in floatVector collection, expected 125, 25, " << 0 << " got " << floatVector[0] << ", " << floatVector[1] << ", " << floatVector[2] << ""; + error << "Wrong data in floatVector collection, expected 125, 25, " << 0 << " got " << floatVector[0] << ", " + << floatVector[1] << ", " << floatVector[2] << ""; throw std::runtime_error(error.str()); } - auto p4 = particles.momentum()[0]; - if ((p4.x != m_magicNumberOffset + 5) || (p4.y != m_magicNumberOffset + 6) || - (p4.z != m_magicNumberOffset + 7) || (particles[0].getMass() != m_magicNumberOffset + 8)) { + auto p4 = particles.momentum()[0]; + if ((p4.x != m_magicNumberOffset + 5) || (p4.y != m_magicNumberOffset + 6) || (p4.z != m_magicNumberOffset + 7) || + (particles[0].getMass() != m_magicNumberOffset + 8)) { std::stringstream error; error << "Wrong data in particles collection, expected " << m_magicNumberOffset + 5 << ", " - << m_magicNumberOffset + 6 << ", " << m_magicNumberOffset + 7 << ", " << - m_magicNumberOffset + 8 << " got " << p4.x << ", " << p4.y << ", " << - p4.z << ", " << particles[0].getMass() << ""; + << m_magicNumberOffset + 6 << ", " << m_magicNumberOffset + 7 << ", " << m_magicNumberOffset + 8 << " got " + << p4.x << ", " << p4.y << ", " << p4.z << ", " << particles[0].getMass() << ""; throw std::runtime_error(error.str()); } if ((simTrackerHits[0].getPosition()[0] != 3) || (simTrackerHits[0].getPosition()[1] != 4) || (simTrackerHits[0].getPosition()[2] != 5)) { std::stringstream error; - error << "Wrong data in simTrackerHits collection, expected 3, 4, 5 got " << simTrackerHits[0].getPosition()[0] << ", " << simTrackerHits[0].getPosition()[1] << ", " << simTrackerHits[0].getPosition()[2] << ""; + error << "Wrong data in simTrackerHits collection, expected 3, 4, 5 got " << simTrackerHits[0].getPosition()[0] + << ", " << simTrackerHits[0].getPosition()[1] << ", " << simTrackerHits[0].getPosition()[2] << ""; throw std::runtime_error(error.str()); } if ((trackerHits[0].getPosition()[0] != 3) || (trackerHits[0].getPosition()[1] != 4) || (trackerHits[0].getPosition()[2] != 5)) { std::stringstream error; - error << "Wrong data in trackerHits collection, expected 3, 4, 5 got " << trackerHits[0].getPosition()[0] << ", " << trackerHits[0].getPosition()[1] << ", " << trackerHits[0].getPosition()[2] << ""; + error << "Wrong data in trackerHits collection, expected 3, 4, 5 got " << trackerHits[0].getPosition()[0] << ", " + << trackerHits[0].getPosition()[1] << ", " << trackerHits[0].getPosition()[2] << ""; throw std::runtime_error(error.str()); } if ((tracks[0].getType() != 1) || (std::abs(tracks[0].getChi2() - 2.1) > 1e-6) || (tracks[0].getNdf() != 3) || (std::abs(tracks[0].getDEdx() - 4.1) > 1e-6) || (std::abs(tracks[0].getDEdxError() - 5.1) > 1e-6) || - (std::abs(tracks[0].getRadiusOfInnermostHit() - 6.1) > 1e-6) - ) { + (std::abs(tracks[0].getRadiusOfInnermostHit() - 6.1) > 1e-6)) { std::stringstream error; - error << "Wrong data in tracks collection, expected 1, 2.1, 3, 4.1, 5.1, 6.1 got " << tracks[0].getType() << ", " << tracks[0].getChi2() << ", " << tracks[0].getNdf() << ", " << tracks[0].getDEdx() << ", " << tracks[0].getDEdxError() << ", " << tracks[0].getRadiusOfInnermostHit() << ""; + error << "Wrong data in tracks collection, expected 1, 2.1, 3, 4.1, 5.1, 6.1 got " << tracks[0].getType() << ", " + << tracks[0].getChi2() << ", " << tracks[0].getNdf() << ", " << tracks[0].getDEdx() << ", " + << tracks[0].getDEdxError() << ", " << tracks[0].getRadiusOfInnermostHit() << ""; throw std::runtime_error(error.str()); } } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index c3476283..fedc87c7 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -18,19 +18,17 @@ using TrackerHit_t = edm4hep::TrackerHitCollection; using Track_t = edm4hep::TrackCollection; struct ExampleFunctionalProducerMultiple final - : Gaudi::Functional::Producer(), + : Gaudi::Functional::Producer(), BaseClass_t> { // The pairs in KeyValue can be changed from python and they correspond // to the names of the output collections ExampleFunctionalProducerMultiple(const std::string& name, ISvcLocator* svcLoc) : Producer( name, svcLoc, - {KeyValue("OutputCollectionFloat", "VectorFloat"), - KeyValue("OutputCollectionParticles1", "MCParticles1"), + {KeyValue("OutputCollectionFloat", "VectorFloat"), KeyValue("OutputCollectionParticles1", "MCParticles1"), KeyValue("OutputCollectionParticles2", "MCParticles2"), KeyValue("OutputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("OutputCollectionTrackerHits", "TrackerHits"), - KeyValue("OutputCollectionTracks", "Tracks")}) {} + KeyValue("OutputCollectionTrackerHits", "TrackerHits"), KeyValue("OutputCollectionTracks", "Tracks")}) {} // This is the function that will be called to produce the data std::tuple operator()() const override { diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index b63a6950..eb7220bc 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -23,7 +23,7 @@ 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_out = edm4hep::MCParticleCollection(); + auto coll_out = edm4hep::MCParticleCollection(); for (const auto& particle : input) { auto new_particle = edm4hep::MutableMCParticle(); new_particle.setPDG(particle.getPDG() + 10); diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 328fc459..8a2f7983 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -13,27 +13,27 @@ #include // Which type of collection we are reading -using FloatColl = podio::UserDataCollection; -using ParticleColl = edm4hep::MCParticleCollection; +using FloatColl = podio::UserDataCollection; +using ParticleColl = edm4hep::MCParticleCollection; using SimTrackerHitColl = edm4hep::SimTrackerHitCollection; -using TrackerHitColl = edm4hep::TrackerHitCollection; -using TrackColl = edm4hep::TrackCollection; +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 = podio::UserDataCollection; using Particle_t = edm4hep::MCParticleCollection; struct ExampleFunctionalTransformerMultiple final - : Gaudi::Functional::MultiTransformer(const FloatColl&, const ParticleColl&, const SimTrackerHitColl&, const TrackerHitColl&, const TrackColl&), + : Gaudi::Functional::MultiTransformer(const FloatColl&, const ParticleColl&, + const SimTrackerHitColl&, + const TrackerHitColl&, const TrackColl&), BaseClass_t> { ExampleFunctionalTransformerMultiple(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( name, svcLoc, - {KeyValue("InputCollectionFloat", "VectorFloat"), - KeyValue("InputCollectionParticles", "MCParticles1"), + {KeyValue("InputCollectionFloat", "VectorFloat"), KeyValue("InputCollectionParticles", "MCParticles1"), KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"), - KeyValue("InputCollectionTrackerHits", "TrackerHits"), - KeyValue("InputCollectionTracks", "Tracks")}, + KeyValue("InputCollectionTrackerHits", "TrackerHits"), KeyValue("InputCollectionTracks", "Tracks")}, {KeyValue("OutputCollectionCounter", "Counter"), KeyValue("OutputCollectionParticles", "NewMCParticles")}) { } @@ -41,8 +41,9 @@ struct ExampleFunctionalTransformerMultiple final // Note that the function has to be const, as well as the collections // we get from the input std::tuple operator()(const FloatColl& floatVector, const ParticleColl& particles, - const SimTrackerHitColl& simTrackerHits, const TrackerHitColl& trackerHits, - const TrackColl& tracks) const override { + const SimTrackerHitColl& simTrackerHits, + const TrackerHitColl& trackerHits, + const TrackColl& tracks) const override { Counter_t counter; counter.push_back(floatVector.size()); diff --git a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp index bff6483f..f4cc99c2 100644 --- a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp +++ b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.cpp @@ -39,8 +39,7 @@ StatusCode k4FWCoreTest_CheckExampleEventData::execute() { auto floatVector = m_vectorFloatHandle.get(); if (floatVector->size() != 3 || (*floatVector)[2] != m_event) { fatal() << "Contents of vectorfloat collection is not as expected: size = " << floatVector->size() - << " (expected 3), contents = " << *floatVector << " (expected [125., 25., " << m_event << "]) " - << endmsg; + << " (expected 3), contents = " << *floatVector << " (expected [125., 25., " << m_event << "]) " << endmsg; // return StatusCode::FAILURE; } diff --git a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h index 7f788bf5..096f6b26 100644 --- a/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h +++ b/test/k4FWCoreTest/src/components/k4FWCoreTest_CheckExampleEventData.h @@ -54,10 +54,10 @@ class k4FWCoreTest_CheckExampleEventData : public GaudiAlgorithm { private: /// integer to add to the dummy values written to the edm - Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, + Gaudi::Property m_magicNumberOffset{this, "magicNumberOffset", 0, "Integer to add to the dummy values written to the edm"}; Gaudi::Property m_keepEventNumberZero{this, "keepEventNumberZero", false, - "Don't add the event number to the dummy values written"}; + "Don't add the event number to the dummy values written"}; /// Handle for the MCParticles to be written DataHandle m_mcParticleHandle{"MCParticles", Gaudi::DataHandle::Reader, this}; DataHandle> m_vectorFloatHandle{"VectorFloat", Gaudi::DataHandle::Reader, this}; From bda0c3c5f6f5f653476b9e33f0f1c6abc6b03e08 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 3 Oct 2023 21:04:18 +0200 Subject: [PATCH 65/68] Fix licenses --- k4FWCore/include/k4FWCore/BaseClass.h | 19 +++++++++++++++++ .../options/runExampleFunctionalConsumer.py | 19 +++++++++++++++++ .../runExampleFunctionalConsumerMultiple.py | 19 +++++++++++++++++ .../options/runExampleFunctionalProducer.py | 19 +++++++++++++++++ .../runExampleFunctionalProducerMultiple.py | 19 +++++++++++++++++ .../runExampleFunctionalTransformer.py | 19 +++++++++++++++++ ...runExampleFunctionalTransformerMultiple.py | 19 +++++++++++++++++ test/k4FWCoreTest/options/runFunctionalMix.py | 21 ++++++++++++++++++- 8 files changed, 153 insertions(+), 1 deletion(-) diff --git a/k4FWCore/include/k4FWCore/BaseClass.h b/k4FWCore/include/k4FWCore/BaseClass.h index 3a74a8df..315106f2 100644 --- a/k4FWCore/include/k4FWCore/BaseClass.h +++ b/k4FWCore/include/k4FWCore/BaseClass.h @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef K4FWCORE_FUNCTIONALUTILS_H #define K4FWCORE_FUNCTIONALUTILS_H diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py index 42db984f..096bfed6 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumer.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example reading from a file and using a consumer with a single input # to check that the contents of the file are the expected ones diff --git a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py index 5d2c0379..48f6ba8b 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalConsumerMultiple.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example reading from a file and using a consumer with several inputs # to check that the contents of the file are the expected ones diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py index 26e8fbfa..410172c4 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducer.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example using a producer with a single output and saving that to a file from Gaudi.Configuration import INFO diff --git a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py index 768fe217..a2be9bed 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalProducerMultiple.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example using a producer with a multiple outputs and saving that to a file from Gaudi.Configuration import INFO diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py index 2e0970e5..8cf19f50 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformer.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example reading from a file and using a consumer with several inputs # to check that the contents of the file are the expected ones diff --git a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py index 1a55c947..0e6a3b88 100644 --- a/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py +++ b/test/k4FWCoreTest/options/runExampleFunctionalTransformerMultiple.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalTransformerMultiple from Configurables import ApplicationMgr diff --git a/test/k4FWCoreTest/options/runFunctionalMix.py b/test/k4FWCoreTest/options/runFunctionalMix.py index 9bf528c6..eae3676f 100644 --- a/test/k4FWCoreTest/options/runFunctionalMix.py +++ b/test/k4FWCoreTest/options/runFunctionalMix.py @@ -1,5 +1,24 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example mixing functional and non-functional algorithms -# +# from Gaudi.Configuration import INFO from Configurables import ExampleFunctionalConsumerMultiple, ExampleFunctionalTransformerMultiple From 86750a46d1747138744ca37a709f4b213b6ff87f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Tue, 3 Oct 2023 21:34:57 +0200 Subject: [PATCH 66/68] Fix remaining licenses --- .../options/runFunctionalChain.py | 19 +++++++++++++++++++ .../components/ExampleFunctionalConsumer.cpp | 19 +++++++++++++++++++ .../ExampleFunctionalConsumerMultiple.cpp | 19 +++++++++++++++++++ .../components/ExampleFunctionalProducer.cpp | 19 +++++++++++++++++++ .../ExampleFunctionalProducerMultiple.cpp | 19 +++++++++++++++++++ .../ExampleFunctionalTransformer.cpp | 19 +++++++++++++++++++ .../ExampleFunctionalTransformerMultiple.cpp | 19 +++++++++++++++++++ 7 files changed, 133 insertions(+) diff --git a/test/k4FWCoreTest/options/runFunctionalChain.py b/test/k4FWCoreTest/options/runFunctionalChain.py index cf512b27..929dc676 100644 --- a/test/k4FWCoreTest/options/runFunctionalChain.py +++ b/test/k4FWCoreTest/options/runFunctionalChain.py @@ -1,3 +1,22 @@ +# +# Copyright (c) 2014-2023 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + # This is an example of how to run several functional algorithms in a chain # The producer produces a collection, the first consumer checks that the collection # is the expected one, the transformer transforms the collection and creates a new diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index bd935840..9bd3273d 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp index 32afb949..8045669c 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumerMultiple.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Consumer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp index f1a066b3..295dead5 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/BaseClass.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index fedc87c7..a972f64c 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Producer.h" #include "k4FWCore/BaseClass.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp index eb7220bc..9762c8e7 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 8a2f7983..932b0e8b 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -1,3 +1,22 @@ +/* + * Copyright (c) 2014-2023 Key4hep-Project. + * + * This file is part of Key4hep. + * See https://key4hep.github.io/key4hep-doc/ for further info. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Gaudi/Property.h" #include "GaudiAlg/Transformer.h" From 550d7c84c1a4840b9dec685557d17b68b324b5b7 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 4 Oct 2023 20:18:16 +0200 Subject: [PATCH 67/68] Fix typedef style --- .../components/ExampleFunctionalConsumer.cpp | 8 +++----- .../components/ExampleFunctionalProducer.cpp | 7 ++----- .../ExampleFunctionalProducerMultiple.cpp | 16 ++++++++-------- .../ExampleFunctionalTransformerMultiple.cpp | 19 +++++++++---------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp index 9bd3273d..c5150aa5 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp @@ -28,10 +28,8 @@ #include #include -// Which type of collection we are reading -using colltype = edm4hep::MCParticleCollection; - -struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer { +struct ExampleFunctionalConsumer final + : Gaudi::Functional::Consumer { // The pair in KeyValue can be changed from python and it corresponds // to the name of the input collection ExampleFunctionalConsumer(const std::string& name, ISvcLocator* svcLoc) @@ -40,7 +38,7 @@ struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer -// Which collection we are producing -using colltype = edm4hep::MCParticleCollection; - -struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { +struct ExampleFunctionalProducer final : Gaudi::Functional::Producer { // The pair in KeyValue can be changed from python and it corresponds // to the name of the output collection ExampleFunctionalProducer(const std::string& name, ISvcLocator* svcLoc) : Producer(name, svcLoc, KeyValue("OutputCollection", "MCParticles")) {} // This is the function that will be called to produce the data - colltype operator()() const override { + edm4hep::MCParticleCollection operator()() const override { auto coll = edm4hep::MCParticleCollection(); coll.push_back({1, 2, 3, 4, 5, 6, {}, {}, {}, {}, {}, {}}); coll.push_back({2, 3, 4, 5, 6, 7, {}, {}, {}, {}, {}, {}}); diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp index a972f64c..2bae590e 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalProducerMultiple.cpp @@ -30,14 +30,14 @@ #include // Which type of collections we are producing -using Float_t = podio::UserDataCollection; -using Particle_t = edm4hep::MCParticleCollection; -using SimTrackerHit_t = edm4hep::SimTrackerHitCollection; -using TrackerHit_t = edm4hep::TrackerHitCollection; -using Track_t = edm4hep::TrackCollection; +using Float = podio::UserDataCollection; +using Particle = edm4hep::MCParticleCollection; +using SimTrackerHit = edm4hep::SimTrackerHitCollection; +using TrackerHit = edm4hep::TrackerHitCollection; +using Track = edm4hep::TrackCollection; struct ExampleFunctionalProducerMultiple final - : Gaudi::Functional::Producer(), + : Gaudi::Functional::Producer(), BaseClass_t> { // The pairs in KeyValue can be changed from python and they correspond // to the names of the output collections @@ -50,7 +50,7 @@ struct ExampleFunctionalProducerMultiple final KeyValue("OutputCollectionTrackerHits", "TrackerHits"), KeyValue("OutputCollectionTracks", "Tracks")}) {} // This is the function that will be called to produce the data - std::tuple operator()() const override { + std::tuple operator()() const override { // The following was copied and adapted from the // k4FWCoreTest_CreateExampleEventData test @@ -92,7 +92,7 @@ struct ExampleFunctionalProducerMultiple final track.addToTrackerHits(trackerHit); track.addToTracks(track2); - return std::make_tuple(std::move(floatVector), std::move(particles), Particle_t(), std::move(simTrackerHits), + return std::make_tuple(std::move(floatVector), std::move(particles), Particle(), std::move(simTrackerHits), std::move(trackerHits), std::move(tracks)); } diff --git a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp index 932b0e8b..83f64b97 100644 --- a/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp +++ b/test/k4FWCoreTest/src/components/ExampleFunctionalTransformerMultiple.cpp @@ -39,13 +39,13 @@ 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 = podio::UserDataCollection; -using Particle_t = edm4hep::MCParticleCollection; +using Counter = podio::UserDataCollection; +using Particle = edm4hep::MCParticleCollection; struct ExampleFunctionalTransformerMultiple final - : Gaudi::Functional::MultiTransformer(const FloatColl&, const ParticleColl&, - const SimTrackerHitColl&, - const TrackerHitColl&, const TrackColl&), + : Gaudi::Functional::MultiTransformer(const FloatColl&, const ParticleColl&, + const SimTrackerHitColl&, const TrackerHitColl&, + const TrackColl&), BaseClass_t> { ExampleFunctionalTransformerMultiple(const std::string& name, ISvcLocator* svcLoc) : MultiTransformer( @@ -59,11 +59,10 @@ 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 FloatColl& floatVector, const ParticleColl& particles, - const SimTrackerHitColl& simTrackerHits, - const TrackerHitColl& trackerHits, - const TrackColl& tracks) const override { - Counter_t counter; + std::tuple operator()(const FloatColl& floatVector, const ParticleColl& particles, + const SimTrackerHitColl& simTrackerHits, const TrackerHitColl& trackerHits, + const TrackColl& tracks) const override { + Counter counter; counter.push_back(floatVector.size()); From 4d03256928a886db5daf304606fd0e41bc43e02a Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 4 Oct 2023 20:27:04 +0200 Subject: [PATCH 68/68] Emphasize message in the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2f41dd7..c00401dd 100644 --- a/README.md +++ b/README.md @@ -92,4 +92,4 @@ have either multiple inputs and / or multiple outputs (like `ExampleFunctionalProducerMultiple`) that can be used as a template for the more typical case when working with multiple inputs or outputs. -`GaudiAlg` is deprecated and will be removed in future versions of Gaudi. +**`GaudiAlg` is deprecated and will be removed in future versions of Gaudi.**