From b2c931793e55739f8c4a3e52618ea9cd176fbe46 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 23 May 2024 19:31:08 +0200 Subject: [PATCH 1/9] Add a header file including all the collections --- python/podio_gen/cpp_generator.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index 079594944..764a0685d 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -89,6 +89,7 @@ def post_process(self, _): self._prepare_iorules() self._create_selection_xml() self._write_cmake_lists_file() + self._write_all_collections_header() def do_process_component(self, name, component): """Handle everything cpp specific after the common processing of a 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 = ( + os.path.basename(f) + for f in self.generated_files + if f.endswith("Collection.h") and "Mutable" not in f + ) + self._write_file( + os.path.join(self.install_dir, self.package_name, "AllCollections.h"), + self._eval_template( + "AllCollections.h.jinja2", + {"includes": collection_files, "incfolder": self.incfolder}, + ), + ) + def _write_edm_def_file(self): """Write the edm definition to a compile time string""" model_encoder = DataModelJSONEncoder() From 480bebc22bbcf6d24cbda6df6c104934bf8ed528 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 23 May 2024 19:39:29 +0200 Subject: [PATCH 2/9] Add missing template --- python/templates/AllCollections.h.jinja2 | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 python/templates/AllCollections.h.jinja2 diff --git a/python/templates/AllCollections.h.jinja2 b/python/templates/AllCollections.h.jinja2 new file mode 100644 index 000000000..a91c408c9 --- /dev/null +++ b/python/templates/AllCollections.h.jinja2 @@ -0,0 +1,5 @@ +// AUTOMATICALLY GENERATED FILE - DO NOT EDIT + +{% for name in includes %} +#include "{{ incfolder }}{{ name }}" +{% endfor %} \ No newline at end of file From 44553069fab2e97125e4a519ec6c214463c1bae6 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Thu, 23 May 2024 19:40:35 +0200 Subject: [PATCH 3/9] Add newline --- python/templates/AllCollections.h.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/templates/AllCollections.h.jinja2 b/python/templates/AllCollections.h.jinja2 index a91c408c9..d5c0f27ad 100644 --- a/python/templates/AllCollections.h.jinja2 +++ b/python/templates/AllCollections.h.jinja2 @@ -2,4 +2,4 @@ {% for name in includes %} #include "{{ incfolder }}{{ name }}" -{% endfor %} \ No newline at end of file +{% endfor %} From 6d97dbd1c1acf04e0819608872180707d93e302d Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Fri, 24 May 2024 10:43:58 +0200 Subject: [PATCH 4/9] Address PR comments --- python/podio_gen/cpp_generator.py | 10 ++++------ python/templates/CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index 764a0685d..a6bde5de4 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -489,13 +489,11 @@ def _write_list(name, target_folder, files, comment): def _write_all_collections_header(self): """Write a header file that includes all collection headers""" - collection_files = ( - os.path.basename(f) - for f in self.generated_files - if f.endswith("Collection.h") and "Mutable" not in f - ) + 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, "AllCollections.h"), + os.path.join( + self.install_dir, self.package_name, f"All{self.package_name}Collections.h" + ), self._eval_template( "AllCollections.h.jinja2", {"includes": collection_files, "incfolder": self.incfolder}, diff --git a/python/templates/CMakeLists.txt b/python/templates/CMakeLists.txt index 503097189..f4b947abc 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}/AllCollections.h.jinja2 ${CMAKE_CURRENT_LIST_DIR}/CollectionData.cc.jinja2 ${CMAKE_CURRENT_LIST_DIR}/CollectionData.h.jinja2 ${CMAKE_CURRENT_LIST_DIR}/Component.h.jinja2 From 8e57faa68e740edca500d43371b6fbca9035618f Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Fri, 24 May 2024 13:54:41 +0200 Subject: [PATCH 5/9] Add a header guard --- python/podio_gen/cpp_generator.py | 6 +++++- python/templates/AllCollections.h.jinja2 | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index a6bde5de4..b48596283 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -496,7 +496,11 @@ def _write_all_collections_header(self): ), self._eval_template( "AllCollections.h.jinja2", - {"includes": collection_files, "incfolder": self.incfolder}, + { + "includes": collection_files, + "incfolder": self.incfolder, + "package_name": self.package_name, + }, ), ) diff --git a/python/templates/AllCollections.h.jinja2 b/python/templates/AllCollections.h.jinja2 index d5c0f27ad..d80b79d18 100644 --- a/python/templates/AllCollections.h.jinja2 +++ b/python/templates/AllCollections.h.jinja2 @@ -1,5 +1,10 @@ // AUTOMATICALLY GENERATED FILE - DO NOT EDIT +#ifndef All{{ package_name }}Collections_H +#define All{{ package_name }}Collections_H + {% for name in includes %} #include "{{ incfolder }}{{ name }}" {% endfor %} + +#endif // All{{ package_name }}Collections_H From b2942e3e6660de374a1aa7fa0bf09184209bcd66 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 11 Jun 2024 15:20:35 +0200 Subject: [PATCH 6/9] Make the generated header name agree with agreed upon convention --- python/podio_gen/cpp_generator.py | 4 +--- python/templates/AllCollections.h.jinja2 | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index b48596283..37799996b 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -491,9 +491,7 @@ def _write_all_collections_header(self): 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"All{self.package_name}Collections.h" - ), + os.path.join(self.install_dir, self.package_name, f"{self.package_name}.h"), self._eval_template( "AllCollections.h.jinja2", { diff --git a/python/templates/AllCollections.h.jinja2 b/python/templates/AllCollections.h.jinja2 index d80b79d18..cf7ee7aea 100644 --- a/python/templates/AllCollections.h.jinja2 +++ b/python/templates/AllCollections.h.jinja2 @@ -1,10 +1,10 @@ // AUTOMATICALLY GENERATED FILE - DO NOT EDIT -#ifndef All{{ package_name }}Collections_H -#define All{{ package_name }}Collections_H +#ifndef {{ package_name.upper() }}_{{ package_name }}_H +#define {{ package_name.upper() }}_{{ package_name }}_H {% for name in includes %} #include "{{ incfolder }}{{ name }}" {% endfor %} -#endif // All{{ package_name }}Collections_H +#endif // {{ package_name.upper() }}_{{ package_name }}_H From 6e8214e87f02b5337093a6ba027621247a02ed8d Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 11 Jun 2024 15:50:23 +0200 Subject: [PATCH 7/9] Make sure that the header is also installed --- python/podio_gen/cpp_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index 37799996b..05a9c625c 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -88,8 +88,8 @@ def post_process(self, _): if "ROOT" in self.io_handlers: self._prepare_iorules() self._create_selection_xml() - self._write_cmake_lists_file() self._write_all_collections_header() + self._write_cmake_lists_file() def do_process_component(self, name, component): """Handle everything cpp specific after the common processing of a component""" From da17465293ed755d15a76d6e1a3b482ea929d0a4 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 11 Jun 2024 21:06:46 +0200 Subject: [PATCH 8/9] Rename template to better reflect generated header name --- python/podio_gen/cpp_generator.py | 2 +- python/templates/CMakeLists.txt | 2 +- .../templates/{AllCollections.h.jinja2 => datamodel.h.jinja2} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename python/templates/{AllCollections.h.jinja2 => datamodel.h.jinja2} (100%) diff --git a/python/podio_gen/cpp_generator.py b/python/podio_gen/cpp_generator.py index 05a9c625c..21ec9d97e 100644 --- a/python/podio_gen/cpp_generator.py +++ b/python/podio_gen/cpp_generator.py @@ -493,7 +493,7 @@ def _write_all_collections_header(self): self._write_file( os.path.join(self.install_dir, self.package_name, f"{self.package_name}.h"), self._eval_template( - "AllCollections.h.jinja2", + "datamodel.h.jinja2", { "includes": collection_files, "incfolder": self.incfolder, diff --git a/python/templates/CMakeLists.txt b/python/templates/CMakeLists.txt index f4b947abc..014b4e0bd 100644 --- a/python/templates/CMakeLists.txt +++ b/python/templates/CMakeLists.txt @@ -1,7 +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 + ${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/AllCollections.h.jinja2 b/python/templates/datamodel.h.jinja2 similarity index 100% rename from python/templates/AllCollections.h.jinja2 rename to python/templates/datamodel.h.jinja2 From 67c9a0c23b6b38afe902b43adf1fe461b827d9d7 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Tue, 11 Jun 2024 21:09:44 +0200 Subject: [PATCH 9/9] Add new template to the documentation --- doc/templates.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) 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.