def __init__(self, setup=True, rest=False, hist=False, fileSpec={}): # self.__couplerFile="../../composing/coupler.xml" self.__couplerFile = "./coupler.xml" self.__modelFile = "../../composing/models.xml" self.__scheduleFile = "../../composing/schedule.xml" self.__deployFile = "../../composing/deploy.xml" self.__fieldFile = "../../composing/field.xml" self.__setupFile = "../../composing/setup.xml" self.__regriddingFile = "../../composing/regriddingFile.xml" self.__fractionFile = "../../composing/fractionSet.xml" self.__fakeModelFile = "../../composing/fakeModel.xml" if len(fileSpec) != 0: # self.__couplerFile = fileSpec['coupler.xml'] self.__modelFile = fileSpec['models.xml'] self.__deployFile = fileSpec['deploy.xml'] self.__fieldFile = fileSpec['field.xml'] self.__setupFile = fileSpec['setup.xml'] self.__regriddingFile = fileSpec['regriddingFile.xml'] self.__fractionFile = fileSpec['fractionSet.xml'] self.__fakeModelFile = fileSpec['fakeModel.xml'] self.__NameManager = NameManager() self.__models = {} self.__attrVectCouple = {} self.__subroutine = {} ## mrg subroutine self.__sMapper = {} self.__deployDistribution = {} # format {id: [first, last, stride]} self.__setupModels = {} self.__setupFakeModels = {} self.__setupModelNames = {} self.__resDict = {} self.__enable_setup = setup if setup: # setup generate couple with fraction setup = Setup(fileName=self.__setupFile) setup.setupParse() setup.genXml() # couplerFile = setup.couplerFile self.__setupModels = setup.model self.__setupModelNames = setup.modelName self.__setupFakeModels = setup.fakeModel self.__resDict = setup.resDict print setup.fakeModel #self.__couplerFile = couplerFile #self.__fieldFile = fieldFile #self.__modelFile = modelFile #self.__scheduleFile = scheduleFile #self.__deployFile = deployFile self.__fractions = {} self.__seqRun = SeqRun() self.fldManager = FieldManager() self.runSubroutine = [] self.__fldDict = {} self.__fldMetaDict = {} # util optional self.__hist = hist self.__rest = rest # for second phase init self.__secondPhaseInitSubrt = {} # for fake model self.__fakeModels = {}
from s826 import S826 from subThread import SubThread from realTimePlot import CustomFigCanvas import syntax from math import sqrt,pow import time #========================================================= # UI Config #========================================================= qtCreatorFile = "mainwindow.ui" Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) #========================================================= # Creating instances of fieldManager and Camera #========================================================= field = FieldManager(S826()) vision = Vision(field,index=1,type='firewire',guid=2672909588927744,buffersize=18) # greyscale mode vision2 = Vision2(field,index=2,type='firewire',guid=2672909587849792,buffersize=18) # greyscale mode #vision = Vision(field,index=2,type='firewire',guid=2672909587849792,buffersize=12) # to use usb camera, try #vision = Vision(index=1,type='usb') #vision = Vision(field,index=1,type='video',guid=0000000000,buffersize=12) #vision2 = Vision2(field,index=2,type='video',guid=0000000000,buffersize=12) # to use 1 camera only, comment out this line: vision2 = ... #========================================================= # Creating instances of PS3 controller #========================================================= # from PS3Controller import DualShock # joystick = DualShock() # to disable controller comment out these 2 lines
class Parser(): def __init__(self, setup=True, rest=False, hist=False, fileSpec={}): # self.__couplerFile="../../composing/coupler.xml" self.__couplerFile = "./coupler.xml" self.__modelFile = "../../composing/models.xml" self.__scheduleFile = "../../composing/schedule.xml" self.__deployFile = "../../composing/deploy.xml" self.__fieldFile = "../../composing/field.xml" self.__setupFile = "../../composing/setup.xml" self.__regriddingFile = "../../composing/regriddingFile.xml" self.__fractionFile = "../../composing/fractionSet.xml" self.__fakeModelFile = "../../composing/fakeModel.xml" if len(fileSpec) != 0: # self.__couplerFile = fileSpec['coupler.xml'] self.__modelFile = fileSpec['models.xml'] self.__deployFile = fileSpec['deploy.xml'] self.__fieldFile = fileSpec['field.xml'] self.__setupFile = fileSpec['setup.xml'] self.__regriddingFile = fileSpec['regriddingFile.xml'] self.__fractionFile = fileSpec['fractionSet.xml'] self.__fakeModelFile = fileSpec['fakeModel.xml'] self.__NameManager = NameManager() self.__models = {} self.__attrVectCouple = {} self.__subroutine = {} ## mrg subroutine self.__sMapper = {} self.__deployDistribution = {} # format {id: [first, last, stride]} self.__setupModels = {} self.__setupFakeModels = {} self.__setupModelNames = {} self.__resDict = {} self.__enable_setup = setup if setup: # setup generate couple with fraction setup = Setup(fileName=self.__setupFile) setup.setupParse() setup.genXml() # couplerFile = setup.couplerFile self.__setupModels = setup.model self.__setupModelNames = setup.modelName self.__setupFakeModels = setup.fakeModel self.__resDict = setup.resDict print setup.fakeModel #self.__couplerFile = couplerFile #self.__fieldFile = fieldFile #self.__modelFile = modelFile #self.__scheduleFile = scheduleFile #self.__deployFile = deployFile self.__fractions = {} self.__seqRun = SeqRun() self.fldManager = FieldManager() self.runSubroutine = [] self.__fldDict = {} self.__fldMetaDict = {} # util optional self.__hist = hist self.__rest = rest # for second phase init self.__secondPhaseInitSubrt = {} # for fake model self.__fakeModels = {} @property def models(self): return self.__models @property def attrVectCouple(self): return self.__attrVectCouple @property def subroutine(self): return self.__subroutine @property def deploy(self): return self.__deployDistribution @property def fractions(self): return self.__fractions @property def fldDict(self): return self.__fldDict @property def sMapper(self): return self.__sMapper @property def fldMetaDict(self): return self.__fldMetaDict @property def fakeModels(self): return self.__fakeModels def addDistribution(self, deployList, ID): self.__deployDistribution[ID] = deployList def addDict(self, attrVect, name): if not self.__attrVectCouple.has_key(name): self.__attrVectCouple[name] = [] self.__attrVectCouple[name].append(attrVect) def visitByName(self, name): for model in self.__models: for av in self.__models[model].attrVects: avName = self.__models[model].attrVects[av].name if avName == name: return self.__models[model].attrVects[av] return None def load(self, filename): tree = ET.parse(filename) root = tree.getroot() return root def modelsParse(self): # bug may happend when modelFile not include relative setup file root = self.load(self.__modelFile) modelParser = ModelParser(self.__NameManager, self.__seqRun) #fakeModelParser = FakeModelParser(self.__seqRun) index = 1 modelCount = 0 for child in root: if self.__enable_setup: modelName = child.find('name').text modelVersion = child.find('version').text # if modelName not in self.__setupModels: # continue # elif self.__setupModels[modelName] != modelVersion: # continue # if self.__enable_setup : for instName in self.__setupModelNames: mName = self.__setupModelNames[instName] # print instName, ', ' , mName, ', ', modelName, ', ', modelVersion, ', ', self.__setupModels[instName] if mName == modelName: if self.__setupModels[instName] != modelVersion: continue if os.environ.get('VERBOSE') == 'true': print 'Parsing model #', index, ': instName = ', instName, ', modelName = ', mName, ', modelVersion = ', modelVersion, ", res = ", self.__resDict[ instName] modelParser.setRoot(child, instName, self.__resDict[instName]) model = modelParser.model model.ID = index index = index + 1 modelCount = modelCount + 1 # self.__models[model.name] = model self.__models[model.instName] = model # self.__NameManager.register.modelDict[model.name] = model self.__NameManager.register.modelDict[ model.instName] = model else: modelParser.setRoot(child) model = modelParser.model model.ID = index index = index + 1 modelCount = modelCount + 1 self.__models[model.name] = model self.__NameManager.register.modelDict[model.name] = model if self.__enable_setup and modelCount != len(self.__setupModels): print "modelCount = ", modelCount, " and self.__setupModels = ", self.__setupModels raise ComposingError("invalid "+self.__modelFile+\ " for some model(s) not supported in this file when setup.xml set them") #for child in root: # if 'type' in child.attrib and child.attrib['type'] == 'fake' \ # and child.find('name').text in self.__setupFakeModels: # fakeModelParser.setRoot(child) # fakeModel = fakeModelParser.model # for dep in fakeModel.deps: # if dep not in self.models: # raise NotProperConfigError('in fakeModel deps') # self.__fakeModels[fakeModel.name] = fakeModel def fakeModelParse(self): root = self.load(self.__fakeModelFile) if self.__enable_setup: for instName in self.__setupFakeModels: # print self.__setupFakeModels[instName] #DEBUG for child in root: if child.find('name').text == self.__setupFakeModels[ instName]['name']: fakeModelParser = FakeModelParser( self.__NameManager, self.__seqRun) fakeModelParser.setRoot(child) fakeModelParser.setDepends( self.__setupFakeModels[instName]['depends']) fakeModel = fakeModelParser.model self.__fakeModels[instName] = fakeModel else: for child in root: fakeModelParser = FakeModelParser(self.__NameManager, self.__seqRun) fakeModelParser.setRoot(child) fakeModel = fakeModelParser.model self.__fakeModels[fakeModel.name] = fakeModel for dep in fakeModel.deps: if dep not in self.models: raise NotProperConfigError('in fakeModelParse') # print self.__fakeModels #DEBUG def deployParse(self): root = self.load(self.__deployFile) deployParser = DeployParser(self.__NameManager) deployParser.setRoot(root) deployParser.deployParse(self) if os.environ.get('VERBOSE') == 'true': for deploy in self.__deployDistribution: d = self.__deployDistribution[deploy] print 'component ', d[3], ', first = ', d[0], ', last = ', d[ 1], ', stride = ', d[2] def schedule(self): #sort seq pass def coupleAttrVectParse(self): # root = self.load(self.__setupFile) # couplerRoot = root.find('coupler') root = self.load(self.__couplerFile) avParser = CouplerParser(self.__NameManager, self.__seqRun) ## not implemented now for child in root: avParser.setRoot(child) avParser.couplerParse(self) mrg = avParser.mergeSubroutine #print attrVect.name, attrVect.atyp self.__subroutine[mrg.name] = mrg if avParser.fraction != None: self.__fractions[avParser.fraction.name] = avParser.fraction def fieldParse(self): for model in self.__models: # self.fldManager.addModel(model) # print self.__models[model].name #DEBUG self.fldManager.addModel(self.__models[model].name) self.fldManager.queryBuild(self.__fieldFile) for model in self.__models: totalFlds = {} # print self.__models[model].fields #DEBUG # print self.__models[model].name, self.__models[model].instName # print self.fldManager.model # print self.fldManager.fldsQuery for fld in self.__models[model].fields: fldList = fld.split('_') fldPrex = fldList[0] + '_' + fldList[1] if not fldPrex in totalFlds: totalFlds[fldPrex] = [] totalFlds[fldPrex].append(fld) self.__models[model].fields[fld] = self.fldManager.fldsQuery[ fld] if not fld in self.fldManager.fldsQuery: raise NotFoundError('fld not found') fldStr = self.fldManager.fldsQuery[fld] self.fldDict[fld] = fldStr fldList = fldStr.split(':') if fldStr else [] for f in fldList: if f in self.fldManager.fieldQuery: self.fldMetaDict[f] = self.fldManager.fieldQuery[f] for fld in totalFlds: fldStr = "" for f in totalFlds[fld]: fldStr += self.fldDict[f] + ":" fldStr = fldStr[:-1] self.fldDict[fld] = fldStr self.__models[model].myFields[fld] = fldStr for model in self.__fakeModels: for fld in self.__fakeModels[model].flds: fldStr = self.fldManager.fldsQuery[fld] self.fldDict[fld] = fldStr # 特殊处理的dom,之后再加入不特殊处理的吧 def parse(self): self.modelsParse() if os.environ.get('VERBOSE') == 'true': print '...................model parsed...................' self.coupleAttrVectParse() if os.environ.get('VERBOSE') == 'true': print '..............couple AttrVect parsed..............' self.fakeModelParse() if os.environ.get('VERBOSE') == 'true': print '..............fake Model parsed...................' self.deployParse() if os.environ.get('VERBOSE') == 'true': print '..................deploy parsed...................' #for node in self.__seqRun.graph.Nodes: # sbr = self.__seqRun.graph.Nodes[node] # print node, sbr.inEdge self.runSubroutine = self.__seqRun.topology() # add rest and hist subroutine here # this is a temp solution utilSubroutineNodeList = [] if self.__rest: cw = CodeWrapper() restStr = "base_rest_write(metaData, EClock_drv)" cw.appendStr(restStr) restBlock = cw.codeBlock("cpl", "cpl", flag="restart") restNode = SubroutineNode("rest", strFormat=restBlock) addNode = Node("rest", data=restNode) utilSubroutineNodeList.append(addNode) if self.__hist: cw = CodeWrapper() histStr = "base_hist_write(metaData, EClock_drv)" cw.appendStr(histStr) histBlock = cw.codeBlock("cpl", "cpl", flag="hist") histNode = SubroutineNode("hist", strFormat=histBlock) addNode = Node("hist", data=histNode) utilSubroutineNodeList.append(addNode) self.runSubroutine.append(utilSubroutineNodeList) # parse field self.fieldParse() def append(self, obj): if obj.atype == 'Model': self.__model[obj.name] = obj elif obj.atype == 'Mrg': self.__subroutine[obj.name] = obj elif obj.atype == "Mapper": self.__sMapper[obj.name] = obj else: raise TypeError("Undefine atype of obj")