lmdb_utilities

LMDB-specific utility functions for use in graphnet.data.

graphnet.data.utilities.lmdb_utilities.get_serialization_method_name(lmdb_path)[source]

Retrieve the serialization method name for an LMDB database.

Parameters:

lmdb_path (str) – Path to the LMDB database directory.

Return type:

Optional[str]

Returns:

The serialization method name (e.g., “pickle”, “json”, “msgpack”, “dill”) or None if the metadata is not found or the database cannot be opened.

graphnet.data.utilities.lmdb_utilities.get_serialization_method(lmdb_path)[source]

Retrieve the deserialization callable for an LMDB database.

Parameters:

lmdb_path (str) – Path to the LMDB database directory.

Return type:

Optional[Callable[[bytes], Any]]

Returns:

Deserialization callable that takes bytes and returns the deserialized object, or None if the metadata is not found, the database cannot be opened, or the serialization method is custom/unsupported.

graphnet.data.utilities.lmdb_utilities.query_database(database, index, deserialization)[source]

Retrieve and deserialize a record from an LMDB database.

Parameters:
  • database (str) – Path to the LMDB database directory.

  • index (int) – The index (event_no) of the record to retrieve.

  • deserialization (Optional[Callable[[bytes], Any]], default: None) – Optional deserialization callable. If not provided, the deserialization method will be fetched from the database metadata.

Return type:

Any

Returns:

The deserialized object stored at the given index.

Raises:
  • KeyError – If the index is not found in the database.

  • ValueError – If deserialization is required but cannot be determined from the database metadata.

graphnet.data.utilities.lmdb_utilities.get_data_representation_from_metadata(lmdb_path, field_name, trust)[source]

Retrieve a DataRepresentation instance from an LMDB database metadata.

Parameters:
  • lmdb_path (str) – Path to the LMDB database directory.

  • field_name (str) – The field name of the data representation to retrieve (e.g., “GraphDefinition”, “GraphDefinition_0”, etc.).

  • trust (bool, default: False) – Whether to trust the ModelConfig enough to eval(…) any lambda function expressions contained. Defaults to False.

Return type:

Optional[DataRepresentation]

Returns:

A DataRepresentation instance reconstructed from the stored config, or None if the metadata is not found, the field name doesn’t exist, or the database cannot be opened.

Raises:

KeyError – If the field_name is not found in the metadata.

graphnet.data.utilities.lmdb_utilities.get_all_indices(database)[source]

Retrieve all indices (event numbers) from an LMDB database.

Parameters:

database (str) – Path to the LMDB database directory.

Return type:

List[int]

Returns:

A sorted list of all indices (event numbers) in the database, excluding the metadata entry.

Raises:

RuntimeError – If the database cannot be opened or accessed.