Skip to main content

A library for flexible data mapping and transformation using TokaMap compatible mappings

Project description

LibTokaMap

A C++20 library for flexible data mapping and transformation with support for multiple data sources and mapping types.

Overview

LibTokaMap is a flexible mapping library designed to handle complex data transformations through configurable JSON-based mapping definitions. It provides a plugin-based architecture for data sources and supports various mapping types including value mappings, data source mappings, expression mappings, and custom mappings.

Features

  • Multiple Mapping Types: Support for value, data source, expression, dimension, and custom mappings
  • Pluggable Data Sources: Extensible architecture for custom data source implementations
  • JSON Configuration: Human-readable JSON-based mapping definitions
  • Caching Support: Built-in RAM caching for improved performance
  • Type Safety: Strong typing with C++20 features
  • Subset Operations: Advanced data slicing and subsetting capabilities
  • Scale/Offset Transformations: Built-in support for linear data transformations

Building

Requirements

  • C++20 compatible compiler
  • CMake 3.15+
  • nlohmann/json library
  • Pantor/Inja templating engine
  • GSL-lite (Guidelines Support Library)
  • ExprTk expression parsing library

Build Instructions

mkdir build
cd build
cmake .. -DENABLE_TESTING=ON -DENABLE_EXAMPLES=ON
make

CMake Options

  • ENABLE_TESTING: Build unit tests (default: OFF)
  • ENABLE_EXAMPLES: Build example applications (default: OFF)

Usage

Basic Example

#include <libtokamap.hpp>

int main() {
    libtokamap::MappingHandler mapping_handler;

    // Initialize with configuration
    nlohmann::json config = {
        {"mapping_directory", "/path/to/mappings"}
    };
    mapping_handler.init(config);

    // Perform mapping
    std::type_index data_type = std::type_index{typeid(double)};
    int rank = 1;
    nlohmann::json extra_attributes = {{"shot", 12345}};

    auto result = mapping_handler.map(
        "my_mapping",
        "path/to/data",
        data_type,
        rank,
        extra_attributes
    );

    return 0;
}

Custom Data Source

class MyDataSource : public libtokamap::DataSource {
public:
    TypedDataArray get(const DataSourceArgs& map_args,
                      const MapArguments& arguments,
                      RamCache* ram_cache) override {
        // Implement your data retrieval logic
        // Return TypedDataArray with your data
    }
};

// Register the data source
auto data_source = std::make_unique<MyDataSource>();
libtokamap::DataSourceMapping::register_data_source("MY_SOURCE", std::move(data_source));

Mapping Types

Value Mapping

Direct value assignment from JSON configuration.

{
    "map_type": "VALUE",
    "value": 42
}

Data Source Mapping

Retrieves data from registered data sources.

{
    "map_type": "DATA_SOURCE",
    "data_source": "JSON",
    "args": {
        "file": "data.json",
        "path": "measurements.temperature"
    },
    "scale": 1.0,
    "offset": 0.0,
    "slice": "[0:10]"
}

Expression Mapping

Evaluates mathematical expressions.

{
    "map_type": "EXPR",
    "expr": "x * 2 + y",
    "parameters": {
        "x": "path/to/x",
        "y": "path/to/y"
    }
}

Dimension Mapping

Handles array dimension information.

{
    "map_type": "DIMENSION",
    "dim_probe": "array/path"
}

Custom Mapping

User-defined mapping logic.

{
    "map_type": "CUSTOM",
    "custom_type": "my_custom_mapping"
}

Configuration

Mapping Directory Structure

mappings/
├── experiment1/
│   ├── mappings.cfg.json
│   ├── globals.json
│   └── group_name1/
│       └── partition1_0/
│           ├── globals.json
│           └── mappings.json
│       └── partition1_100/
│           ├── globals.json
│           └── mappings.json
│       └── ...
│   └── group_name2/
│       └── ...
└── experiment2/
    └── ...

Configuration File Format

{
    "mapping_directory": "/path/to/mappings",
    "cache_enabled": true,
    "cache_size": 100
}

API Reference

MappingHandler

Main class for handling mapping operations.

Methods

  • void init(const nlohmann::json& config): Initialize with configuration
  • TypedDataArray map(...): Perform mapping operation
  • void reset(): Reset handler state

