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