CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
magneticFieldFilterJSON Namespace Reference

Functions

def main
 

Variables

tuple required_version = (2,7)
 

Function Documentation

def magneticFieldFilterJSON.main (   argv = None)
Main routine of the script.

Arguments:
- `argv`: arguments passed to the main routine

Definition at line 21 of file magneticFieldFilterJSON.py.

References join().

Referenced by FWTableView.addTo(), FWTriggerTableView.setFrom(), and FWTableView.setFrom().

21 
22 def main(argv = None):
23  """Main routine of the script.
24 
25  Arguments:
26  - `argv`: arguments passed to the main routine
27  """
28 
29  if argv == None:
30  argv = sys.argv[1:]
31 
32  parser = argparse.ArgumentParser(
33  description="Create JSON selection for a given magnetic field.")
34  parser.add_argument("-i", "--input", dest="input", metavar="JSON",
35  type=str, help="input JSON file")
36  parser.add_argument("-o", "--output", dest="output", metavar="JSON",
37  type=str, help="output JSON file")
38  parser.add_argument("--min", dest="min", metavar="RUN", type=int,
39  help="first run to be considered in the selection")
40  parser.add_argument("--max", dest="max", metavar="RUN", type=int,
41  help="last run to be considered in the selection")
42  parser.add_argument("--epsilon", dest="epsilon", metavar="TESLA",
43  default=0.1, type=float,
44  help="precision of the filter (default: %(default)s T)")
45  parser.add_argument("--debug", dest="debug", action="store_true",
46  help="show more verbose output")
47  required = parser.add_argument_group("required arguments")
48  required.add_argument("--b-field", dest="bfield", metavar="TESLA",
49  required=True, type=float,
50  help="magnetic field to filter")
51  args = parser.parse_args(argv)
52 
53 
54  try:
55  if args.input == None and (args.min == None or args.max == None):
56  msg = ("If no input JSON file ('--input') is provided, you have to "
57  "explicitly provide the first ('--min') and last ('--max') "
58  "run.")
59  raise RuntimeError(msg)
60 
61  if args.min != None and args.max != None and args.min > args.max:
62  msg = "First run ({min:d}) is after last run ({max:d})."
63  msg = msg.format(**args.__dict__)
64  raise RuntimeError(msg)
65 
66  if args.max != None and args.max <= 0:
67  msg = "Last run must be greater than zero: max = {0:d} <= 0."
68  msg = msg.format(args.max)
69  raise RuntimeError(msg)
70  except RuntimeError, e:
71  if args.debug: raise
72  print ">>>", os.path.splitext(os.path.basename(__file__))[0]+":", str(e)
73  sys.exit(1)
74 
75 
76  lumi_list = None if not args.input else LumiList(filename = args.input)
77  input_runs = None if not lumi_list else [int(r) for r in lumi_list.getRuns()]
78 
79  # Run registry API: https://twiki.cern.ch/twiki/bin/viewauth/CMS/DqmRrApi
80  URL = "http://runregistry.web.cern.ch/runregistry/"
81  api = rrapi.RRApi(URL, debug = args.debug)
82 
83  if api.app != "user": return
84 
85  column_list = ("number",)
86  min_run = args.min if args.min != None else input_runs[0]
87  max_run = args.max if args.max != None else input_runs[-1]
88  bfield_min = args.bfield - args.epsilon
89  bfield_max = args.bfield + args.epsilon
90  constraints = {
91  "datasetExists": "= true",
92  "number": ">= {0:d} and <= {1:d}".format(min_run, max_run),
93  "bfield": "> {0:f} and < {1:f}".format(bfield_min, bfield_max)
94  }
95 
96  run_list = [item["number"] for item in
97  api.data(workspace = "GLOBAL", table = "runsummary",
98  template = "json", columns = column_list,
99  filter = constraints)]
100 
101  if lumi_list != None:
102  runs_to_remove = []
103  for run in input_runs:
104  if run not in run_list: runs_to_remove.append(run)
105  lumi_list.removeRuns(runs_to_remove)
106  else:
107  lumi_list = LumiList(runs = run_list)
108 
109  if args.output != None:
110  lumi_list.writeJSON(args.output)
111  with open(args.output+".args", "w") as f:
112  f.write(" ".join(argv)+"\n")
113  else:
114  print lumi_list
115 
116 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18

Variable Documentation

tuple magneticFieldFilterJSON.required_version = (2,7)

Definition at line 10 of file magneticFieldFilterJSON.py.