podio_gen package

Submodules

podio_gen.cpp_generator module

Podio C++ class / code generator

class podio_gen.cpp_generator.CPPClassGenerator(yamlfile, install_dir, package_name, io_handlers, verbose, dryrun, upstream_edm, old_description, evolution_file)

Bases: ClassGeneratorBaseMixin

The c++ class / code generator for podio

do_process_component(name, component)

Handle everything cpp specific after the common processing of a component

do_process_datatype(name, datatype)

Do the cpp specific processing of a datatype

post_process(_)

Do the cpp specific post processing

pre_process()

The necessary specific pre-processing for cpp code generation

print_report()

Print a summary report about the generated code

class podio_gen.cpp_generator.IncludeFrom(value)

Bases: IntEnum

Enum to signify if an include is needed and from where it should come

EXTERNAL = 2
INTERNAL = 1
NOWHERE = 0
podio_gen.cpp_generator.replace_component_in_paths(oldname, newname, paths)

Replace component name by another one in existing paths

podio_gen.generator_base module

podio class / code generator base functionality

class podio_gen.generator_base.ClassGeneratorBaseMixin(yamlfile, install_dir, package_name, verbose, dryrun, upstream_edm)

Bases: object

Base class for code generation providing common functionality and orchestration

The base class takes care of initializing the common state that is necessary for code generation for the different languages. It reads and valiadates the datamodel and sets up the jinja2 environment. Furthermore it provides the functionality for filling templates and it also does the loop over all the components and datatypes in the datamodel offering hooks (see below) to augment the common processing with language specifics.

The following members are initialized and accessible from inheriting classes

  • yamlfile (the path to the yamlfile)

  • install_dir (top level directory into which the code should be generated)

  • package_name (the name of the package)

  • verbose (whether to print some information about the code gen process)

  • dryrun (whether to actually generate the datamodel or to only run the processing without filling the contents)

  • upstream_edm (an optional upstream datamodel)

  • datamodel (the current datamodel read from the yamlfile)

  • get_syntax (whether to use get syntax or not)

  • incfolder (whether to create an includeSubfolder or not)

  • expose_pod_members (whether or not to expose the pod members)

  • formatter_func (an optional formatting function that is called after the jinja template evaluation but before writing the contents to disk)

  • generated_files (a list of files that have been generated)

  • any_changes (a boolean indicating whether the current run of the code generation led to any changes in the generated code wrt the one that is already present in the output directory)

Inheriting classes need to implement the following (potentially empty) methods:

pre_process() -> dict: does some global pre-processing for the datamodel

before any of the components or datatypes are processed. Needs to return a (potentially) empty dictionary

do_process_component(name: str, component: dict): do some language specific

processing for a component populating the component dictionary further. When called only the “class” key will be populated. This function also has to to take care of filling the necessary templates!

do_process_datatype(name: str, datatype: dict): do some language specific

processing for a datatype populating the datatype dictionary further. When called only the “class” key will be populated. This function also has to take care of filling the necessary templates!

post_process(datamodel: dict): do some global post processing for which all

components and datatypes need to have been processed already. Gets called with the dictionary that has been created in pre_proces and filled during the processing. The process components and datatypes are accessible via the “components” and “datatypes” keys respectively.

print_report(): prints a report summarizing what has been generated

process()

Run the actual generation

podio_gen.generator_base.write_file_if_changed(filename, content, force_write=False)

Write the file contents only if it has changed or if the file does not exist yet. Return whether the file has been written or not

podio_gen.generator_utils module

Module holding some generator utility functions

class podio_gen.generator_utils.DataModel(datatypes=None, components=None, options=None, schema_version=None)

Bases: object

A class for holding a complete datamodel read from a configuration file

class podio_gen.generator_utils.DataModelJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

A JSON encoder for DataModels, resp. anything hat has a _to_json method.

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(o)

The override for the default, first trying to call _to_json, otherwise handing off to the default JSONEncoder

class podio_gen.generator_utils.DataType(klass)

Bases: object

Simple class to hold information about a datatype or component that is defined in the datamodel.

exception podio_gen.generator_utils.DefinitionError

Bases: Exception

Exception raised by the ClassDefinitionValidator for invalid definitions. Mainly here to distinguish it from plain exceptions that are otherwise raised. In this way this makes it possible to selectively catch exceptions related to the datamodel definition without also catching all the rest which might point to another problem

