Legacy Containers: Reading .clashDetection Files#
.clashDetection is the Kit-era container format for clash results. The
standalone Suite API reads and writes it through the same SQLite
data handle that opens an .ovclashdb store.
This tutorial runs the legacy sample, creates a container, probes and opens it, migrates an old
schema and moves the data to a plain .ovclashdb. The container format
is the reference for the file layout and for how each operation treats a container.
Prerequisites#
Persistence and the SQLite serializer. This page uses the same
ClashDataSerializerSqlite/ClashDataandovclash_suite_data_tAPI on a different file extension.For Step 2 to Step 5:
dynamic.ovclashdbin the current directory, from Step 3 of Suite Workflows.For Step 1: the
legacy_clash_detectionsample. The SDK archive ships it at<sdk>/samples/legacy_clash_detectionand the wheel at<site-packages>/ovclash/samples/legacy_clash_detection, where<sdk>is the extracted SDK archive and<site-packages>the directory thatpython -m pip show ovclashprints asLocation. The wheel ships only the Python version.The ovstage runtime. With the wheel, pip installed the pinned version with it, and nothing more is needed. With the SDK archive, you need the version that its
requirements.txtpins, because the SDK archive does not bundle it. The sample launchers can prepare it, as Samples describes; Installing the ovstage runtime describes installing it yourself.For the C++ sample and the C example only: the SDK archive, a C++17 toolchain and CMake.
Step 1: Run the sample#
From the sample directory, run the Python or the C++ version. Each line is one version; run either.
On Linux:
./run_legacy_clash_detection_python.sh
./run_legacy_clash_detection_cpp.sh
On Windows:
.\run_legacy_clash_detection_python.bat
.\run_legacy_clash_detection_cpp.bat
The C++ launcher builds the sample first. When that build or the runtime setup fails, the launcher stops with an error; Building and running the shipped samples lists the messages.
With no sample arguments, each program creates a small input.clashDetection that holds one
query. It then writes copy.clashDetection and copy.ovclashdb. The
Python version prints (<version> is the installed version and <output-dir> the launcher’s
output directory):
ovclash <version>
Legacy clashDetection sample
Input: <output-dir>/input.clashDetection
Output legacy: <output-dir>/copy.clashDetection
Output database: <output-dir>/copy.ovclashdb
Input status: ready
Queries: 1
[1] Legacy sample query
Wrote legacy file: <output-dir>/copy.clashDetection
Wrote sidecar DB: <output-dir>/copy.ovclashdb
The launchers of both versions take these options:
Option |
Values |
Required |
Default |
Effect |
|---|---|---|---|---|
|
A directory path |
No |
|
The directory of the three files. The launcher creates it. |
|
The root of an ovclash SDK archive |
No |
|
The runtime that the sample uses. |
|
Three file paths |
No |
The three files in the output directory |
Runs the program on your own files, as the Your own files launcher rule of Step 1 describes. |
|
None |
No |
None |
Prints the usage and exits. |
The C++ launchers also take --release, --debug or --config TYPE for the build
configuration.
Launcher rules:
Output directory. Without
--output-dir, the files go to a default directory inside the SDK archive or the wheel package, so pass--output-dir DIRwhen the package directory is not writable.Runtime. The launchers use the runtime of the SDK archive or the wheel that contains them.
No backend option. Unlike the
clash_apiandclash_suite_apilaunchers, these launchers have no--backendoption and open no stage. Container I/O is data-layer work, so the scene backend plays no part.Your own files. Each program takes three positional paths: the input, the
.clashDetectioncopy and the.ovclashdbsidecar. Pass them after--. Relative paths resolve against the current directory. A missing input is created first; an existing input is never rewritten.
./run_legacy_clash_detection_python.sh -- project.clashDetection copy.clashDetection project.ovclashdb
Samples map describes the sample and its README,
samples/legacy_clash_detection/README.md, which lists every launcher option and the manual C++
build.
The complete programs are samples/legacy_clash_detection/legacy_clash_detection_python_api.py
and, in the SDK archive, samples/legacy_clash_detection/LegacyClashDetection.cpp.
Step 2: Create a container#
save_as() with a .clashDetection target exports a container. This script exports
dynamic.ovclashdb and reads the container’s header:
import struct
from ovclash_suite import ClashData
data = ClashData()
try:
data.open("dynamic.ovclashdb")
data.save_as("results.clashDetection") # an export: the handle stays on dynamic.ovclashdb
finally:
data.destroy()
with open("results.clashDetection", "rb") as container:
magic, version, _reserved = struct.unpack("<II8s", container.read(16))
print(f"magic=0x{magic:08X} version={version}")
Expected output:
magic=0x4A544443 version=1
Step 3: Probe and open the container#
Probe untrusted input before you open it. The probe reads only the header bytes. It does not open the SQLite database or migrate a schema.
from ovclash_suite import ClashDataSerializerSqlite, probe_legacy_clash_detection_file
path = "results.clashDetection"
is_legacy, has_sqlite_payload = probe_legacy_clash_detection_file(path)
print(f"is_legacy={is_legacy} has_sqlite_payload={has_sqlite_payload}")
if is_legacy and not has_sqlite_payload:
raise RuntimeError("the container payload is not a SQLite database")
serializer = ClashDataSerializerSqlite()
try:
serializer.open(path)
for identifier, query in serializer.fetch_all_queries().items():
count = serializer.get_overlaps_count_by_query_id(identifier)
print(f"[{identifier}] {query.query_name}: {count} clashes")
print(f"working copy: {serializer.get_file_path().endswith('.ovclashdb')}")
finally:
serializer.destroy()
Expected output:
is_legacy=True has_sqlite_payload=True
[1] Example Dynamic Query: 8 clashes
working copy: True
The handle works on a temporary .ovclashdb copy of the payload, so get_file_path() names
that copy, not the container. destroy() deletes the copy.
What the probe reports, as a Python tuple (is_legacy, has_sqlite_payload) or through the two C
out-parameters:
Field |
Type |
Required |
Default or values |
Description |
|---|---|---|---|---|
|
Python |
Yes |
True or 1 when the file starts with the legacy magic number |
Whether the file has a container header. |
|
Python |
Yes |
True or 1 when the payload also starts with SQLite’s file header |
Whether the payload looks like a SQLite database. |
is_legacyis true when the file starts with the legacy magic number.has_sqlite_payloadis true when the payload also starts with SQLite’s file header.Neither flag checks the format version, the database contents or the schema version. A file that probes
(True, True)can still fail to open.A missing file, an empty path, a file shorter than the header and a non-legacy file all probe as
(False, False). Because ordinary files never make it fail, the probe is safe in an error path.In Python, a path with an embedded NUL character raises
RuntimeError. A string that cannot be encoded as UTF-8 raisesUnicodeEncodeErrorbefore the call.
In C, a function for a source file of your program:
#include <ovclash_suite/ovclash_suite.h>
#include <stdio.h>
/* Returns 1 when path names a container with a SQLite payload, else 0. */
static int is_sqlite_container(ovclash_suite_string_t path)
{
uint32_t is_legacy = 0u;
uint32_t has_sqlite_payload = 0u;
ovclash_suite_result_t result =
ovclash_suite_probe_legacy_clash_detection_file(path, &is_legacy, &has_sqlite_payload);
if (result.status != OVCLASH_SUITE_STATUS_SUCCESS) {
ovclash_suite_string_t error = ovclash_suite_get_thread_last_error(); /* invalid input */
fprintf(stderr, "probe failed: %.*s\n", (int)error.length, error.ptr ? error.ptr : "");
return 0;
}
return is_legacy && has_sqlite_payload;
}
The C call fails only for invalid input: a null output pointer, an invalid string span, invalid UTF-8, an embedded NUL character or a caught exception.
Both samples probe an existing input before they open it and refuse a container whose payload
lacks a SQLite header. When open() fails, they probe again. That tells a payload without a
SQLite header from one that SQLite rejected despite a valid header.
Step 4: Migrate an old schema#
An older container can hold an older schema. The probe cannot detect this; open() reports it:
In C,
ovclash_suite_data_openfails.In Python,
open()leaves the store closed without raising.Either way,
data_structures_compatible()(Covclash_suite_data_structures_compatible) reports false.data_structures_migration_to_latest_version_possible()(Covclash_suite_data_migration_to_latest_possible) reports true when a migration chain exists.
Migrate, then save the result as an .ovclashdb:
from ovclash_suite import ClashDataSerializerSqlite
serializer = ClashDataSerializerSqlite()
try:
serializer.open("results.clashDetection")
if not serializer.is_open(): # an older schema leaves the store closed
if not serializer.data_structures_migration_to_latest_version_possible():
raise RuntimeError(serializer.last_error())
if not serializer.migrate_data_structures_to_latest_version("results.clashDetection"):
raise RuntimeError(serializer.last_error())
print("migrated")
serializer.save_as("results_latest.ovclashdb") # raises RuntimeError on failure
print(f"compatible={serializer.data_structures_compatible()}")
finally:
serializer.destroy()
Expected output for the container from Step 2, which already has the current schema:
compatible=True
An old-schema container also prints migrated first. Its failed open() also logs the reason as
a warning through the ovclash_suite logger. In C, migrate with
ovclash_suite_data_migrate_to_latest and save with ovclash_suite_data_save_as.
On a ClashDataSerializerSqlite, data_structures_compatible() and
data_structures_migration_to_latest_version_possible() are methods. On ClashData they are
properties of the same names.
After a migration of the container, the next Python save() without a target rewrites the
original container in the latest schema. To keep the original, use save_as() with an
.ovclashdb path, as the script of this step does.
Schema versions and forward compatibility
lists the versions and the migration rules.
Failures that do not raise explains last_error().
Step 5: Write a copy and a modern sidecar#
One open handle can write both a legacy copy and an .ovclashdb sidecar, because a
.clashDetection target is an export:
from ovclash_suite import ClashDataSerializerSqlite
serializer = ClashDataSerializerSqlite()
try:
serializer.open("results.clashDetection")
serializer.save_as("copy.clashDetection") # export: the handle stays on its current store
serializer.save_as("copy.ovclashdb") # sidecar: becomes the current store
print(f"current store is the sidecar: {serializer.get_file_path().endswith('copy.ovclashdb')}")
finally:
serializer.destroy()
Expected output:
current store is the sidecar: True
The second save_as() moves the data off the legacy format. The sidecar is a plain .ovclashdb,
and the original container is untouched. In Python, save_as() raises RuntimeError on failure.
The Python sample uses ClashDataSerializerSqlite directly; a ClashData that wraps it behaves
the same.
The same steps in C, as a complete program:
#include <ovclash_suite/ovclash_suite.h>
#include <stdio.h>
#include <string.h>
static ovclash_suite_string_t text(const char* value)
{
ovclash_suite_string_t span = { value, strlen(value) };
return span;
}
static int ok(ovclash_suite_result_t result)
{
return result.status == OVCLASH_SUITE_STATUS_SUCCESS;
}
int main(void)
{
const ovclash_suite_string_t input = text("results.clashDetection");
ovclash_suite_data_t* data = NULL;
uint32_t is_legacy = 0u;
uint32_t has_sqlite_payload = 0u;
uint32_t query_count = 0u;
int status = 1;
/* The probe fails only for invalid arguments; ordinary files report through the flags. */
if (!ok(ovclash_suite_probe_legacy_clash_detection_file(input, &is_legacy, &has_sqlite_payload)))
goto cleanup;
printf("is_legacy=%u has_sqlite_payload=%u\n", is_legacy, has_sqlite_payload);
if (is_legacy && !has_sqlite_payload) goto cleanup;
if (!ok(ovclash_suite_data_create(&data)) || !ok(ovclash_suite_data_open(data, input)) ||
!ok(ovclash_suite_data_get_query_count(data, &query_count)))
goto cleanup;
printf("queries: %u\n", query_count);
if (!ok(ovclash_suite_data_save_as(data, text("copy_c.clashDetection"))) || /* export only */
!ok(ovclash_suite_data_save_as(data, text("copy_c.ovclashdb")))) /* becomes current */
goto cleanup;
printf("wrote copy_c.clashDetection and copy_c.ovclashdb\n");
status = 0;
cleanup:
if (status != 0)
{
ovclash_suite_string_t error = ovclash_suite_get_thread_last_error();
fprintf(stderr, "error: %.*s\n", (int)error.length, error.ptr ? error.ptr : "");
}
ovclash_suite_data_destroy(data); /* closes the store; after an early failure it also deletes
the temporary copy of the container */
return status;
}
Expected output:
is_legacy=1 has_sqlite_payload=1
queries: 1
wrote copy_c.clashDetection and copy_c.ovclashdb
On failure, ovclash_suite_get_thread_last_error() and ovclash_suite_data_get_last_error() give
the reason.
The container format#
A .clashDetection file is a 16-byte header followed by the bytes of a SQLite database. The
header holds two little-endian 32-bit fields followed by 8 reserved bytes:
Bytes |
Content |
|---|---|
0-3 |
The legacy magic number, |
4-7 |
The format version. ovclash writes |
8-15 |
Reserved. ovclash writes zeros and never reads them. |
The payload is an ordinary .ovclashdb SQLite database, possibly with an older schema, so one API
reads both. The handling differs:
Operation |
Behavior on a legacy container |
|---|---|
Open |
The handle copies the payload to a private temporary |
Writes and commit |
They change only the temporary copy. The container is unchanged. |
Migrate |
Migration works on a temporary copy. The container is only read, so it may be read-only. See Migrating a container. |
|
A target ending in |
|
C |
Close / destroy |
The handle deletes the temporary copy. |
The temporary copy goes to the system temporary directory, or to the current directory when there is none. That directory needs room for the whole payload.
Migrating a container#
Passing the container’s path extracts it again to a new copy and deletes the handle’s earlier copy. Writes made to the earlier copy are lost unless they were first exported to the container.
To keep those writes, migrate the copy’s path (
get_file_path()) instead.In Python, an empty path uses the cached path. After
open()on the container, the cached path names the container until asave()orsave_as()succeeds.In C, an empty path migrates the current copy in place and keeps its writes.
Saving a container from Python#
save()rewrites the container while the cached path names it. That holds afteropen()ormigrate_data_structures_to_latest_version()on the container, until asave()orsave_as()succeeds.Each successful save caches the handle’s file path. Later calls then commit to the copy, or to a plain target that
save_as()adopted.To rewrite the container after that, pass its path to
save_as().
Naming a container#
A path that ends in
.clashDetection, in any letter case, must name a valid container. A missing file, a plain SQLite file or a damaged header fails the open, and a later write does not create the file.A file with a valid header opens as a container under any name.
Kit layer metadata#
ovclash ships no USD file-format plugin for .clashDetection. A stage
that lists one among its sublayers, the layers that the stage composes, does not load its clash
data, so open the file through the data API. ClashData keeps the Kit-era names as constants for
code that reads Kit-authored layers. A layer’s customData is its dictionary of custom metadata:
Constant |
Value |
|---|---|
|
|
|
|
|
|
|
|
Kit writes both customData entries of its clash layer as strings; ovclash writes neither:
Key |
Type |
Required |
Default or values |
Description |
|---|---|---|---|---|
|
string |
No; Kit writes it with the clash layer |
A database file path; Kit reads a missing key as |
The database that holds the layer’s clash data. |
|
string |
No; Kit writes it with the clash layer |
|
Whether that database has changes that Kit has not saved yet. |
To move data off a container, migrate it through the data API, as Step 4 and Step 5 show. ovclash never edits the stage that sublayers the container; remove that sublayer with your own USD tooling.
Result#
You can probe a .clashDetection file, open it, read its queries, migrate an old schema, and write
both a legacy copy and an .ovclashdb sidecar without changing the original. Beyond reading these
containers, work in .ovclashdb: it is the standalone format, which the
SQLite serializer documents, and Persistence and
Export are written around it.