00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 __facility__ = "Online"
00011 __abstract__ = "Hardware Configuration Selector"
00012 __author__ = "S. Tuvi <STuvi@SLAC.Stanford.edu>"
00013 __date__ = "2005/09/15 23:45:02"
00014 __updated__ = "$Date: 2006/04/07 01:17:13 $"
00015 __version__ = "$Revision: 1.3 $"
00016 __release__ = "$Name: HEAD $"
00017 __credits__ = "SLAC"
00018
00019 import LICOS.copyright_SLAC
00020
00021 from qt import *
00022 import logging as log
00023 import time
00024 import sys
00025 import types
00026
00027 from ConfigParser import ConfigParser, NoOptionError
00028
00029 from LICOS.scriptEngine.HwCfgSelector import HwCfgSelector
00030 from LICOS.util.gOptions import Options
00031
00032 class HwCfgSelectorImpl(HwCfgSelector):
00033 """!\brief Hardware Configuration Selector.
00034
00035 """
00036
00037 CFG_PREFIX = 'lat-config'
00038 CROSS_STRAP = ['AA','AB','BA','BB']
00039 MAX_CONFIG = 9
00040
00041 def __init__(self, common, parent = None, name = None, fl = 0):
00042 """!\brief HwCfgSelectorImpl constructor.
00043
00044 \param common ScriptEngineCommon instance
00045 \param parent The parent GUI (typically the Run Control GUI)
00046 \param name Name of the GUI
00047 \param fl Qt flags
00048 """
00049 HwCfgSelector.__init__(self, parent, name, fl)
00050 self.connect(self.buttonOK, SIGNAL("clicked()"), self.screenToPrefs)
00051 self.connect(self.buttonCancel, SIGNAL("clicked()"), self.cancel)
00052 self.connect(self.bgPresetConfig, SIGNAL("clicked(int)"), self.configToScreen)
00053 self.connect(self.checkUnlock, SIGNAL("clicked()"), self.allowDisallow)
00054 self.connect(self.bgSiuSelect, SIGNAL("clicked(int)"), self.updatePresetConfig)
00055 self.connect(self.bgDaqSelect, SIGNAL("clicked(int)"), self.updatePresetConfig)
00056 self.connect(self.bgEpuAselect, SIGNAL("clicked(int)"), self.updatePresetConfig)
00057 self.connect(self.bgEpuBselect, SIGNAL("clicked(int)"), self.updatePresetConfig)
00058 self.connect(self.bgGasuFeed, SIGNAL("clicked(int)"), self.updatePresetConfig)
00059 self.connect(self.bgGasuPriRed, SIGNAL("clicked(int)"), self.updatePresetConfig)
00060 self.connect(self.bgSiuPriRed, SIGNAL("clicked(int)"), self.updatePresetConfig)
00061 self.connect(self.bgPduPriRed, SIGNAL("clicked(int)"), self.updatePresetConfig)
00062 self.connect(self.bgAcdHvbs, SIGNAL("clicked(int)"), self.updatePresetConfig)
00063 if type(common) is types.StringType:
00064
00065 self.__vscConfig = common
00066 self.__common = common
00067 self.initialize()
00068 else:
00069 self.__vscConfig = common.options().vscConfig
00070 self.__common = common
00071 self.initialize()
00072 self.prefsToScreen()
00073
00074 def initialize(self):
00075 config = ConfigParser()
00076 config.readfp(file(self.__vscConfig))
00077 self.setButtonGroup(self.bgPresetConfig, 0)
00078 self.disallowChanges()
00079 for section in config.sections():
00080 if section.startswith(self.CFG_PREFIX):
00081 cfgId = int(section[len(self.CFG_PREFIX):])
00082 button = self.bgPresetConfig.find(cfgId-1)
00083 button.setEnabled(1)
00084 self.__config = config
00085
00086 def allowDisallow(self):
00087 if self.checkUnlock.isOn():
00088 self.allowChanges()
00089 else:
00090 self.disallowChanges()
00091
00092 def allowChanges(self):
00093 self.setButtonGroup(self.bgSiuSelect, 1)
00094 self.setButtonGroup(self.bgDaqSelect, 1)
00095 self.setButtonGroup(self.bgEpuAselect, 1)
00096 self.setButtonGroup(self.bgEpuBselect, 1)
00097 self.setButtonGroup(self.bgGasuFeed, 1)
00098 self.setButtonGroup(self.bgGasuPriRed, 1)
00099 self.setButtonGroup(self.bgSiuPriRed, 1)
00100 self.setButtonGroup(self.bgPduPriRed, 1)
00101 self.setButtonGroup(self.bgAcdHvbs, 1)
00102
00103 def disallowChanges(self):
00104 self.setButtonGroup(self.bgSiuSelect, 0)
00105 self.setButtonGroup(self.bgDaqSelect, 0)
00106 self.setButtonGroup(self.bgEpuAselect, 0)
00107 self.setButtonGroup(self.bgEpuBselect, 0)
00108 self.setButtonGroup(self.bgGasuFeed, 0)
00109 self.setButtonGroup(self.bgGasuPriRed, 0)
00110 self.setButtonGroup(self.bgSiuPriRed, 0)
00111 self.setButtonGroup(self.bgPduPriRed, 0)
00112 self.setButtonGroup(self.bgAcdHvbs, 0)
00113
00114 def setButtonGroup(self, buttonGroup, enable):
00115 for i in range(buttonGroup.count()):
00116 button = buttonGroup.find(i)
00117 button.setEnabled(enable)
00118
00119 def configToScreen(self, id):
00120 section = "%s%d" % (self.CFG_PREFIX, id+1)
00121 siuSelect = self.__config.get(section, 'siuSelect')
00122 self.bgSiuSelect.find(self.CROSS_STRAP.index(siuSelect)).setOn(1)
00123 daqSelect = self.__config.get(section, 'daqSelect')
00124 self.bgDaqSelect.find(self.CROSS_STRAP.index(daqSelect)).setOn(1)
00125 siuIdPhysical = int(self.__config.get(section, 'siuIdPhysical'))
00126 self.bgSiuPriRed.find(siuIdPhysical ^ 1).setOn(1)
00127 pduId = int(self.__config.get(section, 'pduId'))
00128 self.bgPduPriRed.find(pduId).setOn(1)
00129 primaryFeed = int(self.__config.get(section, 'primaryFeed'))
00130 self.bgGasuFeed.find(primaryFeed ^ 1).setOn(1)
00131 gasuPriRed = int(self.__config.get(section, 'primaryGasu'))
00132 self.bgGasuPriRed.find(gasuPriRed ^ 1).setOn(1)
00133 epuAid = int(self.__config.get(section, 'firstEpuId'))
00134 self.bgEpuAselect.find(epuAid).setOn(1)
00135 epuBid = int(self.__config.get(section, 'secondEpuId'))
00136 self.bgEpuBselect.find(epuBid).setOn(1)
00137 acdHvbs = int(self.__config.get(section, 'hvbs'))
00138 self.bgAcdHvbs.find(acdHvbs-1).setOn(1)
00139
00140 def prefsToScreen(self):
00141 if 'hwConfig' in self.__common.preferences():
00142 hwConfig = self.__common.preferences()['hwConfig']
00143 self.bgSiuSelect.find(self.CROSS_STRAP.index(hwConfig['siuSelect'])).setOn(1)
00144 self.bgDaqSelect.find(self.CROSS_STRAP.index(hwConfig['daqSelect'])).setOn(1)
00145 self.bgSiuPriRed.find(hwConfig['siuIdPhysical'] ^ 1).setOn(1)
00146 self.bgPduPriRed.find(hwConfig['pduId']).setOn(1)
00147 self.bgGasuFeed.find(hwConfig['primaryFeed'] ^ 1).setOn(1)
00148 self.bgGasuPriRed.find(hwConfig['primaryGasu'] ^ 1).setOn(1)
00149 self.bgEpuAselect.find(hwConfig['firstEpuId']).setOn(1)
00150 self.bgEpuBselect.find(hwConfig['secondEpuId']).setOn(1)
00151 self.bgAcdHvbs.find(hwConfig['hvbs'] - 1).setOn(1)
00152 self.updatePresetConfig()
00153
00154 def matchStandardConfig(self):
00155 for id in range(1, self.MAX_CONFIG+1):
00156 match = True
00157 section = "%s%d" % (self.CFG_PREFIX, id)
00158 siuSelect = self.CROSS_STRAP.index(self.__config.get(section, 'siuSelect'))
00159 match &= (self.bgSiuSelect.selectedId() == siuSelect)
00160 daqSelect = self.CROSS_STRAP.index(self.__config.get(section, 'daqSelect'))
00161 match &= (self.bgDaqSelect.selectedId() == daqSelect)
00162 siuIdPhysical = int(self.__config.get(section, 'siuIdPhysical')) ^ 1
00163 match &= (self.bgSiuPriRed.selectedId() == siuIdPhysical)
00164 pduId = int(self.__config.get(section, 'pduId'))
00165 match &= (self.bgPduPriRed.selectedId() == pduId)
00166 primaryFeed = int(self.__config.get(section, 'primaryFeed')) ^ 1
00167 match &= (self.bgGasuFeed.selectedId() == primaryFeed)
00168 primaryGasu = int(self.__config.get(section, 'primaryGasu')) ^ 1
00169 match &= (self.bgGasuPriRed.selectedId() == primaryGasu)
00170 firstEpuId = int(self.__config.get(section, 'firstEpuId'))
00171 match &= (self.bgEpuAselect.selectedId() == firstEpuId)
00172 secondEpuId = int(self.__config.get(section, 'secondEpuId'))
00173 match &= (self.bgEpuBselect.selectedId() == secondEpuId)
00174 acdHvbs = int(self.__config.get(section, 'hvbs')) - 1
00175 match &= (self.bgAcdHvbs.selectedId() == acdHvbs)
00176 if match:
00177 return id
00178
00179 def updatePresetConfig(self):
00180 cfgId = self.matchStandardConfig()
00181 if cfgId is None:
00182 for i in range(self.MAX_CONFIG):
00183 self.bgPresetConfig.find(i).setOn(0)
00184 else:
00185 self.bgPresetConfig.find(cfgId-1).setOn(1)
00186
00187 def screenToPrefs(self):
00188 hwConfig = {}
00189 siuSelect = self.bgSiuSelect.selectedId()
00190 if siuSelect == -1:
00191 QMessageBox.critical(self, "Error",
00192 "SIU cross-strapping not selected")
00193 return
00194 hwConfig['siuSelect'] = self.CROSS_STRAP[siuSelect]
00195 daqSelect = self.bgDaqSelect.selectedId()
00196 if daqSelect == -1:
00197 QMessageBox.critical(self, "Error",
00198 "DAQ cross-strapping not selected")
00199 return
00200 hwConfig['daqSelect'] = self.CROSS_STRAP[daqSelect]
00201 siuIdPhysical = self.bgSiuPriRed.selectedId()
00202 if siuIdPhysical == -1:
00203 QMessageBox.critical(self, "Error",
00204 "Primary or Redundant SIU not selected")
00205 return
00206 hwConfig['siuIdPhysical'] = siuIdPhysical ^ 1
00207 pduId = self.bgPduPriRed.selectedId()
00208 if pduId == -1:
00209 QMessageBox.critical(self, "Error",
00210 "Primary or Redundant PDU not selected")
00211 return
00212 hwConfig['pduId'] = pduId
00213 primaryFeed = self.bgGasuFeed.selectedId()
00214 if primaryFeed == -1:
00215 QMessageBox.critical(self, "Error",
00216 "Primary or Redundant GASU feed not selected")
00217 return
00218 hwConfig['primaryFeed'] = primaryFeed ^ 1
00219 primaryGasu = self.bgGasuPriRed.selectedId()
00220 if primaryGasu == -1:
00221 QMessageBox.critical(self, "Error",
00222 "Primary or Redundant GASU not selected")
00223 return
00224 hwConfig['primaryGasu'] = primaryGasu ^ 1
00225 firstEpuId = self.bgEpuAselect.selectedId()
00226 if firstEpuId == -1:
00227 QMessageBox.critical(self, "Error",
00228 "EPU-A not selected")
00229 return
00230 hwConfig['firstEpuId'] = firstEpuId
00231 secondEpuId = self.bgEpuBselect.selectedId()
00232 if secondEpuId == -1:
00233 QMessageBox.critical(self, "Error",
00234 "EPU-B not selected")
00235 return
00236 hwConfig['secondEpuId'] = secondEpuId
00237 hvbs = self.bgAcdHvbs.selectedId()
00238 if hvbs == -1:
00239 QMessageBox.critical(self, "Error",
00240 "ACD HVBS not selected")
00241 return
00242 hwConfig['hvbs'] = hvbs + 1
00243 hvbs = self.bgAcdHvbs.selectedId()
00244 preset = self.bgPresetConfig.selectedId()
00245 if preset == -1:
00246 result = QMessageBox.warning(self, "Warning",
00247 "You have selected a non-standard configuration.\n" + \
00248 "Are you sure you want to continue?",
00249 "&Yes", "&No")
00250 if result == 1:
00251 return
00252 else:
00253 preset += 1
00254 hwConfig['preset'] = preset
00255
00256 if type(self.__common) is not types.StringType:
00257 self.__common.prefMan().setPref('hwConfig', hwConfig)
00258 else:
00259 print hwConfig
00260 QDialog.done(self, QDialog.Accepted)
00261
00262 def cancel(self):
00263 """!\brief Cancel button is clicked.
00264
00265 """
00266 QDialog.done(self, QDialog.Rejected)
00267
00268
00269 def usage():
00270 """!\brief Output command line usage.
00271
00272 """
00273 return """
00274
00275 HwCfgSelectorImpl Usage:
00276
00277 Mandatory options:
00278 --config specify the VSC config file
00279
00280 Example:
00281 $ HwCfgSelectorImpl --config vsc_mcr.cfg
00282
00283 """
00284
00285 if __name__ == "__main__":
00286 log.getLogger().setLevel(log.INFO)
00287
00288 options = Options(['config'])
00289 try:
00290 options.parse()
00291 except Exception, msg:
00292 options.usage(usage())
00293 raise Exception, msg
00294
00295 a = QApplication(sys.argv)
00296 dm = HwCfgSelectorImpl(options.config)
00297 a.setMainWidget(dm)
00298 dm.show()
00299 a.exec_loop()
00300