Belle II Software
release-08-01-10
caf_algorithmdb_access.py
1
18
19
import
basf2
as
b2
20
21
import
os
22
import
sys
23
24
from
ROOT.Belle2
import
TestDBAccessAlgorithm
25
26
from
caf.framework
import
Calibration, CAF
27
from
caf
import
backends
28
29
30
def
main
(argv):
31
if
len(argv) == 1:
32
data_dir = argv[0]
33
else
:
34
print(
"Usage: python3 caf_multiple_options.py <data directory>"
)
35
sys.exit(1)
36
37
41
input_files = [os.path.join(os.path.abspath(data_dir),
'*.root'
)]
42
43
45
dep_col = b2.register_module(
'CaTest'
)
46
dep_col.set_name(
'Dependent'
)
# Sets the prefix of the collected data in the datastore.
47
# Allows us to execute algorithm over input data in a run-by-run way so we can see DB constants from each run.
48
dep_col.param(
'granularity'
,
'run'
)
49
# Specific parameter to our test collector, proportional to the probability of algorithm requesting iteration.
50
dep_col.param(
'spread'
, 15)
51
52
dep_alg = TestDBAccessAlgorithm()
53
# Since we're using several instances of the same test algorithm here, we still want the database entries to have
54
# different names. TestCalibrationAlgorithm outputs to the database using the prefix name so we change it
55
# for each calibration. Not something you'd usually have to do. And you could instead use whatever name you want,
56
# we just use the prefix as a handy string.
57
dep_alg.setPrefix(
'Dependent'
)
# Must be the same as colllector prefix
58
59
# Create our Calibration object
60
dep_cal =
Calibration
(name=
'Dependent_Calibration'
,
61
collector=dep_col,
62
algorithms=dep_alg,
63
input_files=input_files)
64
65
# Let's split up the collector jobs by files
66
dep_cal.max_files_per_collector_job = 1
67
dep_cal.max_iterations = 5
68
69
# This one runs last and picks up the final DB constants from the first one
70
last_col = b2.register_module(
'CaTest'
)
71
last_col.set_name(
'Last'
)
# Sets the prefix of the collected data in the datastore.
72
# Allows us to execute algorithm over input data in a run-by-run way so we can see DB constants from each run.
73
last_col.param(
'granularity'
,
'run'
)
74
# Specific parameter to our test collector, proportional to the probability of algorithm requesting iteration.
75
last_col.param(
'spread'
, 15)
76
77
last_alg = TestDBAccessAlgorithm()
78
last_alg.setGeneratePayloads(
False
)
79
last_alg.setPrefix(
'Last'
)
# Must be the same as colllector prefix
80
81
# Create our Calibration object
82
last_cal =
Calibration
(name=
'Last_Calibration'
,
83
collector=last_col,
84
algorithms=last_alg,
85
input_files=input_files)
86
87
# Let's split up the collector jobs by files
88
last_cal.max_files_per_collector_job = 1
89
last_cal.max_iterations = 5
90
91
# Define dependencies
92
last_cal.depends_on(dep_cal)
93
94
96
cal_fw = CAF()
97
cal_fw.add_calibration(dep_cal)
98
cal_fw.add_calibration(last_cal)
99
# Subjobs from collector jobs being split over input files can be paralellized.
100
# Also Calibrations 1 and 2, can be run at the same time.
101
# If you have 4 cores this backend will run them whenever one of the 4 processes becomes available
102
# For larger data or more calibrations, consider using the LSF or PBS batch system backends at your site
103
cal_fw.backend = backends.Local(max_processes=4)
104
# Start her up!
105
cal_fw.run()
106
print(
"End of CAF processing."
)
107
108
109
if
__name__ ==
"__main__"
:
110
main
(sys.argv[1:])
Calibration
Definition:
Calibration.py:1
main
Definition:
main.py:1
main
int main(int argc, char **argv)
Run all tests.
Definition:
test_main.cc:91
calibration
examples
caf_algorithmdb_access.py
Generated on Mon Sep 23 2024 14:00:48 for Belle II Software by
1.9.1