diff --git a/src/services/io/podio/JFactoryPodioT.h b/src/services/io/podio/JFactoryPodioT.h index 8ab9d93cbb..d1e1045f9e 100644 --- a/src/services/io/podio/JFactoryPodioT.h +++ b/src/services/io/podio/JFactoryPodioT.h @@ -7,6 +7,7 @@ #include #include +#include #include #include "datamodel_glue.h" @@ -16,7 +17,11 @@ namespace eicrecon { template class JFactoryPodioT : public JFactoryT, public JFactoryPodio { public: +#if podio_VERSION >= PODIO_VERSION(0, 17, 0) + using CollectionT = typename T::collection_type; +#else using CollectionT = typename PodioTypeMap::collection_t; +#endif private: // mCollection is owned by the frame. // mFrame is owned by the JFactoryT. @@ -65,7 +70,7 @@ JFactoryPodioT::~JFactoryPodioT() { } template -void JFactoryPodioT::SetCollection(typename PodioTypeMap::collection_t&& collection) { +void JFactoryPodioT::SetCollection(CollectionT&& collection) { /// Provide a PODIO collection. Note that PODIO assumes ownership of this collection, and the /// collection pointer should be assumed to be invalid after this call @@ -85,7 +90,7 @@ void JFactoryPodioT::SetCollection(typename PodioTypeMap::collection_t&& c template -void JFactoryPodioT::SetCollection(std::unique_ptr::collection_t> collection) { +void JFactoryPodioT::SetCollection(std::unique_ptr collection) { /// Provide a PODIO collection. Note that PODIO assumes ownership of this collection, and the /// collection pointer should be assumed to be invalid after this call @@ -93,7 +98,7 @@ void JFactoryPodioT::SetCollection(std::unique_ptr:: throw JException("JFactoryPodioT: Unable to add collection to frame as frame is missing!"); } this->mFrame->put(std::move(collection), this->GetTag()); - const auto* moved = &this->mFrame->template get::collection_t>(this->GetTag()); + const auto* moved = &this->mFrame->template get(this->GetTag()); this->mCollection = moved; for (const T& item : *moved) { @@ -177,12 +182,12 @@ void JFactoryPodioT::Create(const std::shared_ptr& event) { } catch(...) { if (mCollection == nullptr) { - SetCollection(typename PodioTypeMap::collection_t()); + SetCollection(CollectionT()); } throw; } if (mCollection == nullptr) { - SetCollection(typename PodioTypeMap::collection_t()); + SetCollection(CollectionT()); // If calling Process() didn't result in a call to Set() or SetCollection(), we create an empty collection // so that podio::ROOTFrameWriter doesn't segfault on the null mCollection pointer } @@ -193,7 +198,7 @@ void JFactoryPodioT::Create(const std::shared_ptr& event) { template void JFactoryPodioT::Set(const std::vector& aData) { - typename PodioTypeMap::collection_t collection; + CollectionT collection; if (mIsSubsetCollection) collection.setSubsetCollection(true); for (T* item : aData) { collection.push_back(*item); @@ -203,7 +208,7 @@ void JFactoryPodioT::Set(const std::vector& aData) { template void JFactoryPodioT::Set(std::vector&& aData) { - typename PodioTypeMap::collection_t collection; + CollectionT collection; if (mIsSubsetCollection) collection.setSubsetCollection(true); for (T* item : aData) { collection.push_back(*item); @@ -213,7 +218,7 @@ void JFactoryPodioT::Set(std::vector&& aData) { template void JFactoryPodioT::Insert(T* aDatum) { - typename PodioTypeMap::collection_t collection; + CollectionT collection; if (mIsSubsetCollection) collection->setSubsetCollection(true); collection->push_back(*aDatum); SetCollection(std::move(collection)); diff --git a/src/services/io/podio/make_datamodel_glue.py b/src/services/io/podio/make_datamodel_glue.py index 492bcad556..d45a8252e9 100644 --- a/src/services/io/podio/make_datamodel_glue.py +++ b/src/services/io/podio/make_datamodel_glue.py @@ -78,10 +78,12 @@ def AddCollections(datamodelName, collectionfiles): type_map.append(' class ' + basename + 'Collection;') type_map.append(' class Mutable' + basename + ';') type_map.append('};') + type_map.append('#if podio_VERSION < PODIO_VERSION(0, 17, 0)') type_map.append('template <> struct PodioTypeMap<' + datamodelName + '::' + basename + '> {') type_map.append(' using collection_t = ' + datamodelName + '::' + basename + 'Collection;') type_map.append(' using mutable_t = ' + datamodelName + '::Mutable' + basename + ';') type_map.append('};') + type_map.append('#endif') visitor.append(' if (podio_typename == "' + datamodelName + '::' + basename + 'Collection") {') visitor.append(' return visitor(*reinterpret_cast(&collection));') @@ -112,10 +114,16 @@ def AddCollections(datamodelName, collectionfiles): f.write('#pragma once\n') f.write('\n') f.write('#include \n') + f.write('#include \n') f.write('#include \n') f.write('\n') - f.write('\ntemplate struct PodioTypeMap {};') + f.write('\ntemplate struct PodioTypeMap {') + f.write('\n#if podio_VERSION >= PODIO_VERSION(0, 17, 0)') + f.write('\n using collection_t = typename T::collection_type;') + f.write('\n using mutable_t = typename T::mutable_type;') + f.write('\n#endif') + f.write('\n};') f.write('\n\n') f.write('\n'.join(type_map)) f.write('\n')