DataSource

Base class for implementing custom data sources.

Virtual Methods

  • TypedDataArray get(...): Retrieve data from source

Mapping Types

Base classes for different mapping implementations:

  • Mapping: Base mapping interface
  • ValueMapping: Direct value mappings
  • DataSourceMapping: Data source mappings
  • ExprMapping: Expression-based mappings
  • DimMapping: Dimension mappings
  • CustomMapping: User-defined mappings

Utilities

Subset Operations

  • Slice parsing: "[0:10]", "[::2]", "[1:5:2]"
  • Multi-dimensional slicing support
  • Range validation and boundary checking

Scale/Offset Transformations

  • Linear transformations: output = input * scale + offset
  • Applied after data retrieval and slicing

Caching

  • RAM-based caching for frequently accessed data
  • Configurable cache policies
  • Automatic cache invalidation

Examples

See the examples/ directory for complete working examples:

  • simple_mapper/: Basic mapping example with JSON data source

Testing

Run the test suite:

cd build
make test

Version Information

Current version: 0.1.0

Contributing

Code Style

  • Follow C++20 best practices
  • Use clang-format for code formatting
  • Enable all compiler warnings (-Wall -Werror -Wpedantic)

TODO Items

  • Make mapping values case insensitive
  • Remove references to IDSs
  • Replace reinterpret_cast with bit_cast (still exist in map_arguments.hpp)
  • Replace boost::split with std::views::split
  • Switch from using std::type_index to DataType enum?
  • Add exception types
  • Add README and docs for library
  • Tidy up DataSource get(...) arguments
  • Adding system packaging to CMake
  • Make mapping directory nesting configurable
  • Remove SignalType logic
  • Add C++20 template constraints
  • Replace std::string{} with string_literals
  • Fix logging
  • Add tests for parse_slices
  • Replace gsl::span with std::span
  • Handle mismatch of request data type and returned data type, i.e. type conversions?
  • Check returned data against expected rank
  • Add JSON schema files into repo (from IMAS MASTU mapping)
  • Validate JSON mappings on read
  • Use std::format instead of string concatenation

License

See the main project LICENSE file for license information.

Dependencies

  • nlohmann/json: JSON parsing and manipulation
  • Pantor/Inja: Template engine for dynamic content generation
  • ExprTk: Mathematical expression parsing and evaluation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libtokamap-0.2.1-cp314-cp314t-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.14tWindows x86-64

libtokamap-0.2.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libtokamap-0.2.1-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

libtokamap-0.2.1-cp314-cp314t-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14tmacOS 14.0+ ARM64

libtokamap-0.2.1-cp314-cp314t-macosx_13_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14tmacOS 13.0+ x86-64

libtokamap-0.2.1-cp314-cp314-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.14Windows x86-64

libtokamap-0.2.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libtokamap-0.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

libtokamap-0.2.1-cp314-cp314-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

libtokamap-0.2.1-cp314-cp314-macosx_13_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14macOS 13.0+ x86-64

libtokamap-0.2.1-cp313-cp313-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.13Windows x86-64

libtokamap-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

libtokamap-0.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

libtokamap-0.2.1-cp313-cp313-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

libtokamap-0.2.1-cp313-cp313-macosx_13_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

File details

