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  print ("%40s%s%-40s" % (name, " | ", ', '.join(sorted(sgkeys))))
61  print ("="*80)
62  if args.output:
63  outFileName = args.output
64  outFileName = os.path.expanduser(outFileName)
65  outFileName = os.path.expandvars(outFileName)
66  print ("## saving report into [%s]..." % (outFileName,))
67  if os.path.splitext(outFileName)[1] in ('.pkl', '.dat'):
68  import shelve
69  if os.path.exists(outFileName):
70  os.remove(outFileName)
71  with shelve.open(outFileName) as db:
72  db['eventdata_items'] = item_list
73  else:
74  from pprint import pprint
75  with open( outFileName, 'w' ) as txt:
76  pprint( dict(item_list), txt )
77 
78  except Exception as e:
79  print ("## Caught exception [%s] !!" % str(e.__class__))
80  print ("## What:",e)
81  print (sys.exc_info()[0])
82  print (sys.exc_info()[1])
83  import traceback
84  traceback.print_exc()
85  exitcode = 1
86  pass
87 
88  if len(files) > 1:
89  print ()
90  pass # loop over fileNames
91 
92  print ("## Bye.")
93  return exitcode
94 
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:446