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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmacOS 14.0+ ARM64

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

Uploaded CPython 3.14tmacOS 13.0+ x86-64

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.14macOS 13.0+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

libtokamap-0.2.3-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.3-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 14accbd4a92f145b8bc0ea82618a3b1cbcefecf749793488bc8938d82a0ab671
MD5 d5c128cdd231ab90c533f5e4e76b8f1e
BLAKE2b-256 0828c66969bb6c5748ad8848f19e779eb72e57806aabd73f567c61e2ab667b50

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b2e562fa885f2dbec8e7bbfb3825fceedd7e77ab1c048e7aa4adea9faad12eb3
MD5 6ac35c59cad4d87c7735ecb9703e94cb
BLAKE2b-256 e7e0589ace7f7792b02f007d82c6ddfa3b8994364871f67b6fa27ccfaaac254a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2d1c49011540d475cd98f7a1e20b0c20450a02ccf908ead9ff157df7154fc60c
MD5 f3c4b5e6bf34f0eecee12dc3f622cddc
BLAKE2b-256 729727248d6bd2cba2b7bc2065d9ca9127ae59cb9a95d47b2670949a982abc2c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314t-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6fbbd1c09ea68ad0bbd2db0a4a3062f5fcd07cc9e04e3d4630e2a070ff635bbe
MD5 a699b4763cb896ef6bab4bfd37ef2701
BLAKE2b-256 a828ee03c75f4e06b1ee11c208e945130278248a342e4dce7b6a983b5645803f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314t-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 cbe2892204204de8810ceed667a1a9a01d9791e16c33755f522a4d3abe064519
MD5 62d6d2895d907dd93b3fac658f96e1e3
BLAKE2b-256 dcf5136292883fbc875a9664384947713809e94e32220189a978c0a5cd1f1955

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: libtokamap-0.2.3-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.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 e058bcd3fb55406d41cffa4f426128d2fb24df6c9f53e9ca5cd5143ad512666b
MD5 0b69d0f30df5b7fd20b2ec98edc5260b
BLAKE2b-256 2ca7aff26dff175ccf0acf4ea5fe8cbdbb319490f5297394aba68f1424b73d51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 76956bbde91f9e00abd13e53d2df0128033216a2d5455b88badc633d3a01ca7a
MD5 b11a2a874855723cc627333c153ff795
BLAKE2b-256 73d7bb495898a5da8dc30c0cdae8875527662bbb6342943f31d17486f0f31243

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 138a7427f60b1c5dcf95a0878c3e05e44528abb82559f77f27c8899a351b37ba
MD5 b90dcc0d5b5f6ec62c0e4e9d7660d32e
BLAKE2b-256 f6b8237e315571d8316fdc1bd66dc43e71e4fef10d0f1c490e8d98b8a63f86de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1877080ba0d9ec2e21cf5c58bfd1438c379f56991c97f7f92371acb538a4de66
MD5 9c99e9335613ec672f382b40c2ca8fe1
BLAKE2b-256 7d4e176e710e6c60cb535b7e67068960775cb1c7913b7b026b1170819afdc8ce

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp314-cp314-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 40b0d03219635903f2d74762987bc2c8be4b1cd42e0c5fe4afaece9c9d38c9fb
MD5 17019ba56d12ce99eb8e6aeb64332708
BLAKE2b-256 d6143fc2969efeb84892818ec49022ce0c6e99a0cd961549c0f15fe1aa1393dc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: libtokamap-0.2.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3b1772ff458d9236aaf380a2bc5f6edfff3756d4033045e4eb9ab7ce54811c04
MD5 b0fb07f932097389bd431e3e500771b7
BLAKE2b-256 3f6786f16607e6c9bb1a1ebef147969e8a4d65a4ab47524694a369298c7d3120

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5d622b773fa53b1025b60f1dd6f4a1e10d8852ad5baf03721df4c8ceef1ab63
MD5 7119915b82d03a142f42b1e01dbc7687
BLAKE2b-256 1f5cb4ff4f55321e1e5b72562299380d3b2366e89d7194ad6bb716b29ff8372f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 df2fefee05541290f68d09619b77aa33b0cc77cfb4be72d35f1efa6c25980d27
MD5 b58dbc09b9d72f502a6a38655ed90ee0
BLAKE2b-256 3a7f543d4205dea4a1cb178e868899806af33ef72d7fc361a668bccd590c1640

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f84fb42c48dbd0a8bd0a3ff84652a2501a9744abfdf4680cef88a1abd1f9335a
MD5 5f8c27b62d615e6efd1f2fb665c92750
BLAKE2b-256 8c77a41ad59b1c3d0a2ace8d74ff456f5ba23c98bb1d0d2b529b81a7948ad910

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.3-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 e8bf1228b03e53614e494de1ea7d6c356d3edaa26fb41a26d73ba7c66f687586
MD5 aa08889251630448c243a6e826846257
BLAKE2b-256 13ef1e95c10ed7d8f456fbb0f75b874b3220a2272926272d5a6bbadeef168bb1

See more details on using hashes here.

Provenance

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