Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce unnecessary template instantiations #477

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def get_fn_format(tmpl):

endings = {
'Data': ('h',),
'Component': ('h',),
'PrintInfo': ('h',)
}.get(template_base, ('h', 'cc'))

Expand Down
1 change: 1 addition & 0 deletions python/templates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(PODIO_TEMPLATES
${CMAKE_CURRENT_LIST_DIR}/CollectionData.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/CollectionData.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Component.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Component.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/Data.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Obj.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Obj.cc.jinja2
Expand Down
4 changes: 4 additions & 0 deletions python/templates/Collection.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{{ include }}
{% endfor %}

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#endif

// standard includes
#include <stdexcept>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion python/templates/Collection.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "podio/CollectionIDTable.h"

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"
#endif

#include <string>
Expand Down
39 changes: 39 additions & 0 deletions python/templates/Component.cc.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% import "macros/utils.jinja2" as utils %}
// AUTOMATICALLY GENERATED FILE - DO NOT EDIT

#include "{{ incfolder }}{{ class.bare_type }}.h"

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#endif

{{ utils.namespace_open(class.namespace) }}

std::ostream& operator<<(std::ostream& o, const {{class.full_type}}& value) {
{% for member in Members %}
{% if member.is_array %}
for (int i = 0; i < {{ member.array_size }}; ++i) {
o << value.{{ member.name }}[i] << "|";
}
o << " ";
{% else %}
o << value.{{ member.name }} << " ";
{% endif %}
{% endfor %}

return o;
}

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
void to_json(nlohmann::json& j, const {{ class.bare_type }}& value) {
j = nlohmann::json{
{% set comma = joiner(",") %}
{% for member in Members %}
{{ comma() }}{"{{ member.name }}", value.{{ member.name }}}
{% endfor %}
};
}
#endif

{{ utils.namespace_close(class.namespace) }}

26 changes: 3 additions & 23 deletions python/templates/Component.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <ostream>

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#include "nlohmann/json_fwd.hpp"
#endif

{{ utils.namespace_open(class.namespace) }}
Expand All @@ -25,30 +25,10 @@ public:
{{ utils.if_present(ExtraCode, "declaration") }}
};

inline std::ostream& operator<<(std::ostream& o, const {{class.full_type}}& value) {
{% for member in Members %}
{% if member.is_array %}
for (int i = 0; i < {{ member.array_size }}; ++i) {
o << value.{{ member.name }}[i] << "|";
}
o << " ";
{% else %}
o << value.{{ member.name }} << " ";
{% endif %}
{% endfor %}

return o;
}
std::ostream& operator<<(std::ostream& o, const {{class.full_type}}& value);

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
inline void to_json(nlohmann::json& j, const {{ class.bare_type }}& value) {
j = nlohmann::json{
{% set comma = joiner(",") %}
{% for member in Members %}
{{ comma() }}{"{{ member.name }}", value.{{ member.name }}}
{% endfor %}
};
}
void to_json(nlohmann::json& j, const {{ class.bare_type }}& value);
#endif

{{ utils.namespace_close(class.namespace) }}
Expand Down
4 changes: 4 additions & 0 deletions python/templates/MutableObject.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{{ include }}
{% endfor %}

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#endif

#include <ostream>

{{ utils.namespace_open(class.namespace) }}
Expand Down
4 changes: 2 additions & 2 deletions python/templates/MutableObject.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <ostream>
#include <cstddef>

#ifdef PODIO_JSON_OUTPUT
#include "nlohmann/json.hpp"
#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json_fwd.hpp"
#endif

{{ utils.forward_decls(forward_declarations) }}
Expand Down
4 changes: 4 additions & 0 deletions python/templates/Object.cc.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
{{ include }}
{% endfor %}

#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json.hpp"
#endif

#include <ostream>

{{ utils.namespace_open(class.namespace) }}
Expand Down
4 changes: 2 additions & 2 deletions python/templates/Object.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <ostream>
#include <cstddef>

#ifdef PODIO_JSON_OUTPUT
#include "nlohmann/json.hpp"
#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
#include "nlohmann/json_fwd.hpp"
#endif

{{ utils.forward_decls(forward_declarations) }}
Expand Down
2 changes: 1 addition & 1 deletion python/templates/macros/declarations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
{%- endmacro %}

{% macro json_output(type, prefix='') %}
#ifdef PODIO_JSON_OUTPUT
#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
void to_json(nlohmann::json& j, const {{ prefix }}{{ type }}& value);
#endif
{% endmacro %}
2 changes: 1 addition & 1 deletion python/templates/macros/implementations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ std::ostream& operator<<(std::ostream& o, const {{ type }}& value) {
{%- endmacro %}

{% macro json_output(class, members, single_relations, multi_relations, vector_members, get_syntax, prefix='') %}
#ifdef PODIO_JSON_OUTPUT
#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
void to_json(nlohmann::json& j, const {{ prefix }}{{ class.bare_type }}& value) {
j = nlohmann::json{
{% set comma = joiner(",") %}
Expand Down
Loading