Skip to content

Commit

Permalink
Revert "centralize dynamic columns recovery and use typelist"
Browse files Browse the repository at this point in the history
This reverts commit 6dcf392.
  • Loading branch information
paulgessinger committed Nov 29, 2023
1 parent 4ddf5c3 commit e6b50de
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 94 deletions.
48 changes: 46 additions & 2 deletions Plugins/Podio/include/Acts/Plugins/Podio/PodioTrackContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,52 @@ class ConstPodioTrackContainer : public PodioTrackContainerBase {

populateSurfaceBuffer(m_helper, *m_collection, m_surfaces);

podio_detail::recoverDynamicColumns(frame, tracksKey, m_dynamic,
m_dynamicKeys);
// let's find dynamic columns
// See
// https://github.com/AIDASoft/podio/blob/858c0ff0b841705d1b18aafd57569fcbd1beda91/include/podio/UserDataCollection.h#L30-L31
using types = std::tuple<float, double, int8_t, int16_t, int32_t, int64_t,
uint8_t, uint16_t, uint32_t, uint64_t>;

for (const auto& col : available) {
std::string prefix = tracksKey + "_extra__";
std::size_t p = col.find(prefix);
if (p == std::string::npos) {
continue;
}
std::string dynName = col.substr(prefix.size());
const podio::CollectionBase* coll = frame.get(col);

std::unique_ptr<podio_detail::ConstDynamicColumnBase> up;

std::apply(
[&](auto... args) {
auto inner = [&](auto arg) {
if (up) {
return;
}
using T = decltype(arg);
const auto* dyn =
dynamic_cast<const podio::UserDataCollection<T>*>(coll);
if (dyn == nullptr) {
return;
}
up = std::make_unique<podio_detail::ConstDynamicColumn<T>>(
dynName, *dyn);
};

((inner(args)), ...);
},
types{});

if (!up) {
throw std::runtime_error{"Dynamic column '" + dynName +
"' is not of allowed type"};
}

HashedString hashedKey = hashString(dynName);
m_dynamic.insert({hashedKey, std::move(up)});
m_dynamicKeys.push_back(hashedKey);
}
}

std::any component_impl(HashedString key, IndexType itrack) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,54 @@ class ConstPodioTrackStateContainer final

populateSurfaceBuffer(m_helper, *m_collection, m_surfaces);

podio_detail::recoverDynamicColumns(frame, trackStatesKey, m_dynamic,
m_dynamicKeys);
// let's find dynamic columns

using load_type = std::unique_ptr<podio_detail::DynamicColumnBase> (*)(
const podio::CollectionBase*);

using types =
std::tuple<int32_t, int64_t, uint32_t, uint64_t, float, double>;

for (const auto& col : available) {
std::string prefix = trackStatesKey + "_extra__";
std::size_t p = col.find(prefix);
if (p == std::string::npos) {
continue;
}
std::string dynName = col.substr(prefix.size());
const podio::CollectionBase* coll = frame.get(col);

std::unique_ptr<podio_detail::ConstDynamicColumnBase> up;

std::apply(
[&](auto... args) {
auto inner = [&](auto arg) {
if (up) {
return;
}
using T = decltype(arg);
const auto* dyn =
dynamic_cast<const podio::UserDataCollection<T>*>(coll);
if (dyn == nullptr) {
return;
}
up = std::make_unique<podio_detail::ConstDynamicColumn<T>>(
dynName, *dyn);
};

((inner(args)), ...);
},
types{});

if (!up) {
throw std::runtime_error{"Dynamic column '" + dynName +
"' is not of allowed type"};
}

HashedString hashedKey = hashString(dynName);
m_dynamic.insert({hashedKey, std::move(up)});
m_dynamicKeys.push_back(hashedKey);
}
}

