Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:09

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