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("--silent", "-s", action="store_true", dest="silent", default=False, help="silent mode: specify return code and exit")
0011     self.add_option("--subsystem", "-c", action="store", type="string", dest="subsystem", default=None, help="Specify test subsystem")
0012 
0013 if __name__ == "__main__":
0014   
0015   # Create option parser and get options/arguments
0016   optManager  = OptionParser()
0017   (opts, args) = optManager.parse_args()
0018   opts = opts.__dict__
0019 
0020   # Check if at least one root file defined (can be many!)
0021   if len(args) == 0:
0022     print("At least one ROOT file must be priovided, use --help for hit")
0023     sys.exit(1)
0024 
0025   # Check if all files exists and are accessible
0026   for rfile in args:
0027     try:
0028       os.stat(rfile)
0029     except:
0030       print("File [", rfile, "] not exists or is not accessible?")
0031       sys.exit(2)
0032 
0033   ss = opts['subsystem']
0034 
0035   # Lets extract values from files one-by-one, construct hashmap and check values
0036   for rfile in args:
0037 
0038     (run_number, values) = getSummaryValues(file_name = rfile, shift_type = None, translate = False, filters = None)
0039 
0040     if values == None or len(values) == 0:
0041       print("No content summary values found. Skipping file: %s" % rfile)
0042       continue
0043 
0044     messages = []
0045     for sub in SUBSYSTEMS.keys():
0046 
0047       if not ss == None and not sub == ss:
0048         continue
0049 
0050       if sub not in values:
0051         messages.append("%s: missing subsystem!" % sub)
0052         continue
0053 
0054       skeys = {}
0055       sfolders = []
0056 
0057       for folder in FOLDERS.keys():
0058 
0059         if folder not in values[sub]:
0060           messages.append("%s: missing folder EventInfo/%s" % (sub, folder))
0061           continue
0062 
0063         if len(values[sub][folder]) == 0:
0064           messages.append("%s: empty folder EventInfo/%s" % (sub, FOLDERS[folder][1]))
0065           continue
0066 
0067         sfolders.append(folder)
0068 
0069         if 'Summary' not in values[sub][folder]:
0070           messages.append("%s: missing summary value EventInfo/%s" % (sub, FOLDERS[folder][1]))
0071 
0072         for key in values[sub][folder].keys():
0073           if key == 'Summary':
0074             continue
0075           if key not in skeys:
0076             skeys[key] = []
0077           skeys[key].append(folder)
0078           
0079       for key in skeys:
0080         nfound = []
0081         for folder in sfolders:
0082           if skeys[key].count(folder) == 0: nfound.append(folder)
0083         if len(nfound) > 0:
0084           messages.append("%s: value (%s)/%s not found in (%s)" % (sub, ','.join(skeys[key]), key, ','.join(nfound)))
0085 
0086     if not opts['silent']:
0087       for message in sorted(messages):  print(message)          
0088       print("%d errors found" % len(messages))
0089 
0090     if len(messages) > 0: sys.exit(1)
0091 
0092   sys.exit(0)
0093 
0094