-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathchanlist_gen.smk
100 lines (77 loc) · 2.55 KB
/
chanlist_gen.smk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# ruff: noqa: F821, T201
import os
import random
import re
from pathlib import Path
from legenddataflow.FileKey import ChannelProcKey
from legenddataflow.patterns import (
get_pattern_pars_tmp_channel,
get_pattern_plts_tmp_channel,
)
from legenddataflow import execenv_pyexe
from legenddataflow.utils import filelist_path
from dbetto import TextDB
from dbetto.catalog import Catalog
def get_chanlist(config, timestamp, datatype, workflow, det_status, channelmap, system):
if isinstance(det_status, (str, Path)):
det_status = TextDB(det_status, lazy=True)
if isinstance(channelmap, (str, Path)):
channelmap = TextDB(channelmap, lazy=True)
if isinstance(det_status, TextDB):
status_map = det_status.statuses.on(timestamp, system=datatype)
else:
status_map = det_status.valid_for(timestamp, system=datatype)
if isinstance(channelmap, TextDB):
chmap = channelmap.channelmaps.on(timestamp, system=datatype)
else:
chmap = channelmap.valid_for(timestamp, system=datatype)
# only restrict to a certain system (geds, spms, ...)
channels = []
for channel in chmap.map("system", unique=False)[system].map("name"):
if channel not in status_map:
msg = f"{channel} is not found in the status map (on {timestamp})"
raise RuntimeError(msg)
if status_map[channel].processable is False:
continue
channels.append(channel)
if len(channels) == 0:
print("WARNING: No channels found") # noqa: T201
return channels
def get_par_chanlist(
setup,
keypart,
tier,
basedir,
det_status,
chan_maps,
system,
datatype="cal",
name=None,
extension="yaml",
):
key = ChannelProcKey.parse_keypart(keypart)
chan_list = get_chanlist(
setup, key.timestamp, key.datatype, workflow, det_status, chan_maps, system
)
par_pattern = get_pattern_pars_tmp_channel(
setup, tier, name, datatype=datatype, extension=extension
)
filenames = ChannelProcKey.get_channel_files(keypart, par_pattern, chan_list)
return filenames
def get_plt_chanlist(
setup,
keypart,
tier,
basedir,
det_status,
chan_maps,
system,
name=None,
):
key = ChannelProcKey.parse_keypart(keypart)
chan_list = get_chanlist(
setup, key.timestamp, key.datatype, workflow, det_status, chan_maps, system
)
par_pattern = get_pattern_plts_tmp_channel(setup, tier, name)
filenames = ChannelProcKey.get_channel_files(keypart, par_pattern, chan_list)
return filenames