8from b2test_utils
import configure_logging_for_tests
10from ROOT
import Belle2
17class DBInterface(unittest.TestCase):
18 def assertDeath(self, function, *args, **kwargs):
19 """Run function in child process and check if it died. Only way to check for B2FATAL"""
20 ctx = multiprocessing.get_context(
"fork")
21 p = ctx.Process(target=function, args=args, kwargs=kwargs)
24 self.assertNotEqual(p.exitcode, 0)
27 configure_logging_for_tests()
33 """Test object interface"""
36 self.assertFalse(bp.isValid())
40 vertex = ROOT.Math.XYZVector(1, 2, 3)
43 override_object.setVertex(vertex, ROOT.std.vector(
"double")())
47 self.assertTrue(bp.isValid())
51 self.assertDeath(
lambda:
Belle2.PyDBObj(
"BeamParameters", Belle2.PXDSimHit.Class()))
53 self.assertDeath(
lambda:
Belle2.PyDBArray(
"BeamParameters", Belle2.PXDSimHit.Class()))
56 self.assertEqual(bp.obj().getVertex(), vertex)
58 self.assertEqual(bp.getVertex(), vertex)
60 with self.assertRaises(AttributeError):
70 self.assertEqual(copy, bp.obj())
75 self.assertFalse(bplist.isValid())
77 override_array = ROOT.TClonesArray(
"Belle2::BeamParameters")
78 override_array.ExpandCreate(3)
79 for i
in range(override_array.GetEntriesFast()):
80 override_array[i].setVertex(ROOT.Math.XYZVector(i, i, i), ROOT.std.vector(
"double")())
85 self.assertTrue(bplist.isValid())
88 self.assertDeath(
lambda:
Belle2.PyDBArray(
"BeamParameterList", Belle2.PXDSimHit.Class()))
90 self.assertDeath(
lambda:
Belle2.PyDBObj(
"BeamParameterList", Belle2.PXDSimHit.Class()))
92 self.assertEqual(len(bplist), override_array.GetEntriesFast())
95 for i, e
in enumerate(bplist):
97 self.assertEqual(int(e.getVertex().X()), i)
99 self.assertEqual(e, override_array[i])
101 self.assertEqual(e, bplist[i])
104 self.assertEqual(e, copy)
106 copy.setVertex(ROOT.Math.XYZVector(1, 2, 3), ROOT.std.vector(
"double")())
107 self.assertNotEqual(e, copy)
109 with self.assertRaises(AttributeError):
110 e.setVertex(ROOT.Math.XYZVector(1, 2, 3), ROOT.std.vector(
"double")())
112 self.assertEqual(i + 1, len(bplist))
115 with self.assertRaises(TypeError):
119if __name__ ==
"__main__":
This class contains the nominal beam parameters and the parameters used for smearing of the primary v...
Class to access a DB Array from Python.
Class to access a DBObjPtr from Python.
static DBStore & Instance()
Instance of a singleton DBStore.