CMS 3D CMS Logo

Functions
ExtractAppInfoFromXML Namespace Reference

Functions

def appendDataXML (head)
 
def compactNodeValue (head)
 
def fillTable (order, branch=[])
 
def filterNodeList (branch1, nodeList)
 
def getAppInfo (XMLf, s=0, a=2, p=1, c=3)
 getAppInfo # More...
 
def getAppNameFromCfg (filename)
 
def getProcNameFromCfg (filename)
 
def printGrid (grid)
 
def printXMLtree (head, l=0, bn=0)
 Some module's global variables. More...
 
def SortAndGrid (table, order)
 

Detailed Description

Syntax:
    ExtracAppInfoFromXML [-sapc] file
Parameters:
    file    file from where to read a RCMS configuration
    -s      list application servers found in the XML file
    -p      list the ports used found in the XML file
    -a      list the names of the applications configured in the XML file
    -c      list the cfg (eg dqmfu09-1_cfg.py) files
Notes:  
    The default behavior is to present a table organized in the following way
        SERVER PORT CFG_FILE APP_NAME
    which is equivalent to using -sapc
    
    The options selected and their order will affect teeh fields shown and their
    respective sorting. eg.
        -sa will only show SERVER and APP_NAME and will sort first by SERVER and
         then by APP_NAME 
         
    OUTPUT is always unique in a per row bases

Function Documentation

def ExtractAppInfoFromXML.appendDataXML (   head)
Parses information that's XML format from value to the Docuemnt tree

Definition at line 66 of file ExtractAppInfoFromXML.py.

References compactNodeValue().

Referenced by getAppInfo().

66 def appendDataXML(head):
67  """Parses information that's XML format from value to the Docuemnt tree"""
68  compactNodeValue(head)
69  if head.firstChild.nodeValue:
70  newNode=minidom.parseString(head.firstChild.nodeValue)
71  for node in newNode.childNodes:
72  head.appendChild(node.cloneNode(True))
73  newNode.unlink()
def ExtractAppInfoFromXML.compactNodeValue (   head)

Definition at line 52 of file ExtractAppInfoFromXML.py.

Referenced by appendDataXML().

52 def compactNodeValue(head):
53  firstborne=None
54  for item in head.childNodes:
55  if item.nodeType == 3:
56  firstborne = item
57  break
58  if not firstborne:
59  return
60  for item in head.childNodes[1:]:
61  if item.nodeType == 3:
62  firstborne.nodeValue+=item.nodeValue
63  item.nodeValue=None
64 
def ExtractAppInfoFromXML.fillTable (   order,
  branch = [] 
)

Definition at line 141 of file ExtractAppInfoFromXML.py.

References filterNodeList(), getAppNameFromCfg(), getProcNameFromCfg(), and min().

Referenced by getAppInfo().

141 def fillTable(order,branch=[]):
142  global xmldoc
143  table={}
144  if len(order)==0:
145  return table
146  key=min(order.keys())
147  k=order[key]
148  order.pop(key)
149  if k=="s":
150  lista=xmldoc.getElementsByTagName("XdaqExecutive")
151  lista=filterNodeList(branch,lista)
152  for item in lista:
153  table[item.attributes["hostname"].value]=""
154  for item in table.keys():
155  table[item]=fillTable(order.copy(),branch + [item])
156  elif k=="a":
157  lista=xmldoc.getElementsByTagName("XdaqExecutive")
158  lista=filterNodeList(branch,lista)
159  for item in lista:
160  pset=item.getElementsByTagName("parameterSet")
161  if len(pset):
162  arch=pset[0].firstChild.nodeValue[5:]
163  appname=getAppNameFromCfg(arch) or getProcNameFromCfg(arch)
164  table[appname]=""
165  else:
166  App=item.getElementsByTagName("xc:Application")
167  table[App[0].attributes["class"].value]=""
168  for item in table.keys():
169  table[item]=fillTable(order.copy(),branch)
170  elif k=="p":
171  lista=xmldoc.getElementsByTagName("XdaqExecutive")
172  lista=filterNodeList(branch,lista)
173  for item in lista:
174  table[item.attributes["port"].value]=""
175  for item in table.keys():
176  table[item]=fillTable(order.copy(),branch + [item])
177  elif k=="c":
178  lista=xmldoc.getElementsByTagName("XdaqExecutive")
179  lista=filterNodeList(branch,lista)
180  for item in lista:
181  pset=item.getElementsByTagName("parameterSet")
182  if not len(pset):
183  table["No additional file"]=""
184  else:
185  table[pset[0].firstChild.nodeValue]=""
186  for item in table.keys():
187  table[item]=fillTable(order.copy(),branch)
188  else:
189  pass
190  return table
def fillTable(order, branch=[])
T min(T a, T b)
Definition: MathUtil.h:58
def filterNodeList(branch1, nodeList)
def ExtractAppInfoFromXML.filterNodeList (   branch1,
  nodeList 
)

