From aa8d4b745c2fe50ff233c89b01e7ae9384af41bc Mon Sep 17 00:00:00 2001 From: tmadlener Date: Fri, 8 Sep 2023 14:03:21 +0200 Subject: [PATCH] Move function implementations into .cc files for Components --- python/podio_class_generator.py | 1 - python/templates/CMakeLists.txt | 1 + python/templates/Component.cc.jinja2 | 39 ++++++++++++++++++++++++++++ python/templates/Component.h.jinja2 | 26 +++---------------- 4 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 python/templates/Component.cc.jinja2 diff --git a/python/podio_class_generator.py b/python/podio_class_generator.py index 5f74a5ad6..c19375d5d 100755 --- a/python/podio_class_generator.py +++ b/python/podio_class_generator.py @@ -209,7 +209,6 @@ def get_fn_format(tmpl): endings = { 'Data': ('h',), - 'Component': ('h',), 'PrintInfo': ('h',) }.get(template_base, ('h', 'cc')) diff --git a/python/templates/CMakeLists.txt b/python/templates/CMakeLists.txt index be5f4b307..76b36354b 100644 --- a/python/templates/CMakeLists.txt +++ b/python/templates/CMakeLists.txt @@ -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 diff --git a/python/templates/Component.cc.jinja2 b/python/templates/Component.cc.jinja2 new file mode 100644 index 000000000..9ab26cd86 --- /dev/null +++ b/python/templates/Component.cc.jinja2 @@ -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) }} + diff --git a/python/templates/Component.h.jinja2 b/python/templates/Component.h.jinja2 index bc775b362..b410c5c8b 100644 --- a/python/templates/Component.h.jinja2 +++ b/python/templates/Component.h.jinja2 @@ -11,7 +11,7 @@ #include #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__) -#include "nlohmann/json.hpp" +#include "nlohmann/json_fwd.hpp" #endif {{ utils.namespace_open(class.namespace) }} @@ -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) }}