Belle II Software  release-08-01-10
rawdata_compatibility_base.py
1 #!/usr/bin/env python3
2 
3 
10 
11 """
12 Test backwards compatibility for RAW Objects and Unpackers.
13 
14 The ability to unpack all recorded Belle II events also with future release is
15 vital to be able to reconstruct the full Belle II dataset during the lifetime of the experiment
16 and after that.
17 This is the basis of unit tests which execute the unpackers and checks for the properties of the
18 unpacked sub-detector StoreArrays.
19 """
20 
21 import sys
22 import os
23 import glob
24 from ROOT import Belle2
25 from basf2 import create_path, process, LogLevel, set_log_level, set_random_seed, conditions
26 from b2test_utils import require_file
27 from b2test_utils.datastoreprinter import DataStorePrinter, PrintObjectsModule
28 
29 from rawdata import add_unpackers
30 
31 
32 # Now we define a list of all the unpacker output we want to print out and all
33 # the members we want to check
34 unpacked_dataobjects = [
35  DataStorePrinter("PXDRawHit", ["getRow", "getColumn", "getCharge"]),
36  DataStorePrinter("SVDShaperDigit", ["getCellID", "getFADCTime", "toString"]),
37  DataStorePrinter("CDCHit", ["getID", "getStatus", "getTDCCount", "getADCCount"]),
38  DataStorePrinter("ECLDigit", ["getCellId", "getAmp", "getTimeFit"]),
39  DataStorePrinter("TOPDigit", ["getModuleID", "getPixelID", "getPixelRow", "getPixelCol", "getRawTime",
40  "getPulseHeight", "getPulseWidth"]),
41  DataStorePrinter("ARICHDigit", ["getModuleID", "getChannelID", "getBitmap"]),
42  DataStorePrinter("BKLMDigit", ["getUniqueChannelID", "getTime", "getEnergyDeposit", "getCharge", "getTime"]),
43  DataStorePrinter("EKLMDigit", ["getUniqueChannelID", "getCTime", "getCharge", "getPlane", "getStrip"]),
44  DataStorePrinter("CDCTriggerSegmentHit", ["getID"]),
45  DataStorePrinter("CDCTrigger2DFinderTrack", ["getTime", "getPt"]),
46  DataStorePrinter("CDCTriggerNeuroTrack", ["getTime", "getPt"]),
47 ]
48 
49 
50 def unpack_and_print_files(filenames):
51  """
52  process a given files and print its unpacked raw contents
53  Needs to all happen in one process call, otherwise the Geomtery would
54  be loaded multiple times, which results in an error
55  """
56 
57  if len(filenames) == 0:
58  print("TEST SKIPPED: No input files for test",
59  file=sys.stderr)
60  sys.exit(1)
61 
62  raw_files = [Belle2.FileSystem.findFile(f) for f in filenames]
63  main = create_path()
64  main.add_module("RootInput", inputFileNames=raw_files, logLevel=LogLevel.WARNING)
65 
66  main.add_module("EventInfoPrinter")
67 
68  main.add_module("Gearbox")
69  main.add_module("Geometry", useDB=True)
70  add_unpackers(main)
71  main.add_module(PrintObjectsModule(unpacked_dataobjects))
72  # only 5 events for now, otherwise the text file for comparison will be to big
73  # for git
74  process(main, 5)
75 
76 
77 def test_raw(phase_name, postfix, global_tag):
78  """
79  Runs the whole Raw unpacking testing scheme for one global tag for phase 2 or phase 3 events
80  """
81 
82  set_log_level(LogLevel.ERROR)
83  set_random_seed(1)
84  # only override the default global tag if a specific GT was provided for this test
85  if global_tag:
86  conditions.override_globaltags([global_tag])
87  else:
88  # otherwise use current default globaltag
89  conditions.disable_globaltag_replay()
90 
91  rawdata_path = require_file(os.path.join('rawdata', phase_name), "validation")
92  unpack_and_print_files(glob.glob(os.path.join(rawdata_path, f"{postfix}*.root")))
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:148