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("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify DBS DQM XML-RPC server URL. Default is " + SERVER_URL)
0011     self.add_option("--debug", "-d", action="store_true", dest="debug", default=False, help="print values and exit. Do not write to DBS")
0012     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")
0013     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")
0014 
0015 if __name__ == "__main__":
0016   
0017   # Create option parser and get options/arguments
0018   optManager  = OptionParser()
0019   (opts, args) = optManager.parse_args()
0020   opts = opts.__dict__
0021 
0022   # Check if at least one root file defined (can be many!)
0023   if len(args) == 0:
0024     print("At least one ROOT file must be priovided, use --help for hit")
0025     sys.exit(1)
0026 
0027   # Check if all files exists and are accessible
0028   for rfile in args:
0029     try:
0030       os.stat(rfile)
0031     except:
0032       print("File [", rfile, "] not exists or is not accessible?")
0033       sys.exit(2)
0034 
0035   # Take the filter
0036   filter = checkFilter(opts['filter'])
0037 
0038   server = xmlrpclib.ServerProxy(opts['url'])
0039 
0040   # Lets extract values from files one-by-one, construct hashmap and submit to
0041   # defined XML-RPC url 
0042   for rfile in args:
0043 
0044     (run_number, values) = getSummaryValues(file_name = rfile, shift_type = opts['shift'], translate = True, filters = filter)
0045     dataset = getDatasetName(rfile)
0046 
0047     if run_number == None:
0048       print("Run number does not determined. Skipping file: %s" % rfile)
0049       continue
0050     
0051     if dataset == None:
0052       print("Dataset name do not determined. Skipping file: %s" % rfile)
0053       continue
0054 
0055     if values == None or len(values) == 0:
0056       print("No content summary values found. Skipping file: %s" % rfile)
0057       continue
0058 
0059     try:
0060       if opts['debug']:
0061         print("Run number: %d" % run_number)
0062         print("Dataset: %s" % dataset)
0063         print("Data: ", values)
0064       else:
0065         result = server.insertdq_auto(run_number, dataset, values)
0066         print("DBS DQM: %d rows modified for run %d dataset %s" % (result, run_number, dataset))
0067     except xmlrpclib.Error as errstring:
0068       print("ERROR", errstring)
0069       sys.exit(3)
0070   
0071   sys.exit(0)
0072 
0073