haniwers.v1.cli.daq#
Data acquisition command.
This module provides the ‘daq’ command for collecting cosmic ray event data from the OSECHI detector. It handles configuration loading, CLI option overrides, validation, directory creation, and initiates the data acquisition session.
Features: - Load configuration from TOML files or environment variables - Override config settings via CLI options (precedence: CLI > env > config) - Validate all settings before starting DAQ - Support CLI-only mode (no config file required) - Support config file mode with partial CLI overrides
Architecture: Clear & Unified Flow
┌─────────────────────────────────────┐ │ Config File (TOML) │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ ConfigLoader │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ cfg = HaniwersConfig │ │ ├── device → DeviceConfig │ │ └── sampler → SamplerConfig ◄──────┼─── PRIMARY FOR DAQ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ CLI Overrides (only cfg.sampler) │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ Validation │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ Device.connect() │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ Create timestamped workspace │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ Sampler(device, cfg.sampler) │ │ sampler.run(files=…) │ └──────────────┬──────────────────────┘ ↓ ┌─────────────────────────────────────┐ │ Device.disconnect() │ └─────────────────────────────────────┘
Module Contents#
Functions#
Run data acquisition to collect cosmic ray events. |
API#
- haniwers.v1.cli.daq.daq(ctx: typer.Context, config: Optional[pathlib.Path] = ConfigOptions.config, port: Optional[str] = DeviceOptions.port, baudrate: Optional[int] = DeviceOptions.baudrate, timeout: Optional[float] = DeviceOptions.timeout, workspace: pathlib.Path = OutputOptions.workspace, filename_prefix: Optional[str] = OutputOptions.filename_prefix, events_per_file: Optional[int] = SamplerOptions.events_per_file, number_of_files: Optional[int] = SamplerOptions.number_of_files, stream_mode: bool = SamplerOptions.stream_mode, mode: Optional[str] = SamplerOptions.mode, duration: Optional[float] = SamplerOptions.duration, mock: bool = TestingOptions.mock, load_from: Optional[pathlib.Path] = TestingOptions.load_from, speed: float = TestingOptions.speed, shuffle: bool = TestingOptions.shuffle, jitter: float = TestingOptions.jitter, loop: bool = TestingOptions.loop, verbose: bool = LoggerOptions.verbose, logfile: str = LoggerOptions.logfile) None#
Run data acquisition to collect cosmic ray events.
Supports three usage modes:
CLI-only (no config file): $ haniwers-v1 daq --port /dev/ttyUSB0 --workspace ./output
–filename-prefix run001 --events-per-file 1000Config file (all settings from TOML): $ haniwers-v1 daq --config daq.toml
Config with CLI overrides (mix of both): $ haniwers-v1 daq --config daq.toml --port /dev/ttyUSB1 --workspace ./exp02
Mode Resolution (determines count_based vs time_based acquisition):
The command determines the acquisition mode through the following precedence (highest to lowest priority):
Explicit --mode flag: Direct specification wins Example:
haniwers-v1 daq --config config.toml --mode time_basedImplicit --duration flag: Automatically switches to time_based mode Example:
haniwers-v1 daq --config config.toml --duration 60(mode is set to time_based even if config says count_based)Config [sampler] section: Uses configured mode Example:
haniwers-v1 daq --config config.toml(uses mode from [sampler] mode = “count_based” or “time_based”)Default fallback: count_based mode (used when no mode specified anywhere)
Configuration precedence (highest to lowest):
CLI options (–port, --workspace, etc.)
Environment variables (HANIWERS_DEVICE_PORT, etc.)
TOML configuration file
Built-in defaults
Exit codes: 0: Success 1: Configuration error, validation failure, or DAQ runtime error 2: Serial port permission error (rare)