ATLAS Offline Software
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 
13 import 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  """)
26 def 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.PoolFile import extract_items
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  for name, key in extract_items(fname, verbose=False, items_type='eventdata'):
54  item_list[name].append(key)
55 
56  print ("="*80)
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()):
60  # decode b-strings to strings
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 
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.scripts.check_sg.main
def main(args)
Definition: check_sg.py:26
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolFile.extract_items
def extract_items(pool_file, verbose=True, items_type='eventdata')
Definition: PoolFile.py:454