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