Belle II Software development
rawdata_compatibility_base.py
1#!/usr/bin/env python3
2
3
10
11"""
12Test backwards compatibility for RAW Objects and Unpackers.
13
14The ability to unpack all recorded Belle II events also with future release is
15vital to be able to reconstruct the full Belle II dataset during the lifetime of the experiment
16and after that.
17This is the basis of unit tests which execute the unpackers and checks for the properties of the
18unpacked sub-detector StoreArrays.
19"""
20
21import sys
22import os
23import glob
24from ROOT import Belle2
25from basf2 import create_path, process, LogLevel, set_log_level, set_random_seed, conditions
26from b2test_utils import require_file
27from b2test_utils.datastoreprinter import DataStorePrinter, PrintObjectsModule
28
29from 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
34unpacked_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
50def 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
77def 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:151