2 from sys
import stderr, exit
5 from optparse
import OptionParser
6 parser = OptionParser(usage=
8 usage: %prog [options] csv_output_file
14 produces a table of ALL runs and ALL paths (can take quite some time)
16 %prog --path='*ele*' --path='*photon*' out.csv
18 select only paths containing 'ele' and 'photon'
21 parser.add_option(
"--firstRun", dest=
"firstRun", help=
"first run", type=
"int", metavar=
"RUN", default=
"1")
22 parser.add_option(
"--lastRun", dest=
"lastRun", help=
"last run", type=
"int", metavar=
"RUN", default=
"9999999")
23 parser.add_option(
"--groupName", dest=
"groupName", help=
"select runs of name like NAME", metavar=
"NAME", default=
"Collisions%")
24 parser.add_option(
"--rrurl", dest=
"rrurl", help=
"run registry xmlrpc url", metavar=
"URL", default=
"http://cms-service-runregistry-api.web.cern.ch/cms-service-runregistry-api/xmlrpc")
25 parser.add_option(
"--overwrite", dest=
"overwrite", help=
"force overwriting of output CSV file", action=
"store_true", default=
False)
27 parser.add_option(
"--path",
32 help=
"restrict paths to PATTERN. Note that this can be a single path name or a pattern " +
33 "using wildcards (*,?) similar to those used for selecting multiple files (see " +
34 "the documentation of the fnmatch module for details). Note also that this option " +
35 "can be specified more than once to select multiple paths or patterns. If this option " +
36 "is not specified, all paths are considered. Note that the comparison is done " +
37 "in a case-INsensitive manner. " +
38 "You may have to escape wildcards (with quotes or backslash) in order to avoid "+
39 "expansion by the shell"
43 (options, args) = parser.parse_args()
48 csv_output_file = args[0]
50 if os.path.exists(csv_output_file)
and not options.overwrite:
51 print >> stderr,
"cowardly refusing to overwrite existing output file '" + csv_output_file +
"'. Run this script without argument to see options for overriding this check."
56 """ returns a dict of hlt key to vector of prescales
60 for entry
in process.PrescaleService.prescaleTable:
61 retval[entry.pathName.value()] = entry.prescales.value()
69 cmd =
"edmConfigFromDB --orcoff --configName " + hlt_key
71 res = commands.getoutput(cmd)
89 """ returns a dict of run number mapping to the HLT key """
91 stderr.write(
"Querying run registry for range [%d, %d], group name like %s ...\n" % (options.firstRun, options.lastRun, options.groupName))
94 server = xmlrpclib.ServerProxy(options.rrurl)
95 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))
97 xml_data = xml.dom.minidom.parseString(run_data)
98 xml_runs = xml_data.documentElement.getElementsByTagName(
"RUN_DATASET")
99 for xml_run
in xml_runs:
100 ret[xml_run.getElementsByTagName(
"RUN_NUMBER")[0].firstChild.nodeValue] = xml_run.getElementsByTagName(
"RUN_HLTKEY")[0].firstChild.nodeValue
108 if os.system(
"which edmConfigFromDB") != 0:
109 print >> stderr,
"could not find the command edmConfigFromDB. Did you initialize your CMSSW runtime environment ?"
119 hlt_path_names_table = {}
122 all_hlt_path_names_seen = set()
124 runs = sorted(runKeys.keys())
128 all_hlt_keys_seen = set(runKeys.values())
130 print >> stderr,
"found %d runs and %d HLT menus" % ( len(runKeys), len(all_hlt_keys_seen))
134 for hlt_key
in all_hlt_keys_seen:
136 print >> stderr,
"(%3d/%3d) Querying ConfDB for HLT menu %s" % (index, len(all_hlt_keys_seen) , hlt_key)
140 print >> stderr,
"WARNING: unable to retrieve hlt_key '" + hlt_key +
"'"
145 all_path_names = set(process.paths.keys())
148 hlt_path_names_table[hlt_key] = all_path_names
152 all_hlt_path_names_seen.update(all_path_names)
159 all_hlt_path_names_seen = sorted(all_hlt_path_names_seen)
163 if len(options.pathPatterns) > 0:
168 for path
in all_hlt_path_names_seen:
170 for pattern
in options.pathPatterns:
171 if fnmatch.fnmatch(path.lower(), pattern.lower()):
177 all_hlt_path_names_seen = tmp
181 if len(all_hlt_path_names_seen) == 0:
182 print >> stderr,
"no HLT paths found, exiting"
189 previous_hlt_key =
None
191 fout = open(csv_output_file,
"w")
193 csv_writer = csv.writer(fout,delimiter=
";")
195 csv_writer.writerow([
'Table of HLT prescale factors'])
196 csv_writer.writerow([])
197 csv_writer.writerow([
'Explanation:'])
198 csv_writer.writerow([
'number(s) = prescale factor(s), HLT path present in this menu'])
199 csv_writer.writerow([
'empty = HLT path NOT present in this menu'])
200 csv_writer.writerow([
'0 = HLT path present in this menu but prescale factor is zero'])
201 csv_writer.writerow([
'U = could not retrieve menu for this HLT key from confDB'])
202 csv_writer.writerow([])
203 csv_writer.writerow([])
206 column_names = [
'run',
'' ]
207 column_names.extend(all_hlt_path_names_seen)
208 csv_writer.writerow(column_names)
210 csv_writer.writerow([])
213 hlt_key = runKeys[run]
215 if hlt_key == previous_hlt_key:
220 csv_writer.writerow(values)
228 if not hlt_path_names_table.has_key(hlt_key):
234 csv_writer.writerow([hlt_key,
"COULD NOT RETRIEVE MENU FROM CONFDB"])
236 values = [ run ,
'' ]
237 values.extend(len(all_hlt_path_names_seen) * [
"U" ])
239 csv_writer.writerow(values)
241 previous_hlt_key = hlt_key
246 csv_writer.writerow([hlt_key])
249 values = [ run ,
'' ]
253 for hlt_path
in all_hlt_path_names_seen:
255 if hlt_path
in hlt_path_names_table[hlt_key]:
263 prescales = prescaleTable[hlt_key].
get(hlt_path, [ 1 ] )
267 values.append(
",".
join([str(x)
for x
in prescales]))
276 csv_writer.writerow(values)
278 previous_hlt_key = hlt_key
284 print >> stderr,
"created CSV file",csv_output_file,
". Field delimiter is semicolon."
def getProcessObjectFromConfDB
def getPrescaleTableFromProcessObject
static std::string join(char **cmd)
T get(const Candidate &c)