nexatom-downloads

Time Tag Binary Decoder

The Time Tag Binary Decoder allows developers to build offline processing tools in C/C++ that consume the massive .nxtt binary streams generated by the File Saving module (Section 7.17).

Instead of parsing raw bytes manually, this decoder provides an iterator-like interface (nexatom_tt_time_tag_reader_t) to stream batched nexatom_time_tag_t records into memory, completely abstracted from the underlying file compression or framing protocols.

Function Reference

Function Parameters (In/Out) Returns Description
nexatom_tt_open_time_tag_file_reader [In] const char* path
[Out] nexatom_tt_time_tag_reader_t** out_reader
nexatom_error_code_t Opens a single .nxtt file and allocates the iterator handle.
nexatom_tt_open_time_tag_series_reader [In] const char* directory
[In] const char* series_key
[In] uint32_t seq_start
[In] uint32_t seq_end
[Out] nexatom_tt_time_tag_reader_t** out_reader
nexatom_error_code_t Opens a sequence of rotated .nxtt files from directory matching series_key (the base filename pattern). The seq_start (1-based) and seq_end parameters define the inclusive sequence range to load. Pass seq_end = 0 to load all remaining contiguous files.
nexatom_tt_get_time_tag_header [In] nexatom_tt_time_tag_reader_t* reader
[Out] nexatom_time_tag_file_header_t* header
nexatom_error_code_t Extracts metadata (like creation date) embedded at the top of the .nxtt binary.
nexatom_tt_read_time_tag_batch [In] nexatom_tt_time_tag_reader_t* reader
[Out] nexatom_time_tag_t* out_tags
[In] size_t max_tags
[Out] size_t* out_count
nexatom_error_code_t Fills the caller’s batch. EOF is NEXATOM_SUCCESS with zero count; a nonzero error must be preserved.
nexatom_tt_close_time_tag_reader [In] nexatom_tt_time_tag_reader_t* reader void Closes the file handles and frees the iterator memory. Must be called to prevent memory leaks.
nexatom_tt_export_time_tags [In] const nexatom_tt_time_tag_export_options_t* options
[Out] nexatom_tt_time_tag_export_result_t* out_result
nexatom_error_code_t Writes every event of a file or series as one CSV or TAB file. Needs no reader and no device; see Time-tag export.
nexatom_tt_start_time_tags_export [In] const nexatom_tt_time_tag_export_options_t* options
[Out] nexatom_tt_export_job_handle* out_job
nexatom_error_code_t Runs the same export as a job on an SDK thread.
nexatom_tt_get_time_tags_export_progress [In] nexatom_tt_export_job_handle job
[Out] nexatom_tt_time_tag_export_progress_t* out_progress
nexatom_error_code_t Phase and progress of a job; never waits.
nexatom_tt_cancel_time_tags_export [In] nexatom_tt_export_job_handle job nexatom_error_code_t Asks a job to stop; returns at once, from any thread.
nexatom_tt_finish_time_tags_export [In] nexatom_tt_export_job_handle job
[In] uint32_t timeout_ms
[Out] nexatom_tt_time_tag_export_job_result_t* out_result
nexatom_error_code_t Waits for a job and returns its result; NEXATOM_ERROR_TIMEOUT while it still runs. Every job must be finished.

Data Structures

nexatom_time_tag_t

The 16-byte host representation of a decoded event. It is not the packed disk record or the USB wire format.

Field Type Description
timestamp_ps uint64_t Decoded timestamp in ps; raw rollover is extended within a runtime session. Do not assume each acquisition resets the hardware time origin.
channel uint8_t Decoded public channel index. Interpret it using the runtime’s channel mapping; it is not independently a physical connector identifier.
_padding uint8_t[7] Explicit host ABI padding; this makes a 16-byte record, not a universal 16-byte alignment requirement.

nexatom_time_tag_file_header_t

Parsed from the top of the binary file. Note the FFI alignment padding fields.

