Skip to content
New issue

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

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

Already on GitHub? # to your account

Add a header file including all the collections #606

Merged
merged 9 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
17 changes: 17 additions & 0 deletions python/podio_gen/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def post_process(self, _):
if "ROOT" in self.io_handlers:
self._prepare_iorules()
self._create_selection_xml()
self._write_all_collections_header()
self._write_cmake_lists_file()

def do_process_component(self, name, component):
Expand Down Expand Up @@ -485,6 +486,22 @@ def _write_list(name, target_folder, files, comment):
self.any_changes,
)

def _write_all_collections_header(self):
"""Write a header file that includes all collection headers"""

collection_files = (x.split("::")[-1] + "Collection.h" for x in self.datamodel.datatypes)
self._write_file(
os.path.join(self.install_dir, self.package_name, f"{self.package_name}.h"),
self._eval_template(
"AllCollections.h.jinja2",
{
"includes": collection_files,
"incfolder": self.incfolder,
"package_name": self.package_name,
},
),
)

def _write_edm_def_file(self):
"""Write the edm definition to a compile time string"""
model_encoder = DataModelJSONEncoder()
Expand Down
10 changes: 10 additions & 0 deletions python/templates/AllCollections.h.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// AUTOMATICALLY GENERATED FILE - DO NOT EDIT

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we generate include guards here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, although it should not matter much since the headers have their own

#ifndef {{ package_name.upper() }}_{{ package_name }}_H
#define {{ package_name.upper() }}_{{ package_name }}_H

{% for name in includes %}
#include "{{ incfolder }}{{ name }}"
{% endfor %}

#endif // {{ package_name.upper() }}_{{ package_name }}_H
1 change: 1 addition & 0 deletions python/templates/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(PODIO_TEMPLATES
${CMAKE_CURRENT_LIST_DIR}/Collection.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/Collection.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/AllCollections.h.jinja2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nitpicking comment would be to change the name of the jinja2 template as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

${CMAKE_CURRENT_LIST_DIR}/CollectionData.cc.jinja2
${CMAKE_CURRENT_LIST_DIR}/CollectionData.h.jinja2
${CMAKE_CURRENT_LIST_DIR}/Component.h.jinja2
Expand Down