449 lines
12 KiB
Plaintext
449 lines
12 KiB
Plaintext
52c52
|
|
< include "PyCafeDefs_sf.pxi"
|
|
---
|
|
> include "PyCafeDefs.pxi"
|
|
83a84
|
|
>
|
|
172,179c173
|
|
<
|
|
< DBPMKeeper dbpm
|
|
<
|
|
< bint dbpmInitialized
|
|
< bint BSInitialized
|
|
< bint isBSinCAOnly
|
|
< BSDataHolder bsd
|
|
<
|
|
---
|
|
>
|
|
213,216c207
|
|
< self.dbpmInitialized = False
|
|
< self.BSInitialized = False
|
|
< self.isBSinCAOnly = False
|
|
<
|
|
---
|
|
>
|
|
274c265,266
|
|
< self.cs.info(ECA_ALLOCMEM)))
|
|
---
|
|
> self.cs.info(ECA_ALLOCMEM)))
|
|
>
|
|
421c413,414
|
|
< if cb is not None:
|
|
---
|
|
> if cb is not None:
|
|
>
|
|
470c463
|
|
<
|
|
---
|
|
>
|
|
483c476
|
|
< except RuntimeError as e:
|
|
---
|
|
> except RuntimeError as e:
|
|
498c491
|
|
< raise Exception("{} {} \n{}".format(self._exception_text, _METHOD, e))
|
|
---
|
|
> raise Exception("{} {} \n{}".format(self._exception_text, _METHOD, e))
|
|
788c781
|
|
<
|
|
---
|
|
>
|
|
797c790
|
|
< if cb is not None:
|
|
---
|
|
> if cb is not None:
|
|
856,857c849
|
|
<
|
|
< if cb is not None:
|
|
---
|
|
> if cb is not None:
|
|
883,884c875,876
|
|
<
|
|
< if cb is not None:
|
|
---
|
|
>
|
|
> if cb is not None:
|
|
5154c5146
|
|
<
|
|
---
|
|
>
|
|
5184d5175
|
|
<
|
|
5193c5184
|
|
<
|
|
---
|
|
>
|
|
5232d5222
|
|
<
|
|
5279,5280c5269
|
|
< sig = inspect.signature(cb[i])
|
|
<
|
|
---
|
|
> sig = inspect.signature(cb[i])
|
|
5294c5283
|
|
<
|
|
---
|
|
>
|
|
5933a5923
|
|
>
|
|
5941c5931
|
|
<
|
|
---
|
|
>
|
|
5962c5952,5953
|
|
<
|
|
---
|
|
>
|
|
>
|
|
6039c6030
|
|
<
|
|
---
|
|
>
|
|
6043c6034
|
|
<
|
|
---
|
|
>
|
|
6045c6036
|
|
<
|
|
---
|
|
>
|
|
6091,6092c6082,6083
|
|
< global hmd
|
|
<
|
|
---
|
|
> global hmd
|
|
>
|
|
6106c6097
|
|
< del hmd[l]
|
|
---
|
|
> del hmd[l]
|
|
6115c6106
|
|
<
|
|
---
|
|
>
|
|
6122c6113
|
|
<
|
|
---
|
|
>
|
|
6131c6122
|
|
<
|
|
---
|
|
>
|
|
6174a6166
|
|
>
|
|
7225,7538d7216
|
|
<
|
|
< #if HAVE_BSREAD==1:
|
|
<
|
|
< ################################################################################
|
|
<
|
|
< def prepareSFdbpm(self):
|
|
< cdef:
|
|
< vector[string] bpmList
|
|
< vector[unsigned int] bpmHandles
|
|
< vector[string] bpmDev
|
|
< vector[float] bpmPos
|
|
<
|
|
< self._c_cafe.prepareDBPM(bpmList, bpmHandles, bpmDev, bpmPos)
|
|
<
|
|
< # for i in range(0, self.bpmDev.size()):
|
|
< #print (bpmPos[i], bpmDev[i] )
|
|
<
|
|
< if not self.dbpmInitialized:
|
|
< self.dbpm = DBPMKeeper(
|
|
< bpmList, bpmHandles, bpmDev, bpmPos)
|
|
< self.dbpmInitialized = True
|
|
< return
|
|
<
|
|
< ##################################################################################
|
|
< # END def prepareSFdbpm(self)
|
|
< ##################################################################################
|
|
<
|
|
< def setSFdbpmBS(self, bint bsFlag=True):
|
|
< return self.dbpm.setBS(bsFlag)
|
|
<
|
|
< def resetSFdbpmBS(self):
|
|
< return self.dbpm.resetBS()
|
|
<
|
|
< def closeSFdbpmBS(self):
|
|
< return self.dbpm.closeBS()
|
|
<
|
|
< def readSFdbpmOffsets(self):
|
|
< return self._c_cafe.readDBPMOffsets(self.dbpm)
|
|
<
|
|
< def getSFdbpm(self):
|
|
<
|
|
< cdef str _METHOD = "getSFdbpm"
|
|
<
|
|
< cdef int status
|
|
< cdef vector[unsigned int] handleV
|
|
< with nogil:
|
|
< status = self._c_cafe.getDBPM(self.dbpm)
|
|
<
|
|
< if status >= ICAFE_ERRNO_BASE:
|
|
< self._c_cafe.printStatusMessage(status)
|
|
< elif status != ICAFE_NORMAL:
|
|
< if PYCAFE_PRINT_LEVEL >= PYCAFE_PRINT_LOW:
|
|
< # self._c_cafe.printStatusMessage(status)
|
|
<
|
|
< handleV = self.dbpm.getHandle()
|
|
< # for i in range(0, self.dbpm.getNDBPM()):
|
|
< # if x[i].getStatus !=
|
|
< #print (self.bpmPos[i], self.bpmDev[i] )
|
|
< for i in range(0, self.dbpm.getNPV()):
|
|
< if (self.dbpm.pvd[i].getStatus() != ICAFE_NORMAL):
|
|
< self._c_cafe.printStatus(handleV[i], status)
|
|
<
|
|
< return dbpmHolderToStruct(self.dbpm)
|
|
<
|
|
< ##################################################################################
|
|
< # END def getSFdbpm(self):
|
|
< ##################################################################################
|
|
<
|
|
<
|
|
< def getSFdbpmOffs_x(self):
|
|
< return self.dbpm.getOffsetX()
|
|
<
|
|
< def getSFdbpmOffs_y(self):
|
|
< return self.dbpm.getOffsetY()
|
|
<
|
|
< ################################################################################
|
|
<
|
|
< def setBS(self, list pv=None, modulo=None, offset=None, int timeoutMS=0):
|
|
<
|
|
< cdef str _METHOD = "setBS"
|
|
< cdef int status = ICAFE_NORMAL
|
|
< cdef unsigned int i
|
|
< cdef bint pFlag = False
|
|
<
|
|
< if isinstance(modulo, numbers.Number):
|
|
< if int(modulo) <= 0:
|
|
< raise ValueError("{} {} \n{}".format(
|
|
< self._exception_text, _METHOD,
|
|
< "modulo input argument must be positive!"))
|
|
< elif not TypeError(modulo, dict):
|
|
< raise Exception("{} {} \n{}".format(
|
|
< self._exception_text, _METHOD,
|
|
< ("modulo input arg, should be of type <class 'numbers.Number'>, "
|
|
< "else <class 'dict'> {pv_name : modulo}")))
|
|
<
|
|
< if isinstance(offset, (numbers.Number)):
|
|
< if int(offset) < 0:
|
|
< raise ValueError("{} {} \n{}".format(
|
|
< self._exception_text, _METHOD,
|
|
< "offset input argument cannot be negative!"))
|
|
< elif not isinstance(offset, (dict)):
|
|
< raise TypeError("{} {} \n{}".format(
|
|
< self._exception_text, _METHOD,
|
|
< ("offset input arg, should be of type <class 'numbers.Number'>, "
|
|
< "else <class 'dict'> {pv_name : offset} ")))
|
|
<
|
|
< if self.BSInitialized == True:
|
|
< print("Message from setBS: ONLY A SINGLE STREAM IS ALLOWED")
|
|
< return status
|
|
<
|
|
< cdef vector[string] v
|
|
<
|
|
< if timeoutMS > 0:
|
|
< self.bsd.setTimeout(timeoutMS)
|
|
<
|
|
< if pv is not None:
|
|
< # do this to avoid compiler warning messages
|
|
< for i in range(0, len(pv)):
|
|
< v.push_back(pv[i])
|
|
< self.bsd.init(v)
|
|
<
|
|
< if isinstance(modulo, (numbers.Number)):
|
|
< modulo = dict([(pv[i], int(modulo))
|
|
< for i in range(0, len(pv))])
|
|
<
|
|
< if isinstance(offset, (numbers.Number)):
|
|
< offset = dict([(pv[i], int(offset))
|
|
< for i in range(0, len(pv))])
|
|
<
|
|
< if modulo is not None:
|
|
< for eachKey in modulo:
|
|
< self.bsd.setBSModulo(eachKey, modulo[eachKey])
|
|
< if offset is not None:
|
|
< for eachKey in offset:
|
|
< self.bsd.setBSOffset(eachKey, offset[eachKey])
|
|
<
|
|
< # self.initBSwithCA()
|
|
< with nogil:
|
|
< self._c_cafe.initBSwithCA(self.bsd)
|
|
<
|
|
< with nogil:
|
|
< self._c_cafe.getBS(self.bsd)
|
|
<
|
|
< with nogil:
|
|
< # status=self._c_cafe.setBS_Step1(self.bsd)
|
|
< status = self._c_cafe.setBS(self.bsd)
|
|
<
|
|
< if status == ICAFE_NORMAL:
|
|
< self.BSInitialized = True
|
|
< self.isBSinCAOnly = False
|
|
<
|
|
< return status
|
|
<
|
|
< ################################################################################
|
|
<
|
|
< def initBSwithCA(self):
|
|
<
|
|
< # self.openPrepare()
|
|
< with nogil:
|
|
< self._c_cafe.initBSwithCA(self.bsd)
|
|
<
|
|
< # self.openNowAndWait(0.4)
|
|
<
|
|
<
|
|
< ################################################################################
|
|
< def setBS2CA(self, list pv=None):
|
|
<
|
|
< cdef vector[string] v
|
|
< if pv is not None:
|
|
< # do this to avoid compiler warning messages
|
|
< for i in range(0, len(pv)):
|
|
< v.push_back(pv[i])
|
|
< self.bsd.init(v)
|
|
<
|
|
< with nogil:
|
|
< self._c_cafe.setBS2CAGroup(self.bsd)
|
|
< self.isBSinCAOnly = True
|
|
<
|
|
<
|
|
< def getBSSlim(self):
|
|
< if self.BSInitialized == False:
|
|
< if self.isBSinCAOnly == False:
|
|
< print(("Message from getBS: BS stream not initialized;"
|
|
< "cafe.setBS(pvList) has first to be called."))
|
|
< return None
|
|
<
|
|
< with nogil:
|
|
< self._c_cafe.getBS(self.bsd)
|
|
<
|
|
<
|
|
< t1= time.time()
|
|
< PVDataV = self.bsd.getPVDataV()
|
|
<
|
|
< pvlist = [None] * <int>self.bsd.getNPV()
|
|
< #cdef pvdata p1
|
|
<
|
|
< for i in range (0, self.bsd.getNPV()):
|
|
< #p1 = pvdata()
|
|
< #p1 = PVDataHolderToStruct(self.bsd.pvdata[i])
|
|
< pvlist[i]=PVDataHolderToStruct(PVDataV[i])
|
|
<
|
|
<
|
|
< bs_slim = {}
|
|
<
|
|
< for data, handle in zip(pvlist, self.bsd.getHandles()): # self.bsd.getIsBS()):
|
|
< bs_slim[handle] = data
|
|
<
|
|
< t2= time.time()
|
|
< print("diff in reading BSDataHolderToStruc", t2 - t1)
|
|
<
|
|
<
|
|
< return bs_slim
|
|
<
|
|
< ################################################################################
|
|
< def getBS(self):
|
|
<
|
|
< if self.BSInitialized == False:
|
|
< if self.isBSinCAOnly == False:
|
|
< print(("Message from getBS: BS stream not initialized;"
|
|
< "cafe.setBS(pvList) has first to be called."))
|
|
<
|
|
< return None
|
|
< # CHECK STATUS!!!!
|
|
< #print("getBS in cycafe"
|
|
< #start = time.time()
|
|
<
|
|
< with nogil:
|
|
< self._c_cafe.getBS(self.bsd)
|
|
<
|
|
< _bsd = BSDataHolderToStruct(self.bsd)
|
|
< #_bsd.show()
|
|
< return _bsd #BSDataHolderToStruct(self.bsd)
|
|
<
|
|
< '''
|
|
< cdef double _pid = 0
|
|
< _handle = self._c_cafe.getHandleFromPV(str('SIN-TIMAST-EVG0:TX-PULSEID'))
|
|
< _stat = self._c_cafe.getCacheDouble(_handle, _pid)
|
|
< print("cython/cafe/diff in cython ", self.bsd.getPulse_id(), _pid, _pid - self.bsd.getPulse_id())
|
|
< t1= time.time()
|
|
< print("diff in cython", t1 - start)
|
|
< #print("pulse_id in cycafe", self.bsd.getPulse_id())
|
|
<
|
|
< BSd = BSDataHolderToStruct(self.bsd)
|
|
< t2= time.time()
|
|
< print("diff totol in reading BSDataHolderToStruc", t2 - start)
|
|
<
|
|
< return BSd
|
|
< '''
|
|
<
|
|
< ################################################################################
|
|
<
|
|
< def closeBS(self):
|
|
< with nogil:
|
|
< self._c_cafe.closeBS(self.bsd)
|
|
< self.BSInitialized = False
|
|
< self.isBSinCAOnly = False
|
|
<
|
|
<
|
|
< def getTimeoutMSBS(self):
|
|
< return self.bsd.getTimeout()
|
|
<
|
|
< def setTimeoutMSBS(self, int timeoutMS):
|
|
< self.bsd.setTimeout(timeoutMS)
|
|
<
|
|
<
|
|
< def reconnectBS(self):
|
|
< self.bsd.reconnect()
|
|
<
|
|
<
|
|
< def flushBS(self):
|
|
< self.bsd.reconnect()
|
|
<
|
|
<
|
|
< def monitorPulseID(self):
|
|
< with nogil:
|
|
< self._c_cafe.monitorPulseID()
|
|
<
|
|
<
|
|
< def monitorStopPulseID(self):
|
|
< with nogil:
|
|
< self._c_cafe.monitorStopPulseID()
|
|
<
|
|
<
|
|
< def setPulseIDBufferSize(self, handlePV, int bufferSize = 10):
|
|
< cdef str _METHOD = "setPulseIDBufferSize"
|
|
<
|
|
< cdef unsigned int handle = 0
|
|
< if isinstance(handlePV, (int, long)):
|
|
< handle = handlePV
|
|
< elif isinstance(handlePV, (str)):
|
|
< handle = self.checkForHandle(handlePV)
|
|
< else:
|
|
< raise Exception("{} {} \n{}".format(
|
|
< self._exception_text, _METHOD,
|
|
< ("First Input argument should be of type <class 'int'> if handle "
|
|
< "else <class 'str'> if PV.")))
|
|
<
|
|
< self._c_cafe.setPulseIDBufferSize(handle, bufferSize)
|
|
<
|
|
<
|
|
< def setPulseIDBufferSizeAll(self, int bufferSize = 10):
|
|
< self._c_cafe.setPulseIDBufferSizeAll(bufferSize)
|
|
<
|
|
<
|
|
< ###################################################################################
|
|
<
|
|
< def setBSInit(self, list pv):
|
|
< self.bsd.init(pv)
|
|
<
|
|
<
|
|
<
|
|
< ##################################################################################
|
|
< #END: cdef CAFE###################################################################
|
|
< ##################################################################################
|