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 contentValuesLib import *
0004 import xml.dom.minidom
0005 
0006 reDatasetParts = "^/([^/]+)/([^/]+)/([^/]+)$"
0007 DEFAULT_BASE = "/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/data/"
0008 
0009 REMINDERS = [
0010   ('^/StreamExpress/', 'Express/%(numberPart1)03d/%(numberPart2)03d/DQM_V0001_R%(number)09d__StreamExpress__%(datasetPart2)s__%(datasetPart3)s.root'),
0011   ('^/Global/Online/ALL$', 'Online/%(numberPart1)03d/%(numberPart2)03d/DQM_V0003_R%(number)09d.root')
0012 ]
0013 
0014 class OptionParser(optparse.OptionParser):
0015   """ Option parser class """
0016   def __init__(self):
0017     optparse.OptionParser.__init__(self, usage="%prog [options]", version="%prog 0.0.1", conflict_handler="resolve")
0018     self.add_option("--url", action="store", type="string", dest="url", default=SERVER_URL, help="specify RR XML-RPC server URL. Default is " + SERVER_URL)
0019     self.add_option("--from", action="store", type="int", dest="from", default=None, help="specify run number lower threshold inclusive. Note that all runs/datasets retrieval can take a long time!")
0020     self.add_option("--to", action="store", type="int", dest="to", default=None, help="specify run number upper threshold inclusive. Note that all runs/datasets retrieval can take a long time!")
0021     self.add_option("--base", action="store", type="string", dest="base", default=DEFAULT_BASE, help="file base. Default is " + DEFAULT_BASE)
0022 
0023 def getNodeText(nodelist):
0024   rc = ""
0025   for node in nodelist:
0026     if node.nodeType == node.TEXT_NODE:
0027       rc = rc + node.data
0028   return rc
0029 
0030 if __name__ == "__main__":
0031   
0032   # Create option parser and get options/arguments
0033   optManager  = OptionParser()
0034   (opts, args) = optManager.parse_args()
0035   opts = opts.__dict__
0036 
0037   server = xmlrpclib.ServerProxy(opts['url'])
0038   query = {'hasSummaryValues': 'false'}
0039   if opts['from'] != None:
0040     query['number'] = '>= ' + str(opts['from'])
0041   if opts['to'] != None:
0042     if 'number' in query:
0043       query['number'] += ' and <= ' + str(opts['to'])
0044     else:
0045       query['number'] = '<= ' + str(opts['to'])
0046 
0047   xmldata = server.DataExporter.export('GLOBAL', 'xml_all', query)
0048 
0049   datasets = []
0050   dom = xml.dom.minidom.parseString(xmldata)
0051 
0052   for run in dom.getElementsByTagName("RUN"):
0053     number = int(getNodeText(run.getElementsByTagName("NUMBER")[0].childNodes))
0054     for dataset in run.getElementsByTagName("DATASET"):
0055       datasets.append((number, getNodeText(dataset.getElementsByTagName("NAME")[0].childNodes)))
0056 
0057   for (number, dataset) in datasets:
0058     parts = None
0059     m = re.search(reDatasetParts, dataset)
0060     if m == None:
0061       sys.stderr.write("Wrong dataset name (run %d, dataset %s)!\n" % (number, dataset))
0062     else:
0063       parts = m.group(1, 2, 3)
0064       fullPath = None
0065       for (reminderPattern, reminderFormat) in REMINDERS:
0066         if re.match(reminderPattern, dataset):
0067           reminder = reminderFormat % \
0068                     { 'number': number, 'dataset': dataset, 
0069                       'numberPart1': int(re.search('^([0-9]+)([0-9]{3})$', str(number)).group(1)),
0070                       'numberPart2': int(re.search('^([0-9]+)([0-9]{3})$', str(number)).group(2)),
0071                       'datasetPart1': parts[0], 
0072                       'datasetPart2': parts[1], 
0073                       'datasetPart3': parts[2] 
0074                     }
0075           fullPath = opts['base'] + reminder
0076           break
0077 
0078       if fullPath == None:
0079         sys.stderr.write("Dataset was not identified (run %d, dataset %s)!\n" % (number, dataset))
0080       else:
0081         try:
0082           os.stat(fullPath)
0083           sys.stdout.write(fullPath) 
0084           sys.stdout.write('\n') 
0085         except:
0086           sys.stderr.write("File [%s] not exists or is not accessible (run %d, dataset %s)!\n" % (fullPath, number, dataset))
0087 
0088 
0089   sys.exit(0)
0090 
0091