redsun.path_provider¶
Where a session's acquisition files go.
Paths are <base_dir>/<session>/<YYYY-MM-DD>/<datakey>/<plan>_<counter>,
base_dir defaulting to the user data directory. The container builds one
provider per session and passes it to every device taking a path_provider
keyword.
PATH_PROVIDER_PORT
module-attribute
¶
Name the session's path provider is wired under.
SessionPathProvider
¶
SessionPathProvider(
*,
base_dir: Path | None = None,
session: str = "unknown-session",
max_digits: int = 5,
now: Callable[[], datetime] | None = None,
)
Bases: PathProvider
Path provider for one session.
Paths have the layout:
The label, set with set_label, is left out with its _ while empty.
The data key is the one the caller asks with, so each detector writes into a directory of its own and owns its store. A call without one leaves that level out.
The date is read on each request, not at construction. The counter belongs
to (session, plan, datakey), starts one past the highest number already
on disk, and only increases: date directories group files but do not reset
the counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
Path | None
|
Base directory, with |
None
|
session
|
str
|
Session name, fixed for the provider's lifetime. |
'unknown-session'
|
max_digits
|
int
|
Zero-padding width of the counter, as in |
5
|
now
|
Callable[[], datetime] | None
|
Clock giving the date directory, for tests. Defaults to |
None
|
sig_base_dir_changed
class-attribute
instance-attribute
¶
Emitted with the new root once set_base_dir accepted it.
session_dir
property
¶
Directory inside base_dir holding the session's files.
Named after the session, each run of characters other than letters,
digits, ., - and _ replaced by _ and outer dots removed.
set_base_dir
¶
Change the base directory from the next request on, rescanning counters.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
lock_base_dir
¶
Refuse every later set_base_dir, giving reason in the error.
set_label
¶
Lead the file names of every later plan with label.
Each run of characters other than letters, digits, ., - and _
becomes _, and a label of blanks only is no label. A plan already
running keeps its names.
set_plan
¶
Change the active plan name, led by the label if there is one.
reset_plan
¶
Set the plan name back to its placeholder, rescanning counters.
A filename requested by the plan and never written returns to the pool, so the next plan continues from what is on disk.
__call__
¶
Return the PathInfo of the next file for datakey_name.
Each call returns a new path, since it increments that data key's counter for the active plan. The folder of the path is created if it does not exist.
PlanFilenameProvider
¶
Bases: FilenameProvider
Filenames with a counter per plan.
Filenames are <plan_name>_<counter>, zero-padded to max_digits. Each
data key counts on its own; its directory tells two detectors apart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_digits
|
int
|
Zero-padding width of the counter, as in |
5
|
session_directory
¶
Return session's directory under the default root.
Named as SessionPathProvider.session_dir names it.