Skip to content

from_jsonl_to_root.py

Purpose: Convert JSONL event files directly to ROOT TTree format

Use case: One-step conversion for ROOT-based analysis without an intermediate Parquet file

Features:

  • Merges multiple JSONL files into a single ROOT output
  • Adds UNIX timestamp columns in seconds (*_s) alongside microseconds (*_us)
  • Adds bme280_valid branch flagging rows within BME280 hardware spec
  • Creates ROOT TTree with flat branch structure
  • Optional alphabetical branch sorting
  • Output filename is fixed to run.root in the input directory

Required input: JSONL event files produced by get_events.py or get_runs.py

Usage:

# Default pattern (events*.jsonl)
uv run examples/from_jsonl_to_root.py 20251221_run126/

# Custom pattern
uv run examples/from_jsonl_to_root.py 20251221_run126/ --pattern "*.jsonl"

# Preserve original column order
uv run examples/from_jsonl_to_root.py 20251221_run126/ --no-sort-branches

# With verbose output
uv run examples/from_jsonl_to_root.py 20251221_run126/ --verbose

# Overwrite existing output
uv run examples/from_jsonl_to_root.py 20251221_run126/ --overwrite

CLI Options:

Option Default Description
READ_FROM (required) Directory containing JSONL files
--pattern events*.jsonl Glob pattern to filter input files
--add-timestamps / --no-add-timestamps on Add *_s columns from *_us fields
--sort-branches / --no-sort-branches on Sort branches alphabetically
--overwrite off Overwrite existing output file
--verbose / --quiet --quiet Show or suppress status messages
--log-level error Log level (debug/info/error)

Output file: READ_FROM/run.root

  • Flat branch structure (one branch per column)
  • All original fields preserved (31+ branches)
  • Additional *_s timestamp branches (received_s, sent_s, detected_s, gnss_time_s)
  • Additional bme280_valid branch (bool)