CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cfg-viewer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: latin-1 -*-
3 from optparse import OptionParser
4 import imp
5 import re
6 import sys
7 import shutil
8 import os
9 import FWCore.ParameterSet.Config as cms
10 
11 modsNames=[]
12 newModsNames,oldMods,allMods=[],[],[]
13 
15  def __init__(self,htmlFile, cfgFile):
16  self.html = htmlFile
17  self.theDir=''
18  self.pathName = "paths.html"
19  self.js = "search.js"
20  self.thecss = "style.css"
21 
22  rest= html.rsplit('/',1)
23  # Find where the html file is to be stored.
24  # store everything else there, move other stuff there.
25  if(len(rest)>1):
26  self.theDir=rest[0]+'/'
27  if(not os.path.isdir(self.theDir)):
28  os.mkdir(self.theDir)
29  self.javascript("%s%s"%(self.theDir,self.js))
30  self.css("%s%s"%(self.theDir,self.thecss))
31  self.pathLi="""
32  <li class="expand %(className)s" data-name="%(nameID)s">%(nameID)s:</li>
33  """
34  self.cfg = imp.load_source("cfg", cfgFile)
35  # do the psets (in other file, provide link to it.)
36  psetTypes = open("%sparamTypes.js"%(self.theDir),'w')
37  psetTypes.close()
38  print "Starting print out of psets."
39  self.doPsets()
40  print "Finished finding psets. Now onto paths..."
41  self.doPaths()
42  print "Paths done"
43 
44  def doPaths(self):
45  modHTMLName= "%sparamTypes.js"%(self.theDir)
46  modToPathName = "%smodToPath.js" %(self.theDir)
47  tempFile ="%stemp.js"%(self.theDir)
48  f={modHTMLName:"params",modToPathName:"modules"}
49  o={modHTMLName:"a",modToPathName:"w"}
50  theS="var %s={"
51  for key in f.keys():
52  curFile = open(key,o[key])
53  curFile.write(theS%(f[key]))
54  curFile.close()
55  first = True
56  liToBeWritten, frmPathHolder="", "";
57  className, theS,frmPathStr ="path","",'%s%s:["%s"]'
58  newModsStr, oldModsStr='%s\n%s:["%s"]', '%s"%s",%s'
59  dataFile= open(modHTMLName,'a')
60  v = visitor(dataFile)
61  paths = self.cfg.process.paths
62  global oldMods
63  global allMods
64  global newModsNames
65  for item in paths.keys():
66  oldMods=[] # module names which have been seen before.
67  # needed so we can add this path name to the dictionary in modToPath.js
68  allMods =[]# set of current path modules names including duplciates.
69  newModsNames=[] # set of current paths module name without duplicates.
70  # could get oldMods from all Mods if we take away all newModsNames
71  liToBeWritten +=format(self.pathLi,nameID=item,className=className)
72  paths[item].visit(v)
73  frmPathHolder +=frmPathStr%(theS,item,"\",\"".join(allMods))
74  fromMod = open(modToPathName, 'r')
75  fromModTemp = open(tempFile, 'w')
76  for line in fromMod:
77  tLine= re.sub('\[.*?\]', "",line)
78  result = re.split(':|,', tLine[tLine.find('{')+1:])
79  namesFound = [x for i, x in enumerate(result)if not i%2]
80  # the new names we have is going to be smaller,
81  # so we'll loop round that
82  for each in oldMods:
83  if(each in namesFound):
84  oldMods.remove(each)
85  index = line.find(each)+len(each)+2 # as will have :[ after it
86  line = oldModsStr %(line[:index],item,line[index:])
87  fromModTemp.write(line)
88  fromMod.close()
89  for each in newModsNames:
90  fromModTemp.write(newModsStr%(theS,each,item))
91  theS=","
92  fromModTemp.close()
93  os.rename(tempFile,modToPathName)
94  if(first):
95  theS=","
96  first=False
97  out = open("%s%s"%(self.theDir,self.pathName), 'w')
98  self.printStart(self.js,self.thecss, """disabled="True" """, out)
99  out.write("<a href='%s'> See Psets</a>&nbsp;\n<ul>%s"\
100  "</ul>\n</body>\n</html>"%(self.html.rsplit('/',1)[-1],liToBeWritten))
101  out.close()
102  dataFile.write("};\nfunction getAllParams(){\n"\
103  "var newD ={};\n var keys = Object.keys(params);\n"\
104  "for(var i=0; i <keys.length; i++){ \n"\
105  " newD[keys[i]]= params[keys[i]][\"parameters\"];\n}"\
106  " return newD;}\n"\
107  " function getParams(modName){\n"\
108  " return params[modName][\"parameters\"];}\n"\
109  "function getInnerParams(parentsNames){\n"\
110  "var curList=params[parentsNames[0]][\"parameters\"];\n"\
111  "for(var i=1; i < parentsNames.length;i++){\n"\
112  " for(var p=0; p < curList.length;p++){\n"\
113  " if(curList[p][0]==parentsNames[i]){\n"\
114  " var found = curList[p][1];\n"\
115  " break;\n }\n}\n curList = found;\n}\n"\
116  " return curList;}\n"\
117  "function getFile(name){\n"\
118  "return params[name][\"file\"];\n}"\
119  "function getType(name){\n"\
120  "return params[name][\"type\"];\n}")
121  fromPath= open("%spathToMod.js" %(self.theDir),'w')
122  fromPath.write("var paths={%s}\n "\
123  "function getModules(thePath){\n"\
124  "return paths[thePath];\n}"\
125  "\n function keys(){\n return Object.keys(paths); "\
126  "\n}" %(frmPathHolder))
127  fromPath.close()
128  fromMod = open(modToPathName, 'a')
129  fromMod.write("}\n function getPaths(theMod){\n"\
130  "return modules[theMod];\n}")
131  fromMod.close()
132 
133  def doPsets(self):
134  addC,writeOut,toParamWrite= "","",""
135  first = True
136  outStr=self.pathLi
137  pStr="%s%s:'%s'"
138  classN = "module"
139  process = self.cfg.process
140  psets = process.psets
141  theDict ={}
142  for pset in psets:
143  writeOut+=format(outStr,nameID=pset,className=classN)
144  psetCfg = process.__dict__[pset]
145  res = do(psetCfg.parameters_(),[])
146  theDict[pset] = res
147  if(first):
148  addC=","
149  first=False
150  out = open(self.html, 'w')
151  self.printStart(self.js, self.thecss ,"", out)
152  out.write("<a href=\"%s\"> See Paths</a>\n<ul>"\
153  "%s</ul></html>"%(self.pathName,writeOut))
154  out.close()
155 
156  psetTypes = open("%sparamTypes.js"%(self.theDir),'w')
157  psetTypes.write("psetParams=%s\nfunction getAllpsetParams(){\n"\
158  "return psetParams;}\n"\
159  " function getpsetParams(modName){\n"\
160  " return psetParams[modName];}\n"\
161  "function getInnerpsetParams(parentsNames){\n"\
162  "var currentList = psetParams[parentsNames[0]];\n"\
163  "for(var i=1; i < parentsNames.length;i++){\n"\
164  " for(var p=0; p < currentList.length;p++){\n"\
165  " if(currentList[p][0]==parentsNames[i]){\n"\
166  " var found = currentList[p][1];\n"\
167  " break;\n }\n}\n currentList = found;\n}\n"\
168  " return currentList;}\n"%(theDict))
169 
170  # Start of html files.
171  def printStart(self,js, css, dis, out):
172  scripts ="""
173  <script type="text/javascript" src="paramTypes.js"></script>
174  """
175  classType="pset"
176  buttons="""
177  <option id="module" selected="selected">Module</option>
178  """
179  if(len(dis)>0):
180  classType="path"
181  buttons="""
182  <option id="path" selected="selected">Path</option>
183  <option id="module">Module</option>
184  <option value="type">Type</option>
185  <option value="parameter">Parameter</option>
186  <option value="value">Value</option>
187  """
188  scripts= """
189  <script type="text/javascript" src="pathToMod.js"></script>
190  <script type="text/javascript" src="modToPath.js"></script>
191  <script type="text/javascript" src="paramTypes.js"></script>
192  """
193  out.write( """
194  <!DOCTYPE html>
195  <html>
196  <head>
197  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
198  <title>cfg-browser</title>
199  <script type="text/javascript"
200  src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
201  </script>
202  %(scripts)s
203  <script type="text/javascript" src="%(js)s"></script>
204 
205  <link href="%(css)s" rel="stylesheet" type="text/css"/>
206  </head>
207  <body>
208  <!--form name="input" action="html_form_action.asp" method="get"-->
209  <form name="searchInput" onsubmit="return false;">
210  <input type="text" id="searchWord"/>
211  <select id="searchType">
212  %(option)s
213  </select>
214 
215  <input type="submit" value="Search" id="search" disabled/></form>
216  <br/><p id="searchNumber"></p><br/>
217  <a id="hide" style="cursor:default; color:#CCCCCC;"
218  class="%(class)sReset"
219  href="javascript:;" >
220  Hide All</a>
221  <br/><br/>
222  <span id="pageType" data-type=%(class)s></span>
223 
224  <input type="submit" id ="searchReset" style="display:none"
225  value="Reset search results." class="%(class)sReset"/>
226  <br/><input type="checkbox" id="ShowFiles" value="File"/>Show module File.
227  <br/>
228 
229  """%{'js':js,'option':buttons, 'css':css, 'dis':dis,
230  'scripts':scripts, 'class':classType})
231 
232  def javascript(self,thejs):
233  jsFile = open(thejs, 'w')
234  jsFile.write( """
235 $(document).ready(function(){
236  $(document).on('click', '#search', function(e){
237  numFound = 0;
238  var par = $(this).parent();
239  var id = $(par).find('#searchType').attr('id');
240  var option = $('#'+id+' option:selected').text();
241  var val = $(par).find('#searchWord').val()
242  var reg = new RegExp("("+val+")", "gi");
243  switch(option){
244  case "Path":
245  reset('li.path', e, true);
246  numFound = topLevelMatch(keys(),reg,false); // will stay the same
247 
248  case "Module":
249  if(typeof modKeys != 'function' && false){
250  //if modKeys is not defined means we're using pset html.
251  //maybe change this so instead we define top layer li with class top
252  reset('li.module', e, true);
253  //numFound = topLevelMatch
254  numFound = topLevelMatch( $('li.module'),reg,true);
255  }
256  else{
257  // for now pretend that its in html.
258  //searchReplaceHTML(reg, "module");
259  // if not in the html
260  //Okay can either, get allmatched modules and add them
261  // to all html parents
262  // or go round paths and get all matched modules adding to tghe path
263  var strings = allMods(reg);
264  var Li = $(document.createElement('li')).attr(
265  "class","module expand");
266  console.log("hereiam before");
267  searchReplaceNonHTML(strings,Li, reg)
268  }
269 
270  case "File Name":
271  //get all modules names, get files for all modules
272  // once we have a list of all modules we want
273  // add those modules to
274 
275  case "Parameter":
276  // gives the params which match the reg.
277  numFound = lowerLevels(reg,doInnerParams, e)
278 
279  case "Type":
280  reset('li.path',e,true);
281  // similar to params except we're looking at
282  // the types and not the params names.
283  // so need to get all the params, loop over the keys
284  var matches = matchValue(reg);
285  console.log("matches are "+ matches)
286 
287  case "Value":
288  numFound = lowerLevels(reg,doInnerValue, e)
289  }
290  $('#searchNumber').html(numFound+" found.");
291  $('#searchReset').show();
292  });
293 
294 //do Params, values.
295 function lowerLevels(reg,funcCall, e){
296  reset('li.path', e, true);
297  var numFound=0;
298  if($("span[id='pageType']").attr("data-type")=="pset"){
299  var matches = getAllpsetParams();
300  }
301  else var matches = getAllParams();
302 
303  var keys = Object.keys(matches);
304  for(var i=0; i < keys.length; i++){
305  var theKey = keys[i];
306  var params = matches[theKey];
307  var theMod = moduleLI.clone().attr("data-name",theKey).text(theKey);
308  // need to make the ul
309  tempNumber =0;
310  var theUL = funcCall(params,reg);
311  if(tempNumber ==0)continue;
312  theMod.append(theUL);
313  // for now just do parents
314  var pathsAddTo = getPaths(theKey);
315  var mul =0;
316  for(var k=0; k < pathsAddTo.length;k++){
317  // all paths to be added to.
318  var theP = pathsAddTo[k];
319  // find the parent.
320  $('li.path[name='+theP+']').each(function(){
321  // for each one add the theMod.
322  $(this).children().empty();
323  $(this).append(theMod.clone());
324  mul +=1;
325  });
326  }
327  numFound += (tempNumber*mul)
328  }
329  return numFound;
330 }
331 
332 function doInnerValue(modules,reg){
333  var theUL = UL.clone();
334  // okay we have a list where we want to check the
335  // inner list is an inner list.
336  for(var i=0; i < modules.length; i++){
337  var innerList= modules[i];
338  var theName = innerList[0];
339  var next = innerList[1];
340  // next could be inner or could be what we want.
341  if(typeof(next)=="object"){
342  // we have inner params, recurse!
343  var oldNum = tempNumber
344  var newUL = doInnerValue(next, reg); // will return a ul.
345  if(tempNumber == oldNum){
346  var li= LIExpand.clone().attr("data-name", theName).html(theName);
347  }
348  else {
349  var li= LIExpanded.clone().attr("data-name", theName).html(theName);
350  li.append(newUL);
351  }
352  }
353  else{
354  // else do normal and make the
355  // rename the value
356  var newValue = next.replace(reg, "<em>$1</em>");
357  if(newValue != next){
358  tempNumber +=next.match(reg).length;
359  }
360  var li= paramLI.clone().attr("data-name",theName).html(theName);
361  var theClass="value";
362  li.append(span.clone().attr("class", "value").html(": "+newValue));
363  innerList.slice(2).forEach(function(i){
364  li.append(span.clone().attr("class", "type").text(" ("+i+")"));
365  });
366  }
367  theUL.append(li);
368  }
369  return theUL;
370  }
371 
372 function doInnerParams(params,reg){
373  var theUL = UL.clone();
374  // okay we have a list where we want to check the
375  // inner list is an inner list.
376  for(var i=0; i < params.length; i++){
377  var param = params[i];// it's name.
378  var theName = param[0];
379  var newName = theName.replace(reg, "<em>$1</em>");
380  if(newName != theName){
381  tempNumber +=theName.match(reg).length;
382  }
383  var next = param[1];
384  if(typeof(next)=="object"){
385  // we have inner params, recurse!
386  //var cloLI= LIExpand.clone().attr("name", theName).text(theName);
387  //var ul = UL.clone();
388  var old = tempNumber;
389  var newUL = doInnerParams(next, reg); // will return a ul.
390  if(old == tempNumber){
391  var li= LIExpand.clone().attr("data-name", theName).html(newName);
392  }
393  else {
394  var li= LIExpanded.clone().attr("data-name", theName).html(newName);
395  li.append(newUL);
396  }
397  }
398  else{
399  // else do normal and make the
400  var li= paramLI.clone().attr("data-name",theName).html(newName);
401  var theClass="value";
402  for(var w=1; w < param.length;w++){
403  // do types etc.
404  if(w==1)
405  li.append(span.clone().attr("class", "value").text(": "+param[w]));
406  else
407  li.append(span.clone().attr("class", "type").text(
408  " ("+param[w]+")"));
409  }
410  }
411  theUL.append(li);
412  }
413  return theUL;
414  }
415  var LI= $(document.createElement('li'));
416  var moduleLI= LI.clone().attr("class","module expand");
417  var paramLI= LI.clone().attr("class","param expanded");
418  var UL = $(document.createElement('ul'));
419  var span = $(document.createElement('span'));
420  var LIExpand = LI.clone().attr("class","expand paramInner");
421  var LIExpanded = LI.clone().attr("class","expanded paramInner");
422 // All params send here.
423 //[[normaloparam, value,type]
424 //[inner[innervalues, value,type]][norm, value, type]]
425 // we will get [normaloparam, value,type] etc
426 var numFound =0;
427 var tempNumber =0;
428  /*
429  String format should have where they want the string to go as name.
430  For module just now. //
431  */// stringformat would be what we want it to go in,
432  function searchReplaceNonHTML(strings, theLi, regex){
433  // we have the things we want, the string should just be the
434  // what we want to be shwn i.e. an LI, which we clone.
435  var UL = $(document.createElement('ul'));
436  for(var i=0; i <strings.length; i++){
437  var thisOne = strings[i]; // e.g. generator
438  //here i have the string and now i will
439  //need a format string or something, to know what to put around it?
440  var LI = theLi.clone().attr("data-name", thisOne).html(
441  thisOne.replace(regex, "<em>$1</em>"));
442  var paths = getPaths(thisOne);
443  for (var p=0; p < paths.length; p++){
444  // need to find the path on the page and add the module to it.
445  $('li.path[name='+paths[p]+']').each(function(){
446  // for each add this LI
447  if($(this).children('ul').length ==0){
448  $(this).append(UL.clone().append(LI.clone()));
449  }
450  else{
451  $(this).children('ul').append(LI.clone());
452  // so all paths dont point to the same LI,maybe can change this?
453  }
454  $(this).attr("class","expanded path");
455  });
456  }
457  }
458  }
459  /*
460  Search when what we're looking for is in HTML but not topLevel element.
461  To be global replace, find should be regexp object with g.
462  */
463  function searchReplaceHTML(find,identifier){
464  var found =0;
465  var foundParents=[];
466  var notFoundLI=[];
467  $("li ."+identifier).each(function(){
468  var howMany=0;
469  if(howmany = $(this).attr("data-name").match(find)){
470  // we found you
471  found +=howMany
472  $(this).html() = $(this).html().replace(find,"<em>$1</em>");
473  // now find parents
474  // if parents not already showen show them
475  $(this).parents('ul').each(function(){
476  if(foundParents.indexOf(this) ==-1){
477  $(this).show();
478  foundParents.append(this);
479  }
480  else{
481  // already done these parents
482  return false;// (i.e. break out loop);// the parents loop.
483  }
484  });
485  }
486  else{
487  notFoundLI.append(this);
488  // not a match, can just try and find a ul parent,
489  //if there is one, then we need to know whether to
490  // hide it.TODO or do nothing.
491  }
492  });
493  // now we have list of parents we want to hide all other parents
494  $(notFoundLI).each(function(){
495  $(this).parents('ul').each(function(){
496  if(foundParents.indexOf(this) ==-1){
497  $(this).hide();
498  }
499  else{
500  // already done these parents
501  return false;// (i.e. break out loop);// the parents loop.
502  }
503  });
504  });
505  return found;
506  }
507  /*
508  Resets search ouput.
509  */
510  $(document).on('click', '#searchReset', function(e){
511  $('#searchNumber').html("");
512  if($(this).attr('class') == "pathReset"){
513  reset('li.path',e,true);
514  }
515  else{
516  reset('li.module',e,true);
517  }
518  $(this).hide();
519  });
520  /*
521  Hides children of top level. TODO: Done - works
522  */
523  $(document).on('click', '#hide', function(e){
524  //for hiding we just get top level and remove children.
525  if($(this).css('cursor')!='default'){
526  $('#searchNumber').html("");
527  if($(this).attr('class') == "pathReset"){
528  var selec ='li.path';
529  }
530  else var selec ='li.module';
531  $(selec).each(function(){
532  if(removeChildren(this, e))toggleExpand(this, e);
533  });
534  $(this).css('color','#CCCCCC');
535  $(this).css('cursor','default');
536  }
537  });
538  /*
539  Retrieves and expands path elements. - works
540  */
541  $(document).on('click', '.path.expand',function(event){
542  var UL = addModules(getModules($(this).attr('data-name')));
543  $(this).append(UL);
544  $('#hide').css('color','')
545  $('#hide').css('cursor','')
546  });
547  /*
548  Adds modules to a list and returns list.
549  */
550  function addModules(results){
551  var UL = $(document.createElement("ul"));
552  var LI = $(document.createElement('li')).attr("class","module expand");
553  for(var i=0; i < results.length; i++){
554  var theName = results[i];
555  var val = theName+"("+getType(theName)+")"
556  if(document.getElementById("ShowFiles").checked)
557  val+=" ("+getFile(theName)+")"
558  UL.append(LI.clone().attr("data-name", theName).text(val));
559  }
560  return UL;
561  }
562 
563  /*
564  Retrieve and expands module elements.
565  //changed to deal with new data format,
566  //(data now seperate from html specification) - works
567  */
568  $(document).on('click','.module.expand', function(event){
569  addParams(this);
570  event.stopPropagation();
571  });
572 
573  /*
574  Add params to the object. Object can be of any type
575  (normally module or param).
576  It's name needs to be in the data to find its parameters. - works
577  */
578  function addParams(obj, results){
579  var LIBasic = $(document.createElement('li')).attr("class","param");
580  var LIExpand = LIBasic.clone().attr("class","expand paramInner");
581  var span = $(document.createElement("span"));
582  var UL = $(document.createElement("ul"));
583  // getParams returns list of list.
584  // Format:[[name,value,type,trackedornot]].CHANGED!!
585  // new format
586  // :[[name, value,type,trackedornot],[namePset,[name,value,type]]]
587  // If 2nd element is list then its a pset.
588  var objName = $(obj).attr('data-name');
589  if(!results){
590  if($("span[id='pageType']").attr("data-type")=="pset"){
591  var results = getpsetParams(objName);
592  }
593  else {
594  var results = getParams(objName);
595  var type = getType(objName);
596  if(type == "Sequence"){
597  // inside will be names of modules
598  //- so do the same as if this was a path obj
599  var ul = addModules(results);
600  $(obj).append(ul);
601  return
602  }
603  }
604  }
605  for(var i =0; i < results.length; i++){
606  var all = results[i].slice();
607  var theName = all.shift();
608  if(typeof(all[0]) == "object"){
609  var cloLI= LIExpand.clone().attr("data-name", theName).text(theName);
610  //for(var p=0; p < all[0].length;p++){
611  // add all children.
612  //}
613  }
614  else{
615  // Not a Pset.
616  var cloLI = LIBasic.clone().attr("data-name", theName).text(theName);
617  var value = all.shift()
618  // formating so lots of strings look nicer
619  if(value.indexOf(",")>-1)
620  value = "<ul>"+value.replace(/,/g, "</li><li>")+"</li></ul>"
621  cloLI.append(span.clone().attr("class","value").html(": "+value))
622  for(var p=0; p < all.length; p++){
623  cloLI.append(span.clone().attr("class","type").text(
624  " ("+all[p]+")"))
625  }
626  }
627  UL.append(cloLI);
628  }
629  $(obj).append(UL);
630  $('#hide').css('color','')
631  $('#hide').css('cursor','')
632  }
633  /*
634  Hides/Shows children from class param.
635  //changed to deal with new data format - works
636  */
637 $(document).on('click', '.paramInner.expand, .paramInner.expanded',
638  function(event){
639  if($(this).children('ul').length ==0){
640  // find parents
641  var theClass =""
642  var obj = this;
643  var parents =[$(this).attr("data-name")]
644  while(theClass.indexOf("module")==-1){
645  obj = $(obj).parent();
646  if(obj.prop("tagName")=="UL") continue;
647  var parName = obj.attr("data-name");
648  parents.unshift(parName);
649  theClass = obj.attr("class");
650  }
651  if($("span[id='pageType']").attr("data-type")=="pset"){
652  var result = getInnerpsetParams(parents);
653  }
654  else var result = getInnerParams(parents);
655  addParams(this, result);
656  }
657  else{
658  $(this).children('ul').toggle();
659  }
660  event.stopPropagation();
661  });
662  // Needed to stop the propagation of event when it should not be expanded.
663  $(document).on('click', '.param',function(event){
664  if($(this).find('ul').length >0){
665  $(this).find('ul').toggle();
666  }
667  event.stopPropagation();
668  });
669  /*
670  Removes children from expanded paths or modules.
671  */
672  $(document).on('click', '.path.expanded, .module.expanded',function(event){
673  removeChildren(this,event);
674  });
675 
676  // Toggles class names.
677  $(document).on('click','.expand, .expanded', function(event){
678  toggleExpand(this, event);
679  });
680  /*
681  Does matching for top level list elements.
682  Returns number of matches.
683  */
684  function topLevelMatch(list, reg, haveLIs){
685  var numFound =0;
686  for(var p=0; p < list.length; p++){
687  if(haveLIs){
688  var li = $(list[p]);
689  var item = li.attr('data-name');
690  }
691  else{
692  var item = list[p];
693  var li= $('li[name='+item+']');
694  }
695  if(num=item.match(reg)){
696  numFound +=num.length;
697  li.html(li.html().replace(reg, "<em>$1</em>"));
698  }
699  else{
700  li.hide();
701  }
702  }
703  return numFound;
704  }
705  /*
706  Removes highlights from selector, removes also children
707  if rmChildren == true.
708  */
709  function reset(selector, e, rmChildren){
710  var rm = new RegExp('<em>|</em>', 'g');
711  $(selector).each(function(i){
712  var html = $(this).html();
713  if(html.match(rm)){
714  $(this).html(html.replace(rm, ''));
715  }
716  else{
717  $(this).show();
718  }
719  if(rmChildren)if(removeChildren(this, e))toggleExpand(this, e);});
720  }
721  /*
722  Removes children from parent.
723  */
724  function removeChildren(parent, event){
725  var c = $(parent).children('ul');
726  if(c.length >0){
727  $(c).remove();
728  event.stopPropagation();
729  return true;
730  }
731  return false;
732  }
733  /*
734  Helper function toggles classes.
735  */
736  function toggleExpand(me,event){
737  $(me).toggleClass("expanded expand");
738  event.stopPropagation();
739  }
740 });
741  """)
742  jsFile.close()
743 
744  def css(self,thecss):
745  cssFile= open(thecss, 'w')
746  cssFile.write( """
747 
748 em {
749  background-color: rgb(255,255,0);
750  font-style: normal;
751 }
752 .module{
753  color: #0000CC
754 }
755 .param {
756  color: #9999CC;
757  cursor:default;
758 }
759 .paramInner {
760  color: #9999FF;
761  cursor:default;
762 }
763 .value{
764  color:#0000FF;
765 }
766 .type{
767  color: #00CCFF;
768 }
769 
770 ul {
771  list-style-type:none;
772  padding-left:0.6em;
773 }
774  .expand:before{
775  content:'›';
776  float: left;
777  margin-right: 10px;
778 }
779  .expanded:before, .param:before{
780  content:'ˇ';
781  float: left;
782  margin-right: 10px;
783 }
784 .expand, .expanded, .param{
785  cursor:pointer;
786 }
787 
788  """)
789  cssFile.close()
790 
791 """
792  Do Module Objects e.g. producers etc
793 """
794 
795 def doModules(modObj, dataFile, seq, seqs, currentName, innerSeq):
796  name = modObj.label_()
797  typ = re.sub("<|>|'", "", str(type(modObj))).split(".")[-1]
798  if(seq==0):allMods.append(name)
799  elif(not innerSeq and currentName not in allMods):
800  allMods.append(currentName)
801  if(name not in modsNames):
802  theList = do(modObj.parameters_(), [])
803  modsNames.append(name)
804  newModsNames.append(name)
805  filename = modObj._filename.split("/")[-1]
806  theS =""
807  if(len(modsNames) > 1): theS=","
808  theS+="%s:%s"
809  d = getParamSeqDict(theList, typ, filename)
810  dataFile.write(theS%(name, d))
811  if(seq >0):
812  seqs[currentName].append(name)
813 
814  else:
815  oldMods.append(name)
816 
817 def format(s, **kwds):
818  return s % kwds
819 
820 class visitor:
821  def __init__(self, df):
822  self.df = df
823  self.seq = 0
824  self.currentName =""
825  self.oldNames =[]
826  self.done =[]
827  self.seqs={}
828  self.innerSeq = False
829 
830  def enter(self, value):
831  if(isinstance(value,cms._Module)):
832  doModules(value, self.df, self.seq,
833  self.seqs, self.currentName, self.innerSeq)
834  if(isinstance(value,cms.Sequence)):
835  if(len(self.currentName) >0):self.oldNames.insert(0, self.currentName)
836  if(self.seq >0):
837  # this is an inner sequence
838  self.innerSeq = True;
839  self.seqs[self.currentName].append(value.label())
840  self.currentName = value.label()
841  self.seqs[self.currentName] = []
842  self.seq +=1
843 
844  def leave(self, value):
845  if(isinstance(value,cms.Sequence)):
846  name = value.label()
847  if(name in self.oldNames):self.oldNames.remove(name)
848  if(self.currentName == name and len(self.oldNames) >0):
849  self.currentName = self.oldNames.pop(0)
850  if(name not in self.done):
851  d = getParamSeqDict(self.seqs.pop(name),
852  re.sub("<|>|'", "", str(type(value))).split(".")[-1], "")
853  self.df.write(",%s:%s"%(name,d))
854  self.done.append(name)
855  self.seq -=1
856  if(self.seq==0): self.innerSeq = False;
857 
858 # Used to enforce dictionary in datfile have same format.
859 def getParamSeqDict(params, typ, fil):
860  d={}
861  d["parameters"] = params
862  d["type"] = typ
863  d["file"] =fil
864  return d
865 
866 """
867  Prints out inner details of parameters.
868 """
869 def do(params, o):
870  for item in params:
871  thing = params[item]
872  if(hasattr(thing, "parameters_")):
873  theList =[]
874  theList.append("%s(%s)"%(item,thing.configTypeName()))
875  # do will now return the list that the thing takes
876  theList.append(do(getattr(thing,"parameters_")(),[]))
877  o.append(theList)
878  elif(thing.configTypeName()== "VPSet"):
879  theList =[]
880  theList.append("%s(%s)"%(item,thing.configTypeName()))
881  newInS = "%s-%d"
882  li2 =[]
883  for popped in thing:
884  if(hasattr(popped, "parameters_")):
885  innerList =[]
886  innerList.append("(%s)"%(popped.configTypeName()))
887  innerList.append(do(getattr(popped,"parameters_")(),[]))
888  li2.append(innerList)
889  theList.append(li2)
890  o.append(theList)
891  else:
892  # easy version. Just save what we have -
893  # all going to have the same module..
894  # have parent as an input, so we can send it.
895  theList =[]
896  theList.append(item)
897  theType = thing.configTypeName()
898  if(hasattr(thing, "pop") and len(thing)>0):
899  value = "%s"% (",".join(str(li) for li in thing))
900  else:
901  value = thing.configValue()
902  theList.append(value)
903 
904  if(theType =="double" or theType =="int"):
905  theList.append(theType)
906  else:
907  if(thing.isTracked()):
908  theList.append(theType)
909  theList.append("tracked")
910  o.append(theList)
911  return o
912 
913 if __name__ == "__main__":
914  parser = OptionParser(usage="%prog <cfg-file> <html-file>")
915  flags =['-c', '-o']
916  parser.add_option("-c", "--cfg_file", dest="_cfgfile",
917  help="The configuration file.")
918  parser.add_option("-o", "--html_file", dest="_htmlfile",
919  help="The output html file.")
920  opts, args = parser.parse_args()
921  cfg, html = opts._cfgfile, opts._htmlfile
922  more =0
923  cfgGet, htmlGet = False, False
924  if(cfg == None):
925  cfgGet = True
926  more +=1
927  if(html == None):
928  htmlGet = True
929  more+=1
930  if len(args) < more:
931  parser.error("Please provide one and only one configuration"\
932  "file and one output file.")
933  if(cfgGet): cfg = args[0]
934  if(htmlGet): html = args[1]
935  try:
936  f = open(cfg)
937  except:
938  parser.error("File %s does not exist." % cfg)
939  generateBrowser(html,cfg)
def getParamSeqDict
Definition: cfg-viewer.py:859
def visit
Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment...
def doModules
Definition: cfg-viewer.py:795
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
if(dp >Float(M_PI)) dp-
double split
Definition: MVATrainer.cc:139