CMS 3D CMS Logo

Functions | Variables
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)
 
def SortAndGrid (table, order)
 

Variables

 appinfo
 
 apptable
 
 args
 
 options
 
 xmldoc
 Some module's global variables. More...
 
 XMLfile
 

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

◆ appendDataXML()

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

◆ compactNodeValue()

def ExtractAppInfoFromXML.compactNodeValue (   head)

Definition at line 53 of file ExtractAppInfoFromXML.py.

Referenced by appendDataXML().

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

◆ fillTable()

def ExtractAppInfoFromXML.fillTable (   order,
  branch = [] 
)

Definition at line 142 of file ExtractAppInfoFromXML.py.

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

Referenced by getAppInfo().

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

◆ filterNodeList()

def ExtractAppInfoFromXML.filterNodeList (   branch1,
  nodeList 
)

Definition at line 126 of file ExtractAppInfoFromXML.py.

References FastTimerService_cff.range.

Referenced by fillTable().

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

◆ getAppInfo()

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().

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

◆ getAppNameFromCfg()

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

◆ getProcNameFromCfg()

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().

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

◆ printGrid()

def ExtractAppInfoFromXML.printGrid (   grid)

Definition at line 214 of file ExtractAppInfoFromXML.py.

References print(), and FastTimerService_cff.range.

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

◆ printXMLtree()

def ExtractAppInfoFromXML.printXMLtree (   head,
  l = 0,
  bn = 0 
)

Definition at line 31 of file ExtractAppInfoFromXML.py.

References print(), FastTimerService_cff.range, and str.

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

◆ SortAndGrid()

def ExtractAppInfoFromXML.SortAndGrid (   table,
  order 
)
table => {s:{p:{c:{a:{}}}}}

Definition at line 193 of file ExtractAppInfoFromXML.py.

Referenced by getAppInfo().

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

Variable Documentation

◆ appinfo

ExtractAppInfoFromXML.appinfo

Definition at line 306 of file ExtractAppInfoFromXML.py.

◆ apptable

ExtractAppInfoFromXML.apptable

Definition at line 306 of file ExtractAppInfoFromXML.py.

◆ args

ExtractAppInfoFromXML.args

Definition at line 293 of file ExtractAppInfoFromXML.py.

◆ options

ExtractAppInfoFromXML.options

Definition at line 295 of file ExtractAppInfoFromXML.py.

◆ xmldoc

ExtractAppInfoFromXML.xmldoc

Some module's global variables.

Definition at line 29 of file ExtractAppInfoFromXML.py.

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

◆ XMLfile

ExtractAppInfoFromXML.XMLfile

Definition at line 292 of file ExtractAppInfoFromXML.py.