CMS 3D CMS Logo

contentValuesToDBS.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 from contentValuesLib import *
5 
6 class OptionParser(optparse.OptionParser):
7  """ Option parser class """
8  def __init__(self):
9  optparse.OptionParser.__init__(self, usage="%prog [options] root_file ...", version="%prog 0.0.1", conflict_handler="resolve")
10  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)
11  self.add_option("--debug", "-d", action="store_true", dest="debug", default=False, help="print values and exit. Do not write to DBS")
12  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")
13  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")
14 
15 if __name__ == "__main__":
16 
17  # Create option parser and get options/arguments
18  optManager = OptionParser()
19  (opts, args) = optManager.parse_args()
20  opts = opts.__dict__
21 
22  # Check if at least one root file defined (can be many!)
23  if len(args) == 0:
24  print("At least one ROOT file must be priovided, use --help for hit")
25  sys.exit(1)
26 
27  # Check if all files exists and are accessible
28  for rfile in args:
29  try:
30  os.stat(rfile)
31  except:
32  print("File [", rfile, "] not exists or is not accessible?")
33  sys.exit(2)
34 
35  # Take the filter
36  filter = checkFilter(opts['filter'])
37 
38  server = xmlrpclib.ServerProxy(opts['url'])
39 
40  # Lets extract values from files one-by-one, construct hashmap and submit to
41  # defined XML-RPC url
42  for rfile in args:
43 
44  (run_number, values) = getSummaryValues(file_name = rfile, shift_type = opts['shift'], translate = True, filters = filter)
45  dataset = getDatasetName(rfile)
46 
47  if run_number == None:
48  print("Run number does not determined. Skipping file: %s" % rfile)
49  continue
50 
51  if dataset == None:
52  print("Dataset name do not determined. Skipping file: %s" % rfile)
53  continue
54 
55  if values == None or len(values) == 0:
56  print("No content summary values found. Skipping file: %s" % rfile)
57  continue
58 
59  try:
60  if opts['debug']:
61  print("Run number: %d" % run_number)
62  print("Dataset: %s" % dataset)
63  print("Data: ", values)
64  else:
65  result = server.insertdq_auto(run_number, dataset, values)
66  print("DBS DQM: %d rows modified for run %d dataset %s" % (result, run_number, dataset))
67  except xmlrpclib.Error as errstring:
68  print("ERROR", errstring)
69  sys.exit(3)
70 
71  sys.exit(0)
72 
73 
def getDatasetName(file_name)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def getSummaryValues(file_name, translate, filters=None)
def checkFilter(raw_filter)