Skip to content

Commit

Permalink
Added glue code into Algorithm base class
Browse files Browse the repository at this point in the history
  • Loading branch information
sly2j committed Sep 21, 2022
1 parent f6dea6e commit ffe353c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SpaceAfterControlStatementKeyword: true
PointerBindsToType: true
IncludeBlocks: Preserve
UseTab: Never
ColumnLimit: 120
ColumnLimit: 100
NamespaceIndentation: Inner
AlignConsecutiveAssignments: true
...
25 changes: 14 additions & 11 deletions JugAlgo/JugAlgo/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@

namespace Jug::Algo {

namespace detail {

} // namespace detail
namespace detail {} // namespace detail

template <class AlgoImpl> class Algorithm : public GaudiAlgorithm {
public:
using AlgoType = AlgoImpl;
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<algorithms::LogLevel>(msgLevel() > 0 ? msgLevel() - 1 : 0)};
const algorithms::LogLevel level{
static_cast<algorithms::LogLevel>(msgLevel() > 0 ? msgLevel() - 1 : 0)};
debug() << "Setting the logger level to " << algorithms::logLevelName(level) << endmsg;
m_algo->level(level);

Expand All @@ -45,7 +49,7 @@ template <class AlgoImpl> class Algorithm : public GaudiAlgorithm {
}

StatusCode execute() override {
;
m_algo.process(m_input.get(), m_output.get());
return StatusCode::SUCCESS;
}

Expand All @@ -55,16 +59,15 @@ template <class AlgoImpl> class Algorithm : public GaudiAlgorithm {
template <typename T, typename U> void setAlgoProp(std::string_view name, U&& value) {
m_algo.template setProperty<T>(name, value);
}
template <typename T> T getAlgoProp(std::string name) const { return m_algo.template getProperty<T>(name); }
template <typename T> T getAlgoProp(std::string name) const {
return m_algo.template getProperty<T>(name);
}
bool hasAlgoProp(std::string_view name) const { return m_algo.hasProperty(name); }

private:
InputType getInput() const {}

// template <class Function, class RefTuple, std::size_t... I>
// RefTuple initialize

AlgoType m_algo;
detail::DataProxy<InputType> m_input;
detail::DataProxy<OutputType> m_output;
};

} // namespace Jug::Algo
Expand Down
38 changes: 22 additions & 16 deletions JugAlgo/JugAlgo/detail/DataProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace Jug::Algo::detail {
// Generate properties for each of the data arguments
template <class T, bool kIsInput> class DataElement {
public:
using value_type =
std::conditional_t<algorithms::is_input_v<T>, algorithms::input_type_t<T>, algorithms::output_type_t<T>>;
using data_type = algorithms::data_type_t<T>;
using value_type = std::conditional_t<algorithms::is_input_v<T>, algorithms::input_type_t<T>,
algorithms::output_type_t<T>>;
using data_type = algorithms::data_type_t<T>;

DataElement(gsl::not_null<GaudiAlgorithm*> owner, std::string_view name)
: m_owner{owner}, m_data_name(m_owner, name, "") {}
Expand Down Expand Up @@ -52,9 +52,9 @@ template <class T, bool kIsInput> class DataElement {
// Specialization for vectors
template <class T, class A, bool kIsInput> class DataElement<std::vector<T, A>, kIsInput> {
public:
using value_type =
std::conditional_t<algorithms::is_input_v<T>, algorithms::input_type_t<T>, algorithms::output_type_t<T>>;
using data_type = algorithms::data_type_t<T>;
using value_type = std::conditional_t<algorithms::is_input_v<T>, algorithms::input_type_t<T>,
algorithms::output_type_t<T>>;
using data_type = algorithms::data_type_t<T>;

DataElement(gsl::not_null<GaudiAlgorithm*> owner, std::string_view name)
: m_owner{owner}, m_data_names(m_owner, name, "") {}
Expand Down Expand Up @@ -94,7 +94,8 @@ template <class T, class A, bool kIsInput> class DataElement<std::vector<T, A>,
};

template <bool kIsInput, class NamesArray, class Tuple, size_t... I>
auto createElements(GaudiAlgorithm* owner, const NamesArray& names, const Tuple&, std::index_sequence<I...>)
auto createElements(GaudiAlgorithm* owner, const NamesArray& names, const Tuple&,
std::index_sequence<I...>)
-> std::tuple<DataElement<std::tuple_element_t<I, Tuple>, kIsInput>...> {
return {{owner, std::get<I>(names)}...};
}
Expand All @@ -108,22 +109,27 @@ ReturnTuple getElements(HandleTuple& handles, std::index_sequence<I...>) {

// Create data handle structure for all members

template <class Data, bool kIsInput> class DataProxy {
template <class Data> 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<kIsInput>(std::declval<GaudiAlgorithm*>(), names_type(), data_type(),
std::make_index_sequence<kSize>()));
static constexpr bool kIsInput = algorithms::is_input_v<Data>;
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<kIsInput>(std::declval<GaudiAlgorithm*>(), names_type(), data_type(),
std::make_index_sequence<kSize>()));

DataProxy(gsl::not_null<GaudiAlgorithm*> owner, const names_type& names)
: m_owner{owner}
, m_elements{createElements<kIsInput>(m_owner, names, data_type(), std::make_index_sequence<kSize>())} {}
, m_elements{createElements<kIsInput>(m_owner, names, data_type(),
std::make_index_sequence<kSize>())} {}
void init() {
std::apply([](auto el) { el.init(); }, m_elements);
}
value_type get() const { return getElements<value_type>(m_elements, std::make_index_sequence<kSize>()); }
value_type get() const {
return getElements<value_type>(m_elements, std::make_index_sequence<kSize>());
}

private:
GaudiAlgorithm* m_owner;
Expand Down

0 comments on commit ffe353c

Please sign in to comment.