Definition at line 125 of file ExtractAppInfoFromXML.py.

Referenced by fillTable().

125 def filterNodeList(branch1,nodeList):
126  if len(branch1) > 0:
127  branch=branch1[:len(branch1)]
128  idx=0
129  for item in range(len(nodeList)):
130  vals=[v for (k,v) in nodeList[idx].attributes.items()]
131  if branch[0] not in vals:
132  del nodeList[idx]
133  else:
134  idx=idx+1
135  del branch[0]
136  elif len(branch1)==0:
137  return nodeList
138  return filterNodeList(branch,nodeList)
139 
def filterNodeList(branch1, nodeList)
def ExtractAppInfoFromXML.getAppInfo (   XMLf,
  s = 0,
  a = 2,
  p = 1,
  c = 3 
)

getAppInfo #

getAppInfo(XMLf,s=0,a=2,p=1,c=3) takes the file name of a valid RCMS 
    configuration and 4 variables that represent which fields are desired 
    and in which order. 
    
    It returns a touple containing a directory that contains all the 
    relevant information in the XMLf file and a list of rows each row 
    containing the fiels specified by the other four variables in the r
    espective order
    
    The fields are Servers (s) ports(p) Appnames a.k.a. consumer names(a) 
    and consumer config file. (Note: The consumerName is directly extracted 
    from the config file.) if one field is not desired it should be assigned
    a value of -1 eg s=-1. other wise their value is mapped from smallest to
    largest ==> left to right. Note the default values, they will take 
    precedence if not specifyed giving unexpected results

Definition at line 232 of file ExtractAppInfoFromXML.py.

References appendDataXML(), fillTable(), printGrid(), and SortAndGrid().

232 def getAppInfo(XMLf,s=0,a=2,p=1,c=3):
233  """ getAppInfo(XMLf,s=0,a=2,p=1,c=3) takes the file name of a valid RCMS
234  configuration and 4 variables that represent which fields are desired
235  and in which order.
236 
237  It returns a touple containing a directory that contains all the
238  relevant information in the XMLf file and a list of rows each row
239  containing the fiels specified by the other four variables in the r
240  espective order
241 
242  The fields are Servers (s) ports(p) Appnames a.k.a. consumer names(a)
243  and consumer config file. (Note: The consumerName is directly extracted
244  from the config file.) if one field is not desired it should be assigned
245  a value of -1 eg s=-1. other wise their value is mapped from smallest to
246  largest ==> left to right. Note the default values, they will take
247  precedence if not specifyed giving unexpected results
248  """
249  global xmldoc
250  try:
251  os.path.exists(XMLf)
252  except:
253  sys.stderr.write('File doesn\'t exist\n')
254  sys.exit(2)
255  try:
256  xmldoc = minidom.parse(XMLf)
257  except IOError:
258  sys.stderr.write('Unable to locate file ' +XMLf +'\n')
259  return ({},[])
260  except:
261  sys.stderr.write('Parser error\n')
262  return ({},[])
263 
264  configFileNodes=xmldoc.getElementsByTagName("configFile")
265  for node in configFileNodes:
266  appendDataXML(node)
267  ## The table is always filled in a specific order, to properly get the data
268  order={0:"s",1:"p",3:"a",2:"c"}
269  #try:
270  table=fillTable(order)
271  #except:
272  # return ({},[])
273  del order
274  order={}
275  if a != -1:
276  order[a]="a"
277  if c != -1:
278  order[c]="c"
279  if s != -1:
280  order[s]="s"
281  if p != -1:
282  order[p]="p"
283  grid=SortAndGrid(table,order)
284  #printXMLtree(xmldoc)
285  #Clean Up
286  xmldoc.unlink()
287  return (table,grid)
288 
def fillTable(order, branch=[])
def SortAndGrid(table, order)
def getAppInfo(XMLf, s=0, a=2, p=1, c=3)
getAppInfo #
def ExtractAppInfoFromXML.getAppNameFromCfg (   filename)
it searches for the line containing the string consumerName, usually
found as a property of the process, and returns the set value found.
eg. 
matches line:
    process.EventStreamHttpReader.consumerName = 'EcalEndcap DQM Consumer' 
returns:
    EcalEndcap DQM Consumer 

Definition at line 75 of file ExtractAppInfoFromXML.py.

