From cc6da41f9a67aab0dc9a853e18048a2f46c24bbb Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Mon, 21 Oct 2024 21:20:23 +0200 Subject: [PATCH] fix: Make `DataHandle` type check more robust --- Examples/Framework/CMakeLists.txt | 1 + .../ActsExamples/Framework/DataHandle.hpp | 57 ++++++++----------- .../ActsExamples/Framework/Sequencer.hpp | 1 - Examples/Python/CMakeLists.txt | 4 ++ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/Examples/Framework/CMakeLists.txt b/Examples/Framework/CMakeLists.txt index 692db8f2f15..efe06302800 100644 --- a/Examples/Framework/CMakeLists.txt +++ b/Examples/Framework/CMakeLists.txt @@ -13,6 +13,7 @@ add_library( src/Framework/WhiteBoard.cpp src/Framework/RandomNumbers.cpp src/Framework/Sequencer.cpp + src/Framework/DataHandle.cpp src/Utilities/EventDataTransforms.cpp src/Utilities/Paths.cpp src/Utilities/Options.cpp diff --git a/Examples/Framework/include/ActsExamples/Framework/DataHandle.hpp b/Examples/Framework/include/ActsExamples/Framework/DataHandle.hpp index 2aaa469446c..eebe8cae749 100644 --- a/Examples/Framework/include/ActsExamples/Framework/DataHandle.hpp +++ b/Examples/Framework/include/ActsExamples/Framework/DataHandle.hpp @@ -8,11 +8,9 @@ #pragma once -#include "Acts/Utilities/ThrowAssert.hpp" #include "ActsExamples/Framework/SequenceElement.hpp" #include "ActsExamples/Framework/WhiteBoard.hpp" -#include #include #include @@ -54,14 +52,33 @@ class DataHandleBase { std::optional m_key{}; }; -template -class ReadDataHandle; +class WriteDataHandleBase : public DataHandleBase { + protected: + WriteDataHandleBase(SequenceElement* parent, const std::string& name) + : DataHandleBase{parent, name} {} + + public: + void initialize(const std::string& key); + + bool isCompatible(const DataHandleBase& other) const final; +}; + +class ReadDataHandleBase : public DataHandleBase { + protected: + ReadDataHandleBase(SequenceElement* parent, const std::string& name) + : DataHandleBase{parent, name} {} + + public: + void initialize(const std::string& key); + + bool isCompatible(const DataHandleBase& other) const final; +}; template -class WriteDataHandle final : public DataHandleBase { +class WriteDataHandle final : public WriteDataHandleBase { public: WriteDataHandle(SequenceElement* parent, const std::string& name) - : DataHandleBase{parent, name} { + : WriteDataHandleBase{parent, name} { m_parent->registerWriteHandle(*this); } @@ -77,37 +94,17 @@ class WriteDataHandle final : public DataHandleBase { wb.add(m_key.value(), std::move(value)); } - void initialize(const std::string& key) { - if (key.empty()) { - throw std::invalid_argument{"Write handle '" + fullName() + - "' cannot receive empty key"}; - } - m_key = key; - } - - bool isCompatible(const DataHandleBase& other) const override { - return dynamic_cast*>(&other) != nullptr; - } - const std::type_info& typeInfo() const override { return typeid(T); }; }; template -class ReadDataHandle final : public DataHandleBase { +class ReadDataHandle final : public ReadDataHandleBase { public: ReadDataHandle(SequenceElement* parent, const std::string& name) - : DataHandleBase{parent, name} { + : ReadDataHandleBase{parent, name} { m_parent->registerReadHandle(*this); } - void initialize(const std::string& key) { - if (key.empty()) { - throw std::invalid_argument{"Read handle '" + fullName() + - "' cannot receive empty key"}; - } - m_key = key; - } - const T& operator()(const AlgorithmContext& ctx) const { return (*this)(ctx.eventStore); } @@ -120,10 +117,6 @@ class ReadDataHandle final : public DataHandleBase { return wb.get(m_key.value()); } - bool isCompatible(const DataHandleBase& other) const override { - return dynamic_cast*>(&other) != nullptr; - } - const std::type_info& typeInfo() const override { return typeid(T); }; }; diff --git a/Examples/Framework/include/ActsExamples/Framework/Sequencer.hpp b/Examples/Framework/include/ActsExamples/Framework/Sequencer.hpp index 91f229a8c0b..a8f2ad27950 100644 --- a/Examples/Framework/include/ActsExamples/Framework/Sequencer.hpp +++ b/Examples/Framework/include/ActsExamples/Framework/Sequencer.hpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/Examples/Python/CMakeLists.txt b/Examples/Python/CMakeLists.txt index c932b3ef081..0a834ae546f 100644 --- a/Examples/Python/CMakeLists.txt +++ b/Examples/Python/CMakeLists.txt @@ -66,6 +66,10 @@ target_link_libraries( ActsExamplesDetectorTelescope ActsExamplesUtilities ActsExamplesAmbiguityResolution + ActsExamplesTruthTracking + ActsExamplesDigitization + ActsExamplesPropagation + ActsExamplesMaterialMapping ) set(py_files