Changeset 78
- Timestamp:
- Nov 6, 2009 10:10:08 AM (14 years ago)
- Location:
- epics2xml
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
epics2xml/config.xml
r75 r78 1 1 <?xml version="1.0" ?> 2 <!-- <?xml-stylesheet type="text/xsl" href="display.xsl" ?>-->2 <!--<?xml-stylesheet type="text/xsl" href="display.xsl" ?>--> 3 3 4 4 <!-- … … 12 12 --> 13 13 14 <epics2www version="1.0"> 15 <title>epics2www: demonstration of function</title> 16 <targetFile name="/home/beams/S32USAXS/jemian/epics2www/pvdata.xml"> 14 <epics2xml version="1.0"> 15 <title>epics2xml: demonstration of function</title> 16 <targetFile name="./pvdata.xml"> 17 <!-- /home/beams/S32USAXS/jemian/epics2xml/pvdata.xml --> 17 18 <refreshMinimum units="s"> 18 19 10 <!-- do not refresh the target file any faster than this interval --> … … 22 23 <description>APS Storage ring current, mA</description> 23 24 </pv> 24 </epics2 www>25 </epics2xml> -
epics2xml/epics2xml.py
r77 r78 28 28 import datetime 29 29 import copy 30 31 32 class Epics2Www: 30 import pvConnect 31 32 33 class Epics2Xml: 33 34 '''watch PVs and write to XMl''' 34 35 35 def __init__(self, settingsFile=None):36 def __init__(self, configFile=None): 36 37 '''prepare the settings file 37 @param settingsFile: [string] name of XML file with settings'''38 self.rootElement = 'epics2 www'38 @param configFile: [string] name of XML file with settings''' 39 self.rootElement = 'epics2xml' 39 40 self.Clear() 40 self.Set SettingsFile(settingsFile)41 self.SetConfigFile(configFile) 41 42 42 43 def GetDb(self): … … 44 45 return self.db 45 46 46 def Get SettingsFile(self):47 def GetConfigFile(self): 47 48 '''@return: name of XML settings file''' 48 49 return self.settingsFile 49 50 50 def Set SettingsFile(self, thefile):51 '''set the name of XML settingsfile52 @param thefile: [string] name of XML file with settings'''51 def SetConfigFile(self, thefile): 52 '''set the name of XML configuration file 53 @param thefile: [string] name of XML file with the configuration''' 53 54 self.settingsFile = thefile 54 55 … … 56 57 '''reset the internal data representation (db) to empty''' 57 58 self.db = {} 58 59 def NewPair(self, title=''):60 ''' create space in the database (db) for a new pair61 and sets defaults for fields62 63 @param title: [string] the title of the XY_pair set (default="")64 @return: the index number'''65 if self.CountPairs() == -1:66 self.db[u"pairs"] = []67 pairdb = {}68 pairdb[u"@name"] = title69 pairdb[u"@selected"] = False70 self.db[u'pairs'].append(pairdb)71 return len(self.db[u'pairs'])-172 73 def GetPairTitle(self, pairnum):74 '''return the name of the XY_pair75 @param pairnum: [int] index number of the XY_pair'''76 return self.db[u"pairs"][pairnum][u"@name"]77 78 def SetPairTitle(self, pairnum, title):79 '''set the name of the XY_pair80 @param pairnum: [int] index number of the XY_pair'81 @param title: [string] name of the XY_pair'''82 self.db[u"pairs"][pairnum][u"@name"] = title83 84 def SelectPair(self, pairnum):85 '''set the "selected" attribute of the pair86 @param pairnum: [int] index number of the XY_pair'''87 for pair in self.db[u"pairs"]: # first, deselect all pairs88 pair[u"@selected"] = False89 self.db[u"pairs"][pairnum][u"@selected"] = True90 91 def GetSelectedPair(self):92 '''@return: index number of the "selected" pair (-1 if none selected)'''93 selected = -194 try:95 pairs = self.db[u"pairs"]96 for pairnum in range(len(pairs)):97 if pairs[pairnum][u"@selected"]:98 selected = pairnum99 break100 except:101 pass102 return selected103 104 def CountPairs(self):105 '''@return: number of pairs'''106 try:107 return len(self.db[u"pairs"])108 except:109 return -1110 111 def NewEpicsConfig(self, pairnum):112 '''Create internal space for a new EPICS configuration113 @param pairnum: [int] index number of the XY_pair'''114 pairdb = self.db[u"pairs"][pairnum]115 pairdb[u"epics"] = {}116 epicsdb = pairdb[u"epics"]117 for axis in ['x', 'y']:118 epicsdb[axis] = {}119 axisdb = epicsdb[axis]120 for field in wxmtxy_axis.field_list:121 axisdb[field] = ""122 axisdb[u"isMotorRec"] = False123 124 def GetEpicsConfig(self, pairnum):125 '''Get a deep copy Python dictionary of the current EPICS PV config.126 @param pairnum: [int] index number of the XY_pair127 @return: the current EPICS configuration'''128 return copy.deepcopy(self.db[u"pairs"][pairnum][u"epics"])129 130 def SetEpicsConfig(self, pairnum, config):131 '''set the current EPICS configuration132 @param pairnum: [int] index number of the XY_pair133 @param config: Python dictionary of EPICS PV configuration'''134 pairdb = self.db[u"pairs"][pairnum]135 pairdb[u"epics"] = copy.deepcopy(config)136 137 def SetEpicsField(self, pairnum, axis, field, value):138 '''Define the EPICS config for a specific field139 @param pairnum: [int] index number of the XY_pair'140 @param axis: [string] "x" or "y"'141 @param field: [string] member of wxmtxy_axis.field_list'142 @param value: [string] value of this field'''143 try:144 axisdb = self.db[u"pairs"][pairnum][u"epics"][axis]145 axisdb[field] = value146 except:147 print "Could not assign EPICS field", pairnum, axis, field, value148 149 150 def NewTab(self, pairnum, title=''):151 ''' create space in the database (db) pair for a new tab152 and sets defaults for fields153 154 @param pairnum: [int] index number of the XY_pair155 @param title: the title of the pair set (default="")156 @return the index number'''157 pairdb = self.db[u"pairs"][pairnum]158 if not pairdb.has_key(u"tabs"):159 pairdb[u"tabs"] = []160 tabdb = {}161 tabdb[u"@name"] = title162 tabdb[u"@selected"] = False163 pairdb[u"tabs"].append(tabdb)164 return len(pairdb[u"tabs"])-1165 166 def GetTabTitle(self, pairnum, tabnum):167 '''return the name of the tab168 @param pairnum: [int] index number of the XY_pair169 @param tabnum: [int] index number of the Tab object'''170 return self.db[u"pairs"][pairnum][u"tabs"][tabnum][u"@name"]171 172 def SetTabTitle(self, pairnum, tabnum, title):173 '''set the name attribute of the tab174 @param pairnum: [int] index number of the XY_pair175 @param tabnum: [int] index number of the Tab object176 @param title: [string] title the Tab object'''177 self.db[u"pairs"][pairnum][u"tabs"][tabnum]["@name"] = title178 179 def SelectTab(self, pairnum, tabnum):180 '''set the selected attribute of the pair181 @param pairnum: [int] index number of the XY_pair182 @param tabnum: [int] index number of the Tab object'''183 pairdb = self.db[u"pairs"][pairnum]184 for tab in pairdb[u"tabs"]: # first, deselect all tabs185 tab[u"@selected"] = False186 pairdb[u"tabs"][tabnum][u"@selected"] = True187 188 def GetSelectedTab(self, pairnum):189 '''return the index number of the selected tab190 @param pairnum: [int] index number of the XY_pair'''191 selected = -1192 try:193 tabs = self.db[u"pairs"][pairnum][u"tabs"]194 for tabnum in range(len(tabs)):195 if tabs[tabnum][u"@selected"]:196 selected = tabnum197 break198 except:199 pass200 return selected201 202 def CountTabs(self, pairnum):203 '''return the number of tabs204 @param pairnum: [int] index number of the XY_pair'''205 try:206 return len(self.db[u"pairs"][pairnum][u"tabs"])207 except:208 return -1209 210 def NewRow(self, pairnum, tabnum, title=''):211 ''' create space in the database (db) pair for a new tab212 and sets defaults for fields213 214 @param pairnum: [int] index number of the XY_pair215 @param tabnum: [int] index number of the Tab object216 @param title: the title of the Tab object (default="")217 @return the index number'''218 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]219 if not tabdb.has_key(u"rows"):220 tabdb[u"rows"] = []221 rowdb = {}222 rowdb[u"@name"] = title223 rowdb[u"@selected"] = False224 rowdb[u"@x"] = ""225 rowdb[u"@y"] = ""226 tabdb[u"rows"].append(rowdb)227 return len(tabdb[u"rows"])-1228 229 def GetRowTitle(self, pairnum, tabnum, rownum):230 '''return the name of the row231 @param pairnum: [int] index number of the XY_pair232 @param tabnum: [int] index number of the Tab object233 @param rownum: [int] index number of the Row object'''234 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]235 return tabdb[u"rows"][rownum][u"@name"]236 237 def SetRowTitle(self, pairnum, tabnum, rownum, title):238 '''set the name attribute of the row239 @param pairnum: [int] index number of the XY_pair240 @param tabnum: [int] index number of the Tab object241 @param rownum: [int] index number of the Row object242 @param title: [string] title the Tab object'''243 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]244 tabdb[u"rows"][rownum][u"@name"] = title245 246 def GetRowXY(self, pairnum, tabnum, rownum):247 '''return the name of the row248 @param pairnum: [int] index number of the XY_pair249 @param tabnum: [int] index number of the Tab object250 @param rownum: [int] index number of the Row object'''251 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]252 x = tabdb[u"rows"][rownum][u"@x"]253 y = tabdb[u"rows"][rownum][u"@y"]254 return x, y255 256 def SetRowXY(self, pairnum, tabnum, rownum, x, y):257 '''set the name attribute of the row258 @param pairnum: [int] index number of the XY_pair259 @param tabnum: [int] index number of the Tab object260 @param x: [float] X axis position261 @param y: [float] Y axis position'''262 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]263 tabdb[u"rows"][rownum][u"@x"] = x264 tabdb[u"rows"][rownum][u"@y"] = y265 266 def CountRows(self, pairnum, tabnum):267 '''return the number of rows268 @param pairnum: [int] index number of the XY_pair269 @param tabnum: [int] index number of the Tab object'''270 try:271 return len(self.db[u"pairs"][pairnum][u"tabs"][tabnum][u"rows"])272 except:273 return -1274 275 def GetSelectedRow(self, pairnum, tabnum):276 '''return the index number of the selected row277 @param pairnum: [int] index number of the XY_pair278 @param tabnum: [int] index number of the Tab object'''279 selected = -1280 try:281 rows = self.db[u"pairs"][pairnum][u"tabs"][tabnum][u"rows"]282 for rownum in range(len(rows)):283 if rows[rownum][u"@selected"]:284 selected = rownum285 break286 except:287 pass288 return selected289 290 def SelectRow(self, pairnum, tabnum, rownum):291 '''set the selected attribute of the pair292 @param pairnum: [int] index number of the XY_pair293 @param tabnum: [int] index number of the Tab object294 @param rownum: [int] index number of the Row object'''295 tabdb = self.db[u"pairs"][pairnum][u"tabs"][tabnum]296 for row in tabdb[u"rows"]: # first, deselect all rows297 row[u"@selected"] = False298 tabdb[u"rows"][rownum][u"@selected"] = True299 59 300 60 def ReadXmlFile(self): … … 419 179 self._SetAttr(root, "time", hhmmss) 420 180 doc.appendChild(root) 421 selectedpairnum = self.GetSelectedPair()422 for pairnum in range(self.CountPairs()):423 pairnode = doc.createElement("XYpair")424 self._SetAttr(pairnode, "name",425 self.GetPairTitle(pairnum))426 if selectedpairnum == pairnum:427 self._SetAttr(pairnode, "selected", "True")428 if self.db[u"pairs"][pairnum].has_key(u"epics"):429 epicsnode = doc.createElement("EPICS_configuration")430 epicsdb = self.db[u"pairs"][pairnum][u"epics"]431 for axis in epicsdb:432 axisnode = doc.createElement("axis")433 self._SetAttr(axisnode, "name", axis)434 field = "isMotorRec"435 node = doc.createElement("flag")436 self._SetAttr(node, field, str(epicsdb[axis][field]))437 axisnode.appendChild(node)438 for field in wxmtxy_axis.field_list:439 if len(epicsdb[axis][field])>0:440 node = doc.createElement("field")441 self._SetAttr(node, "name", field)442 self._SetAttr(node, "pv", str(epicsdb[axis][field]))443 axisnode.appendChild(node)444 epicsnode.appendChild(axisnode)445 pairnode.appendChild(epicsnode)446 selectedtabnum = self.GetSelectedTab(pairnum)447 for tabnum in range(self.CountTabs(pairnum)):448 tabnode = doc.createElement("tab")449 self._SetAttr(tabnode, "name", self.GetTabTitle(pairnum, tabnum))450 if selectedtabnum == tabnum:451 self._SetAttr(tabnode, "selected", "True")452 selectedrownum = self.GetSelectedRow(pairnum, tabnum)453 for rownum in range(self.CountRows(pairnum, tabnum)):454 rownode = doc.createElement("row")455 label = self.GetRowTitle(pairnum, tabnum, rownum)456 x, y = self.GetRowXY(pairnum, tabnum, rownum)457 self._SetAttr(rownode, "name", label)458 self._SetAttr(rownode, "x", x)459 self._SetAttr(rownode, "y", y)460 if selectedrownum == rownum:461 self._SetAttr(rownode, "selected", "True")462 tabnode.appendChild(rownode)463 pairnode.appendChild(tabnode)464 root.appendChild(pairnode)181 # selectedpairnum = self.GetSelectedPair() 182 # for pairnum in range(self.CountPairs()): 183 # pairnode = doc.createElement("XYpair") 184 # self._SetAttr(pairnode, "name", 185 # self.GetPairTitle(pairnum)) 186 # if selectedpairnum == pairnum: 187 # self._SetAttr(pairnode, "selected", "True") 188 # if self.db[u"pairs"][pairnum].has_key(u"epics"): 189 # epicsnode = doc.createElement("EPICS_configuration") 190 # epicsdb = self.db[u"pairs"][pairnum][u"epics"] 191 # for axis in epicsdb: 192 # axisnode = doc.createElement("axis") 193 # self._SetAttr(axisnode, "name", axis) 194 # field = "isMotorRec" 195 # node = doc.createElement("flag") 196 # self._SetAttr(node, field, str(epicsdb[axis][field])) 197 # axisnode.appendChild(node) 198 # for field in wxmtxy_axis.field_list: 199 # if len(epicsdb[axis][field])>0: 200 # node = doc.createElement("field") 201 # self._SetAttr(node, "name", field) 202 # self._SetAttr(node, "pv", str(epicsdb[axis][field])) 203 # axisnode.appendChild(node) 204 # epicsnode.appendChild(axisnode) 205 # pairnode.appendChild(epicsnode) 206 # selectedtabnum = self.GetSelectedTab(pairnum) 207 # for tabnum in range(self.CountTabs(pairnum)): 208 # tabnode = doc.createElement("tab") 209 # self._SetAttr(tabnode, "name", self.GetTabTitle(pairnum, tabnum)) 210 # if selectedtabnum == tabnum: 211 # self._SetAttr(tabnode, "selected", "True") 212 # selectedrownum = self.GetSelectedRow(pairnum, tabnum) 213 # for rownum in range(self.CountRows(pairnum, tabnum)): 214 # rownode = doc.createElement("row") 215 # label = self.GetRowTitle(pairnum, tabnum, rownum) 216 # x, y = self.GetRowXY(pairnum, tabnum, rownum) 217 # self._SetAttr(rownode, "name", label) 218 # self._SetAttr(rownode, "x", x) 219 # self._SetAttr(rownode, "y", y) 220 # if selectedrownum == rownum: 221 # self._SetAttr(rownode, "selected", "True") 222 # tabnode.appendChild(rownode) 223 # pairnode.appendChild(tabnode) 224 # root.appendChild(pairnode) 465 225 return doc.toprettyxml(indent=" ") 466 226 467 227 468 228 if __name__ == '__main__': 469 rc = Settings("examples/test-settings.xml") 470 rc.ReadXmlFile() 471 rc.SetSettingsFile('output-test.xml') 472 rc.SaveXmlFile() 473 474 pj = Settings() 475 pairnum = pj.NewPair("my test pair") 476 tabnum = pj.NewTab(pairnum, title='my test tab') 477 tabnum = pj.NewTab(pairnum, title='another') 478 pj.SelectTab(pairnum, tabnum) 479 tabnum = pj.NewTab(pairnum, title='another') 480 tabnum = pj.NewTab(pairnum, title='another') 481 pairnum = pj.NewPair("another") 482 pj.SelectPair(pairnum) 483 tabnum = pj.NewTab(pairnum, title='another') 484 rownum = pj.NewRow(pairnum, tabnum, "beam center") 485 pj.SelectRow(pairnum, tabnum, rownum) 486 tabnum = pj.NewTab(pairnum, title='another') 487 pairnum = pj.NewPair("another") 488 print str(pj) 229 # rc = Settings("examples/test-settings.xml") 230 # rc.ReadXmlFile() 231 # rc.SetConfigFile('output-test.xml') 232 # rc.SaveXmlFile() 233 # 234 # pj = Settings() 235 # pairnum = pj.NewPair("my test pair") 236 # tabnum = pj.NewTab(pairnum, title='my test tab') 237 # tabnum = pj.NewTab(pairnum, title='another') 238 # pj.SelectTab(pairnum, tabnum) 239 # tabnum = pj.NewTab(pairnum, title='another') 240 # tabnum = pj.NewTab(pairnum, title='another') 241 # pairnum = pj.NewPair("another") 242 # pj.SelectPair(pairnum) 243 # tabnum = pj.NewTab(pairnum, title='another') 244 # rownum = pj.NewRow(pairnum, tabnum, "beam center") 245 # pj.SelectRow(pairnum, tabnum, rownum) 246 # tabnum = pj.NewTab(pairnum, title='another') 247 # pairnum = pj.NewPair("another") 248 # print str(pj) 249 print "Hello" -
epics2xml/pvdata.xml
r75 r78 2 2 <?xml-stylesheet type="text/xsl" href="display.xsl" ?> 3 3 4 <!--5 ########### SVN repository information ###################6 # $Date: 2009-05-23 09:53:17 -0500 (Sat, 23 May 2009) $7 # $Author: jemian $8 # $Revision: 56 $9 # $URL: https://subversion.xor.aps.anl.gov/bcdaext/wxmtxy/trunk/examples/USAXS_XY.xml $10 # $Id: USAXS_XY.xml 56 2009-05-23 14:53:17Z jemian $11 ########### SVN repository information ###################12 -->13 14 4 <pvdata version="1.0"> 15 <title>epics2 www: demonstration of function</title>5 <title>epics2xml: demonstration of function</title> 16 6 <pv name="S:SRcurrentAI" rate="monitor" timeStamp="2009-11-06 09:26:00"> 17 7 <description>APS Storage ring current, mA</description>
Note: See TracChangeset
for help on using the changeset viewer.