ATLAS Offline Software
sg-dump.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 # @file: PyDumper/bin/sg-dump.py
5 # @purpose: a simple python script to run pyathena and use PySgDumper to dump
6 # a (set of) event(s) from a POOL (esd/aod) file into an ASCII file
7 # @author: Sebastien Binet <binet@cern.ch>
8 # @date: October 2008
9 #
10 # @example:
11 # @verbatim
12 # sg-dump aod.pool -o aod.ascii
13 # sg-dump /castor/cern.ch/foo.pool -o foo.ascii
14 # sg-dump aod1.pool aod2.pool -o aods.ascii
15 # @endcode
16 
17 import sys
18 import os
19 
20 __version__ = "$Revision: 1.4 $"
21 __author__ = "Sebastien Binet <binet@cern.ch>"
22 __doc__ = """\
23 a simple python script to run pyathena and use PySgDumper to dump
24 a (set of) event(s) from a POOL (esd/aod) file into an ASCII file\
25 """
26 
27 from optparse import OptionParser
28 
29 import PyDumper.SgDumpLib as SgDumpLib
30 
31 def _str_to_slice (slice_str):
32  """translate a string into a python slice
33  """
34  sl= [int(s) if s != '' else None for s in slice_str.split(':')]
35  if len(sl)==2:
36  sl.append (None)
37  assert len(sl)==3, 'invalid input slice string'
38  start = sl[0]
39  stop = sl[1]
40  step = sl[2]
41  return slice (start, stop, step)
42 
43 if __name__ == "__main__":
44  parser = OptionParser(
45  usage="usage: %prog [options] -o out.ascii in1.pool "\
46  "[in2.pool [in3.pool [...]]]"
47  )
48  _add = parser.add_option
49  _add("-o",
50  "--output",
51  dest = "oname",
52  default = None,
53  help = "Name of the output file which will contain the informations"\
54  " gathered during athena processing. These informations "\
55  "will be stored into an ascii file.")
56 
57  _add('--evts',
58  dest = 'evts',
59  type = int,
60  default = -1,
61  help = "list of events or event-max or (python) slice of events."\
62  " (dummy for now: only understand event-max syntax)")
63 
64  _add('--skip',
65  dest = 'skip',
66  type = int,
67  default = 0,
68  help = "number of events to skip.")
69 
70  _add("--dump-jobo",
71  dest = "dump_jobo",
72  default = None,
73  help = "tell application to save the automatically generated "\
74  "joboption under some name for (mainly) debugging "\
75  "and/or customization purposes.")
76 
77  _add("--do-clean-up",
78  dest = "do_clean_up",
79  action = "store_true",
80  default = True,
81  help = "switch to enable the attempt at removing all the (temporary) files sg-dump produces during the course of its execution")
82 
83  _add("--no-clean-up",
84  dest = "do_clean_up",
85  action = "store_false",
86  help = "switch to enable the attempt at removing all the (temporary) files sg-dump produces during the course of its execution")
87 
88  _add("--athena-opts",
89  dest = "athena_opts",
90  default = None,
91  help = "space-separated list of athena command-line options. "\
92  "these will be passed to the validation job. (e.g. "\
93  "'--perfmon --stdcmalloc')" )
94 
95  _add("--pyalg",
96  dest = "pyalg_cls",
97  default = "PyDumper.PyComps:PySgDumper",
98  help = "name of the class to use to process the file(s) content (default: '%default'. validation uses: 'PyDumper.PyComps:DataProxyLoader')")
99 
100  _add("--include",
101  dest = "include",
102  default = "*",
103  help = "comma-separated list of type#key containers to dump (default: all)")
104 
105  _add("--exclude",
106  dest = "exclude",
107  default = "",
108  help = "comma-separated list of glob patterns of keys/types to ignore")
109 
110  _add("--conditions-tag",
111  dest = "conditions_tag",
112  default = "",
113  help = "override setting of global conditions tag")
114 
115  _add("--full-log",
116  dest = "full_log",
117  action = "store_true",
118  default = False,
119  help = "preserve full log file")
120 
121  (options, args) = parser.parse_args()
122 
123  input_files = []
124 
125  from AthenaCommon.Logging import logging
126  msg = logging.getLogger ('sg-dumper')
127  msg.setLevel (logging.INFO)
128 
129  input_files=[]
130  if len(args) > 0:
131  input_files = [arg for arg in args if arg[0] != "-"]
132  pass
133 
134  if len(input_files) == 0 or options.oname is None:
135  parser.print_help()
136  msg.error('please provide an output filename and '
137  'at least one input file')
138  raise SystemExit(1)
139 
140  sc = 1
141  try:
142  sc, out = SgDumpLib.run_sg_dump(
143  files=input_files,
144  output=options.oname,
145  nevts=int(options.evts),
146  skip=int(options.skip),
147  dump_jobo=options.dump_jobo,
148  pyalg_cls=options.pyalg_cls,
149  include=options.include,
150  exclude=options.exclude,
151  do_clean_up=options.do_clean_up,
152  athena_opts=options.athena_opts,
153  conditions_tag = options.conditions_tag,
154  full_log = options.full_log,
155  msg=msg
156  )
157  except Exception as err:
158  msg.error('problem while running sg-dump:\n%s', err)
159  import traceback
160  traceback.print_exc()
161  sys.exit(sc)
sg-dump._add
_add
Definition: sg-dump.py:48
sg-dump._str_to_slice
def _str_to_slice(slice_str)
Definition: sg-dump.py:31
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45