/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
xmlIndex::XmlIndexGenerator Class Reference

List of all members.

Public Member Functions

def __init__
def process
def openFile
def processPath
def xmlOpen
def xmlClose
def indexFigure
def createXmlNode
def tryDiagnostics
def tryRun
def tryDetector
def tryChannel

Public Attributes

 filename
 rootPath
 fileRoot
 xmlIndex
 pathReplace
 file
 format
 xml
 rootElem

Detailed Description

XML Index Generator Class

Definition at line 65 of file xmlIndex.py.


Constructor & Destructor Documentation

def xmlIndex::XmlIndexGenerator::__init__ (   self,
  filename,
  rootPath,
  fileRoot,
  xmlIndex,
  pathReplace 
)

Definition at line 67 of file xmlIndex.py.

00068                                                                            :
00069         "Constructor"
00070         self.filename = filename
00071         self.rootPath = rootPath
00072         self.fileRoot = fileRoot
00073         self.xmlIndex = xmlIndex
00074         self.pathReplace = pathReplace
00075         self.file = None
00076         self.format = "png"
00077         self.xml = None
00078         self.rootElem = None
00079         return


Member Function Documentation

def xmlIndex::XmlIndexGenerator::process (   self)
Generate XML

Definition at line 80 of file xmlIndex.py.

00081                      :
00082         """Generate XML"""
00083         if not self.openFile():
00084             return
00085         self.xmlOpen()
00086         self.processPath("diagnostics",None)
00087         self.xmlClose()
00088         return
        
def xmlIndex::XmlIndexGenerator::openFile (   self)

Definition at line 89 of file xmlIndex.py.

00090                       :
00091         "Open root file"
00092         import ROOT
00093         rootFile = ROOT.TFile(self.filename)
00094         if not rootFile:
00095             print "Failed to open root file:",filename
00096             return False
00097         self.file = rootFile
00098         return True

def xmlIndex::XmlIndexGenerator::processPath (   self,
  itemPath,
  parentElem 
)
Process a path in the current root file

Definition at line 99 of file xmlIndex.py.

00100                                                :
00101         """Process a path in the current root file"""
00102         #print "Processing:",itemPath
00103         filePath = self.fileRoot + "/" + itemPath
00104         content = self.file.Get(filePath);
00105         if not content:
00106             print "Failed to get item at: ", itemPath
00107             return
00108         if (content.IsA().InheritsFrom("TH1")
00109             or content.IsA().InheritsFrom("TGraph")):
00110             # Found a figure.  Index it.
00111             self.indexFigure(content, itemPath, parentElem)
00112         elif content.IsA().InheritsFrom("TDirectory"):
00113             # Found a directory.  Index it
00114             newElem = None
00115             newElem = self.tryDiagnostics(itemPath, parentElem)
00116             if not newElem:
00117                 newElem = self.tryRun(itemPath, parentElem)
00118             if not newElem:
00119                 newElem = self.tryDetector(itemPath, parentElem)
00120             if not newElem:
00121                 newElem = self.tryChannel(itemPath, parentElem)
00122             if not newElem:
00123                 print "Will not index path: ", itemPath
00124                 return
00125             keylist = content.GetListOfKeys()
00126             for key in keylist:
00127                 dirItem = key.ReadObj()
00128                 dirItemPath = None
00129                 if len(itemPath)>0:
00130                     dirItemPath = itemPath+"/"+dirItem.GetName()
00131                 else:
00132                     dirItemPath = dirItem.GetName()
00133                 self.processPath(dirItemPath, newElem)
00134         else:
00135             # Won't handle this object
00136             print "Not handing %s of type %s" % (filePath,content.ClassName())
00137         return

def xmlIndex::XmlIndexGenerator::xmlOpen (   self)
Create XML index header

Definition at line 138 of file xmlIndex.py.

00139                      :
00140         """Create XML index header"""
00141         import xml.dom.minidom
00142         self.xml = xml.dom.minidom.Document()
00143         return

def xmlIndex::XmlIndexGenerator::xmlClose (   self)
Close XML index, write to output file

Definition at line 144 of file xmlIndex.py.

00145                       :
00146         """Close XML index, write to output file"""
00147         writeXml(self.xmlIndex, self.rootElem)
00148         return

def xmlIndex::XmlIndexGenerator::indexFigure (   self,
  item,
  itemPath,
  parentElem 
)
Check path and add to XML index

Definition at line 149 of file xmlIndex.py.