std::vector<Acts::HashedString> dynamicKeys_impl() const {
Expand Down
22 changes: 3 additions & 19 deletions Plugins/Podio/include/Acts/Plugins/Podio/PodioUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@
#include "Acts/EventData/SourceLink.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Plugins/Podio/PodioDynamicColumns.hpp"
#include "Acts/Utilities/HashedString.hpp"
#include "Acts/Utilities/Helpers.hpp"

#include <limits>
#include <memory>

#include <podio/Frame.h>

namespace ActsPodioEdm {
class Surface;
}

namespace Acts {
namespace PodioUtil {
namespace Acts::PodioUtil {

using Identifier = uint64_t;
constexpr Identifier kNoIdentifier = std::numeric_limits<Identifier>::max();
Expand All @@ -47,16 +42,5 @@ std::shared_ptr<const Surface> convertSurfaceFromPodio(

ActsPodioEdm::Surface convertSurfaceToPodio(const ConversionHelper& helper,
const Acts::Surface& surface);
} // namespace PodioUtil

namespace podio_detail {
/// This is used by both the track and track state container, so the
/// implementation is shared here
void recoverDynamicColumns(
const podio::Frame& frame, const std::string& stem,
std::unordered_map<HashedString,
std::unique_ptr<podio_detail::ConstDynamicColumnBase>>&
dynamic,
std::vector<HashedString>& dynamicKeys);
} // namespace podio_detail
} // namespace Acts

} // namespace Acts::PodioUtil
73 changes: 2 additions & 71 deletions Plugins/Podio/src/PodioUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@
#include "Acts/Surfaces/StrawSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/ThrowAssert.hpp"
#include "Acts/Utilities/TypeList.hpp"
#include "ActsPodioEdm/Surface.h"

#include <limits>
#include <memory>

namespace Acts {
namespace PodioUtil {
namespace Acts::PodioUtil {

namespace {
template <typename bounds_t>
Expand Down Expand Up @@ -205,71 +203,4 @@ std::shared_ptr<const Surface> convertSurfaceFromPodio(
return result;
}

} // namespace PodioUtil
namespace podio_detail {

template <typename F, typename... Args>
void apply(F&& f, TypeList<Args...>) {
f(Args{}...);
}

void recoverDynamicColumns(
const podio::Frame& frame, const std::string& stem,
std::unordered_map<HashedString,
std::unique_ptr<podio_detail::ConstDynamicColumnBase>>&
dynamic,
std::vector<HashedString>& dynamicKeys) {
using load_type = std::unique_ptr<podio_detail::DynamicColumnBase> (*)(
const podio::CollectionBase*);

// See
// https://github.com/AIDASoft/podio/blob/858c0ff0b841705d1b18aafd57569fcbd1beda91/include/podio/UserDataCollection.h#L30-L31
using types = TypeList<float, double, int8_t, int16_t, int32_t, int64_t,
uint8_t, uint16_t, uint32_t, uint64_t>;

std::vector<std::string> available = frame.getAvailableCollections();

for (const auto& col : available) {
std::string prefix = stem + "_extra__";
std::size_t p = col.find(prefix);
if (p == std::string::npos) {
continue;
}
std::string dynName = col.substr(prefix.size());
const podio::CollectionBase* coll = frame.get(col);

std::unique_ptr<podio_detail::ConstDynamicColumnBase> up;

apply(
[&](auto... args) {
auto inner = [&](auto arg) {
if (up) {
return;
}
using T = decltype(arg);
const auto* dyn =
dynamic_cast<const podio::UserDataCollection<T>*>(coll);
if (dyn == nullptr) {
return;
}
up = std::make_unique<podio_detail::ConstDynamicColumn<T>>(dynName,
*dyn);
};

((inner(args)), ...);
},
types{});

if (!up) {
throw std::runtime_error{"Dynamic column '" + dynName +
"' is not of allowed type"};
}

HashedString hashedKey = hashString(dynName);
dynamic.insert({hashedKey, std::move(up)});
dynamicKeys.push_back(hashedKey);
}
}

} // namespace podio_detail
} // namespace Acts
} // namespace Acts::PodioUtil

0 comments on commit e6b50de

Please sign in to comment.