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