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(
"--overwrite", dest=
"overwrite", help=
"force overwriting of output CSV file", action=
"store_true", default=
False)
26 parser.add_option(
"--path",
31 help=
"restrict paths to PATTERN. Note that this can be a single path name or a pattern " +
32 "using wildcards (*,?) similar to those used for selecting multiple files (see " +
33 "the documentation of the fnmatch module for details). Note also that this option " +
34 "can be specified more than once to select multiple paths or patterns. If this option " +
35 "is not specified, all paths are considered. Note that the comparison is done " +
36 "in a case-INsensitive manner. " +
37 "You may have to escape wildcards (with quotes or backslash) in order to avoid "+
38 "expansion by the shell"
42 (options, args) = parser.parse_args()
47 csv_output_file = args[0]
49 if os.path.exists(csv_output_file)
and not options.overwrite:
50 print >> stderr,
"cowardly refusing to overwrite existing output file '" + csv_output_file +
"'. Run this script without argument to see options for overriding this check."
55 """ returns a dict of hlt key to vector of prescales
59 for entry
in process.PrescaleService.prescaleTable:
60 retval[entry.pathName.value()] = entry.prescales.value()
68 cmd =
"edmConfigFromDB --orcoff --configName " + hlt_key
70 res = commands.getoutput(cmd)
87 from queryRR
import queryRR
94 if os.system(
"which edmConfigFromDB") != 0:
95 print >> stderr,
"could not find the command edmConfigFromDB. Did you initialize your CMSSW runtime environment ?"
98 runKeys =
queryRR(options.firstRun,options.lastRun,options.groupName)
105 hlt_path_names_table = {}
108 all_hlt_path_names_seen = set()
110 runs = sorted(runKeys.keys())
114 all_hlt_keys_seen = set(runKeys.values())
116 print >> stderr,
"found %d runs and %d HLT menus" % ( len(runKeys), len(all_hlt_keys_seen))
120 for hlt_key
in all_hlt_keys_seen:
122 print >> stderr,
"(%3d/%3d) Querying ConfDB for HLT menu %s" % (index, len(all_hlt_keys_seen) , hlt_key)
126 print >> stderr,
"WARNING: unable to retrieve hlt_key '" + hlt_key +
"'"
131 all_path_names = set(process.paths.keys())
134 hlt_path_names_table[hlt_key] = all_path_names
138 all_hlt_path_names_seen.update(all_path_names)
145 all_hlt_path_names_seen = sorted(all_hlt_path_names_seen)
149 if len(options.pathPatterns) > 0:
154 for path
in all_hlt_path_names_seen:
156 for pattern
in options.pathPatterns:
157 if fnmatch.fnmatch(path.lower(), pattern.lower()):
163 all_hlt_path_names_seen = tmp
167 if len(all_hlt_path_names_seen) == 0:
168 print >> stderr,
"no HLT paths found, exiting"
175 previous_hlt_key =
None
177 fout = open(csv_output_file,
"w")
179 csv_writer = csv.writer(fout,delimiter=
";")
181 csv_writer.writerow([
'Table of HLT prescale factors'])
182 csv_writer.writerow([])
183 csv_writer.writerow([
'Explanation:'])
184 csv_writer.writerow([
'number(s) = prescale factor(s), HLT path present in this menu'])
185 csv_writer.writerow([
'empty = HLT path NOT present in this menu'])
186 csv_writer.writerow([
'0 = HLT path present in this menu but prescale factor is zero'])
187 csv_writer.writerow([
'U = could not retrieve menu for this HLT key from confDB'])
188 csv_writer.writerow([])
189 csv_writer.writerow([])
192 column_names = [
'run',
'' ]
193 column_names.extend(all_hlt_path_names_seen)
194 csv_writer.writerow(column_names)
196 csv_writer.writerow([])
199 hlt_key = runKeys[run]
201 if hlt_key == previous_hlt_key:
206 csv_writer.writerow(values)
214 if hlt_key
not in hlt_path_names_table:
220 csv_writer.writerow([hlt_key,
"COULD NOT RETRIEVE MENU FROM CONFDB"])
222 values = [ run ,
'' ]
223 values.extend(len(all_hlt_path_names_seen) * [
"U" ])
225 csv_writer.writerow(values)
227 previous_hlt_key = hlt_key
232 csv_writer.writerow([hlt_key])
235 values = [ run ,
'' ]
239 for hlt_path
in all_hlt_path_names_seen:
241 if hlt_path
in hlt_path_names_table[hlt_key]:
249 prescales = prescaleTable[hlt_key].
get(hlt_path, [ 1 ] )
253 values.append(
",".
join([str(x)
for x
in prescales]))
262 csv_writer.writerow(values)
264 previous_hlt_key = hlt_key
270 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)