2 from __future__
import print_function
3 from sys
import stderr, exit
6 from optparse
import OptionParser
7 parser = OptionParser(usage=
9 usage: %prog [options] csv_output_file 15 produces a table of ALL runs and ALL paths (can take quite some time) 17 %prog --path='*ele*' --path='*photon*' out.csv 19 select only paths containing 'ele' and 'photon' 22 parser.add_option(
"--firstRun", dest=
"firstRun", help=
"first run", type=
"int", metavar=
"RUN", default=
"1")
23 parser.add_option(
"--lastRun", dest=
"lastRun", help=
"last run", type=
"int", metavar=
"RUN", default=
"9999999")
24 parser.add_option(
"--groupName", dest=
"groupName", help=
"select runs of name like NAME", metavar=
"NAME", default=
"Collisions%")
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(
"cowardly refusing to overwrite existing output file '" + csv_output_file +
"'. Run this script without argument to see options for overriding this check.", file=stderr)
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)
88 from queryRR
import queryRR
95 if os.system(
"which edmConfigFromDB") != 0:
96 print(
"could not find the command edmConfigFromDB. Did you initialize your CMSSW runtime environment ?", file=stderr)
99 runKeys =
queryRR(options.firstRun,options.lastRun,options.groupName)
106 hlt_path_names_table = {}
109 all_hlt_path_names_seen = set()
111 runs = sorted(runKeys.keys())
115 all_hlt_keys_seen = set(runKeys.values())
117 print(
"found %d runs and %d HLT menus" % ( len(runKeys), len(all_hlt_keys_seen)), file=stderr)
121 for hlt_key
in all_hlt_keys_seen:
123 print(
"(%3d/%3d) Querying ConfDB for HLT menu %s" % (index, len(all_hlt_keys_seen) , hlt_key), file=stderr)
127 print(
"WARNING: unable to retrieve hlt_key '" + hlt_key +
"'", file=stderr)
132 all_path_names = set(process.paths.keys())
135 hlt_path_names_table[hlt_key] = all_path_names
139 all_hlt_path_names_seen.update(all_path_names)
146 all_hlt_path_names_seen = sorted(all_hlt_path_names_seen)
150 if len(options.pathPatterns) > 0:
155 for path
in all_hlt_path_names_seen:
157 for pattern
in options.pathPatterns:
158 if fnmatch.fnmatch(path.lower(), pattern.lower()):
164 all_hlt_path_names_seen = tmp
168 if len(all_hlt_path_names_seen) == 0:
169 print(
"no HLT paths found, exiting", file=stderr)
176 previous_hlt_key =
None 178 fout = open(csv_output_file,
"w")
180 csv_writer = csv.writer(fout,delimiter=
";")
182 csv_writer.writerow([
'Table of HLT prescale factors'])
183 csv_writer.writerow([])
184 csv_writer.writerow([
'Explanation:'])
185 csv_writer.writerow([
'number(s) = prescale factor(s), HLT path present in this menu'])
186 csv_writer.writerow([
'empty = HLT path NOT present in this menu'])
187 csv_writer.writerow([
'0 = HLT path present in this menu but prescale factor is zero'])
188 csv_writer.writerow([
'U = could not retrieve menu for this HLT key from confDB'])
189 csv_writer.writerow([])
190 csv_writer.writerow([])
193 column_names = [
'run',
'' ]
194 column_names.extend(all_hlt_path_names_seen)
195 csv_writer.writerow(column_names)
197 csv_writer.writerow([])
200 hlt_key = runKeys[run]
202 if hlt_key == previous_hlt_key:
207 csv_writer.writerow(values)
215 if hlt_key
not in hlt_path_names_table:
221 csv_writer.writerow([hlt_key,
"COULD NOT RETRIEVE MENU FROM CONFDB"])
223 values = [ run ,
'' ]
224 values.extend(len(all_hlt_path_names_seen) * [
"U" ]) 226 csv_writer.writerow(values) 228 previous_hlt_key = hlt_key 233 csv_writer.writerow([hlt_key])
236 values = [ run ,
'' ]
240 for hlt_path
in all_hlt_path_names_seen:
242 if hlt_path
in hlt_path_names_table[hlt_key]:
250 prescales = prescaleTable[hlt_key].
get(hlt_path, [ 1 ] )
254 values.append(
",".
join([
str(x)
for x
in prescales]))
263 csv_writer.writerow(values)
265 previous_hlt_key = hlt_key
271 print(
"created CSV file",csv_output_file,
". Field delimiter is semicolon.", file=stderr)
def getProcessObjectFromConfDB(hlt_key)
S & print(S &os, JobReport::InputFile const &f)
static std::string join(char **cmd)
def getPrescaleTableFromProcessObject(process)
T get(const Candidate &c)