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