test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
contentValuesToDBS.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("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify DBS DQM XML-RPC server URL. Default is " + SERVER_URL)
10  self.add_option("--debug", "-d", action="store_true", dest="debug", default=False, help="print values and exit. Do not write to DBS")
11  self.add_option("--shift", "-s", action="store", type="choice", dest="shift", default="offline", choices=("online","offline"), help="specify shift type: online or offline values allowed")
12  self.add_option("--filter", "-f", action="store", type="string", dest="filter", default=None, help="Specify filters in the form \"('subsystem','folder','value')\" in regexp expression. Default is None and this takes all the subsystems, all folders and allvalues")
13 
14 if __name__ == "__main__":
15 
16  # Create option parser and get options/arguments
17  optManager = OptionParser()
18  (opts, args) = optManager.parse_args()
19  opts = opts.__dict__
20 
21  # Check if at least one root file defined (can be many!)
22  if len(args) == 0:
23  print "At least one ROOT file must be priovided, use --help for hit"
24  sys.exit(1)
25 
26  # Check if all files exists and are accessible
27  for rfile in args:
28  try:
29  os.stat(rfile)
30  except:
31  print "File [", rfile, "] not exists or is not accessible?"
32  sys.exit(2)
33 
34  # Take the filter
35  filter = checkFilter(opts['filter'])
36 
37  server = xmlrpclib.ServerProxy(opts['url'])
38 
39  # Lets extract values from files one-by-one, construct hashmap and submit to
40  # defined XML-RPC url
41  for rfile in args:
42 
43  (run_number, values) = getSummaryValues(file_name = rfile, shift_type = opts['shift'], translate = True, filters = filter)
44  dataset = getDatasetName(rfile)
45 
46  if run_number == None:
47  print "Run number does not determined. Skipping file: %s" % rfile
48  continue
49 
50  if dataset == None:
51  print "Dataset name do not determined. Skipping file: %s" % rfile
52  continue
53 
54  if values == None or len(values) == 0:
55  print "No content summary values found. Skipping file: %s" % rfile
56  continue
57 
58  try:
59  if opts['debug']:
60  print "Run number: %d" % run_number
61  print "Dataset: %s" % dataset
62  print "Data: ", values
63  else:
64  result = server.insertdq_auto(run_number, dataset, values)
65  print "DBS DQM: %d rows modified for run %d dataset %s" % (result, run_number, dataset)
66  except xmlrpclib.Error, errstring:
67  print "ERROR", errstring
68  sys.exit(3)
69 
70  sys.exit(0)
71 
72