Referenced by fillTable().

75 def getAppNameFromCfg(filename):
76  """it searches for the line containing the string consumerName, usually
77  found as a property of the process, and returns the set value found.
78  eg.
79  matches line:
80  process.EventStreamHttpReader.consumerName = 'EcalEndcap DQM Consumer'
81  returns:
82  EcalEndcap DQM Consumer
83  """
84  try:
85  f = open(filename)
86  consumer = f.readline()
87  name=""
88  while consumer :
89  consumer=consumer.strip()
90  if "consumerName" in consumer:
91  name=consumer[consumer.index("'")+1:consumer.index("'",consumer.index("'")+1)]
92  break
93  consumer = f.readline()
94  f.close()
95  except:
96  sys.stderr.write("WARNING: Unable to open file: " + filename + " from <configFile> section of XML\n")
97  name = "CONFIG FILE IS M.I.A"
98  return name
def ExtractAppInfoFromXML.getProcNameFromCfg (   filename)
it searches for the line containing the string consumerName, usually
found as a property of the process, and returns the set value found.
eg. 
matches line:
    process = cms.Process ("ECALDQM") 
returns:
    ECALDQM

Definition at line 100 of file ExtractAppInfoFromXML.py.

Referenced by fillTable().

100 def getProcNameFromCfg(filename):
101  """it searches for the line containing the string consumerName, usually
102  found as a property of the process, and returns the set value found.
103  eg.
104  matches line:
105  process = cms.Process ("ECALDQM")
106  returns:
107  ECALDQM
108  """
109  try:
110  f = open(filename)
111  except:
112  sys.stderr.write("Unable to open file: " + filename + " from <configFile> section of XML\n")
113  raise IOError
114  consumer = f.readline()
115  name=""
116  while consumer :
117  consumer=consumer.strip()
118  if "cms.Process(" in consumer:
119  name=consumer[consumer.index("(")+2:consumer.index(")")-1]
120  break
121  consumer = f.readline()
122  f.close()
123  return name
def ExtractAppInfoFromXML.printGrid (   grid)

Definition at line 213 of file ExtractAppInfoFromXML.py.

References edm.print().

Referenced by getAppInfo().

213 def printGrid(grid):
214  numcols=len(grid[0])
215  PPGrid=grid[:]
216  maxs=[]
217  for col in range(numcols):
218  maxs.append(0)
219  for line in grid:
220  for col in range(numcols):
221  if len(line[col])>maxs[col]:
222  maxs[col]=len(line[col])
223  for line in PPGrid:
224  pline=""
225  for col in range(numcols):
226  pline+=line[col].ljust(maxs[col]+2)
227  print(pline)
228 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def ExtractAppInfoFromXML.printXMLtree (   head,
  l = 0,
  bn = 0 
)

Some module's global variables.

Definition at line 30 of file ExtractAppInfoFromXML.py.

References edm.print(), and str.

30 def printXMLtree(head,l=0,bn=0):
31  tabs=""
32  for a in range(l):
33  tabs+="\t"
34  try:
35  print("[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+"+++++>"+head.tagName)
36  except AttributeError as e:
37  print("[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+"+++++>"+str(e))
38  print("[%d-%d-%d-v]"%(l,bn,head.nodeType)+tabs+"."+ (head.nodeValue or "None"))
39  try:
40  for katt,vatt in head.attributes.items():
41  if katt!="environmentString":
42  print(tabs+"%s=%s"%(katt,vatt))
43  else:
44  print(tabs+"%s= 'Some Stuff'"%(katt,))
45  except:
46  pass
47  i=0
48  for node in head.childNodes:
49  printXMLtree(node,l+1,i)
50  i+=1
def printXMLtree(head, l=0, bn=0)
Some module&#39;s global variables.
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)
def ExtractAppInfoFromXML.SortAndGrid (   table,
  order 
)
table => {s:{p:{c:{a:{}}}}}

Definition at line 192 of file ExtractAppInfoFromXML.py.

Referenced by getAppInfo().

192 def SortAndGrid(table,order):
193  """table => {s:{p:{c:{a:{}}}}}"""
194  grid=[]
195  for (server,ports) in table.items():
196  for (port,configfiles) in ports.items():
197  for (configfile,appnames) in configfiles.items():
198  for appname in appnames.keys():
199  line=[]
200  for col in order.values():
201  if col=="s":
202  line.append(server)
203  if col=="p":
204  line.append(port)
205  if col=="c":
206  line.append(configfile)
207  if col=="a":
208  line.append(appname)
209  grid.append(line)
210  grid.sort()
211  return grid
def SortAndGrid(table, order)