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

Uploaded CPython 3.14tWindows x86-64

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

Uploaded CPython 3.14tmacOS 14.0+ ARM64

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

Uploaded CPython 3.14tmacOS 13.0+ x86-64

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

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.14macOS 13.0+ x86-64

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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

libtokamap-0.2.0-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.0-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 6d1ec62927d2ec5ee5497f9155d0038234432e35e34e5e56e954300707610677
MD5 d8c6528193b8a706fc23c3bb114b5fda
BLAKE2b-256 7585f8a8b2ee0fd021c9569e1abc04b307c44be394eb27e12f058c2c97204a30

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c77848ca1f203f2e9a64fccdd0619f5ae9e77ee714c37e48564fbd1c83fed443
MD5 f8126580b014e590d2661513140e162b
BLAKE2b-256 89702bc398b96cffb669dea1e118e635c32a44c4f0e44a40bbc11d59764e682b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 92bc82ccb94edc32bfc609950b12456d9579703f3e294247b824cab036e5ee56
MD5 0f285aaa62237ea6749b7d349aae8685
BLAKE2b-256 f8d67afef3296b32c904c674b85728aee4996ca0aadf19500b0f11e2a265d3f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314t-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2820b3a1b5d623b13b49cdce6a1c0f69ee0f346e1f0cb0d00a72d33266bfcd79
MD5 8f8947c93ede40da1bb461b5dad48f3a
BLAKE2b-256 06c5f29802d0d6dd12922c6a16361fa9d7cd945186b18c826e5df633fc9eab1b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314t-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 1727b345b44d92e4cba56dbde1ce078ff1263449f641c23ff83edeb8259e67e9
MD5 c514b264cad87e8baf2b4cfca139335a
BLAKE2b-256 e079e1ef9d21e174f3f92d41887e94b7e223f04fc338e1e46c34e65a603af597

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: libtokamap-0.2.0-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.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 2ce3f57a5862863d0da24491b438286a773e6f1a5a50ffc91aa182fcecf8c37d
MD5 a630b0e95c6ad0041824bc00aadaed59
BLAKE2b-256 69a2cdeef373816f83827755082490e9609285baa9e4ea232a5f12c6497fb9b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6febed81baa5b492f2e8d44da7d3c5b1df8e6b542556dc621b473d282eaeaee2
MD5 6508ee128310c69b7f22b92ea140c065
BLAKE2b-256 040d4f101428c4343a29d1c50830314db165ac1ca9c6d7547081db6d3c5f968c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ee551145ad9660bb8225b5365d989cf642da140e2058ff4873a0955d26eb9405
MD5 ae0a1e205493ea9bc2220f389614ed70
BLAKE2b-256 268736bc540237ba29a91a4fc34ea87d56cc25bd3a54c2fd4b5cebeabbaf83d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bf0648ad230e675ae17e6ccc4f5e61f8889bb93d96400f650eb1120dcdfc03cd
MD5 9a752881cc47d9922823c12821214d27
BLAKE2b-256 0d21f96647235dedb150ac602e0ca24235eb56498d269368538dd7deaa3b5803

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp314-cp314-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 01b020fcbd49271215d26ba90856bd254cda893b06683ba1d22bfd6ef9760d41
MD5 af454fa89d944ee9b75bcc2028a5b806
BLAKE2b-256 948e5c594ed04be0ba1fdb0df96ae6cef5c57573d318bae65be01a6277472924

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: libtokamap-0.2.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1a0b2d14955b9fb5d07b8ae7085baa12a53dfbe0dc04e738198e54162366c216
MD5 e99db52402a2563a0bf99f4d4564df10
BLAKE2b-256 30f807dfe7a5db89de2ce68ea2d18d5f25abf3832ebd862bcda80f422027c39a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c0852ba1f707b64f3de2a4a59e6c79e42cef5c9d01499b6ec05c159d2ad69efd
MD5 13e68cabf206a437c1f1197bad3e8897
BLAKE2b-256 200e8af52f9516aa9ba4868065ab9218a1ac16c262edbf4b920f66d3f5887970

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6256e72db2c6403354b937123b9603f46e9d5ebdd35504c9a4147cfa9171e53e
MD5 f9197efeb30b12b9fdc784efff8ae298
BLAKE2b-256 fad8ff536860062bb31550e1b357e80f7cb025d671d966fb7cfd5f3307ca6c4f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 224318c36898e350d5d3631f8c35b1b3f1055bf567ce9031fe51a93a3bf79aa7
MD5 99abbdc76c848d0c3bfe892ba8fe4a13
BLAKE2b-256 14639cc77a2713730f2c0f873fc19af910aae639c1d1f3298d049a79d6c7049c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for libtokamap-0.2.0-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 075fa1c2df26096874546f9ce4f0fcececbdbf5aab94218b41bc0e83403bc60f
MD5 f32f3cf6a5d9948332b11a5f56d2afaa
BLAKE2b-256 05bbf051d8265e6777a3a9b28a283517f539d8d1cdf23289b9ec065847e9ae4b

See more details on using hashes here.

Provenance

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