Field Type Description
magic char[5] File format identifier: "NXTT\0" (null-terminated).
_padding0 uint8_t[3] FFI alignment padding after magic.
created_timestamp_us uint64_t POSIX Unix epoch timestamp (in microseconds) of when the file was created.
output_data_type uint32_t Echoes the active mode from nexatom_output_data_type_t when the file was recorded (2 raw tags, 1 encoded tags).
format_version uint32_t File format version, 1 or 2. Occupies the place of the earlier _padding1[4], so the record keeps its size.

The SDK writes format 2: the same tag blocks as format 1, and a closed file ends with an end record that says how the recording ended (see the NXTT layout). The reader returns the tags of a closed file and stops at its end record; a closed file whose blocks do not run exactly to the end record returns NEXATOM_ERROR_FILE_IO with the file name and byte position in the last error message. A file without its end record was not closed (a crash, a power loss, or a file still being written) and reads every whole tag up to its torn end. A reader from an SDK that predates format 2 refuses a format 2 file at open with NEXATOM_ERROR_NOT_SUPPORTED.

C Example: Decoding a Run Offline

nexatom_tt_time_tag_reader_t* reader = NULL;

// 1. Open the file
if (nexatom_tt_open_time_tag_file_reader("/data/run_1.nxtt", &reader) == 0) {
    
    // 2. Allocate our batch buffer
    size_t batch_size = 10000;
    nexatom_time_tag_t* batch = malloc(batch_size * sizeof(nexatom_time_tag_t));
    if (batch == NULL) {
        nexatom_tt_close_time_tag_reader(reader); // Reader ownership exists even on allocation failure.
        return -1;
    }
    size_t tags_read = 0;
    nexatom_error_code_t read_status;
    
    // 3. Iterate through the file until EOF
    while ((read_status = nexatom_tt_read_time_tag_batch(reader, batch, batch_size, &tags_read)) == NEXATOM_SUCCESS) {
        if (tags_read == 0) break; // End of file
        
        // Process this block (e.g., software cross-correlation)
        for (size_t i = 0; i < tags_read; i++) {
            if (batch[i].channel == 0) {
                // Photon detected on Channel 0 at batch[i].timestamp_ps!
            }
        }
    }
    
    // 4. An error is not EOF; report it before subsequent diagnostics change.
    if (read_status != NEXATOM_SUCCESS)
        fprintf(stderr, "Decode failed: %s\n", nexatom_tt_get_last_error_message());
    // The complete caller also propagates read_status as its failed run result.
    free(batch);
    nexatom_tt_close_time_tag_reader(reader);
}

Offline readers require no device handle but enforce safe output/saving conditions if a device is connected. Quiet and finalize acquisition first. Reader close releases resources; EOF also releases temporary output ownership. A mode-restore failure remains an error. See reader lifecycle and series keys.

C Example: Loading a Rotated Series

nexatom_tt_time_tag_reader_t* reader = NULL;

// Open files matching pattern "my_experiment_TAGS_*.nxtt" in /data/
// Loads sequence numbers 1 through 10
nexatom_error_code_t err = nexatom_tt_open_time_tag_series_reader(
    "/data/",                // directory
    "my_experiment_TAGS",    // series_key (base filename pattern)
    1,                       // seq_start (1-based)
    10,                      // seq_end (0 = all remaining)
    &reader
);

if (err == 0) {
    // Read batches across all 10 files seamlessly...
    nexatom_tt_close_time_tag_reader(reader);
}

Time-tag export

nexatom_tt_export_time_tags() turns one .nxtt file or a whole series into one CSV or TAB file. It reads files only and never touches a board: it does not switch the output mode, and it runs during a recording, during raw output and with several boards connected. The input is read in batches and never held in memory.

Zero-initialize the options and the result and set abi_version = NEXATOM_TT_TIME_TAG_EXPORT_ABI_VERSION and struct_size in both. The input is one file (input_path; series_directory and series_key NULL, seq_start and seq_end 0) or a series (input_path NULL; series_directory, series_key, seq_start >= 1 and seq_end as for nexatom_tt_open_time_tag_series_reader()). format is NEXATOM_TT_TIME_TAG_EXPORT_FORMAT_CSV or _TAB; flags is 0 or NEXATOM_TT_TIME_TAG_EXPORT_NO_HEADER (rows only). Reserved fields stay zero. The strings are read only during the call.

