Skip to content

Commit

Permalink
Add asserts to have error messages when using a disallowed type
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Apr 2, 2024
1 parent adef7e4 commit e8e0ee4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions k4FWCore/include/k4FWCore/Consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace k4FWCore {
: Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_> {
using Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_>::DataHandleMixin;

static_assert(((std::is_base_of_v<podio::CollectionBase, In> || is_map_like<In>::value) && ...),
"Consumer input types must be EDM4hep collections or maps to collections");

template <typename T>
using InputHandle_t = Gaudi::Functional::details::InputHandle_t<Traits_, std::remove_pointer_t<T>>;

Expand All @@ -64,8 +67,7 @@ namespace k4FWCore {
}
std::get<I>(m_inputs) = std::move(h);
},
Gaudi::Details::Property::ImmediatelyInvokeHandler{true}}...}
{}
Gaudi::Details::Property::ImmediatelyInvokeHandler{true}}...} {}

Consumer(std::string name, ISvcLocator* locator,
Gaudi::Functional::details::RepeatValues_<KeyValues, sizeof...(In)> const& inputs)
Expand Down
15 changes: 12 additions & 3 deletions k4FWCore/include/k4FWCore/Transformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ namespace k4FWCore {
: Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_> {
using Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_>::DataHandleMixin;

static_assert(((std::is_base_of_v<podio::CollectionBase, In> || is_map_like<In>::value) && ...),
"Transformer and Producer input types must be EDM4hep collections or maps to collections");
static_assert((std::is_base_of_v<podio::CollectionBase, Out> || is_map_like<Out>::value),
"Transformer and Producer output types must be EDM4hep collections or maps to collections");

template <typename T>
using InputHandle_t = Gaudi::Functional::details::InputHandle_t<Traits_, std::remove_pointer_t<T>>;
template <typename T>
using OutputHandle_t = Gaudi::Functional::details::OutputHandle_t<Traits_, std::remove_pointer_t<T>>;

std::tuple<std::vector<InputHandle_t<typename transformType<In>::type>>...> m_inputs;
std::tuple<std::vector<OutputHandle_t<typename transformType<Out>::type>>> m_outputs;
std::tuple<std::vector<OutputHandle_t<typename transformType<Out>::type>>> m_outputs;
std::array<Gaudi::Property<std::vector<DataObjID>>, sizeof...(In)> m_inputLocations{};
std::array<Gaudi::Property<std::vector<DataObjID>>, 1> m_outputLocations{};

Expand Down Expand Up @@ -115,7 +120,7 @@ namespace k4FWCore {
// }
} else {
Gaudi::Functional::details::put(
std::get<0>(this->m_outputs)[0],
std::get<0>(this->m_outputs)[0],
ptrOrCast(std::move(filter_evtcontext_tt<In...>::apply(*this, ctx, this->m_inputs))));
}
return Gaudi::Functional::FilterDecision::PASSED;
Expand All @@ -136,6 +141,11 @@ namespace k4FWCore {
: Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_> {
using Gaudi::Functional::details::DataHandleMixin<std::tuple<>, std::tuple<>, Traits_>::DataHandleMixin;

static_assert(((std::is_base_of_v<podio::CollectionBase, In> || is_map_like<In>::value) && ...),
"Transformer and Producer input types must be EDM4hep collections or maps to collections");
static_assert(((std::is_base_of_v<podio::CollectionBase, Out> || is_map_like<Out>::value) && ...),
"Transformer and Producer output types must be EDM4hep collections or maps to collections");

template <typename T>
using InputHandle_t = Gaudi::Functional::details::InputHandle_t<Traits_, std::remove_pointer_t<T>>;
template <typename T>
Expand Down Expand Up @@ -191,7 +201,6 @@ namespace k4FWCore {
: MultiTransformer(std::move(name), locator, inputs, std::index_sequence_for<In...>{}, outputs,
std::index_sequence_for<Out...>{}) {}


// derived classes are NOT allowed to implement execute ...
StatusCode execute(const EventContext& ctx) const override final {
try {
Expand Down

0 comments on commit e8e0ee4

Please sign in to comment.