class podio_gen.generator_utils.MemberVariable(name, **kwargs)

Bases: object

Simple class to hold information about a member variable

property docstring

Docstring to be used in code generation

getter_name(get_syntax)

Get the getter name of the variable

getter_return_type(for_array=False)

Get the return type for a getter function for a variable

All types that are builtin will be returned by value, the rest will be returned as const&

Parameters:

for_array (bool, optional) – Whether the type should be for an indexed array access

normalize_fw_type(fw_type)

Normalize the fixed width type and make sure to inclde <cstdint>

setter_name(get_syntax, is_relation=False)

Get the setter name of the variable

property signature

Get the signature for this member variable to be used in function definitions

podio_gen.generator_utils.get_julia_type(cpp_type, is_array=False, array_type=None, array_size=None)

Parse the given c++ type to a Julia type

podio_gen.julia_generator module

podio Julia class / code generator

class podio_gen.julia_generator.JuliaClassGenerator(yamlfile, install_dir, package_name, verbose, dryrun, upstream_edm)

Bases: ClassGeneratorBaseMixin

The julia class / code generator for podio

do_process_component(_, component)

Do the julia specific processing of a component

do_process_datatype(_, datatype)

Do the julia specific processing for a datatype

get_upstream_name()

Get the name of the upstream datamodel if any

post_process(datamodel)

The necessary julia specific post processing

pre_process()

The necessary specific pre-processing for julia code generation

print_report()

Print a summary of the generated code

podio_gen.podio_config_reader module

Datamodel yaml configuration file reading and validation utilities.

class podio_gen.podio_config_reader.ClassDefinitionValidator

Bases: object

Validate the datamodel read from the input yaml file for the most obvious problems.

not_yet_implemented_extra_code = ('declarationFile', 'implementationFile')
not_yet_implemented_keys = ('TransientMembers', 'Typedefs')
required_datatype_keys = ('Description', 'Author')
valid_datatype_member_keys = ('Members', 'VectorMembers', 'OneToOneRelations', 'OneToManyRelations')
valid_extra_code_keys = ('declaration', 'implementation', 'includes')
valid_extra_datatype_keys = ('ExtraCode', 'MutableExtraCode')
classmethod validate(datamodel, upstream_edm=None)

Validate the datamodel.

class podio_gen.podio_config_reader.MemberParser

Bases: object

Class to parse member variables from strings without doing too much validation

array_re = re.compile(' *std::array *< *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9)
array_str = ' *std::array *< *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9:_]*) *, *([0-9]+) *>'
bare_array_re = re.compile(' * *std::array *< *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0)
bare_member_re = re.compile(' *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9:_]*) +([a-zA-Z)
builtin_str = '(?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)'
comment_str = '\\/\\/ *(.*)'
def_val_str = '(?:{(.+)})?'
full_array_re = re.compile(' *std::array *< *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9)
member_re = re.compile(' *((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9:_]*) +([a-zA-Z)
name_re = re.compile('([a-zA-Z_]+\\w*)')
name_str = '([a-zA-Z_]+\\w*)'
parse(string, require_description=True)

Parse the passed string

type_re = re.compile('((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9:_]*)')
type_str = '((?:unsigned long long)|(?:unsigned long)|(?:unsigned int)|(?:long long)|(?:unsigned)|(?:double)|(?:float)|(?:short)|(?:long)|(?:char)|(?:bool)|(?:int)|(?:\\:{2})?[a-zA-Z]+[a-zA-Z0-9:_]*)'
unit_re = re.compile('(?:\\[([a-zA-Z_*\\/]+\\w*)\\])?')
unit_str = '(?:\\[([a-zA-Z_*\\/]+\\w*)\\])?'
class podio_gen.podio_config_reader.PodioConfigReader

Bases: object

Config reader that does basic parsing of the member definitions and puts everything into a somewhat uniform structure without doing any fancy validation

member_parser = <podio_gen.podio_config_reader.MemberParser object>
options = {'exposePODMembers': True, 'getSyntax': False, 'includeSubfolder': False}
classmethod parse_model(model_dict, package_name, upstream_edm=None)

Parse a model from the dictionary, e.g. read from a yaml file.

classmethod read(yamlfile, package_name, upstream_edm=None)

Read the datamodel definition from the yamlfile.

Module contents