12from ROOT
import Belle2
13from b2test_utils
import clean_working_directory, safe_process
21class CreateDummyData(basf2.Module):
22 """Create some random data to have event size not be too small"""
24 def __init__(self, size, persistent=False):
27 durability = Belle2.DataStore.c_Persistent
if persistent
else Belle2.DataStore.c_Event
31 self.chunk_data.registerInDataStore()
37def get_metadata(filename):
38 meta = subprocess.check_output([
"b2file-metadata-show",
"--json", filename])
39 return json.loads(meta)
42def check_jobfile(jobfile, expected_files):
43 """Check that all output files are in the jobfile"""
44 with open(jobfile)
as inputfile:
45 data = json.load(inputfile)
48 for output
in data[
'output_files']:
49 seen.add(output[
'filename'])
50 assert all(output[
'checks_passed'])
is True,
"Output file didn't pass all tests"
51 assert os.path.exists(output[
'filename']),
"Output file doesn't exist"
53 assert seen == expected_files,
"didn't find all expected files"
56if __name__ ==
"__main__":
57 basf2.logging.log_level = basf2.LogLevel.ERROR
58 basf2.logging.enable_summary(
False)
59 basf2.set_random_seed(
"something important")
60 with clean_working_directory():
64 path.add_module(
"EventInfoSetter", evtNumList=550)
65 path.add_module(CreateDummyData(1024 * 10))
66 path.add_module(
"RootOutput", outputFileName=
"test_split.root", buildIndex=
False, updateFileCatalog=
False,
67 compressionAlgorithm=0, compressionLevel=0, outputSplitSize=3)
68 assert safe_process(path) == 0,
"RootOutput failed"
69 check_jobfile(
"job-info1.json", {f
"test_split.f0000{i}.root" for i
in range(2)})
72 meta = [get_metadata(e)
for e
in [
"test_split.f00000.root",
"test_split.f00001.root"]]
73 assert meta[0][
"parents"] == [],
"There should be no parents"
74 assert meta[1][
"parents"] == [],
"There should be no parents"
78 subprocess.check_call([
"b2file-metadata-add",
"-l", f
"parent{i}", f
"test_split.f0000{i}.root"])
79 assert os.path.exists(
"test_split.f00002.root")
is False,
"There should not be a third file"
84 path.add_module(
"RootInput", inputFileNames=[
"test_split.f00000.root",
"test_split.f00001.root"])
85 path.add_module(
"RootOutput", outputFileName=
"file://test_parents.root", buildIndex=
False, updateFileCatalog=
False,
86 compressionAlgorithm=0, compressionLevel=0, outputSplitSize=2)
87 assert safe_process(path) == 0,
"RootInput/Output failed"
89 check_jobfile(
"job-info2.json", {f
"test_parents.f0000{i}.root" for i
in range(3)})
90 assert os.path.exists(
"test_split.f00003.root")
is False,
"There should not be a fourth file"
93 meta = [get_metadata(e)
for e
in [
"test_parents.f00000.root",
"test_parents.f00001.root",
"test_parents.f00002.root"]]
94 assert meta[0][
"parents"] == [
"parent0"],
"parents wrong"
95 assert meta[1][
"parents"] == [
"parent0",
"parent1"],
"parents wrong"
96 assert meta[2][
"parents"] == [
"parent1"],
"parents wrong"
100 assert m[
"eventLow"] == last + 1,
"eventLow is not correct"
101 last = m[
"eventHigh"]
102 assert m[
"eventLow"] + m[
"nEvents"] - 1 == m[
"eventHigh"],
"event high is inconsistent"
103 assert m[
"mcEvents"] == 0,
"MC events cannot be saved"
105 assert sum(e[
"nEvents"]
for e
in meta) == 550,
"number of events must be correct"
110 "test_noext":
"test_noext.f00000.root",
112 "test_otherext.foo":
"test_otherext.f00000.root",
115 "file://test_param?foo=bar":
"test_param.f00000.root",
116 "file://test_anchor#foo":
"test_anchor.f00000.root",
118 basf2.logging.log_level = basf2.LogLevel.INFO
120 for name, result
in check_filenames.items():
121 with clean_working_directory():
123 path.add_module(
"EventInfoSetter")
124 path.add_module(CreateDummyData(10,
True))
125 path.add_module(
"RootOutput", outputFileName=name, outputSplitSize=1, updateFileCatalog=
False)
127 assert os.listdir() == [result],
"wrong output file name"
a (simplified) python wrapper for StoreObjPtr.
Storable object which can be filled with random chunk data of a certain size.