Go to the documentation of this file.00001
00002 from sys import stderr, exit
00003 import commands
00004
00005 from optparse import OptionParser
00006 parser = OptionParser(usage="usage: %prog [options] Trigger_Path")
00007 parser.add_option("--firstRun", dest="firstRun", help="first run", type="int", metavar="RUN", default="1")
00008 parser.add_option("--lastRun", dest="lastRun", help="last run", type="int", metavar="RUN", default="9999999")
00009 parser.add_option("--groupName", dest="groupName", help="select runs of name like NAME", metavar="NAME", default="Collisions%")
00010 parser.add_option("--rrurl", dest="rrurl", help="run registry xmlrpc url", metavar="URL", default="https://cms-service-runregistry-api.web.cern.ch/cms-service-runregistry-api/xmlrpc")
00011 parser.add_option("--jsonOut", dest="jsonOut", help="dump prescales in JSON format on FILE", metavar="FILE")
00012 (options, args) = parser.parse_args()
00013 if len(args) != 1:
00014 parser.print_usage()
00015 exit(2)
00016 path = args[0]
00017
00018
00019 edmCfgFromDB = "edmConfigFromDB --orcoff --format summary.ascii --paths " + path;
00020
00021 def getPrescalesFromKey(key):
00022
00023 cmd = ( edmCfgFromDB +" --configName "+key + " | grep -i "+ path + " | tail -1 | awk ' $2 ==\"%s\" {print $NL}' " ) % path
00024 res = commands.getoutput(cmd)
00025 res_split = res.split()
00026 psMap = {}
00027 aa=""
00028 if len(res)>0:
00029 for uu in range(3,len(res_split)-1):
00030 if uu % 2 == 1:
00031 aa = aa + res_split[uu] + "\t"
00032 psMap[path] = aa
00033 else:
00034 psMap[path] = 0
00035 return psMap
00036
00037
00038 def queryRR():
00039 stderr.write("Querying run registry for range [%d, %d], group name like %s ...\n" % (options.firstRun, options.lastRun, options.groupName))
00040 import xmlrpclib
00041 import xml.dom.minidom
00042 server = xmlrpclib.ServerProxy(options.rrurl)
00043 run_data = server.DataExporter.export('RUN', 'GLOBAL', 'xml_datasets', "{runNumber} >= %d AND {runNumber} <= %d AND {groupName} like '%s' AND {datasetName} = '/Global/Online/ALL'" % (options.firstRun, options.lastRun, options.groupName))
00044 ret = {}
00045 xml_data = xml.dom.minidom.parseString(run_data)
00046 xml_runs = xml_data.documentElement.getElementsByTagName("RUN_DATASET")
00047 for xml_run in xml_runs:
00048 ret[xml_run.getElementsByTagName("RUN_NUMBER")[0].firstChild.nodeValue] = xml_run.getElementsByTagName("RUN_HLTKEY")[0].firstChild.nodeValue
00049 return ret
00050
00051 runKeys = queryRR()
00052 prescaleTable = {}
00053 runs = runKeys.keys(); runs.sort()
00054 stderr.write("Querying ConfDB for prescales for path %s...\n" % (path));
00055 jsout = {}
00056 for run in runs:
00057 key = runKeys[run]
00058 if not prescaleTable.has_key(key):
00059 prescaleTable[key] = getPrescalesFromKey(key)
00060 psfactor = 1
00061 if prescaleTable[key].has_key(path): psfactor = prescaleTable[key][path]
00062 print "%s\t%s" % (run, psfactor)
00063 jsout[run] = psfactor
00064
00065 if options.jsonOut:
00066 stderr.write("Exporting to JSON file %s...\n" % (options.jsonOut))
00067 import json
00068 jsonFile = open(options.jsonOut, "w")
00069 jsonFile.write(json.dumps(jsout))
00070 jsonFile.close()