From a716c012af4767c995cc6bb40216fc6bbee29da5 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:03:42 +0200 Subject: [PATCH] Add a header file including all the collections (#606) * Add a header file including all the collections * Add new template to the documentation --------- Co-authored-by: jmcarcell Co-authored-by: tmadlener --- doc/templates.md | 25 +++++++++++++------------ python/podio_gen/cpp_generator.py | 17 +++++++++++++++++ python/templates/CMakeLists.txt | 1 + python/templates/datamodel.h.jinja2 | 10 ++++++++++ 4 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 python/templates/datamodel.h.jinja2 diff --git a/doc/templates.md b/doc/templates.md index 7229c71d3..643d5ea55 100644 --- a/doc/templates.md +++ b/doc/templates.md @@ -26,18 +26,19 @@ Note that some of the information below will only apply to either of these gener Currently PODIO loads templates that are placed in [`/python/templates`](/python/templates). They are broadly split along the classes that are generated for each datatype or component from the EDM definition: -| template file(s) | content | generated file(s) | -|---------------------------------|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------| -| `Component.h.jinja2` | Definition for each component | `[/].h` | -| `Data.h.jinja2` | POD struct of each datatype (living in the POD layer) | `[/]Data.h` | -| `Obj.{h,cc}.jinja2` | `Obj` class for each datatype (living in the object layer) and managing resources | `[/]Obj.h`, `src/Obj.cc` | -| `[Mutable]Object.{h,cc}.jinja2` | The user facing interfaces for each datatype (living in the user layer) | `[/][Mutable].h`, `src/[Mutable].cc` | -| `Collection.{h,cc}.jinja2` | The user facing collection interface (living in the user layer) | `[/]Collection.h`, `src/Collection.cc` | -| `CollectionData.{h,cc}.jinja2` | The classes managing the collection storage (not user facing!) | `[/]CollectionData.h`, `src/CollectionData.cc` | -| `selection.xml.jinja2` | The `selection.xml` file that is necessary for generating a root dictionary for the generated datamodel | `src/selection.xml` | -| `SIOBlock.{h,cc}.jinja2` | The SIO blocks that are necessary for the SIO backend | `[/]SIOBlock.h`, `src/SIOBlock.cc` | -| `MutableStruct.jl.jinja2` | The mutable struct definitions of components and datatypes for julia |`[/]Struct.jl`, `[/]Struct.jl` | -| `ParentModule.jl.jinja2` | The constructor and collection definitions of components and datatypes in the data model are contained within a single module named after the package-name |`[/].jl` | +| template file(s) | content | generated file(s) | +|---------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------| +| `Component.h.jinja2` | Definition for each component | `[/].h` | +| `Data.h.jinja2` | POD struct of each datatype (living in the POD layer) | `[/]Data.h` | +| `Obj.{h,cc}.jinja2` | `Obj` class for each datatype (living in the object layer) and managing resources | `[/]Obj.h`, `src/Obj.cc` | +| `[Mutable]Object.{h,cc}.jinja2` | The user facing interfaces for each datatype (living in the user layer) | `[/][Mutable].h`, `src/[Mutable].cc` | +| `Collection.{h,cc}.jinja2` | The user facing collection interface (living in the user layer) | `[/]Collection.h`, `src/Collection.cc` | +| `CollectionData.{h,cc}.jinja2` | The classes managing the collection storage (not user facing!) | `[/]CollectionData.h`, `src/CollectionData.cc` | +| `datamodel.h.jinja2` | The *full datamodel header* that includes everything of a generated EDM (via including all generated `Collections`). | `[]/.h` | +| `selection.xml.jinja2` | The `selection.xml` file that is necessary for generating a root dictionary for the generated datamodel | `src/selection.xml` | +| `SIOBlock.{h,cc}.jinja2` | The SIO blocks that are necessary for the SIO backend | `[/]SIOBlock.h`, `src/SIOBlock.cc` | +| `MutableStruct.jl.jinja2` | The mutable struct definitions of components and datatypes for julia | `[/]Struct.jl`, `[/]Struct.jl` | +| `ParentModule.jl.jinja2` | The constructor and collection definitions of components and datatypes in the data model are contained within a single module named after the package-name | `[/].jl` | The presence of a `[]` subdirectory for the header files is controlled by the `includeSubfolder` option in the yaml definition file. diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index 079594944..21ec9d97e 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -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): @@ -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( + "datamodel.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() diff --git a/python/templates/CMakeLists.txt b/python/templates/CMakeLists.txt index 503097189..014b4e0bd 100644 --- a/python/templates/CMakeLists.txt +++ b/python/templates/CMakeLists.txt @@ -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}/datamodel.h.jinja2 ${CMAKE_CURRENT_LIST_DIR}/CollectionData.cc.jinja2 ${CMAKE_CURRENT_LIST_DIR}/CollectionData.h.jinja2 ${CMAKE_CURRENT_LIST_DIR}/Component.h.jinja2 diff --git a/python/templates/datamodel.h.jinja2 b/python/templates/datamodel.h.jinja2 new file mode 100644 index 000000000..cf7ee7aea --- /dev/null +++ b/python/templates/datamodel.h.jinja2 @@ -0,0 +1,10 @@ +// AUTOMATICALLY GENERATED FILE - DO NOT EDIT + +#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