ATLAS Offline Software
Loading...
Searching...
No Matches
check_sg.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3# @file PyUtils.scripts.check_sg
4# @purpose read a POOL file and dump the DataHeader's content
5# @author Sebastien Binet
6# @date February 2010
7
8__doc__ = "read a POOL file and dump the DataHeader's content"
9__author__ = "Sebastien Binet"
10
11
12
13import PyUtils.acmdlib as acmdlib
14
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',
19 default=None,
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)
25 """)
26def main(args):
27 """read a POOL file and dump the DataHeader's content
28
29 ex:
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
34 """
35 files = args.files
36 if isinstance(files, str):
37 files = [files]
38
39 from collections import defaultdict
40 from PyUtils.MetaReader import read_metadata
41 import os
42 import sys
43
44 for i,f in enumerate(files):
45 files[i] = os.path.expandvars(os.path.expanduser(f))
46
47 exitcode = 0
48 for fname in files:
49 try:
50 print ("## checking [%s]..." % (fname,))
51
52 item_list = defaultdict(list)
53 md = read_metadata(fname)
54 for name, key in md.get(fname, {}).get('itemList', []):
55 item_list[name].append(key)
56
57 print ("="*80)
58 print ("%40s%s%-40s" % ("Container type", " | ","StoreGate keys"))
59 print ("%40s%s%-40s" % ("-"*40, "-+-", "-"*(40-3)))
60 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))))
63 print ("="*80)
64 if args.output:
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'):
70 import shelve
71 if os.path.exists(outFileName):
72 os.remove(outFileName)
73 with shelve.open(outFileName) as db:
74 db['eventdata_items'] = item_list
75 else:
76 from pprint import pprint
77 with open( outFileName, 'w' ) as txt:
78 pprint( dict(item_list), txt )
79
80 except Exception as e:
81 print ("## Caught exception [%s] !!" % str(e.__class__))
82 print ("## What:",e)
83 print (sys.exc_info()[0])
84 print (sys.exc_info()[1])
85 import traceback
86 traceback.print_exc()
87 exitcode = 1
88 pass
89
90 if len(files) > 1:
91 print ()
92 pass # loop over fileNames
93
94 print ("## Bye.")
95 return exitcode
96
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130