CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
nano_postproc.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
3 from importlib import import_module
4 import os
5 import sys
6 import ROOT
7 ROOT.PyConfig.IgnoreCommandLineOptions = True
8 
9 if __name__ == "__main__":
10  from optparse import OptionParser
11  parser = OptionParser(usage="%prog [options] outputDir inputFiles")
12  parser.add_option("-s", "--postfix", dest="postfix", type="string", default=None,
13  help="Postfix which will be appended to the file name (default: _Friend for friends, _Skim for skims)")
14  parser.add_option("-J", "--json", dest="json", type="string",
15  default=None, help="Select events using this JSON file")
16  parser.add_option("-c", "--cut", dest="cut", type="string",
17  default=None, help="Cut string")
18  parser.add_option("-b", "--branch-selection", dest="branchsel",
19  type="string", default=None, help="Branch selection")
20  parser.add_option("--bi", "--branch-selection-input", dest="branchsel_in",
21  type="string", default=None, help="Branch selection input")
22  parser.add_option("--bo", "--branch-selection-output", dest="branchsel_out",
23  type="string", default=None, help="Branch selection output")
24  parser.add_option("--friend", dest="friend", action="store_true", default=False,
25  help="Produce friend trees in output (current default is to produce full trees)")
26  parser.add_option("--full", dest="friend", action="store_false", default=False,
27  help="Produce full trees in output (this is the current default)")
28  parser.add_option("--noout", dest="noOut", action="store_true",
29  default=False, help="Do not produce output, just run modules")
30  parser.add_option("-P", "--prefetch", dest="prefetch", action="store_true", default=False,
31  help="Prefetch input files locally instead of accessing them via xrootd")
32  parser.add_option("--long-term-cache", dest="longTermCache", action="store_true", default=False,
33  help="Keep prefetched files across runs instead of deleting them at the end")
34  parser.add_option("-N", "--max-entries", dest="maxEntries", type="long", default=None,
35  help="Maximum number of entries to process from any single given input tree")
36  parser.add_option("--first-entry", dest="firstEntry", type="long", default=0,
37  help="First entry to process in the three (to be used together with --max-entries)")
38  parser.add_option("--justcount", dest="justcount", default=False,
39  action="store_true", help="Just report the number of selected events")
40  parser.add_option("-I", "--import", dest="imports", type="string", default=[], action="append",
41  nargs=2, help="Import modules (python package, comma-separated list of ")
42  parser.add_option("-z", "--compression", dest="compression", type="string",
43  default=("LZMA:9"), help="Compression: none, or (algo):(level) ")
44 
45  (options, args) = parser.parse_args()
46 
47  if options.friend:
48  if options.cut or options.json:
49  raise RuntimeError(
50  "Can't apply JSON or cut selection when producing friends")
51 
52  if len(args) < 2:
53  parser.print_help()
54  sys.exit(1)
55  outdir = args[0]
56  args = args[1:]
57 
58  modules = []
59  for mod, names in options.imports:
60  import_module(mod)
61  obj = sys.modules[mod]
62  selnames = names.split(",")
63  mods = dir(obj)
64  for name in selnames:
65  if name in mods:
66  print("Loading %s from %s " % (name, mod))
67  if type(getattr(obj, name)) == list:
68  for mod in getattr(obj, name):
69  modules.append(mod())
70  else:
71  modules.append(getattr(obj, name)())
72  if options.noOut:
73  if len(modules) == 0:
74  raise RuntimeError(
75  "Running with --noout and no modules does nothing!")
76  if options.branchsel != None:
77  options.branchsel_in = options.branchsel
78  options.branchsel_out = options.branchsel
79  p = PostProcessor(outdir, args,
80  cut=options.cut,
81  branchsel=options.branchsel_in,
82  modules=modules,
83  compression=options.compression,
84  friend=options.friend,
85  postfix=options.postfix,
86  jsonInput=options.json,
87  noOut=options.noOut,
88  justcount=options.justcount,
89  prefetch=options.prefetch,
90  longTermCache=options.longTermCache,
91  maxEntries=options.maxEntries,
92  firstEntry=options.firstEntry,
93  outputbranchsel=options.branchsel_out)
94  p.run()
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4