Skip to content

Commit

Permalink
Make LinkData an explicit type
Browse files Browse the repository at this point in the history
Makes backwards compatibility easier to achieve
  • Loading branch information
tmadlener committed Sep 23, 2024
1 parent c4f4270 commit 8a43b6e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions include/podio/detail/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class LinkT {

/// Constructor with weight
LinkT(float weight) : m_obj(new LinkObjT{}, podio::utils::MarkOwned) {
m_obj->weight = weight;
m_obj->data.weight = weight;
}

/// Copy constructor
Expand Down Expand Up @@ -89,7 +89,7 @@ class LinkT {
/// original one
template <typename FromU = FromT, typename ToU = ToT, typename = std::enable_if_t<sameTypes<FromU, ToU>>>
MutableLink<FromU, ToU> clone(bool cloneRelations = true) const {
auto tmp = new LinkObjT(podio::ObjectID{}, m_obj->weight);
auto tmp = new LinkObjT(podio::ObjectID{}, m_obj->data);
if (cloneRelations) {
if (m_obj->m_from) {
tmp->m_from = new FromT(*m_obj->m_from);
Expand All @@ -112,13 +112,13 @@ class LinkT {

/// Get the weight of the link
float getWeight() const {
return m_obj->weight;
return m_obj->data.weight;
}

/// Set the weight of the link
template <bool Mut = Mutable, typename = std::enable_if_t<Mut && Mutable>>
void setWeight(float value) {
m_obj->weight = value;
m_obj->data.weight = value;
}

/// Access the related-from object
Expand Down
4 changes: 2 additions & 2 deletions include/podio/detail/LinkCollectionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LinkCollectionData {
m_rel_to(new std::vector<ToT>()),
m_refCollections(std::move(*buffers.references)) {
if (!isSubsetColl) {
m_data.reset(buffers.dataAsVector<float>());
m_data.reset(buffers.dataAsVector<LinkData>());
}
}

Expand Down Expand Up @@ -100,7 +100,7 @@ class LinkCollectionData {

m_data->reserve(entries.size());
for (const auto obj : entries) {
m_data->push_back(obj->weight);
m_data->push_back(obj->data);

if (obj->m_from) {
m_refCollections[0]->emplace_back(obj->m_from->getObjectID());
Expand Down
8 changes: 7 additions & 1 deletion include/podio/detail/LinkFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ class LinkObj;
template <typename FromT, typename ToT>
using LinkObjPointerContainer = std::deque<LinkObj<FromT, ToT>*>;

using LinkDataContainer = std::vector<float>;
/// Simple struct to keep implementation more in line with generated links and
/// to ease evolution of generated links into templated ones
struct LinkData {
float weight{};
};

using LinkDataContainer = std::vector<LinkData>;

template <typename FromT, typename ToT, bool Mutable>
class LinkT;
Expand Down
10 changes: 5 additions & 5 deletions include/podio/detail/LinkObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class LinkObj {

public:
/// Constructor
LinkObj() : id(), weight(0.0f), m_from(nullptr), m_to(nullptr) {
LinkObj() : id(), data(0.0f), m_from(nullptr), m_to(nullptr) {
}

/// Constructor from ObjectID and weight (does not initialize relations yet!)
LinkObj(const podio::ObjectID id_, float weight_) : id(id_), weight(weight_) {
/// Constructor from ObjectID and data (does not initialize relations yet!)
LinkObj(const podio::ObjectID id_, LinkData data_) : id(id_), data(data_) {
}

/// Copy constructor (deep-copy of relations)
LinkObj(const LinkObj& other) : id(), weight(other.weight), m_from(nullptr), m_to(nullptr) {
LinkObj(const LinkObj& other) : id(), data(other.data), m_from(nullptr), m_to(nullptr) {
if (other.m_from) {
m_from = new FromT(*other.m_from);
}
Expand All @@ -43,7 +43,7 @@ class LinkObj {

public:
podio::ObjectID id{};
float weight{1.0f};
LinkData data{1.0f};
FromT* m_from{nullptr};
ToT* m_to{nullptr};
};
Expand Down

0 comments on commit 8a43b6e

Please sign in to comment.