Skip to content

Commit

Permalink
Only read / write vector member buffers if they exist with SIO
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 25, 2023
1 parent c0c5a5c commit 5408225
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
20 changes: 11 additions & 9 deletions python/templates/SIOBlock.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ void {{ block_class }}::read(sio::read_device& device, sio::version_type version
}

{% if VectorMembers %}
if (not m_subsetColl) {
{% for member in VectorMembers %}
// auto {{ member.name }}Buffers = new std::vector<{{ member.full_type }}>();
// m_buffers.vectorMembers->emplace_back("{{ member.full_type }}", &{{ member.name }}Buffers);
m_buffers.vectorMembers->emplace_back("{{ member.full_type }}", new std::vector<{{ member.full_type }}>());
m_buffers.vectorMembers->emplace_back("{{ member.full_type }}", new std::vector<{{ member.full_type }}>());
{% endfor %}
//---- read vector members
auto* vecMemInfo = m_buffers.vectorMembers;
unsigned size{0};
//---- read vector members
auto* vecMemInfo = m_buffers.vectorMembers;
unsigned size{0};

{% for member in VectorMembers %}
{{ macros.vector_member_read(member, loop.index0) }}
{% endfor %}
}
{% endif %}
}

Expand All @@ -72,13 +72,15 @@ void {{ block_class }}::write(sio::write_device& device) {
}

{% if VectorMembers %}
//---- write vector members
auto* vecMemInfo = m_buffers.vectorMembers;
unsigned size{0};
if (not m_subsetColl) {
//---- write vector members
auto* vecMemInfo = m_buffers.vectorMembers;
unsigned size{0};

{% for member in VectorMembers %}
{{ macros.vector_member_write(member, loop.index0) }}
{% endfor %}
}
{% endif %}
}

Expand Down
18 changes: 9 additions & 9 deletions python/templates/macros/sioblocks.jinja2
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{% macro vector_member_write(member, index) %}
auto* vec{{ index }} = *reinterpret_cast<std::vector<{{ member.full_type }}>**>(vecMemInfo->at({{ index }}).second);
size = vec{{ index }}->size();
device.data(size);
podio::handlePODDataSIO(device, &(*vec{{ index }})[0], size);
auto* vec{{ index }} = *reinterpret_cast<std::vector<{{ member.full_type }}>**>(vecMemInfo->at({{ index }}).second);
size = vec{{ index }}->size();
device.data(size);
podio::handlePODDataSIO(device, &(*vec{{ index }})[0], size);

{% endmacro %}


{% macro vector_member_read(member, index) %}
auto* vec{{ index }} = reinterpret_cast<std::vector<{{ member.full_type }}>*>(vecMemInfo->at({{ index }}).second);
size = 0u;
device.data(size);
vec{{ index }}->resize(size);
podio::handlePODDataSIO(device, vec{{ index }}->data(), size);
auto* vec{{ index }} = reinterpret_cast<std::vector<{{ member.full_type }}>*>(vecMemInfo->at({{ index }}).second);
size = 0u;
device.data(size);
vec{{ index }}->resize(size);
podio::handlePODDataSIO(device, vec{{ index }}->data(), size);
{% endmacro %}

0 comments on commit 5408225

Please sign in to comment.