8 __doc__ =
"read a POOL file and dump the DataHeader's content"
9 __author__ =
"Sebastien Binet"
13 import PyUtils.acmdlib
as acmdlib
15 @acmdlib.command(name=
'chk-sg')
16 @acmdlib.argument(
'files', nargs=
'+',
17 help=
'path to the POOL file(s) to analyze')
18 @acmdlib.argument(
'-o',
'--output',
20 help=
"""name of the output file which will contain the
21 informations gathered during checkSG processing.
22 These informations will be stored into a python-shelve or
23 an ASCII/py file (depending on the extension:
24 .pkl,.dat -> shelve; everything else -> ASCII/py)
27 """read a POOL file and dump the DataHeader's content
30 $ check-sg aod.pool.root
31 $ check-sg /castor/foo.pool
32 $ check-sg root://castoratlas//castor/foo.pool
33 $ check-sg LFN:ttbar.pool
36 if isinstance(files, str):
39 from collections
import defaultdict
40 from PyUtils.PoolFile
import extract_items
44 for i,f
in enumerate(files):
45 files[i] = os.path.expandvars(os.path.expanduser(f))
50 print (
"## checking [%s]..." % (fname,))
52 item_list = defaultdict(list)
53 for name, key
in extract_items(fname, verbose=
False, items_type=
'eventdata'):
54 item_list[name].
append(key)
57 print (
"%40s%s%-40s" % (
"Container type",
" | ",
"StoreGate keys"))
58 print (
"%40s%s%-40s" % (
"-"*40,
"-+-",
"-"*(40-3)))
59 for name, sgkeys
in sorted(item_list.items()):
61 sgkeys = [(k.decode(
"utf-8")
if not isinstance(k, str)
else k)
for k
in sgkeys]
62 print (
"%40s%s%-40s" % (name,
" | ",
', '.
join(
sorted(sgkeys))))
65 outFileName = args.output
66 outFileName = os.path.expanduser(outFileName)
67 outFileName = os.path.expandvars(outFileName)
68 print (
"## saving report into [%s]..." % (outFileName,))
69 if os.path.splitext(outFileName)[1]
in (
'.pkl',
'.dat'):
71 if os.path.exists(outFileName):
72 os.remove(outFileName)
73 with shelve.open(outFileName)
as db:
74 db[
'eventdata_items'] = item_list
76 from pprint
import pprint
77 with open( outFileName,
'w' )
as txt:
78 pprint( dict(item_list), txt )
80 except Exception
as e:
81 print (
"## Caught exception [%s] !!" %
str(e.__class__))
83 print (sys.exc_info()[0])
84 print (sys.exc_info()[1])