5 from string
import rstrip,atoi,replace
11 teIdtoName = {
'0':
'0'}
12 featureCLIDtoName = {}
18 if 'CMTROOT' not in os.environ.keys():
19 print 'Can not find out graphviz binaries: ',GraphivizBinPath
20 print 'Have you setup CMT environmet? CMTROOT not set'
25 GraphivizPath = os.environ[
'CMTROOT']+
'/../Grafviz/2.2'
26 GraphivizBinPath = GraphivizPath+
'/bin/'
27 GraphivizLibPath = GraphivizPath+
'/lib/graphviz'
29 if 'LD_LIBRARY_PATH' not in os.environ.keys():
30 os.environ[
'LD_LIBRARY_PATH'] =
''
31 os.environ[
'LD_LIBRARY_PATH'] = os.environ[
'LD_LIBRARY_PATH']+
':'+GraphivizLibPath
33 print "Graphviz programs from there: ", GraphivizBinPath
37 options = {
'drawFeatures':
False,
43 'regex': re.compile(
'.*')}
47 """ converts the CLID to ClassName in C++. If falied then CLID instead.
48 The CLIDS to name is taken from CLID Svc dump."""
49 if clid
in featureCLIDtoName.keys():
50 return featureCLIDtoName[clid]
52 if options[
'clid']
is False:
55 name = commands.getoutput(
'clid '+clid).
split(
' ')[1]
56 featureCLIDtoName[clid] = name
60 if teid
in teIdtoName.keys():
61 return teIdtoName[teid]
63 print "TE id: ", teid,
" unknown"
91 if options[
'drawFeatures']:
93 if 'keyprints' in part:
98 for field
in part.split(
" "):
99 if field.find(
"CLID")
is not -1:
100 clid = field.split(
":")[1].lstrip(
' ').lstrip(
' ')
101 elif field.find(
"label")
is not -1:
102 label = field.split(
":")[1].rstrip(
"\"").lstrip(
"\"")
103 elif field.find(
"idx")
is not -1:
114 """ Draws node of the graph. """
121 nodename =
'X'+
str(self.
ptr)
122 line = nodename +
' [ label="{TE: ' + self.
tename
124 line +=
reduce(
lambda x,y: x +
"|"+y[0]+
"(" +y[1] +
' '+ y[2]+
str(y[3])+
")", self.
features,
"")
125 line +=
'}", style=filled, '
129 line +=
'fillcolor=pink, '
132 line +=
'color=green, '
134 line +=
'color=plum, '
138 line +=
'fillcolor=red, '
140 line +=
'fillcolor=palegreen, '
145 line +=
'shape=record'
150 """ Draws node and edges. """
153 line +=
'X'+self.
ptr +
' -> X' + rel +
'\n'
159 return r + self.
edges()
167 inputTEs = nav.split(
'\n')
171 stringTEs.append(te.lstrip(
' |\_'))
175 for ste
in stringTEs:
176 if ste
not in uniqueTEs:
177 uniqueTEs.append(ste)
180 objectTEs = map(
lambda x:
TE(x), uniqueTEs)
181 dot =
'digraph Menu {\n'\
183 +
'graph [ rankdir = "TR"];'\
184 +
'node [ shape=polygon, fontname=Helvetica ]\n'\
185 +
'edge [ fontname=Helvetica ]\n'
186 dot +=
reduce(
lambda x,y: x+
str(y), objectTEs,
'')
189 fname =
'navigationEvent-'+level+
'-'+
str(eventId)
190 if options[
'event']
is None or str(options[
'event']) ==
str(eventId):
191 print 'writing file: '+fname+
'.dot'
192 f =
file(
'temp.dot',
'w')
196 print commands.getoutput(
'mv -f temp.dot '+fname+
'.dot')
197 print commands.getoutput(
'/bin/rm -f temp.dot')
198 if options[
'convert']:
199 print 'converting file: '+fname+
'.dot to graphics'
200 global GraphivizBinPath
201 print commands.getoutput(GraphivizBinPath+options[
'program']+
' ' + fname +
'.dot -Tpng -o '+fname+
'.png')
203 print commands.getoutput(
'rm -f '+fname+
'.dot')
208 navigationStarted=
False
211 stepToLevel = [
"L2",
"EFunpacking",
"EF"]
214 if line.find(
"- --")
is not -1:
216 if line.find(
"inputTEs")
is not -1:
218 teId = line.split(
" ")[5]
219 teId = string.strip(teId,
"(), \"\n")
220 teId = rstrip(teId,
",")
221 teName = line.split(
" ")[4]
222 teName = string.strip(teName,
"(), \"\n")
223 teIdtoName[teId] = teName
226 if line.find(
" outputTE : (")
is not -1:
227 teId = line.split(
" ")[7]
228 teId = string.strip(teId,
"() \n")
229 teName = line.split(
" ")[6]
230 teName = string.strip(teName,
"()\",\n")
231 teIdtoName[teId] = teName
234 if line.find(
"start processing event #")
is not -1:
235 eventId = line.split(
"#")[1].
split(
",")[0]
237 print "scanning event: ",eventId
240 if line.find(
"Start of HLT Processing in L2")
is not -1:
243 if line.find(
"Start of HLT Processing in EF")
is not -1:
246 if line.find(
"TrigSteer_EF.ResultBuilder")
is not -1:
250 if line.find(
"\\_")
is not -1:
251 if navigationStarted
is False:
252 navigationStarted=
True
255 if navigationStarted
is True:
256 navigationStarted=
False
257 nav2dot(nav, eventId, stepToLevel[step] )
264 if options[
'clid']
is False:
265 clids =
file(
"CLIDDBout.txt")
267 clid = line.split(
" ")[0]
268 name = line.split(
" ")[1].rstrip(
"\n")
269 featureCLIDtoName[clid] = name
279 options[
'drawFeatures'] =
True
280 print "OPTION: will draw features"
283 options[
'clid'] =
True
284 print "OPTION: will use clid command to get class names (slower)"
286 options[
'regex'] = re.compile(sys.argv[sys.argv.index(
'-x')+1])
287 print "OPTION: will use only TEs accepted by regex", sys.argv[sys.argv.index(
'-x')+1]
290 options[
'event'] = string.atoi(sys.argv[sys.argv.index(
'-e')+1])
291 print "OPTION: will only draw event: ", options[
"event"]
294 options[
'convert'] =
True;
295 print "OPTION: will convert to graphics on the fly"
298 options[
'program'] = sys.argv[sys.argv.index(
'-p')+1]
299 print "OPTION: will convert to graphics on the fly using ", options[
'program']
302 options[
'raw'] =
True
303 options[
'configdump'] = sys.argv[sys.argv.index(
'-r')+2]
304 options[
'navigationdump'] = sys.argv[sys.argv.index(
'-r')+1]
308 print "OPTION: Help needed? Here it is:"
310 Files generated by this utility can be viewed by programs like 'dotty'.
311 Thay can be converted to graphics using probram 'dot':
312 dot nav_event_123.dot -o nav123.png -Tpng
315 -f -- draw freatures atteched to TE (with lables)
316 -d -- use clid command instead of CLIDDBout.txt to get human class names rather than CLIDs
317 -e X -- writeout only event (X)
318 -x regex -- use the regex to select only wanted TEs
319 -c -- convert graphs to png on the fly using dot program
320 -p prog -- use other program(neato, twopi, circo, fdp)
321 -r navigationfile configfile -- take files with the navigation dump and the configuration dump (rather than plain log)
328 if not options[
'raw']:
329 logname = sys.argv[-1]
334 conflog =
file(options[
'configdump'])
336 navlog =
file(options[
'navigationdump'])