ATLAS Offline Software
check_file.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_file
4 # @purpose read a POOL file and dump its content.
5 # @author Sebastien Binet
6 # @date February 2010
7 
8 __doc__ = "read a POOL file and dump its content."
9 __author__ = "Sebastien Binet"
10 
11 
12 
13 import PyUtils.acmdlib as acmdlib
14 
15 @acmdlib.command(name='chk-file')
16 @acmdlib.argument('files', nargs='+',
17  help='path to the POOL file(s) to analyze')
18 @acmdlib.argument('-d', '--detailed-dump',
19  action='store_true',
20  default=False,
21  help="""Switch to activate or not a detailed dump
22  of each TTree in the POOL file""")
23 @acmdlib.argument('--sort-fct',
24  choices=('diskSize','memSize','name'),
25  default='diskSize',
26  help="Sorting function used to list containers")
27 @acmdlib.argument('--fast',
28  action='store_true',
29  default=False,
30  help="""Enable fast mode.
31  Memory size will not be accurate AT ALL""")
32 @acmdlib.argument('-o', '--output',
33  default=None,
34  help="""name of the output file which will contain the
35  informations gathered during processing.
36  These informations will be stored into a python-shelve or
37  an ASCII/py file (depending on the extension:
38  .pkl,.dat -> shelve; everything else -> ASCII/py)
39  """)
40 def main(args):
41  """read a POOL file and dump its content.
42  """
43  files = args.files
44  if isinstance(files, str):
45  files=[files]
46 
47  import sys
48  import os
49 
50  for i,f in enumerate(files):
51  files[i] = os.path.expandvars(os.path.expanduser(f))
52 
53  exitcode = 0
54  for fname in files:
55  try:
56  import PyUtils.PoolFile as PF
57  PF.PoolOpts.FAST_MODE = args.fast
58  pool_file = PF.PoolFile(fname)
59  pool_file.checkFile(sorting=args.sort_fct)
60  if args.detailed_dump:
61  dump_file = os.path.basename(fname) + '.txt'
62  print ("## dumping details into [%s]" % (dump_file,))
63  pool_file.detailedDump(dump_file)
64  if args.output:
65  oname = args.output
66  print ("## saving report into [%s]..." % (oname,))
67  pool_file.saveReport(oname)
68  except Exception as e:
69  print ("## Caught exception [%s] !!" % str(e.__class__))
70  print ("## What:",e)
71  print (sys.exc_info()[0])
72  print (sys.exc_info()[1])
73  import traceback
74  traceback.print_exc()
75  exitcode = 1
76  pass
77 
78  if len(files) > 1:
79  print ("")
80  pass # loop over fileNames
81 
82  print ("## Bye.")
83  return exitcode
84 
python.scripts.check_file.main
def main(args)
Definition: check_file.py:40
str
Definition: BTagTrackIpAccessor.cxx:11