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.2-cp314-cp314t-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.14tWindows x86-64

libtokamap-0.2.2-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.2-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.2-cp314-cp314t-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14tmacOS 14.0+ ARM64

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

Uploaded CPython 3.14tmacOS 13.0+ x86-64

libtokamap-0.2.2-cp314-cp314-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.14Windows x86-64

libtokamap-0.2.2-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.2-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.2-cp314-cp314-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.14macOS 13.0+ x86-64

libtokamap-0.2.2-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

libtokamap-0.2.2-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.2-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.2-cp313-cp313-macosx_14_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

libtokamap-0.2.2-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.2-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 824b19f499b8b03428ac0c02b8e6070ed6623a34ccdf1ac916fb53be1f9a0624
MD5 4a33122712f4a0296522a7906d96edc6
BLAKE2b-256 11a3eb284148f013ae4477e671325db936fe067d76f773f9f030cd42675bbad2

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3fd4a10d696da128ad5ca52cd4e683f3a0bcf711090ec1f34cc022c624e89eb1
MD5 c0e5fc3f398e75181cd08796ee0ea108
BLAKE2b-256 c946df5042fece64ac3a88b08f426bd31630092ba2377813755234d2833c8f2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a4d200af558d958e08e6f81055702740c4de67ef867c6f124e6828e096d2a438
MD5 1a60edd3020447b39d3352235259090d
BLAKE2b-256 1c8aab192033f6c4337a714f09a4d8120c1ca84e60162aec4055103f5396a7af

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314t-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314t-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1f03bea14e3c206b6f9e02083ccd02098f6cd90311a6e350fb88a3dbc3c9aa8c
MD5 274eaf31b8deec0f92dc6123d00ba280
BLAKE2b-256 939774944456ee8235d69b6eb35600e164312e3c93742d34100843b4274cc08f

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314t-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314t-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ae455f528ac899339f04348427a4fe15cf1361e6f7c6957ddd01736b379b1a33
MD5 e4ffa71e40fd37804b6dd3857e361582
BLAKE2b-256 a99975fba1eba0f82054d70668d41c4ea2691374d53db627a59d8dd992250db4

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: libtokamap-0.2.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.4 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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b29bc086c2d12e3d5daa4e656d1fd1fc394650d33fbe2a15a14751d78a0a1d30
MD5 ffd58ee3974f0b4ecffe402cf3bfc527
BLAKE2b-256 2dcf052a078f68e43c9f591eccd5706c7a6c15ce77145c6ec9653b2e4c39423c

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3dca1b0b175faa64c945f37487237e8e23ad1af5b3e77ecee8b79da43fc02f4c
MD5 af205aa678b7f07eef1ae4bb42bc90c3
BLAKE2b-256 49aef1788dac60b900b6e5f3eff937f7fcfc2459b710b8a64a9d9e32e087b226

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 76468f864622261603579ee94c8897ce88a3819ba5353d26e8e03500084d5d8d
MD5 ff06f63a17ee59f944c677758118df86
BLAKE2b-256 12e2bf78d70e4a7e64f788bf1217098338d280a2e9323929b8ace92e2d5b85e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aed4cc91de4b6a66e30268ee7ee888de75a15ada43f012f62a5c451fd2a425f8
MD5 7f8c4b24d0ab3e3ed35565794d443e90
BLAKE2b-256 3c6c637292debbdb08ae37f4cb3ce5a63b002fcf050628628e18e1b7a1c0a733

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp314-cp314-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp314-cp314-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 525589cacbbe36803e60a7e52dcee789e8359423a9050f26b100a8ec1082cc04
MD5 f3dd91b442805639c4ae772cb07df4b9
BLAKE2b-256 5ee08da776952d8bbd36aaf5fcc82e17338acdc0d654767c6a2c954d20a324b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: libtokamap-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.4 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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e993fbfa359cd6e4179a48195e25372b4ca16a426781d4d3698ee2d25c51d5b1
MD5 4b1b8765cbb0edd114eec0203882e0ff
BLAKE2b-256 ed60eadf68b7d4e62d04c87904d98fdf590f10f0ef6f1881e4494b541f201787

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9cfb4ff10a10af10eaaa50ff6d4af807b04fa84a0d66b5b819d5fa3a8f1e2cb7
MD5 9b9c5997e0c7812ee4ae2c95f1b508a7
BLAKE2b-256 26e1e0da82f576fdb8f396c5ccbc4b8a230ec444f6ea227c70c88e07e35524f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9beacca28da3b401f4731084d8e403528f8bf17222943e74b390f3dd4aafd54d
MD5 32eff1e8117492696f239a0e3dea5106
BLAKE2b-256 65d00ee99dd5ab93af5248b204cefa27c355d16f62bc8953a4fb121ae0922d57

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f7dac90b75d3b520b24c6c34841471c8292df973c6dc4f1e1226f2b8341bc7c2
MD5 e8a1087e5cb314e261c467c5b4059bbd
BLAKE2b-256 bb20077343954a00fbb90dafa2b57d6d0542f595b1713a79c277fc617f88c706

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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.2-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.2-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 3ce83f64039a4d6b621e59f798427e0f5574d5fbf32540f2e977b0f2a0dc83e2
MD5 b32632788f62c817150f430ba454df64
BLAKE2b-256 e6e0cffeea95f74a0c09815fb153a305b1d9892c20447e0568b52dedfc6bab30

See more details on using hashes here.

Provenance

The following attestation bundles were made for libtokamap-0.2.2-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