Skip to content

Commit

Permalink
Suggested Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2003Gupta committed Nov 27, 2023
1 parent a22b697 commit 6cdc07e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ tests/src
tests/datamodel
tests/extension_model
tests/datamodeljulia
tests/unittests/Project.toml
tests/unittests/Manifest.toml

# Python
*pyc
Expand Down
4 changes: 2 additions & 2 deletions cmake/podioMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ function(PODIO_GENERATE_DATAMODEL datamodel YAML_FILE RETURN_HEADERS RETURN_SOUR

# Check if the LANG argument is specified and set the language accordingly.
IF(ARG_LANG)
SET(LANGUAGE_ARG "-l=${ARG_LANG}")
SET(LANGUAGE_ARG "--lang=${ARG_LANG}")
ELSE()
SET(LANGUAGE_ARG "-l=cpp") # Default to C++
SET(LANGUAGE_ARG "--lang=cpp") # Default to C++
ENDIF()

SET(SCHEMA_EVOLUTION_ARG "")
Expand Down
10 changes: 4 additions & 6 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ def _process_component(self, name, component):
if self.upstream_edm:
component['upstream_edm_name'] = self.upstream_edm.options["includeSubfolder"].split("/")[-2].capitalize()

if self.proglang == "julia":
self._fill_templates('MutableStruct', component)

if self.proglang == "cpp":
self._fill_templates('Component', component)
# Add potentially older schema for schema evolution
Expand All @@ -336,6 +333,8 @@ def _process_component(self, name, component):
self._fill_templates('Component', component)
self.root_schema_component_names.add(name + self.old_schema_version)

if self.proglang == "julia":
self._fill_templates('MutableStruct', component)
return component

@staticmethod
Expand All @@ -354,9 +353,6 @@ def _process_datatype(self, name, definition):
"""Process one datatype"""
datatype = self._preprocess_datatype(name, definition)

if self.proglang == "julia":
self._fill_templates('MutableStruct', datatype)

if self.proglang == "cpp":
# ROOT schema evolution preparation
# Compute and prepare the potential schema evolution parts
Expand Down Expand Up @@ -399,6 +395,8 @@ def _process_datatype(self, name, definition):
if 'SIO' in self.io_handlers:
self._fill_templates('SIOBlock', datatype)

if self.proglang == "julia":
self._fill_templates('MutableStruct', datatype)
return datatype

def prepare_iorules(self):
Expand Down
4 changes: 2 additions & 2 deletions python/templates/MutableStruct.jl.jinja2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% import "macros/params.jinja2" as params %}
mutable struct {{ class.bare_type }}Struct{{ params.julia_parameters(params_jl,"T" ) }}
{% import "macros/julia_helpers.jinja2" as julia_helpers %}
mutable struct {{ class.bare_type }}Struct{{ julia_helpers.julia_parameters(params_jl,"T" ) }}
{% for member in Members %}
{% if member.is_array %}
{% if not member.is_builtin_array and upstream_edm and (member.array_type in upstream_edm.components or member.array_type in upstream_edm.datatypes) %}
Expand Down
24 changes: 15 additions & 9 deletions python/templates/ParentModule.jl.jinja2
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% import "macros/params.jinja2" as params %}
{% import "macros/abstracttypes.jinja2" as abstdatatype %}
{% import "macros/julia_helpers.jinja2" as julia_helpers %}
{% if upstream_edm %}
include("{{ upstream_edm.options["includeSubfolder"] }}{{ upstream_edm_name }}.jl")
{% endif %}
Expand All @@ -18,7 +17,14 @@ import ..{{ upstream_edm_name }}
{% endif %}

