-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollInfo
executable file
·47 lines (36 loc) · 1.6 KB
/
collInfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
'''
Simple script to read podio CollectionID table from reco file
originally by Louis Portales
'''
import uproot
import argparse
parser = argparse.ArgumentParser(description='Print out Collection IDs')
parser.add_argument('input', type=str)
args = parser.parse_args()
infile = uproot.open(args.input)
if 'podio_metadata;1' in infile.keys():
ids = infile['podio_metadata']['events___idTable']['m_collectionIDs'].array()[0]
names = infile['podio_metadata']['events___idTable']['m_names'].array()[0]
types = infile['podio_metadata']['events___CollectionTypeInfo._1'].array()[0]
ids_width = len(str(max(ids)))
names_width = len(max(names, key=len))
types_width = len(max(types, key=len))
print('ID ' + ids_width * ' ' + 'Name' + (names_width - 1) * ' ' + 'Type')
print((6 + ids_width + names_width + types_width) * '-')
for id,name,type in zip(ids, names, types):
print(f"{id:{ids_width}} {name:{names_width}} {type:{types_width}}")
print((6 + ids_width + names_width + types_width) * '-')
elif 'metadata;1' in infile.keys():
ids = infile['metadata']['CollectionIDs']['m_collectionIDs'].array()[0]
names = infile['metadata']['CollectionIDs']['m_names'].array()[0]
ids_width = len(str(max(ids)))
names_width = len(max(names, key=len))
print('ID ' + ids_width * ' ' + 'Name')
print((3 + ids_width + names_width) * '-')
for id,name in zip(ids, names):
print(f"{id:{ids_width}} {name:{names_width}}")
print((3 + ids_width + names_width) * '-')
else:
print('ERROR: File format not known! Aborting...')
exit(1)