2 from __future__
import print_function
3 from __future__
import absolute_import
4 from sys
import stderr, exit
7 from optparse
import OptionParser
8 parser = OptionParser(usage=
10 usage: %prog [options] csv_output_file 16 produces a table of ALL runs and ALL paths (can take quite some time) 18 %prog --path='*ele*' --path='*photon*' out.csv 20 select only paths containing 'ele' and 'photon' 23 parser.add_option(
"--firstRun", dest=
"firstRun", help=
"first run", type=
"int", metavar=
"RUN", default=
"1")
24 parser.add_option(
"--lastRun", dest=
"lastRun", help=
"last run", type=
"int", metavar=
"RUN", default=
"9999999")
25 parser.add_option(
"--groupName", dest=
"groupName", help=
"select runs of name like NAME", metavar=
"NAME", default=
"Collisions%")
26 parser.add_option(
"--overwrite", dest=
"overwrite", help=
"force overwriting of output CSV file", action=
"store_true", default=
False)
28 parser.add_option(
"--path",
33 help=
"restrict paths to PATTERN. Note that this can be a single path name or a pattern " +
34 "using wildcards (*,?) similar to those used for selecting multiple files (see " +
35 "the documentation of the fnmatch module for details). Note also that this option " +
36 "can be specified more than once to select multiple paths or patterns. If this option " +
37 "is not specified, all paths are considered. Note that the comparison is done " +
38 "in a case-INsensitive manner. " +
39 "You may have to escape wildcards (with quotes or backslash) in order to avoid "+
40 "expansion by the shell" 44 (options, args) = parser.parse_args()
49 csv_output_file = args[0]
51 if os.path.exists(csv_output_file)
and not options.overwrite:
52 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)
57 """ returns a dict of hlt key to vector of prescales 61 for entry
in process.PrescaleService.prescaleTable:
62 retval[entry.pathName.value()] = entry.prescales.value()
70 cmd =
"edmConfigFromDB --orcoff --configName " + hlt_key
72 res = commands.getoutput(cmd)
89 from .queryRR
import queryRR
96 if os.system(
"which edmConfigFromDB") != 0:
97 print(
"could not find the command edmConfigFromDB. Did you initialize your CMSSW runtime environment ?", file=stderr)
100 runKeys =
queryRR(options.firstRun,options.lastRun,options.groupName)
107 hlt_path_names_table = {}
110 all_hlt_path_names_seen = set()
112 runs = sorted(runKeys.keys())
116 all_hlt_keys_seen = set(runKeys.values())
118 print(
"found %d runs and %d HLT menus" % ( len(runKeys), len(all_hlt_keys_seen)), file=stderr)
122 for hlt_key
in all_hlt_keys_seen:
124 print(
"(%3d/%3d) Querying ConfDB for HLT menu %s" % (index, len(all_hlt_keys_seen) , hlt_key), file=stderr)
128 print(
"WARNING: unable to retrieve hlt_key '" + hlt_key +
"'", file=stderr)
133 all_path_names = set(process.paths.keys())
136 hlt_path_names_table[hlt_key] = all_path_names
140 all_hlt_path_names_seen.update(all_path_names)
147 all_hlt_path_names_seen = sorted(all_hlt_path_names_seen)
151 if len(options.pathPatterns) > 0:
156 for path
in all_hlt_path_names_seen:
158 for pattern
in options.pathPatterns:
159 if fnmatch.fnmatch(path.lower(), pattern.lower()):
165 all_hlt_path_names_seen = tmp
169 if len(all_hlt_path_names_seen) == 0:
170 print(
"no HLT paths found, exiting", file=stderr)
177 previous_hlt_key =
None 179 fout = open(csv_output_file,
"w")
181 csv_writer = csv.writer(fout,delimiter=
";")
183 csv_writer.writerow([
'Table of HLT prescale factors'])
184 csv_writer.writerow([])
185 csv_writer.writerow([
'Explanation:'])
186 csv_writer.writerow([
'number(s) = prescale factor(s), HLT path present in this menu'])
187 csv_writer.writerow([
'empty = HLT path NOT present in this menu'])
188 csv_writer.writerow([
'0 = HLT path present in this menu but prescale factor is zero'])
189 csv_writer.writerow([
'U = could not retrieve menu for this HLT key from confDB'])
190 csv_writer.writerow([])
191 csv_writer.writerow([])
194 column_names = [
'run',
'' ]
195 column_names.extend(all_hlt_path_names_seen)
196 csv_writer.writerow(column_names)
198 csv_writer.writerow([])
201 hlt_key = runKeys[run]
203 if hlt_key == previous_hlt_key:
208 csv_writer.writerow(values)
216 if hlt_key
not in hlt_path_names_table:
222 csv_writer.writerow([hlt_key,
"COULD NOT RETRIEVE MENU FROM CONFDB"])
224 values = [ run ,
'' ]
225 values.extend(len(all_hlt_path_names_seen) * [
"U" ]) 227 csv_writer.writerow(values) 229 previous_hlt_key = hlt_key 234 csv_writer.writerow([hlt_key])
237 values = [ run ,
'' ]
241 for hlt_path
in all_hlt_path_names_seen:
243 if hlt_path
in hlt_path_names_table[hlt_key]:
251 prescales = prescaleTable[hlt_key].
get(hlt_path, [ 1 ] )
255 values.append(
",".
join([
str(x)
for x
in prescales]))
264 csv_writer.writerow(values)
266 previous_hlt_key = hlt_key
272 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)