Belle II Software  release-06-00-14
algorithm_dbaccess.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from ROOT import Belle2
14 
15 import pathlib
16 import argparse
17 parser = argparse.ArgumentParser()
18 parser.add_argument("input_data", help=("The path to the input data directory you want to use."
19  "It must contain a CollectorOutput.root file."))
20 # If the iteration is 0 then a localdb is created but no DBObjects are accessed inside
21 # the algorithm
22 # If the iteration is >0 then the previous DBObjects are read and then new ones are created
23 parser.add_argument("iteration",
24  type=int,
25  help="The iteration number used by the algorithm.")
26 
27 parser.add_argument("--resetdb-after-execute",
28  action="store_true",
29  dest="reset",
30  help=("Should we reset the database chain each time we execute the algorithm. "
31  "Or only set the database once before all executions (default)."))
32 
33 
34 args = parser.parse_args()
35 
36 b2.set_log_level(b2.LogLevel.DEBUG)
37 # View the framework debugging
38 b2.set_debug_level(100)
39 # For just the Algorithm debugging
40 # set_debug_level(29)
41 
43 
44 # Can use a Python list of input files/wildcards. It will resolve the existing files
45 inputFileNames = [pathlib.Path(args.input_data, "CollectorOutput.root").absolute().as_posix()]
46 algo.setInputFileNames(inputFileNames)
47 
48 if not args.reset:
49  # The local db that we will both write to and read from
50  b2.conditions.prepend_testing_payloads("localdb/database.txt")
51 
52 # We iterate over some runs and execute separately.
53 # This means that we repeatedly access the DB interface after committing
54 for i in range(1, 5):
55  if args.reset:
56  # We're doing this here to test what happens when resetting in a single Python process
57  # The local db that we will both write to and read from
58  b2.conditions.prepend_testing_payloads("localdb/database.txt")
59  print("Result of calibration =", algo.execute([(0, i)], args.iteration))
60  algo.commit()
Test class implementing calibration algorithm.