Belle II Software development
filemetadata.py
1#!/usr/bin/env python3
2
3
10
11from ROOT import Belle2
12import os
13import subprocess
14import json
15import basf2
16from basf2.version import get_version
17from b2test_utils import safe_process, clean_working_directory
18
19basf2.set_random_seed("something important")
20
21testFile = 'b2filemetadata.root'
22
23with clean_working_directory():
24
25 # Generate a small test file
26 main = basf2.Path()
27 main.add_module('EventInfoSetter', evtNumList=[9, 1], runList=[1, 15], expList=[7, 7])
28 main.add_module('RootOutput', outputFileName=testFile, updateFileCatalog=False)
29 safe_process(main)
30
31 # Check the file meta data (via DataStore)
32 read = basf2.Path()
33 read.add_module('RootInput', inputFileName=testFile)
34 basf2.process(read)
35
36 metadata = Belle2.PyStoreObj('FileMetaData', 1)
37
38 # print (metadata.getLfn()) #?
39 assert 10 == metadata.getNEvents()
40 assert 10 == metadata.getNFullEvents()
41
42 assert 7 == metadata.getExperimentLow()
43 assert 1 == metadata.getRunLow()
44 assert 1 == metadata.getEventLow()
45 assert 7 == metadata.getExperimentHigh()
46 assert 15 == metadata.getRunHigh()
47 assert 1 == metadata.getEventHigh() # highest evt. no in highest run
48 assert metadata.containsEvent(7, 1, 1)
49 assert metadata.containsEvent(7, 1, 9)
50 assert metadata.containsEvent(7, 15, 1)
51 assert metadata.containsEvent(7, 1, 10) # does not exist, but would be plausible
52 assert metadata.containsEvent(7, 3, 6) # same
53 assert not metadata.containsEvent(7, 0, 10) # does not exist, but would be plausible
54 assert not metadata.containsEvent(7, 16, 6) # same
55 assert not metadata.containsEvent(0, 15, 6)
56
57 assert 0 == metadata.getNParents()
58
59 # print (metadata.getDate())
60 # assert socket.gethostname() == metadata.getSite()
61 # print (metadata.getUser()) #different env variables, not checked
62 assert "something important" == metadata.getRandomSeed()
63
64 assert get_version() == metadata.getRelease()
65 assert metadata.getSteering().startswith('#!/usr/bin/env python3')
66 assert metadata.getSteering().strip().endswith('dummystring')
67 assert 10 == metadata.getMcEvents()
68
69 os.system('touch Belle2FileCatalog.xml')
70 assert 0 == os.system('b2file-metadata-add --lfn /logical/file/name ' + testFile)
71
72 assert 0 == os.system('b2file-metadata-show ' + testFile)
73
74 # Check JSON output (contains steering file, so we cannot use .out)
75 metadata_output = subprocess.check_output(['b2file-metadata-show', '--json', testFile])
76 m = json.loads(metadata_output.decode('utf-8'))
77 assert 7 == m['experimentLow']
78 assert 1 == m['runLow']
79 assert 1 == m['eventLow']
80 assert 7 == m['experimentHigh']
81 assert 15 == m['runHigh']
82 assert 1 == m['eventHigh']
83 assert 'something important' == m['randomSeed']
84 assert 10 == m['nEvents']
85 assert isinstance(m['nEvents'], int)
86 assert 10 == m['nFullEvents']
87 assert isinstance(m['nFullEvents'], int)
88 assert '/logical/file/name' == m['LFN']
89
90 # steering file is in metadata, so we check for existence of this string:
91 # dummystring
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67