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