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