// Fragment: export a rotated series into one CSV file.
nexatom_tt_time_tag_export_options_t options = {0};
options.abi_version = NEXATOM_TT_TIME_TAG_EXPORT_ABI_VERSION;
options.struct_size = sizeof(options);
options.format = NEXATOM_TT_TIME_TAG_EXPORT_FORMAT_CSV;
options.series_directory = "/data/raw-1";
options.series_key = "my_experiment_TAGS";
options.seq_start = 1;
options.seq_end = 0;                       // all remaining contiguous files
options.output_path = "/data/my_experiment.csv";

nexatom_tt_time_tag_export_result_t result = {0};
result.abi_version = NEXATOM_TT_TIME_TAG_EXPORT_ABI_VERSION;
result.struct_size = sizeof(result);
nexatom_error_code_t err = nexatom_tt_export_time_tags(&options, &result);
if (err == NEXATOM_SUCCESS) {
    printf("%u files, %llu tags\n", result.files_read,
           (unsigned long long)result.tags_written);
} else {
    fprintf(stderr, "Export failed: %s\n", nexatom_tt_get_last_error_message());
}

The output has three # lines (what the file is with the input’s creation time and files; what the columns mean; the tag count with the inputs and how the saving ended), the heading row Event time (ps),Input and one row per event in recorded order. Input counts from 1 (Input N is channel N-1); the reader and the .nxtt file keep the 0-based channel. The result gives files_read, tags_written, and from the first input file output_data_type and created_timestamp_us.

As a job. nexatom_tt_start_time_tags_export() takes the same options and writes the same file on an SDK thread; the options and the input are checked before it returns. The job writes into <output_path>.partial, created new, and renames it to output_path only when complete. It never replaces a file: an existing output_path or .partial is refused with NEXATOM_ERROR_INVALID_PARAMETER, and a failed or cancelled job leaves no file under output_path. nexatom_tt_get_time_tags_export_progress() reports the phase (CHECKING, WRITING, FINISHING, then DONE, CANCELLED or FAILED), file_index / file_count, bytes_done / bytes_total (the progress bar) and tags_written / tags_total (0 until the first pass ends). nexatom_tt_cancel_time_tags_export() returns at once. nexatom_tt_finish_time_tags_export() must be called for every job; it returns NEXATOM_ERROR_TIMEOUT while the job still runs and, once it has ended, the result with check_text (the check line) and flags (NEXATOM_TT_FAST_TIHI_INDEX_EXPORT_INTEGRITY_FOUND when every input file has its end record; _COMPLETE and _SAVING_CONFIRMED when the check says confirmed; 0 for a format 1 input), or NEXATOM_ERROR_CANCELLED after a cancel.

The offline decoder guide describes the check line and the Python calls.

Fast TIHI click files (.nxti)

On the UTT160810, the click records of a Fast TIHI run are saved as .nxti files. nexatom_tt_open_fast_tihi_index_file_reader() and nexatom_tt_open_fast_tihi_index_series_reader() open a nexatom_tt_fast_tihi_index_reader_t; nexatom_tt_get_fast_tihi_index_header(), nexatom_tt_read_fast_tihi_index_batch(), nexatom_tt_get_fast_tihi_index_reader_status(), nexatom_tt_get_fast_tihi_index_file_facts(), nexatom_tt_get_fast_tihi_index_input_switch() and nexatom_tt_get_fast_tihi_index_input_setting() read it, and nexatom_tt_close_fast_tihi_index_reader() closes it. nexatom_tt_export_fast_tihi_index() writes the readable click table, and nexatom_tt_start_fast_tihi_index_export() with nexatom_tt_get_fast_tihi_index_export_progress(), nexatom_tt_cancel_fast_tihi_index_export() and nexatom_tt_finish_fast_tihi_index_export() runs it as a job. See Fast TIHI click files.