forked from legend-exp/legend-dataflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
779 lines (690 loc) · 25.5 KB
/
Snakefile
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
import pathlib, os, json, sys
import scripts as ds
from scripts.util.patterns import *
from datetime import datetime
from collections import OrderedDict
# Set with `snakemake --configfile=/path/to/your/config.json`
# configfile: "have/to/specify/path/to/your/config.json"
subst_vars_in_snakemake_config(workflow, config)
setup = config["setups"]["l200"]
configs = config_path(setup)
chan_maps = chan_map_path(setup)
swenv = runcmd(setup)
part = ds.dataset_file(setup, os.path.join(configs, "partitions.json"))
basedir = workflow.basedir
localrules:
gen_filelist,
autogen_output,
ds.pars_key_resolve.write_par_catalog(
["-*-*-*-cal"],
os.path.join(pars_path(setup), "pht", "validity.jsonl"),
get_pattern_tier_raw(setup),
{"cal": ["par_pht"], "lar": ["par_pht"]},
)
onstart:
print("Starting workflow")
shell(f"rm {pars_path(setup)}/dsp/validity.jsonl || true")
shell(f"rm {pars_path(setup)}/hit/validity.jsonl || true")
shell(f"rm {pars_path(setup)}/pht/validity.jsonl || true")
ds.pars_key_resolve.write_par_catalog(
setup,
["-*-*-*-cal"],
os.path.join(pars_path(setup), "dsp", "validity.jsonl"),
get_pattern_tier_raw(setup),
{"cal": ["par_dsp"], "lar": ["par_dsp"]},
)
ds.pars_key_resolve.write_par_catalog(
setup,
["-*-*-*-cal"],
os.path.join(pars_path(setup), "hit", "validity.jsonl"),
get_pattern_tier_raw(setup),
{"cal": ["par_hit"], "lar": ["par_hit"]},
)
ds.pars_key_resolve.write_par_catalog(
setup,
["-*-*-*-cal"],
os.path.join(pars_path(setup), "pht", "validity.jsonl"),
get_pattern_tier_raw(setup),
{"cal": ["par_pht"], "lar": ["par_pht"]},
)
onsuccess:
print("Workflow finished, no error")
shell("rm *.gen || true")
shell(f"rm {filelist_path(setup)}/* || true")
# Placeholder, can email or maybe put message in slack
onerror:
print("An error occurred :( ")
checkpoint gen_filelist:
output:
os.path.join(filelist_path(setup), "{label}-{tier}.{extension}list"),
params:
setup=lambda wildcards: setup,
search_pattern=lambda wildcards: get_pattern_tier_raw(setup),
basedir=basedir,
configs=configs,
chan_maps=chan_maps,
script:
"scripts/create_{wildcards.extension}list.py"
def read_filelist(wildcards):
with checkpoints.gen_filelist.get(
label=wildcards.label, tier=wildcards.tier, extension="file"
).output[0].open() as f:
files = f.read().splitlines()
return files
rule gen_fileDB_config:
output:
"fdb_config.json",
script:
"scripts/gen_fiileDB_config.py"
# Create "{label}-{tier}.gen", based on "{label}.keylist" via
# "{label}-{tier}.filelist". Will implicitly trigger creation of all files
# in "{label}-{tier}.filelist".
# Example: "all[-{detector}[-{measurement}[-{run}[-{timestamp}]]]]-{tier}.gen":
rule autogen_output:
input:
filelist=read_filelist,
output:
gen_output="{label}-{tier}.gen",
summary_log=f"{log_path(setup)}/summary-"
+ "{label}-{tier}"
+ f"-{datetime.strftime(datetime.utcnow(), '%Y%m%dT%H%M%SZ')}.log",
warning_log=f"{log_path(setup)}/warning-"
+ "{label}-{tier}"
+ f"-{datetime.strftime(datetime.utcnow(), '%Y%m%dT%H%M%SZ')}.log",
params:
log_path=tmp_log_path(setup),
tmp_par_path=os.path.join(tmp_par_path(setup), "*_db.json"),
valid_keys_path=os.path.join(pars_path(setup), "valid_keys"),
filedb_path=os.path.join(pars_path(setup), "filedb"),
setup=lambda wildcards: setup,
basedir=basedir,
script:
"scripts/complete_run.py"
# This rule builds the tcm files each raw file
rule build_tier_tcm:
input:
get_pattern_tier_raw(setup),
output:
get_pattern_tier_tcm(setup),
log:
get_pattern_log(setup, "tier_tcm"),
group:
"tier-tcm"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/build_tcm.py --log {log} --configs {configs} {input} {output}"
def read_filelist_raw_cal_channel(wildcards):
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal"
with checkpoints.gen_filelist.get(label=label, tier="raw", extension="file").output[
0
].open() as f:
files = f.read().splitlines()
return files
rule build_pars_dsp_tau:
input:
files=read_filelist_raw_cal_channel,
params:
timestamp="{timestamp}",
datatype="cal",
channel="{channel}",
output:
decay_const=temp(get_pattern_pars_tmp_channel(setup, "dsp", "decay_constant")),
plots=temp(get_pattern_plts_tmp_channel(setup, "dsp", "decay_constant")),
log:
get_pattern_log_channel(setup, "par_dsp_decay_constant"),
group:
"par-dsp"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_dsp_tau.py "
"--configs {configs} "
"--log {log} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--channel {params.channel} "
"--plot_path {output.plots} "
"--output_file {output.decay_const} "
"{input.files}"
# This rule builds the optimal energy filter parameters for the dsp using calibration dsp files
rule build_pars_dsp_eopt:
input:
files=os.path.join(
filelist_path(setup), "all-{experiment}-{period}-{run}-cal-raw.filelist"
),
decay_const=get_pattern_pars_tmp_channel(setup, "dsp", "decay_constant"),
inplots=get_pattern_plts_tmp_channel(setup, "dsp", "decay_constant"),
params:
timestamp="{timestamp}",
datatype="cal",
channel="{channel}",
output:
dsp_pars=temp(get_pattern_pars_tmp_channel(setup, "dsp")),
qbb_grid=temp(get_pattern_pars_tmp_channel(setup, "dsp", "energy_grid")),
plots=temp(get_pattern_plts_tmp_channel(setup, "dsp")),
log:
get_pattern_log_channel(setup, "pars_dsp_eopt"),
group:
"par-dsp"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_dsp_eopt.py "
"--log {log} "
"--configs {configs} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--channel {params.channel} "
"--raw_filelist {input.files} "
"--inplots {input.inplots} "
"--decay_const {input.decay_const} "
"--plot_path {output.plots} "
"--qbb_grid_path {output.qbb_grid} "
"--final_dsp_pars {output.dsp_pars}"
def read_filelist_pars_dsp_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="dsp", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
return files
def read_filelist_plts_dsp_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="dsp", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
files = [file.replace("par", "plt").replace("json", "pkl") for file in files]
return files
def read_filelist_pars_dsp_cal_channel_results(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(
label=label, tier="dsp_energy_grid", extension="chan"
).output[0].open() as f:
files = f.read().splitlines()
return files
rule build_pars_dsp:
input:
read_filelist_pars_dsp_cal_channel,
read_filelist_pars_dsp_cal_channel_results,
read_filelist_plts_dsp_cal_channel,
output:
get_pattern_par_dsp(setup),
get_pattern_par_dsp(setup, name="energy_grid", extension="pkl"),
get_pattern_plts(setup, "dsp"),
group:
"merge-dsp"
shell:
"{swenv} python3 -B {basedir}/scripts/merge_channels.py --input {input} --output {output}"
def get_pars_dsp_file(wildcards):
"""
This function will get the pars file for the run checking the pars_overwrite
"""
out = ds.pars_catalog.get_par_file(setup, wildcards.timestamp, "dsp")
return out
rule build_dsp:
input:
raw_file=get_pattern_tier_raw(setup),
tcm_file=get_pattern_tier_tcm(setup),
pars_file=ancient(get_pars_dsp_file),
params:
timestamp="{timestamp}",
datatype="{datatype}",
output:
tier_file=get_pattern_tier_dsp(setup),
db_file=get_pattern_pars_tmp(setup, "dsp_db"),
log:
get_pattern_log(setup, "tier_dsp"),
group:
"tier-dsp"
resources:
runtime=300,
mem_swap=30,
shell:
"{swenv} python3 -B {basedir}/scripts/build_dsp.py "
"--log {log} "
"--configs {configs} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--input {input.raw_file} "
"--output {output.tier_file} "
"--db_file {output.db_file} "
"--pars_file {input.pars_file}"
def read_filelist_dsp_cal(wildcards):
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal"
with checkpoints.gen_filelist.get(label=label, tier="dsp", extension="file").output[
0
].open() as f:
files = f.read().splitlines()
return files
# This rule builds the energy calibration using the calibration dsp files
rule build_energy_calibration:
input:
files=read_filelist_dsp_cal,
ctc_dict=ancient(get_pars_dsp_file),
params:
timestamp="{timestamp}",
datatype="cal",
channel="{channel}",
output:
ecal_file=temp(get_pattern_pars_tmp_channel(setup, "hit", "energy_cal")),
results_file=temp(
get_pattern_pars_tmp_channel(
setup, "hit", "energy_cal_results", extension="pkl"
)
),
plot_file=temp(get_pattern_plts_tmp_channel(setup, "hit", "energy_cal")),
log:
get_pattern_log_channel(setup, "pars_hit_energy_cal"),
group:
"par-hit"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_hit_ecal.py "
"--log {log} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--channel {params.channel} "
"--configs {configs} "
"--plot_path {output.plot_file} "
"--results_path {output.results_file} "
"--save_path {output.ecal_file} "
"--ctc_dict {input.ctc_dict} "
"--files {input.files}"
# This rule builds the a/e calibration using the calibration dsp files
rule build_aoe_calibration:
input:
files=os.path.join(
filelist_path(setup), "all-{experiment}-{period}-{run}-cal-dsp.filelist"
),
ecal_file=get_pattern_pars_tmp_channel(setup, "hit", "energy_cal"),
eres_file=get_pattern_pars_tmp_channel(
setup, "hit", "energy_cal_results", extension="pkl"
),
inplots=get_pattern_plts_tmp_channel(setup, "hit", "energy_cal"),
params:
timestamp="{timestamp}",
datatype="cal",
channel="{channel}",
output:
hit_pars=temp(get_pattern_pars_tmp_channel(setup, "hit")),
aoe_results=temp(
get_pattern_pars_tmp_channel(setup, "hit", "results", extension="pkl")
),
plot_file=temp(get_pattern_plts_tmp_channel(setup, "hit")),
log:
get_pattern_log_channel(setup, "pars_hit_aoe_cal"),
group:
"par-hit"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_hit_aoe.py "
"--log {log} "
"--configs {configs} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--inplots {input.inplots} "
"--channel {params.channel} "
"--aoe_results {output.aoe_results} "
"--eres_file {input.eres_file} "
"--hit_pars {output.hit_pars} "
"--plot_file {output.plot_file} "
"--ecal_file {input.ecal_file} {input.files}"
def read_filelist_pars_hit_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="hit", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
return files
def read_filelist_plts_hit_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="hit", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
files = [file.replace("par", "plt").replace("json", "pkl") for file in files]
return files
def read_filelist_pars_hit_cal_channel_results(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(
label=label, tier="hit_results", extension="chan"
).output[0].open() as f:
files = f.read().splitlines()
files = [file.replace("json", "pkl") for file in files]
return files
checkpoint build_pars_hit:
input:
read_filelist_pars_hit_cal_channel,
read_filelist_pars_hit_cal_channel_results,
read_filelist_plts_hit_cal_channel,
output:
get_pattern_par_hit(setup),
get_pattern_par_hit(setup, name="results", extension="dir"),
get_pattern_plts(setup, "hit"),
group:
"merge-hit"
shell:
"{swenv} python3 -B {basedir}/scripts/merge_channels.py --input {input} --output {output}"
def get_pars_hit_file(wildcards):
"""
This function will get the pars file for the run checking the pars_overwrite
"""
return ds.pars_catalog.get_par_file(setup, wildcards.timestamp, "hit")
rule build_hit:
input:
dsp_file=get_pattern_tier_dsp(setup),
pars_file=get_pars_hit_file,
output:
tier_file=get_pattern_tier_hit(setup),
db_file=get_pattern_pars_tmp(setup, "hit_db"),
params:
timestamp="{timestamp}",
datatype="{datatype}",
tier="hit",
log:
get_pattern_log(setup, "tier_hit"),
group:
"tier-hit"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/build_hit.py "
"--configs {configs} "
"--log {log} "
"--tier {params.tier} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--pars_file {input.pars_file} "
"--output {output.tier_file} "
"--input {input.dsp_file} "
"--db_file {output.db_file}"
# This rule builds the energy calibration using the calibration dsp files
rule build_per_energy_calibration:
input:
files=read_filelist_dsp_cal,
ctc_dict=ancient(get_pars_dsp_file),
params:
timestamp="{timestamp}",
datatype="cal",
channel="{channel}",
output:
ecal_file=temp(get_pattern_pars_tmp_channel(setup, "pht", "energy_cal")),
results_file=temp(
get_pattern_pars_tmp_channel(
setup, "pht", "energy_cal_results", extension="pkl"
)
),
plot_file=temp(get_pattern_plts_tmp_channel(setup, "pht", "energy_cal")),
log:
get_pattern_log_channel(setup, "pars_pht_energy_cal"),
group:
"par-pht"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_hit_ecal.py "
"--log {log} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--channel {params.channel} "
"--configs {configs} "
"--plot_path {output.plot_file} "
"--results_path {output.results_file} "
"--save_path {output.ecal_file} "
"--ctc_dict {input.ctc_dict} "
"--files {input.files}"
def read_filelist_pars_pht_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="pht", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
return files
def read_filelist_plts_pht_cal_channel(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(label=label, tier="pht", extension="chan").output[
0
].open() as f:
files = f.read().splitlines()
files = [file.replace("par", "plt").replace("json", "pkl") for file in files]
return files
def read_filelist_pars_pht_cal_channel_results(wildcards):
"""
This function will read the filelist of the channels and return a list of dsp files one for each channel
"""
label = f"all-{wildcards.experiment}-{wildcards.period}-{wildcards.run}-cal-{wildcards.timestamp}-channels"
with checkpoints.gen_filelist.get(
label=label, tier="pht_results", extension="chan"
).output[0].open() as f:
files = f.read().splitlines()
files = [file.replace("json", "pkl") for file in files]
return files
checkpoint build_pars_pht:
input:
read_filelist_pars_pht_cal_channel,
read_filelist_pars_pht_cal_channel_results,
read_filelist_plts_pht_cal_channel,
output:
get_pattern_par_pht(setup),
get_pattern_par_pht(setup, name="results", extension="dir"),
get_pattern_plts(setup, "pht"),
group:
"merge-hit"
shell:
"{swenv} python3 -B {basedir}/scripts/merge_channels.py --input {input} --output {output}"
def get_pars_pht_file(wildcards):
"""
This function will get the pars file for the run checking the pars_overwrite
"""
return ds.pars_catalog.get_par_file(setup, wildcards.timestamp, "pht")
rule build_pht:
input:
dsp_file=get_pattern_tier_dsp(setup),
#hit_file = get_pattern_tier_hit(setup),
pars_file=get_pars_pht_file,
output:
tier_file=get_pattern_tier_pht(setup),
db_file=get_pattern_pars_tmp(setup, "pht_db"),
params:
timestamp="{timestamp}",
datatype="{datatype}",
tier="pht",
log:
get_pattern_log(setup, "tier_pht"),
group:
"tier-pht"
resources:
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/build_hit.py "
"--configs {configs} "
"--log {log} "
"--tier {params.tier} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--pars_file {input.pars_file} "
"--output {output.tier_file} "
"--input {input.dsp_file} "
"--db_file {output.db_file}"
# def fix_name(new_name):
# """ sets the name of the most recently created rule to be new_name
# """
# list(workflow.rules)[-1].name = new_name
# temp_rules = list(rules.__dict__.items())
# temp_rules[-1] = (new_name, temp_rules[-1][1])
# rules.__dict__ = dict(temp_rules)
part_pht_rules = {}
for key, dataset in part.datasets.items():
for partition in dataset.keys():
rule:
input:
files=part.get_filelists(partition, key, "dsp"),
ecal_file=part.get_par_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
name="energy_cal",
),
eres_file=part.get_par_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
name="energy_cal_results",
extension="pkl",
),
inplots=part.get_plt_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
name="energy_cal",
),
params:
datatype="cal",
channel="{channel}",
timestamp=part.get_timestamp(
f"{par_pht_path(setup)}/validity.jsonl", partition, key, tier="pht"
),
output:
hit_pars=[
temp(file)
for file in part.get_par_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
)
],
aoe_results=[
temp(file)
for file in part.get_par_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
name="results",
extension="pkl",
)
],
plot_file=[
temp(file)
for file in part.get_plt_files(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
tier="pht",
)
],
log:
part.get_log_file(
f"{par_pht_path(setup)}/validity.jsonl",
partition,
key,
"pht",
name="par_pht",
),
group:
"par-pht"
resources:
mem_swap=75,
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_pht.py "
"--log {log} "
"--configs {configs} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--inplots {input.inplots} "
"--channel {params.channel} "
"--aoe_results {output.aoe_results} "
"--eres_file {input.eres_file} "
"--hit_pars {output.hit_pars} "
"--plot_file {output.plot_file} "
"--ecal_file {input.ecal_file} "
"--input_files {input.files}"
# fix_name(f"{key}-{partition}")
if key in part_pht_rules:
part_pht_rules[key].append(list(workflow.rules)[-1])
else:
part_pht_rules[key] = [list(workflow.rules)[-1]]
# Merged energy and a/e supercalibrations to reduce number of rules as they have same inputs/outputs
# This rule builds the a/e calibration using the calibration dsp files for the whole partition
rule build_pht_super_calibrations:
input:
files=os.path.join(
filelist_path(setup), "all-{experiment}-{period}-{run}-cal-dsp.filelist"
),
ecal_file=get_pattern_pars_tmp_channel(setup, "pht", "energy_cal"),
eres_file=get_pattern_pars_tmp_channel(
setup, "pht", "energy_cal_results", extension="pkl"
),
inplots=get_pattern_plts_tmp_channel(setup, "pht", "energy_cal"),
params:
datatype="cal",
channel="{channel}",
timestamp="{timestamp}",
output:
hit_pars=temp(get_pattern_pars_tmp_channel(setup, "pht")),
aoe_results=temp(
get_pattern_pars_tmp_channel(setup, "pht", "results", extension="pkl")
),
plot_file=temp(get_pattern_plts_tmp_channel(setup, "pht")),
log:
get_pattern_log_channel(setup, "pars_pht_aoe_cal"),
group:
"par-pht"
resources:
mem_swap=60,
runtime=300,
shell:
"{swenv} python3 -B {basedir}/scripts/pars_pht.py "
"--log {log} "
"--configs {configs} "
"--datatype {params.datatype} "
"--timestamp {params.timestamp} "
"--inplots {input.inplots} "
"--channel {params.channel} "
"--aoe_results {output.aoe_results} "
"--eres_file {input.eres_file} "
"--hit_pars {output.hit_pars} "
"--plot_file {output.plot_file} "
"--ecal_file {input.ecal_file} "
"--input_files {input.files}"
fallback_pht_rule = list(workflow.rules)[-1]
rule_order_list = []
ordered = OrderedDict(part_pht_rules)
ordered.move_to_end("default")
for key, items in ordered.items():
rule_order_list += [item.name for item in items]
rule_order_list.append(fallback_pht_rule.name)
workflow._ruleorder.add(*rule_order_list) # [::-1]