From ffe353c8fbef57a9e2fd999eabd671934423b20f Mon Sep 17 00:00:00 2001 From: Sylvester Joosten Date: Mon, 19 Sep 2022 21:11:32 +0000 Subject: [PATCH] Added glue code into Algorithm base class --- .clang-format | 2 +- JugAlgo/JugAlgo/Algorithm.h | 25 +++++++++++--------- JugAlgo/JugAlgo/detail/DataProxy.h | 38 +++++++++++++++++------------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.clang-format b/.clang-format index 5737aca..5c443be 100644 --- a/.clang-format +++ b/.clang-format @@ -9,7 +9,7 @@ SpaceAfterControlStatementKeyword: true PointerBindsToType: true IncludeBlocks: Preserve UseTab: Never -ColumnLimit: 120 +ColumnLimit: 100 NamespaceIndentation: Inner AlignConsecutiveAssignments: true ... diff --git a/JugAlgo/JugAlgo/Algorithm.h b/JugAlgo/JugAlgo/Algorithm.h index ce8b5b8..d441455 100644 --- a/JugAlgo/JugAlgo/Algorithm.h +++ b/JugAlgo/JugAlgo/Algorithm.h @@ -13,9 +13,7 @@ namespace Jug::Algo { -namespace detail { - -} // namespace detail +namespace detail {} // namespace detail template class Algorithm : public GaudiAlgorithm { public: @@ -23,11 +21,17 @@ template class Algorithm : public GaudiAlgorithm { using InputType = typename AlgoType::InputType; using OutputType = typename AlgoType::OutputType; + Algorithm(const std::string& name, ISvcLocator* svcLoc) + : GaudiAlgorithm(name, svcLoc) + , m_input{this, m_algo.inputNames()} + , m_output{this, m_algo.outputNames()} {} + StatusCode initialize() override { debug() << "Initializing " << name() << endmsg; // Forward the log level of this algorithm - const algorithms::LogLevel level{static_cast(msgLevel() > 0 ? msgLevel() - 1 : 0)}; + const algorithms::LogLevel level{ + static_cast(msgLevel() > 0 ? msgLevel() - 1 : 0)}; debug() << "Setting the logger level to " << algorithms::logLevelName(level) << endmsg; m_algo->level(level); @@ -45,7 +49,7 @@ template class Algorithm : public GaudiAlgorithm { } StatusCode execute() override { - ; + m_algo.process(m_input.get(), m_output.get()); return StatusCode::SUCCESS; } @@ -55,16 +59,15 @@ template class Algorithm : public GaudiAlgorithm { template void setAlgoProp(std::string_view name, U&& value) { m_algo.template setProperty(name, value); } - template T getAlgoProp(std::string name) const { return m_algo.template getProperty(name); } + template T getAlgoProp(std::string name) const { + return m_algo.template getProperty(name); + } bool hasAlgoProp(std::string_view name) const { return m_algo.hasProperty(name); } private: - InputType getInput() const {} - - // template - // RefTuple initialize - AlgoType m_algo; + detail::DataProxy m_input; + detail::DataProxy m_output; }; } // namespace Jug::Algo diff --git a/JugAlgo/JugAlgo/detail/DataProxy.h b/JugAlgo/JugAlgo/detail/DataProxy.h index 1d4ed6b..5dc370b 100644 --- a/JugAlgo/JugAlgo/detail/DataProxy.h +++ b/JugAlgo/JugAlgo/detail/DataProxy.h @@ -15,9 +15,9 @@ namespace Jug::Algo::detail { // Generate properties for each of the data arguments template class DataElement { public: - using value_type = - std::conditional_t, algorithms::input_type_t, algorithms::output_type_t>; - using data_type = algorithms::data_type_t; + using value_type = std::conditional_t, algorithms::input_type_t, + algorithms::output_type_t>; + using data_type = algorithms::data_type_t; DataElement(gsl::not_null owner, std::string_view name) : m_owner{owner}, m_data_name(m_owner, name, "") {} @@ -52,9 +52,9 @@ template class DataElement { // Specialization for vectors template class DataElement, kIsInput> { public: - using value_type = - std::conditional_t, algorithms::input_type_t, algorithms::output_type_t>; - using data_type = algorithms::data_type_t; + using value_type = std::conditional_t, algorithms::input_type_t, + algorithms::output_type_t>; + using data_type = algorithms::data_type_t; DataElement(gsl::not_null owner, std::string_view name) : m_owner{owner}, m_data_names(m_owner, name, "") {} @@ -94,7 +94,8 @@ template class DataElement, }; template -auto createElements(GaudiAlgorithm* owner, const NamesArray& names, const Tuple&, std::index_sequence) +auto createElements(GaudiAlgorithm* owner, const NamesArray& names, const Tuple&, + std::index_sequence) -> std::tuple, kIsInput>...> { return {{owner, std::get(names)}...}; } @@ -108,22 +109,27 @@ ReturnTuple getElements(HandleTuple& handles, std::index_sequence) { // Create data handle structure for all members -template class DataProxy { +template class DataProxy { public: - using value_type = Data; - using data_type = typename Data::data_type; - constexpr static size_t kSize = Data::kSize; - using names_type = typename Data::DataNames; - using elements_type = decltype(createElements(std::declval(), names_type(), data_type(), - std::make_index_sequence())); + static constexpr bool kIsInput = algorithms::is_input_v; + using value_type = Data; + using data_type = typename Data::data_type; + constexpr static size_t kSize = Data::kSize; + using names_type = typename Data::DataNames; + using elements_type = + decltype(createElements(std::declval(), names_type(), data_type(), + std::make_index_sequence())); DataProxy(gsl::not_null owner, const names_type& names) : m_owner{owner} - , m_elements{createElements(m_owner, names, data_type(), std::make_index_sequence())} {} + , m_elements{createElements(m_owner, names, data_type(), + std::make_index_sequence())} {} void init() { std::apply([](auto el) { el.init(); }, m_elements); } - value_type get() const { return getElements(m_elements, std::make_index_sequence()); } + value_type get() const { + return getElements(m_elements, std::make_index_sequence()); + } private: GaudiAlgorithm* m_owner;