Skip to content

Commit

Permalink
Merge pull request #325 from veprbl/pr/drop_PodioTypeMap
Browse files Browse the repository at this point in the history
drop PodioTypeMap
  • Loading branch information
nathanwbrei authored Jul 30, 2024
2 parents 979ae3b + 27c6cd7 commit 1da0efe
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 88 deletions.
31 changes: 0 additions & 31 deletions src/examples/PodioExample/DatamodelGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,11 @@
#ifndef JANA2_DATAMODELGLUE_H
#define JANA2_DATAMODELGLUE_H

#include <podio/podioVersion.h>

#include <datamodel/ExampleHitCollection.h>
#include <datamodel/ExampleClusterCollection.h>
#include <datamodel/EventInfoCollection.h>
#include <datamodel/TimesliceInfoCollection.h>

/// Legacy PODIO support
template <typename T>
struct PodioTypeMap {
};

template <>
struct PodioTypeMap<ExampleHit> {
using mutable_t = MutableExampleHit;
using collection_t = ExampleHitCollection;
};

template <>
struct PodioTypeMap<ExampleCluster> {
using mutable_t = MutableExampleCluster;
using collection_t = ExampleClusterCollection;
};

template <>
struct PodioTypeMap<EventInfo> {
using mutable_t = MutableEventInfo;
using collection_t = EventInfoCollection;
};

template <>
struct PodioTypeMap<TimesliceInfo> {
using mutable_t = MutableTimesliceInfo;
using collection_t = TimesliceInfoCollection;
};