00150                                                      :
00151         """Check path and add to XML index"""
00152         if parentElem.localName in ['run','detector','channel']: 
00153             # Add figure to parent
00154             figPath = itemPath + '.' + self.format
00155             # Replace figure path if needed
00156             if self.pathReplace:
00157                 for key in self.pathReplace.keys():
00158                     figPath = figPath.replace(key,self.pathReplace[key])
00159             parentId = parentElem.attributes['id'].value
00160             figElem = self.createXmlNode('figure',
00161                                          {'figname':item.GetName(),
00162                                           'path':figPath,
00163                                           'figtitle':item.GetTitle(),
00164                                           'rootPath':self.rootPath},
00165                                          {'id':parentId+'_'+item.GetName()})
00166             parentElem.appendChild(figElem)
00167         return figElem

def xmlIndex::XmlIndexGenerator::createXmlNode (   self,
  name,
  children = None,
  attributes = None 
)

Definition at line 168 of file xmlIndex.py.

00169                                                                  :
00170         newElem = self.xml.createElement(name)
00171         if children:
00172             for child in children.keys():
00173                 childElem = self.xml.createElement(child)
00174                 childContent = self.xml.createTextNode(children[child])
00175                 childElem.appendChild(childContent)
00176                 newElem.appendChild(childElem)
00177         if attributes:
00178             for attrName in attributes.keys():
00179                 newElem.setAttribute(attrName, attributes[attrName])
00180         return newElem

def xmlIndex::XmlIndexGenerator::tryDiagnostics (   self,
  itemPath,
  parentElem 
)
Check if path is in 'diagnostics' format

Definition at line 181 of file xmlIndex.py.

00182                                                   :
00183         """Check if path is in 'diagnostics' format"""
00184         if parentElem: return None
00185         pathParts = itemPath.split('/')
00186         if len(pathParts)!=1: return None
00187         if itemPath != 'diagnostics': return None
00188         self.rootElem = self.createXmlNode('diagnostic_index')
00189         return self.rootElem

def xmlIndex::XmlIndexGenerator::tryRun (   self,
  itemPath,
  parentElem 
)
Check if path is in 'run' format

Definition at line 190 of file xmlIndex.py.

00191                                           :
00192         """Check if path is in 'run' format"""
00193         if parentElem.localName != 'diagnostic_index':
00194             return None
00195         pathParts = itemPath.split('/')
00196         if len(pathParts)!=2: return None
00197         runPart = pathParts[-1]
00198         if len(runPart)!=11: return None
00199         if not runPart.startswith("run_"): return None
00200         if not runPart[4:].isdigit(): return None
00201         runnumber = int(runPart[4:])
00202         runId = runPart
00203         if runnumber == 0:
00204             print "FIXME: sim data has runnumber == 0"
00205             runpathfix = self.pathReplace.keys()[0]
00206             runnumber = int(runpathfix[-7:])
00207             self.pathReplace = {runPart : self.pathReplace[runpathfix]}
00208             print "FIXME: replacing with runnumber ",runnumber
00209             runId = runpathfix
00210         runElem = self.createXmlNode('run',{'runnumber':str(runnumber)},
00211                                      {'id':runId})
00212         parentElem.appendChild(runElem)
00213         return runElem

def xmlIndex::XmlIndexGenerator::tryDetector (   self,
  itemPath,
  parentElem 
)
Check if path is in 'detector' format

Definition at line 214 of file xmlIndex.py.

00215                                                :
00216         """Check if path is in 'detector' format"""
00217         if parentElem.localName != 'run':
00218             return None
00219         pathParts = itemPath.split('/')
00220         if len(pathParts)!=3: return None
00221         detPart = pathParts[-1]
00222         if not detPart.startswith("detector_"): return None
00223         detectorId = parentElem.attributes.get('id').nodeValue + '_' + detPart
00224         detectorName = detPart[9:]
00225         detElem = self.createXmlNode('detector',{'detname':detectorName},
00226                                      {'id':detectorId})
00227         parentElem.appendChild(detElem)
00228         return detElem

def xmlIndex::XmlIndexGenerator::tryChannel (   self,
  itemPath,
  parentElem 
)
Check if path is in 'channel' format

Definition at line 229 of file xmlIndex.py.

00230                                               :
00231         """Check if path is in 'channel' format"""
00232         if parentElem.localName != 'detector':
00233             return None
00234         pathParts = itemPath.split('/')
00235         if len(pathParts)!=4: return None
00236         chanPart = pathParts[-1]
00237         if not chanPart.startswith("channel_"): return None
00238         channelId = parentElem.attributes.get('id').nodeValue + '_' + chanPart
00239         channelName = chanPart[8:]
00240         channelElem = self.createXmlNode('channel',
00241                                          {'channelname':channelName},
00242                                          {'id':channelId})
00243         parentElem.appendChild(channelElem)
00244         return channelElem


Member Data Documentation

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.

Definition at line 67 of file xmlIndex.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:09 for RunDiagnostics by doxygen 1.7.4