CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
ExtractAppInfoFromXML Namespace Reference

Functions

def appendDataXML
 
def compactNodeValue
 
def fillTable
 
def filterNodeList
 
def getAppInfo
 getAppInfo # More...
 
def getAppNameFromCfg
 
def getProcNameFromCfg
 
def printGrid
 
def printXMLtree
 
def SortAndGrid
 

Variables

 args = sys.argv
 
string options = ""
 
string xmldoc = ""
 Some module's global variables. More...
 
string XMLfile = ""
 

Function Documentation

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

Definition at line 67 of file ExtractAppInfoFromXML.py.

References compactNodeValue().

Referenced by getAppInfo().

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

Definition at line 53 of file ExtractAppInfoFromXML.py.

Referenced by appendDataXML().

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

Definition at line 142 of file ExtractAppInfoFromXML.py.

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

Referenced by getAppInfo().

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

Definition at line 126 of file ExtractAppInfoFromXML.py.

References sistrip::SpyUtilities.range().

Referenced by fillTable().

127 def filterNodeList(branch1,nodeList):
128  if len(branch1) > 0:
129  branch=branch1[:len(branch1)]
130  idx=0
131  for item in range(len(nodeList)):
132  vals=[v for (k,v) in nodeList[idx].attributes.items()]
133  if branch[0] not in vals:
134  del nodeList[idx]
135  else:
136  idx=idx+1
137  del branch[0]
138  elif len(branch1)==0:
139  return nodeList
140  return filterNodeList(branch,nodeList)
const uint16_t range(const Frame &aFrame)
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 233 of file ExtractAppInfoFromXML.py.

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

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

Referenced by fillTable().

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

Referenced by fillTable().

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

Definition at line 214 of file ExtractAppInfoFromXML.py.

References print(), and sistrip::SpyUtilities.range().

215 def printGrid(grid):
216  numcols=len(grid[0])
217  PPGrid=grid[:]
218  maxs=[]
219  for col in range(numcols):
220  maxs.append(0)
221  for line in grid:
222  for col in range(numcols):
223  if len(line[col])>maxs[col]:
224  maxs[col]=len(line[col])
225  for line in PPGrid:
226  pline=""
227  for col in range(numcols):
228  pline+=line[col].ljust(maxs[col]+2)
229  print(pline)
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def ExtractAppInfoFromXML.printXMLtree (   head,
  l = 0,
  bn = 0 
)

Definition at line 31 of file ExtractAppInfoFromXML.py.

References print(), sistrip::SpyUtilities.range(), and str.

31 
32 def printXMLtree(head,l=0,bn=0):
33  tabs=""
34  for a in range(l):
35  tabs+="\t"
36  try:
37  print("[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+"+++++>"+head.tagName)
38  except AttributeError as e:
39  print("[%d-%d-%d]"%(l,bn,head.nodeType)+tabs+"+++++>"+str(e))
40  print("[%d-%d-%d-v]"%(l,bn,head.nodeType)+tabs+"."+ (head.nodeValue or "None"))
41  try:
42  for katt,vatt in head.attributes.items():
43  if katt!="environmentString":
44  print(tabs+"%s=%s"%(katt,vatt))
45  else:
46  print(tabs+"%s= 'Some Stuff'"%(katt,))
47  except:
48  pass
49  i=0
50  for node in head.childNodes:
51  printXMLtree(node,l+1,i)
i+=1
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#define str(s)
def ExtractAppInfoFromXML.SortAndGrid (   table,
  order 
)
table => {s:{p:{c:{a:{}}}}}

Definition at line 193 of file ExtractAppInfoFromXML.py.

Referenced by getAppInfo().

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

Variable Documentation

ExtractAppInfoFromXML.args = sys.argv

Definition at line 293 of file ExtractAppInfoFromXML.py.

string ExtractAppInfoFromXML.options = ""

Definition at line 295 of file ExtractAppInfoFromXML.py.

string ExtractAppInfoFromXML.xmldoc = ""

Some module's global variables.

Definition at line 29 of file ExtractAppInfoFromXML.py.

Referenced by emtf::Tree.loadFromXML(), and emtf::Tree.saveToXML().

ExtractAppInfoFromXML.XMLfile = ""

Definition at line 292 of file ExtractAppInfoFromXML.py.