Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:33:02

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 from contentValuesLib import *
0005  
0006 class OptionParser(optparse.OptionParser):
0007   """ Option parser class """
0008   def __init__(self):
0009     optparse.OptionParser.__init__(self, usage="%prog [options] root_file ...", version="%prog 0.0.1", conflict_handler="resolve")
0010     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.")
0011     self.add_option("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify RR XML-RPC server URL. Default is " + SERVER_URL)
0012     self.add_option("--dataset", "-t", action="store", type="string", dest="dataset", default=None, help="explicitly specify dataset name. If not set then script \
0013       (1) for offline shift will try to get it from the filename or (2) for online shift will set it to " + ONLINE_DATASET)
0014     self.add_option("--debug", "-d", action="store_true", dest="debug", default=False, help="print values and exit. Do not write to RR")
0015     self.add_option("--filter", "-f", action="store", type="string", dest="filter", default=None, help="Specify filters in the form \"('subsystem','folder','value')\" \
0016       in regexp expression. Default is None and this takes all the subsystems, all folders and allvalues")
0017 
0018 if __name__ == "__main__":
0019   
0020   # Create option parser and get options/arguments
0021   optManager  = OptionParser()
0022   (opts, args) = optManager.parse_args()
0023   opts = opts.__dict__
0024 
0025   # Check if at least one root file defined (can be many!)
0026   if len(args) == 0:
0027     print("At least one ROOT file must be priovided, use --help for hit")
0028     sys.exit(1)
0029 
0030   # Check if shift type is provided (mandatory!)
0031   if not opts['shift']:
0032     print("Shift type must be provided, use --help for hit")
0033     sys.exit(1)
0034 
0035   # Get default dataset name (optional)
0036   default_dataset = opts['dataset']
0037   if default_dataset == None and opts['shift'] == 'online':
0038     default_dataset = ONLINE_DATASET
0039 
0040   # Check if all files exists and are accessible
0041   for rfile in args:
0042     try:
0043       os.stat(rfile)
0044     except:
0045       print("File [", rfile, "] not exists or is not accessible?")
0046       sys.exit(2)
0047 
0048   # Take the filter
0049   filter = checkFilter(opts['filter'])
0050 
0051   server = xmlrpclib.ServerProxy(opts['url'])
0052 
0053   # Lets extract values from files one-by-one, construct hashmap and submit to
0054   # defined XML-RPC url 
0055   for rfile in args:
0056 
0057     (run_number, values) = getSummaryValues(file_name = rfile, translate = True, filters = filter)
0058 
0059     if default_dataset == None:
0060       dataset = getDatasetName(rfile)
0061     else:
0062       dataset = default_dataset
0063 
0064     if run_number == None:
0065       print("Run number does not determined. Skipping file: %s" % rfile)
0066       continue
0067     
0068     if dataset == None:
0069       print("Dataset name do not determined. Skipping file: %s" % rfile)
0070       continue
0071 
0072     if values == None or len(values) == 0:
0073       print("No content summary values found. Skipping file: %s" % rfile)
0074       continue
0075 
0076     try:
0077       if opts['debug']:
0078         print("Run number: %d" % run_number)
0079         print("Dataset: %s" % dataset)
0080         print("Data: ", values)
0081       else:
0082         result = server.SummaryValuesWriter.write(run_number, dataset, json.dumps(values))
0083         print("RR: %d rows modified for run# %d dataset %s" % (result, run_number, dataset))
0084     except xmlrpclib.Error as errstring:
0085       print("ERROR", errstring)
0086       sys.exit(3)
0087   
0088   sys.exit(0)
0089 
0090