Draft for Mars2Grib RawEncoders migration #183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
TLDR: Have a look in
multio/mars2grib/Encoder.ccto see the separation of ALLOCATE, PRESET and RUNTIME.This draft is migrating the
ALLOCATEpart from MULTIOM (fortran) to mars2grib (C++).At the moment the mars2grib mapping is mapping to an intermediate configuration which is then passed to MULTIOM.
MULTIOM then sets all GRIB2 keys. This happens through a separation in many
section settersthat are constructed from a partial configuration (which is passed from C++). Each section setters implements multiple methods that set keys in different stages "ALLOCATE" (to set the grib2 structure), "PRESET" (to preset all keys that can be hashed), and "RUNTIME" to set all keys that eventually vary from message to message.The division in these stages is mandatory due to avoid unwanted ECCODES sideeffects. If all keys are set directly, some keys are not found, hence a
cloneis required to maintain a deterministic behaviour.Instead of reimplementing the same structure, the draft aims to separate the mapping from
MARStoGRIB2from the workarounds of setting keys to eccodes - that means the separation in stages should not dominate the overall code structure.This is achieved by created an
structofstructs calledGrib2Layout. TheGrib2Layoutcontains a set of structs which are groups of keys that are always set together. Then themars2grib/Rulesdirectly map to GRIB2 keys instead of an intermediate encoder configuration. As a result, after the mapping all GRIB2 keys that are intended to set are already completely mapped - no further mapping logic is happening afterwards.In a separate step the keys are then set to a grib handle - this happens through 3 hardcoded functions
allocateSample,presetSampleandsetSampleDetails. These functions then only set specific groups of Grib2Keys, resulting in the same setting behaviour as performed in the MULTIOM Fortran code.Benefits:
For now draft serves as show-case for the alternative structure. After discussion it can be split up in multiple PR if desired - however as the intermediate interfacing structure can/must be changed now, in some cases multiple changes are needed all at once.
Contributor Declaration
By opening this pull request, I affirm the following:
🌈🌦️📖🚧 Documentation 🚧📖🌦️🌈
https://sites.ecmwf.int/docs/dev-section/multio/pull-requests/PR-183