readOpWave
Description
readOpWave is a utility designed to parse ASCII Optech waveform data files and convert them into a custom binary format suitable for processing by other OMG tools. It extracts waveform traces for different channels (PMT, GAPD, IR, RAMAN) and stores a summary of each waveform record (timestamp, counter, and byte offsets/lengths) in a .wave file, and the actual 16-bit waveform trace data in a .16_data file.
This tool essentially “unpacks” the ASCII waveform data into a more efficient binary representation, facilitating faster access and integration into the OMG processing pipeline.
Usage
readOpWave <infile> <outfile_prefix> [-noraman] [-v]
Arguments
| Option | Description |
|---|---|
<infile> | Required. The path to the input ASCII Optech waveform file. |
<outfile_prefix> | Required. The base name for the output files. The tool will generate <outfile_prefix>.wave (summary) and <outfile_prefix>.16_data (raw waveform traces). |
-noraman | (Present in USAGE but its effect is inverted in code logic) Intended to handle RAMAN waveforms, but its current implementation seems to trigger an error if RAMAN data is present while this flag is set. |
-v | Enable verbose output. |
Data Structures
optech_waveform: This structure holds summary information for each waveform record, includingtimestamp,counter, and byte offsets/number of samples for PMT, GAPD, IR, and RAMAN waveforms.
How It Works
- File Opening: Opens the input ASCII waveform file for reading. Opens two output binary files:
<outfile_prefix>.wavefor writing waveform record summaries, and<outfile_prefix>.16_datafor writing raw 16-bit waveform traces. - Record Processing Loop: Reads the ASCII input file line by line, identifying blocks of data associated with different waveform types:
- Waveform Type Detection: It checks for lines starting with “PMT”, “GAPD”, “IR”, or “RAMAN”.
- Header Parsing: For each waveform type block, it parses the
timestampandcounter. - Trace Data Extraction: It then reads subsequent lines containing
trace_countanddatavalues, accumulating them into adataarray. - Waveform Structure Population: Populates an
optech_waveformstructure (owave) with the extracted timestamp, counter, and the number of samples (tslength) for the current waveform type. It setsPMT_byte_offset(or the offset for the respective waveform type) to the current file position indatfile. - Waveform Trace Writing: Writes the
dataarray (as 16-bit shorts) to the.16_datafile. - Waveform Summary Writing: If it’s a “complete” set of waveforms (e.g., after processing RAMAN or if
-noramanis used after IR), it writes theowavestructure (summary) to the.wavefile.
- Cleanup: Closes all open files.
Output Files
<outfile_prefix>.wave: A binary file containingoptech_waveformsummary structures.<outfile_prefix>.16_data: A binary file containing raw 16-bit waveform trace data.
Dependencies
support.h: For general utility functions and error handling.Optech_waveform.h: Foroptech_waveformdata structure.
Notes
Byte Order and Alignment: The code explicitly warns that writing and reading is “not byte order or dstructure alignment independent.” This means the binary files (.wave, .16_data) generated by this tool (and expected by mergeOpWave) should ideally be processed on the same machine architecture to avoid endianness or padding issues. -noraman flag: The -noraman option’s description in USAGE and its actual implementation logic in the provided code snippet (if (noraman) { error(...) }) appear contradictory or incomplete. It seems designed to prevent processing if RAMAN data is present while this flag is set, leading to an error. The code includes a commented-out section for parsing an ASCII version of the waveform data, suggesting an alternative input format was considered or used previously.