Details for the file libtokamap-0.2.1-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 ba65b771f5efc7e4191244697b26e084270d83ce79b524a00725458776871635
MD5 c7afe92db528255e6e57cfb5e35fd9b1
BLAKE2b-256 aca6cbcc4eb3d6b3288363dc96dddeb28f72086cd807c20b2269857d8a611312

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314t-win_amd64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 42d9d8efac6da43c7ed9aa2ae74f740771003e82eccc2656d7f8f25aa1307fae
MD5 82d208ca76768a2b96c29641d991fb1e
BLAKE2b-256 bb7b75cd2da111bdeffa813c41965813d5daa196bcd6d5fd0f4d0f047027828e

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 354e51ddb3c56672be64ce0d165ad9257b7cbab2a26e9ff3ab8d170be7f96d6c
MD5 bf21051c71493067393d6da8d9e7cdae
BLAKE2b-256 e76cf8ca48d56c512be5c25a6cf696f7d015d4569ccbfe7aeefb7e6b394b713b

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314t-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314t-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 933090d0625e6642627c20a0af67dfd28bc20a3a03867144204d3d8f91e6dfac
MD5 43bbce69a2544779dcddcb3cbb7ee7ad
BLAKE2b-256 31d5c846e20798b424e8bf94128dff76d24657a19648f103c77f625893f8fd96

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314t-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314t-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314t-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 e150a6c678e564ea09109a3d37040141155b7464926dc427aec37f9c787ff192
MD5 70e581c7e4a653afebc776af629524c7
BLAKE2b-256 d414d5d82b2b5e945ec0c75f5a88473a7c57de8d770a644079f741c508247505

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314t-macosx_13_0_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: libtokamap-0.2.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2d0bb53eb50c81ce2cee7a497ccf58dc7c5f00a8725e08122f22e349b9beea57
MD5 804f390aa71544ff92d2db7f6ee01c69
BLAKE2b-256 a710a4c2f3a4b7e65d43585503ccae5d7465fec2b71dac0dcb7b64cbdcdaa665

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314-win_amd64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bde9b6e901a63e860c850f32d6add93ec4a7542ba09e97df7869c039b248961b
MD5 6ac923db3bd10cb8f73734406db8bebe
BLAKE2b-256 f8661829ffc27f61e2fab80d2019f7b7c66dcba60e46d41b66a18819d36fb820

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0756c9ccee65dce765ff0f0cab8c0861278010d845d30d1374ee6ba39b8ff0dc
MD5 5ac902146ab88b87b81440c32be0eee9
BLAKE2b-256 e7e63e82529f2626589b975e818b4c69ad2ae19acea6c1d3fa842e88cdcba2a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 24e00383c1c77ed753c41018d48615c66be49130ff6d922f173b418f5c546fff
MD5 617fe396cd925741674b7b1546dfab79
BLAKE2b-256 b55869750e9996146d7d6fda26137973bd9a6df571720bd0c80a99be8d875852

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp314-cp314-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp314-cp314-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 1d43c66a99164dc3867b031281b66be7c2aba1bf0ac29f7593d59edc437339e6
MD5 82669df6fd0a7473970ca20c18f23a3c
BLAKE2b-256 f5cd893179c165e9084fa02d56144932e862a13d75f7de3e37b016e334a4c9f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp314-cp314-macosx_13_0_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: libtokamap-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for libtokamap-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 072ca94bafcb76881b400480c40c1ce6a94f9203faa96f843a496a29585b21ee
MD5 f55ef1af349b5cb12c4a30b40ac60675
BLAKE2b-256 a66bc301f49a3290f5bc17857e3e3dab70af65cfd423333a310f82a7ff2c648b

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp313-cp313-win_amd64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac1a1bc04c13ea305396eb4891e2bd7ac313f13c16aed9ef194cd44445a54eb1
MD5 c4e9bcc0635b76d8767a6c7b6dff432e
BLAKE2b-256 859b91c1b8e5472114b22bc465f0f3c1bd2b82d2177561ef4e8d636aac45abaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5a079e64e88c110f49610ff74f8d7b2020eb2fd41fe2ffb06749b1a57b93576c
MD5 22370b5d5732d88322be4ca74078bc8a
BLAKE2b-256 fa45d54825106cbe048eb1ccb2ed93e9b13f5a7697779ba1960bb1b7288bbdad

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d6a0bca3dd3be63a96acb2e050e8e548aa6d914e8e3ecf71b0d0767913bcbd2e
MD5 861c00cd323296cd0ee33660467ee620
BLAKE2b-256 916765c45dfc63a4a8826e98bcc52c8ead895487f91d6119f653b0580631feb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libtokamap-0.2.1-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.1-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 f3f92e2e7820cc52aa6501d2708bb6217497dbbde610a8fb8e1b07faee9bc102
MD5 5b8fc09f6e8b17caded95fab2d459b5e
BLAKE2b-256 a419aabf48e0379114b750158c5b560c1c9a43602bc2291a8aa4408cc91e982b

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.1-cp313-cp313-macosx_13_0_x86_64.whl:

Publisher: build_wheels.yml on ukaea/libtokamap

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page