Path Dictionary#
The ovstage.PathDictionary maps strings and prim paths to reusable
identifiers. Registering a string this way is called interning. Use the
stage’s dictionary so the identifiers your application creates match those
used by ovstage.
Create PathDictionary(stage) to borrow the instance-owned dictionary.
In C, obtain it with ovstage_get_path_dictionary().
Names, Paths, and Lists#
Python method |
Result |
|---|---|
A |
|
A |
|
An immutable, ordered |
Within one dictionary, interning the same string or prim path returns the same
identifier. Compare those identifiers directly rather than resolving their strings.
Path lists are different: creating the same ordered list twice can return different
handles. Do not compare path-list handles to determine whether their contents match.
The C types are ovx_token_t, ovx_primpath_t, and ovx_primpath_list_t
respectively.
These are distinct structs containing one uint64_t raw_id in C, with
same-kind comparison and hashing in C++. Python uses distinct handle classes,
not integer subclasses. APIs reject another handle kind or a bare integer.
In C/C++, keep handles typed in scalars, arrays, and containers. A DLPack tensor
can point directly at typed handle storage while describing it as uint64.
Read uint64 tensor payloads as numeric IDs, applying tensor.byte_offset in
bytes before accessing the elements, then construct the corresponding handle
(for example, ovx_token_t token{values[i]} in C++).
Use handle.raw_id when an interface requires an integer,
such as a Python NumPy uint64 array or numeric diagnostic output. Explicitly
construct the correct handle kind when reading such integers back. Equal numeric
values across kinds do not imply identity.
All native producers, consumers, and Python bindings must be rebuilt together.
PathList extends PrimPathList with ownership. Copying it or constructing
PrimPathList(owned_list) produces a non-owning typed handle, without adding a
native reference. Use add_path_list_reference when an extra reference is needed.
The empty string is a valid token and always interns to ID 0. Resolving
that ID returns an empty string (a non-null pointer with length zero in C).
OVX_INVALID_TOKEN is UINT64_MAX and resolving it returns OVX_API_ERROR
(OvxError in Python). Empty prim-path strings remain invalid.
create_paths_from_tokens rejects token ID 0 as a path component.
OVX_INVALID_PRIMPATH and OVX_INVALID_PRIMPATH_LIST remain 0.
No successful creation call returns the corresponding invalid sentinel.
Interning and Resolving#
Intern a string to a token, then resolve the token back to its string:
# Intern a string -> a stable integer token, and resolve it back.
attr = paths.intern_token("temperature")
print("attribute token", attr, "=", paths.token_to_string(attr))
// The path dictionary is owned by the instance (no app-side create/destroy):
// obtain it, intern strings -> stable tokens, and resolve tokens back.
path_dictionary_instance_t* dict = ovstage_get_path_dictionary(stage);
if (!dict)
{
std::fprintf(stderr, "no path dictionary for instance\n");
return EXIT_FAILURE;
}
ovx_string_t attrName = literal_to_ovx_string("temperature");
ovx_token_t attr = OVX_INVALID_TOKEN;
ovx_api_result_t ovxResult = path_dictionary_create_tokens_from_strings(dict, &attrName, 1, &attr);
checkOvx(dict, ovxResult, "intern-token");
ovx_string_t resolved{};
ovxResult = path_dictionary_get_strings_from_tokens(dict, &attr, 1, &resolved);
checkOvx(dict, ovxResult, "resolve-token");
Constructing Prim Paths#
In Python, use intern_path() with
an absolute path such as /World/Box. Use / for the root.
In C, path_dictionary_create_paths_from_tokens() also accepts component
names: tokens for World and Box produce /World/Box. Do not include
separators in the names. Within one dictionary, this returns the same handle as
path_dictionary_create_paths_from_strings(), regardless of call order.
Python exposes only string-based path construction.
For the root in C, set its num_tokens_per_path entry to zero. Supply a
non-null tokens_per_path array; no component tokens are read for that entry.
path_dictionary_get_tokens_from_paths() returns zero components for
/.
Building a Path List and Opening a Query#
An interned prim-path list is the input to Queries. Build one from strings and open a query over those prims:
# Build an interned prim-path list and open a query over those prims.
# The query is a context manager: block exit releases its handle, and
# Stage teardown requires all handles released first -- the try/finally
# releases the path list even when an error interrupts the flow.
prim_paths = paths.create_path_list_from_strings(["/World/A", "/World/B", "/World/C"])
try:
with stage.query_from_path_list(prim_paths) as query:
// Build an immutable prim-path list from strings and open a query over it.
const ovx_string_t paths[] = { literal_to_ovx_string("/World/A"), literal_to_ovx_string("/World/B"),
literal_to_ovx_string("/World/C") };
ovx_primpath_list_t pathList = OVX_INVALID_PRIMPATH_LIST;
ovxResult = path_dictionary_create_path_list_from_strings(dict, paths, 3, &pathList);
checkOvx(dict, ovxResult, "create-path-list");
ovstage_query_handle_t query = OVSTAGE_INVALID_QUERY_HANDLE;
status = ovstage_query_from_path_list(stage, pathList, &query);
check(stage, status, "query_from_path_list");
Attribute Arguments: String or Token#
Attribute arguments accept a string or an ovstage.Token. Reusing an interned
token avoids a string lookup on each call. In C, ovx_token_or_string_t holds
either form. These snippets show both:
# Attribute arguments accept an interned token (int) or a plain str:
# a token skips the per-call dictionary lookup, a str is interned for
# you at call time.
stage.write_attribute(
query, "temperature", ordinal=2, tensors=np.array([4.0, 5.0, 6.0], np.float32),
is_array=False,
).wait()
stage.advance_write_floor(ordinal=2).wait()
// Attributes pass as ovx_token_or_string_t. We already hold an interned
// token, so use its ID and leave string.ptr null to skip a string lookup.
ovx_token_or_string_t attrArg{ attr, {} };
Ownership and Lifetime#
Each stage owns its dictionary. Python requires
PathDictionary(stage); the wrapper does not own the stage. Do not destroy the native dictionary separately.Path lists belong to that stage. To use the same selection on another stage, recreate the list in its dictionary. Release list references before destroying their stage; neither a list reference nor another live stage keeps them valid.
Tokens and individual path identifiers last for the dictionary’s lifetime; do not release them individually.
create_path_list()andcreate_path_list_from_strings()return an ownedovstage.PathList. Use awithblock or callrelease(). The object is aPrimPathListand can be passed wherever a list handle is accepted. Reuse a list outside a per-frame loop when its paths do not change.Lists borrowed from read results are non-owning
ovstage.PrimPathListhandles. Do not release them.An unreleased Python
PathListreleases its reference on garbage collection and emitsResourceWarning. Explicit release avoids relying on that cleanup.
In C, release each created path-list reference through the dictionary exactly
once. Returned ovx_string_t values borrow dictionary storage; copy any text
that must outlive the dictionary. See String Handling.
Errors#
Python dictionary failures raise ovstage.OvxError. Invalid, unknown,
or expired path identifiers fail rather than resolving to an empty string.
ovstage.PathDictionary.path_to_string() returns / for the valid
absolute root.
In C, dictionary calls return ovx_api_result_t. On OVX_API_ERROR, release
the error string with path_dictionary_release_error().
path_dictionary_get_tokens_from_paths() returns component tokens, not a joined
path string. The root succeeds as one processed path with zero tokens; callers
join the components themselves. See Error Handling and Diagnostics.
Further Reading#
Queries — resolve a path list into per-attribute prim groups.
Writing Attributes / Reading Attributes — use tokens as attribute keys.
String Handling — working with
ovx_string_tin C.