template<typename ... Ts>
struct Overload : Ts ... {
Expand Down
10 changes: 4 additions & 6 deletions src/libraries/JANA/Omni/JHasInputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#pragma once
#include <JANA/JEvent.h>

template <typename T> struct PodioTypeMap;

namespace jana {
namespace omni {

Expand Down Expand Up @@ -131,7 +129,7 @@ struct JHasInputs {
template <typename PodioT>
class PodioInput : public InputBase {

const typename PodioTypeMap<PodioT>::collection_t* m_data;
const typename PodioT::collection_type* m_data;

public:

Expand All @@ -146,7 +144,7 @@ struct JHasInputs {
Configure(options);
}

const typename PodioTypeMap<PodioT>::collection_t* operator()() {
const typename PodioT::collection_type* operator()() {
return m_data;
}

Expand Down Expand Up @@ -179,7 +177,7 @@ struct JHasInputs {
template <typename PodioT>
class VariadicPodioInput : public InputBase {

std::vector<const typename PodioTypeMap<PodioT>::collection_t*> m_data;
std::vector<const typename PodioT::collection_type*> m_data;

public:

Expand All @@ -196,7 +194,7 @@ struct JHasInputs {
ConfigureVariadic(options);
}

const std::vector<const typename PodioTypeMap<PodioT>::collection_t*> operator()() {
const std::vector<const typename PodioT::collection_type*> operator()() {
return m_data;
}

Expand Down
14 changes: 6 additions & 8 deletions src/libraries/JANA/Omni/JHasOutputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include <JANA/JEvent.h>

template <typename T> struct PodioTypeMap;

namespace jana {
namespace omni {

Expand Down Expand Up @@ -55,7 +53,7 @@ struct JHasOutputs {
template <typename PodioT>
class PodioOutput : public OutputBase {

std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t> m_data;
std::unique_ptr<typename PodioT::collection_type> m_data;

public:

Expand All @@ -65,22 +63,22 @@ struct JHasOutputs {
this->type_name = JTypeInfo::demangle<PodioT>();
}

std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>& operator()() { return m_data; }
std::unique_ptr<typename PodioT::collection_type>& operator()() { return m_data; }

protected:
void InsertCollection(JEvent& event) override {
event.InsertCollection<PodioT>(std::move(*m_data), this->collection_names[0]);
}
void Reset() override {
m_data = std::move(std::make_unique<typename PodioTypeMap<PodioT>::collection_t>());
m_data = std::move(std::make_unique<typename PodioT::collection_type>());
}
};


template <typename PodioT>
class VariadicPodioOutput : public OutputBase {

std::vector<std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>> m_data;
std::vector<std::unique_ptr<typename PodioT::collection_type>> m_data;

public:

Expand All @@ -91,7 +89,7 @@ struct JHasOutputs {
this->is_variadic = true;
}

std::vector<std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>>& operator()() { return m_data; }
std::vector<std::unique_ptr<typename PodioT::collection_type>>& operator()() { return m_data; }

protected:
void InsertCollection(JEvent& event) override {
Expand All @@ -108,7 +106,7 @@ struct JHasOutputs {
void Reset() override {
m_data.clear();
for (auto& coll_name : this->collection_names) {
m_data.push_back(std::make_unique<typename PodioTypeMap<PodioT>::collection_t>());
m_data.push_back(std::make_unique<typename PodioT::collection_type>());
}
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/libraries/JANA/Omni/JOmniFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class JOmniFactory : public JMultifactory, public jana::omni::JHasInputs {
template <typename PodioT>
class PodioOutput : public OutputBase {

std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t> m_data;
std::unique_ptr<typename PodioT::collection_type> m_data;

public:

Expand All @@ -84,7 +84,7 @@ class JOmniFactory : public JMultifactory, public jana::omni::JHasInputs {
this->type_name = JTypeInfo::demangle<PodioT>();
}

std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>& operator()() { return m_data; }
std::unique_ptr<typename PodioT::collection_type>& operator()() { return m_data; }

private:
friend class JOmniFactory;
Expand All @@ -102,15 +102,15 @@ class JOmniFactory : public JMultifactory, public jana::omni::JHasInputs {
}

void Reset() override {
m_data = std::move(std::make_unique<typename PodioTypeMap<PodioT>::collection_t>());
m_data = std::move(std::make_unique<typename PodioT::collection_type>());
}
};


template <typename PodioT>
class VariadicPodioOutput : public OutputBase {

std::vector<std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>> m_data;
std::vector<std::unique_ptr<typename PodioT::collection_type>> m_data;

public:

Expand All @@ -121,7 +121,7 @@ class JOmniFactory : public JMultifactory, public jana::omni::JHasInputs {
this->is_variadic = true;
}

std::vector<std::unique_ptr<typename PodioTypeMap<PodioT>::collection_t>>& operator()() { return m_data; }
std::vector<std::unique_ptr<typename PodioT::collection_type>>& operator()() { return m_data; }

private:
friend class JOmniFactory;
Expand All @@ -146,7 +146,7 @@ class JOmniFactory : public JMultifactory, public jana::omni::JHasInputs {
void Reset() override {
m_data.clear();
for (auto& coll_name : this->collection_names) {
m_data.push_back(std::make_unique<typename PodioTypeMap<PodioT>::collection_t>());
m_data.push_back(std::make_unique<typename PodioT::collection_type>());
}
}
};
Expand Down
9 changes: 0 additions & 9 deletions src/libraries/JANA/Podio/JFactoryPodioT.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
#pragma once

#include <JANA/JFactoryT.h>
#include <podio/podioVersion.h>
#include <podio/Frame.h>

#if podio_VERSION < PODIO_VERSION(0, 17, 0)
template <typename S> struct PodioTypeMap;
#endif

/// The point of this additional base class is to allow us _untyped_ access to the underlying PODIO collection,
/// at the cost of some weird multiple inheritance. The JEvent can trigger the untyped factory using Create(), then
///
Expand Down Expand Up @@ -40,11 +35,7 @@ class JFactoryPodio {
template <typename T>
class JFactoryPodioT : public JFactoryT<T>, public JFactoryPodio {
public:
#if podio_VERSION >= PODIO_VERSION(0, 17, 0)
using CollectionT = typename T::collection_type;
#else
using CollectionT = typename PodioTypeMap<T>::collection_t;
#endif
private:
// mCollection is owned by the frame.
// mFrame is owned by the JFactoryT<podio::Frame>.
Expand Down
13 changes: 0 additions & 13 deletions src/libraries/JANA/Podio/JPodioTypeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,18 @@
#pragma once
#include <type_traits>

#include <podio/podioVersion.h>
#include <JANA/JVersion.h>

/// These allow us to have both a PODIO-enabled and a PODIO-free definition of certain key structures and functions.

#if JANA2_HAVE_PODIO
// Sadly, this will only work with C++17 or higher, and for now JANA still supports C++14 (when not using PODIO)

template <typename T>
struct PodioTypeMap;

template <typename, typename=void>
struct is_podio : std::false_type {};

template <typename T>
#if podio_VERSION >= PODIO_VERSION(0, 17, 0)
struct is_podio<T, std::void_t<typename T::collection_type>> : std::true_type {};
#else
/// The user was expected to provide some datamodel glue which specializes PodioTypeMap like this:
/// template <> struct PodioTypeMap<ExampleHit> {
/// using collection_t = ExampleHitCollection;
/// using mutable_t = MutableExampleHit;
/// }
struct is_podio<T, std::void_t<typename PodioTypeMap<T>::collection_t>> : std::true_type {};
#endif

template <typename T>
static constexpr bool is_podio_v = is_podio<T>::value;
Expand Down
15 changes: 0 additions & 15 deletions src/programs/unit_tests/Components/PodioTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,13 @@ struct MyWrapper {
}
};

#if podio_VERSION < PODIO_VERSION(0, 17, 0)
template <typename T>
struct MyWrapper<T, std::void_t<typename PodioTypeMap<T>::collection_t>> {
int x = 2;
bool have_podio() {
return true;
}
};
#else
template <typename T>
struct MyWrapper<T, std::void_t<typename T::collection_type>> {
int x = 2;
bool have_podio() {
return true;
}
};
#endif

TEST_CASE("SFINAE for JFactoryT || JFactoryPodioT") {

Expand All @@ -86,13 +76,8 @@ TEST_CASE("SFINAE for JFactoryT || JFactoryPodioT") {
template <typename, typename=void>
struct is_podio : std::false_type {};

#if podio_VERSION < PODIO_VERSION(0, 17, 0)
template <typename T>
struct is_podio<T, std::void_t<typename PodioTypeMap<T>::collection_t>> : std::true_type {};
#else
template <typename T>
struct is_podio<T, std::void_t<typename T::collection_type>> : std::true_type {};
#endif

template <typename T>
static constexpr bool is_podio_v = is_podio<T>::value;
Expand Down

0 comments on commit 1da0efe

Please sign in to comment.