test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
contentValuesToRR.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from contentValuesLib import *
4 
5 class OptionParser(optparse.OptionParser):
6  """ Option parser class """
7  def __init__(self):
8  optparse.OptionParser.__init__(self, usage="%prog [options] root_file ...", version="%prog 0.0.1", conflict_handler="resolve")
9  self.add_option("--shift", "-s", action="store", type="choice", dest="shift", choices=("online","offline"), help="specify shift type: online or offline values allowed. Default is offline.")
10  self.add_option("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify RR XML-RPC server URL. Default is " + SERVER_URL)
11  self.add_option("--dataset", "-t", action="store", type="string", dest="dataset", default=None, help="explicitly specify dataset name. If not set then script \
12  (1) for offline shift will try to get it from the filename or (2) for online shift will set it to " + ONLINE_DATASET)
13  self.add_option("--debug", "-d", action="store_true", dest="debug", default=False, help="print values and exit. Do not write to RR")
14  self.add_option("--filter", "-f", action="store", type="string", dest="filter", default=None, help="Specify filters in the form \"('subsystem','folder','value')\" \
15  in regexp expression. Default is None and this takes all the subsystems, all folders and allvalues")
16 
17 if __name__ == "__main__":
18 
19  # Create option parser and get options/arguments
20  optManager = OptionParser()
21  (opts, args) = optManager.parse_args()
22  opts = opts.__dict__
23 
24  # Check if at least one root file defined (can be many!)
25  if len(args) == 0:
26  print "At least one ROOT file must be priovided, use --help for hit"
27  sys.exit(1)
28 
29  # Check if shift type is provided (mandatory!)
30  if not opts['shift']:
31  print "Shift type must be provided, use --help for hit"
32  sys.exit(1)
33 
34  # Get default dataset name (optional)
35  default_dataset = opts['dataset']
36  if default_dataset == None and opts['shift'] == 'online':
37  default_dataset = ONLINE_DATASET
38 
39  # Check if all files exists and are accessible
40  for rfile in args:
41  try:
42  os.stat(rfile)
43  except:
44  print "File [", rfile, "] not exists or is not accessible?"
45  sys.exit(2)
46 
47  # Take the filter
48  filter = checkFilter(opts['filter'])
49 
50  server = xmlrpclib.ServerProxy(opts['url'])
51 
52  # Lets extract values from files one-by-one, construct hashmap and submit to
53  # defined XML-RPC url
54  for rfile in args:
55 
56  (run_number, values) = getSummaryValues(file_name = rfile, translate = True, filters = filter)
57 
58  if default_dataset == None:
59  dataset = getDatasetName(rfile)
60  else:
61  dataset = default_dataset
62 
63  if run_number == None:
64  print "Run number does not determined. Skipping file: %s" % rfile
65  continue
66 
67  if dataset == None:
68  print "Dataset name do not determined. Skipping file: %s" % rfile
69  continue
70 
71  if values == None or len(values) == 0:
72  print "No content summary values found. Skipping file: %s" % rfile
73  continue
74 
75  try:
76  if opts['debug']:
77  print "Run number: %d" % run_number
78  print "Dataset: %s" % dataset
79  print "Data: ", values
80  else:
81  result = server.SummaryValuesWriter.write(run_number, dataset, json.dumps(values))
82  print "RR: %d rows modified for run# %d dataset %s" % (result, run_number, dataset)
83  except xmlrpclib.Error as errstring:
84  print "ERROR", errstring
85  sys.exit(3)
86 
87  sys.exit(0)
88 
89