{% if static_arrays_import %}
using StaticArrays
try
using StaticArrays
catch
import Pkg
Pkg.activate(@__DIR__)
Pkg.add("StaticArrays")
using StaticArrays
end
{% endif %}
{% for sort_include in includes %}
include("{{ sort_include }}Struct.jl")
Expand All @@ -38,7 +44,7 @@ function {{ component['class'].bare_type }}(
{% endif %}
{% endif %}
{% elif member.is_builtin %}
{{ member.name }}::{{ abstdatatype.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0),
{{ member.name }}::{{ julia_helpers.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0),
{% else %}
{% if upstream_edm and (member.full_type in upstream_edm.components or member.full_type in upstream_edm.datatypes) %}
{{ member.name }}::{{ upstream_edm_name }}.{{ member.julia_type }}Struct = {{ upstream_edm_name }}.{{ member.julia_type }}(),
Expand All @@ -48,7 +54,7 @@ function {{ component['class'].bare_type }}(
{% endif %}
{% endfor %}
)
return {{ component['class'].bare_type }}Struct{{ params.julia_parameters(component['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}(
return {{ component['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(component['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}(
{% for member in component['Members'] %}
{% if member.is_builtin %}
{{ member.julia_type }}({{ member.name }}),
Expand All @@ -75,7 +81,7 @@ function {{ datatype['class'].bare_type }}(
{% endif %}
{% endif %}
{% elif member.is_builtin %}
{{ member.name }}::{{ abstdatatype.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0),
{{ member.name }}::{{ julia_helpers.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0),
{% else %}
{% if upstream_edm and (member.full_type in upstream_edm.components or member.full_type in upstream_edm.datatypes) %}
{{ member.name }}::{{ upstream_edm_name }}.{{ member.julia_type }}Struct = {{ upstream_edm_name }}.{{ member.julia_type }}(),
Expand Down Expand Up @@ -115,13 +121,13 @@ function {{ datatype['class'].bare_type }}(
where {{ structure_start -}}
{% for member in datatype['VectorMembers'] %}
{% if member.is_builtin %}
{{ member.name }}T<:{{ abstdatatype.classify_data_type(member.julia_type) }}{% if not loop.last %},{% endif %}
{{ member.name }}T<:{{ julia_helpers.classify_data_type(member.julia_type) }}{% if not loop.last %},{% endif %}
{% endif %}
{% endfor -%}
{{ structure_end }}
{% endif %}

return {{ datatype['class'].bare_type }}Struct{{ params.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}(
return {{ datatype['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}(
{% for member in datatype['Members'] %}
{% if member.is_builtin %}
{{ member.julia_type }}({{ member.name }}),
Expand All @@ -145,7 +151,7 @@ function {{ datatype['class'].bare_type }}(
)
end

{{ datatype['class'].bare_type }}Collection = Vector{ {{ datatype['class'].bare_type }}Struct{{ params.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }} }
{{ datatype['class'].bare_type }}Collection = Vector{ {{ datatype['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }} }

{% endfor %}
end
17 changes: 0 additions & 17 deletions python/templates/macros/abstracttypes.jinja2

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{% macro classify_data_type(data_type) %}
{%- set type_map = {
'Int8': 'Integer',
'UInt8': 'Integer',
'Int16': 'Integer',
'UInt16': 'Integer',
'Int32': 'Integer',
'UInt32': 'Integer',
'Int64': 'Integer',
'UInt64': 'Integer',
'Float16': 'Real',
'Float32': 'Real',
'Float64': 'Real'
} -%}

{{ type_map.get(data_type, data_type) }}
{%- endmacro -%}


{% macro julia_parameters(params, suffix, upstream_edm=None, upstream_edm_name=None) %}
{%- if params -%}{
{%- set comma = joiner(',') -%}
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ PODIO_GENERATE_DATAMODEL(extensionmodeljulia datalayout_extension.yaml ext_heade
find_program(Julia_EXECUTABLE julia)
if (Julia_EXECUTABLE)
message(STATUS "Found Julia, will add the Julia tests")
add_test(NAME julia-unittests COMMAND julia unittest.jl)
set(UNITTEST_SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/unittests/unittest.jl)
add_test(NAME julia-unittests COMMAND julia ${UNITTEST_SCRIPT_PATH})
set_tests_properties(julia-unittests PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
Expand Down
3 changes: 1 addition & 2 deletions tests/unittest.jl → tests/unittests/unittest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ catch
Pkg.add("StaticArrays")
using StaticArrays
end

# datamodeljulia/Datamodeljulia.jl file included inside extension_model/extensionmodeljulia/Extensionmodeljulia.jl file
include("extension_model/extensionmodeljulia/Extensionmodeljulia.jl")
include("../extension_model/extensionmodeljulia/Extensionmodeljulia.jl")
using .Datamodeljulia
using .Extensionmodeljulia
using Test
Expand Down

0 comments on commit 6cdc07e

Please sign in to comment.