CMS 3D CMS Logo

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