Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #287 from mexanick/feature/ge21compatibility
Browse files Browse the repository at this point in the history
Feature/ge21compatibility
  • Loading branch information
mexanick authored Jul 8, 2019
2 parents 48e2f26 + 8b022ff commit 0dedd40
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 59 deletions.
41 changes: 24 additions & 17 deletions gempython/tools/amc_user_functions_xhal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ctypes import *
from gempython.tools.hw_constants import maxVfat3DACSize,gbtsPerGemVariant
from gempython.tools.hw_constants import maxVfat3DACSize, gbtsPerGemVariant, vfatsPerGemVariant
from gempython.utils.gemlogger import colors, printRed, printYellow
from gempython.utils.wrappers import runCommand, runCommandWithOutput

Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__(self, cardName, debug=False, gemType="ge11"):

# Define Link Monitoring
self.getmonGBTLink = self.lib.getmonGBTLink
self.getmonGBTLink.argTypes = [ OHLinkMonitorArrayType, c_uint, c_uint, c_bool ]
self.getmonGBTLink.argTypes = [ OHLinkMonitorArrayType, c_uint, c_uint, c_bool, c_uint]
self.getmonGBTLink.restype = c_uint

self.getmonOHLink = self.lib.getmonOHLink
Expand All @@ -125,11 +125,11 @@ def __init__(self, cardName, debug=False, gemType="ge11"):
self.confDacMonitorMulti.restype = c_uint

self.readADCsMulti = self.lib.readVFAT3ADCMultiLink
self.readADCsMulti.argTypes = [ c_uint, POINTER(c_uint32), POINTER(c_uint), c_bool ]
self.readADCsMulti.argTypes = [ c_uint, POINTER(c_uint32), POINTER(c_uint), c_bool, c_uint ]
self.readADCsMulti.restype = c_uint

self.dacScanMulti = self.lib.dacScanMultiLink
self.dacScanMulti.argTypes = [ c_uint, c_uint, c_uint, c_uint, c_bool, POINTER(c_uint) ]
self.dacScanMulti.argTypes = [ c_uint, c_uint, c_uint, c_uint, c_bool, POINTER(c_uint), c_uint ]
self.dacScanMulti.restype = c_uint

# Define SCA & Sysmon Monitoring
Expand Down Expand Up @@ -165,7 +165,7 @@ def __init__(self, cardName, debug=False, gemType="ge11"):
self.readSBits.restype = c_uint

self.sbitRateScanMulti = self.lib.sbitRateScan
self.sbitRateScanMulti.argTypes = [c_uint, c_uint, c_uint, c_uint, c_uint, c_char_p, POINTER(c_uint32), POINTER(c_uint32), POINTER(c_uint32)]
self.sbitRateScanMulti.argTypes = [c_uint, c_uint, c_uint, c_uint, c_uint, c_char_p, POINTER(c_uint32), POINTER(c_uint32), POINTER(c_uint32), c_uint]
self.sbitRateScanMulti.restype = c_uint

# Parse XML
Expand All @@ -185,6 +185,12 @@ def __init__(self, cardName, debug=False, gemType="ge11"):
else:
raise KeyError("Unrecognized gemType {0}".format(gemType))

#Determine the number of VFATs per geb based on the gemType
if gemType in vfatsPerGemVariant.keys():
self.nVFATs = vfatsPerGemVariant[gemType]
else:
raise KeyError("Unrecognized gemType {0}".format(gemType))

return

def acquireSBits(self, ohN, outFilePath, acquireTime=300):
Expand Down Expand Up @@ -278,13 +284,14 @@ def getGBTLinkStatus(self,doReset=False,printSummary=False, ohMask=None):
ohMask = self.getOHMask(callingMthd="getGBTLinkStatus")

gbtMonData = OHLinkMonitorArrayType()
self.getmonGBTLink(gbtMonData, self.nOHs, ohMask, doReset)
self.getmonGBTLink(gbtMonData, self.nOHs, ohMask, doReset, self.NGBT)

if printSummary:
print("--=======================================--")
print("-> GEM SYSTEM GBT INFORMATION")
print("--=======================================--")
print("")
print("Number of GBTs per optical link: %s" %(self.NGBT))
hfmt = "{:4s}"
dfmt = "{}{:4d}{}"
gbtfmt = []
Expand Down Expand Up @@ -346,7 +353,7 @@ def getL1ACount(self):
def getLinkVFATMask(self,ohN):
"""
V3 electronics only
Returns a 24 bit number that can be used as the VFAT Mask
Returns a self.nVFATs bit number that can be used as the VFAT Mask
for the Optohybrid ohN
"""
if self.fwVersion < 3:
Expand Down Expand Up @@ -585,7 +592,7 @@ def getVFATLinkStatus(self,doReset=False,printSummary=False, ohMask=None):
colw = len(max([colors.GREEN,colors.RED],key=len))+len(colors.ENDC)+4
xfmt = "{}0x{:1x}{}"

vfatsyncfmt = ["VFAT{}.SYNC_ERR_CNT".format(vfat) for vfat in range(24) ]
vfatsyncfmt = ["VFAT{}.SYNC_ERR_CNT".format(vfat) for vfat in range(self.nVFATs) ]

lines = [[] for x in range(len(vfatsyncfmt)+1)]
lines[0].append("{}".format(" "*(len(max(vfatsyncfmt,key=len)))))
Expand All @@ -603,7 +610,7 @@ def getVFATLinkStatus(self,doReset=False,printSummary=False, ohMask=None):
# print("----------OH{0}----------".format(ohN))
pass

for vfatN in range(24):
for vfatN in range(self.nVFATs):
nSyncErrors = vfatMonData[ohN].syncErrCnt[vfatN]
totalSyncErrors += nSyncErrors

Expand Down Expand Up @@ -656,12 +663,12 @@ def performDacScanMultiLink(self, dacDataAll, dacSelect, dacStep=1, ohMask=None,
exit(os.EX_USAGE)

# Check length of results container
lenExpected = self.nOHs * (maxVfat3DACSize[dacSelect][0] - 0+1)*24 / dacStep
lenExpected = self.nOHs * (maxVfat3DACSize[dacSelect][0] - 0+1)*self.nVFATs / dacStep
if (len(dacDataAll) != lenExpected):
printRed("HwAMC::performDacScanMultiLink(): I expected container of length {0} but provided 'dacDataAll' has length {1}",format(lenExpected, len(dacDataAll)))
exit(os.EX_USAGE)

return self.dacScanMulti(ohMask, self.nOHs, dacSelect, dacStep, useExtRefADC, dacDataAll)
return self.dacScanMulti(ohMask, self.nOHs, dacSelect, dacStep, useExtRefADC, dacDataAll, self.nVFATs)

def performSBITRateScanMultiLink(self, outDataDacVal, outDataTrigRate, outDataTrigRatePerVFAT, chan=128, dacMin=0, dacMax=254, dacStep=1, ohMask=None, scanReg="THR_ARM_DAC"):
"""
Expand All @@ -674,7 +681,7 @@ def performSBITRateScanMultiLink(self, outDataDacVal, outDataTrigRate, outDataTr
outDataTrigRate - As outDataDacVal but for trigger rate
outDataTrigRatePerVFAT - As outDataTrigRate but for each VFAT, array size
must be:
(24 * (12 * (dacMax - dacMin + 1) / stepSize))
(self.nVFATs * (12 * (dacMax - dacMin + 1) / stepSize))
chan - VFAT channel to be considered, for all channels
set to 128
dacMin - Starting dac value of the scan
Expand Down Expand Up @@ -713,11 +720,11 @@ def performSBITRateScanMultiLink(self, outDataDacVal, outDataTrigRate, outDataTr
exit(os.EX_USAGE)

# Check length of results container - outDataTrigRatePerVFAT
if (len(outDataTrigRatePerVFAT) != (24*lenExpected)):
printRed("HwAMC::performSBITRateScanMultiLink(): I expected container of length {0} but provided 'outDataTrigRatePerVFAT' has length {1}".format(24*lenExpected, len(outDataTrigRatePerVFAT)))
if (len(outDataTrigRatePerVFAT) != (self.nVFATs*lenExpected)):
printRed("HwAMC::performSBITRateScanMultiLink(): I expected container of length {0} but provided 'outDataTrigRatePerVFAT' has length {1}".format(self.nVFATs*lenExpected, len(outDataTrigRatePerVFAT)))
exit(os.EX_USAGE)

return self.sbitRateScanMulti(ohMask, dacMin, dacMax, dacStep, chan, scanReg, outDataDacVal, outDataTrigRate, outDataTrigRatePerVFAT)
return self.sbitRateScanMulti(ohMask, dacMin, dacMax, dacStep, chan, scanReg, outDataDacVal, outDataTrigRate, outDataTrigRatePerVFAT, self.nVFATs)

def programAllOptohybridFPGAs(self, maxIter=5, ohMask=None):
"""
Expand Down Expand Up @@ -800,7 +807,7 @@ def programAllOptohybridFPGAs(self, maxIter=5, ohMask=None):
def readADCsMultiLink(self, adcDataAll, useExtRefADC=False, ohMask=None, debug=False):
"""
Reads the ADC value from all unmasked VFATs
adcDataAll - Array of type c_uint32 of size 24*12=288
adcDataAll - Array of type c_uint32 of size self.nVFATs*12 (288 for GE1/1 or 144 for GE2/1)
useExtRefADC - True (False) use the externally (internally) referenced ADC
ohMask - Mask which defines which OH's to query; 12 bit number where
having a 1 in the N^th bit means to query the N^th optohybrid.
Expand All @@ -821,7 +828,7 @@ def readADCsMultiLink(self, adcDataAll, useExtRefADC=False, ohMask=None, debug=F
for ohN in range(0,12):
print("| {0} | 0x{1:x} |".format(ohN, ohVFATMaskArray[ohN]))

return self.readADCsMulti(ohMask,ohVFATMaskArray, adcDataAll, useExtRefADC)
return self.readADCsMulti(ohMask,ohVFATMaskArray, adcDataAll, useExtRefADC, self.nVFATs)

def readBlock(register, nwords, debug=False):
"""
Expand Down
58 changes: 57 additions & 1 deletion gempython/tools/hw_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

gbtsPerGemVariant = {
"ge11":3,
"ge21":1,
"ge21":2,
"me0":0}

# Size of VFAT3 DAC's
Expand Down Expand Up @@ -57,6 +57,62 @@
vfat3GBTPhaseLookupTable["ge21"][ge21Type] = [ 0 for x in range(0,vfatsPerGemVariant["ge21"]) ]
vfat3GBTPhaseLookupTable["me0"]["null"] = [ 0 for x in range(0,vfatsPerGemVariant["me0"]) ]

# Fill Info for GE21 - m1
vfat3GBTPhaseLookupTable["ge21"]["m1"][0] = 6 #VFAT0
vfat3GBTPhaseLookupTable["ge21"]["m1"][1] = 10 #VFAT1
vfat3GBTPhaseLookupTable["ge21"]["m1"][2] = 6 #VFAT2
vfat3GBTPhaseLookupTable["ge21"]["m1"][3] = 9 #VFAT3
vfat3GBTPhaseLookupTable["ge21"]["m1"][4] = 8 #VFAT4
vfat3GBTPhaseLookupTable["ge21"]["m1"][5] = 7 #VFAT5
vfat3GBTPhaseLookupTable["ge21"]["m1"][6] = 4 #VFAT6
vfat3GBTPhaseLookupTable["ge21"]["m1"][7] = 8 #VFAT7
vfat3GBTPhaseLookupTable["ge21"]["m1"][8] = 12 #VFAT8
vfat3GBTPhaseLookupTable["ge21"]["m1"][9] = 9 #VFAT9
vfat3GBTPhaseLookupTable["ge21"]["m1"][10] = 9 #VFAT10
vfat3GBTPhaseLookupTable["ge21"]["m1"][11] = 8 #VFAT11

# Fill Info for GE21 - m2
vfat3GBTPhaseLookupTable["ge21"]["m2"][0] = 6 #VFAT0
vfat3GBTPhaseLookupTable["ge21"]["m2"][1] = 6 #VFAT1
vfat3GBTPhaseLookupTable["ge21"]["m2"][2] = 10 #VFAT2
vfat3GBTPhaseLookupTable["ge21"]["m2"][3] = 7 #VFAT3
vfat3GBTPhaseLookupTable["ge21"]["m2"][4] = 8 #VFAT4
vfat3GBTPhaseLookupTable["ge21"]["m2"][5] = 7 #VFAT5
vfat3GBTPhaseLookupTable["ge21"]["m2"][6] = 4 #VFAT6
vfat3GBTPhaseLookupTable["ge21"]["m2"][7] = 8 #VFAT7
vfat3GBTPhaseLookupTable["ge21"]["m2"][8] = 7 #VFAT8
vfat3GBTPhaseLookupTable["ge21"]["m2"][9] = 5 #VFAT9
vfat3GBTPhaseLookupTable["ge21"]["m2"][10] = 8 #VFAT10
vfat3GBTPhaseLookupTable["ge21"]["m2"][11] = 7 #VFAT11

# Fill Info for GE21 - m3
vfat3GBTPhaseLookupTable["ge21"]["m3"][0] = 7 #VFAT0
vfat3GBTPhaseLookupTable["ge21"]["m3"][1] = 5 #VFAT1
vfat3GBTPhaseLookupTable["ge21"]["m3"][2] = 7 #VFAT2
vfat3GBTPhaseLookupTable["ge21"]["m3"][3] = 10 #VFAT3
vfat3GBTPhaseLookupTable["ge21"]["m3"][4] = 9 #VFAT4
vfat3GBTPhaseLookupTable["ge21"]["m3"][5] = 7 #VFAT5
vfat3GBTPhaseLookupTable["ge21"]["m3"][6] = 8 #VFAT6
vfat3GBTPhaseLookupTable["ge21"]["m3"][7] = 10 #VFAT7
vfat3GBTPhaseLookupTable["ge21"]["m3"][8] = 7 #VFAT8
vfat3GBTPhaseLookupTable["ge21"]["m3"][9] = 10 #VFAT9
vfat3GBTPhaseLookupTable["ge21"]["m3"][10] = 6 #VFAT10
vfat3GBTPhaseLookupTable["ge21"]["m3"][11] = 4 #VFAT11

# Fill Info for GE21 - m4
vfat3GBTPhaseLookupTable["ge21"]["m4"][0] = 3 #VFAT0
vfat3GBTPhaseLookupTable["ge21"]["m4"][1] = 3 #VFAT1
vfat3GBTPhaseLookupTable["ge21"]["m4"][2] = 3 #VFAT2
vfat3GBTPhaseLookupTable["ge21"]["m4"][3] = 9 #VFAT3
vfat3GBTPhaseLookupTable["ge21"]["m4"][4] = 4 #VFAT4
vfat3GBTPhaseLookupTable["ge21"]["m4"][5] = 3 #VFAT5
vfat3GBTPhaseLookupTable["ge21"]["m4"][6] = 8 #VFAT6
vfat3GBTPhaseLookupTable["ge21"]["m4"][7] = 8 #VFAT7
vfat3GBTPhaseLookupTable["ge21"]["m4"][8] = 11 #VFAT8
vfat3GBTPhaseLookupTable["ge21"]["m4"][9] = 6 #VFAT9
vfat3GBTPhaseLookupTable["ge21"]["m4"][10] = 6 #VFAT10
vfat3GBTPhaseLookupTable["ge21"]["m4"][11] = 4 #VFAT11

# Fill Info for GE11 - Short
# FIXME It would be great if this was in the DB and I could just load it from there...
vfat3GBTPhaseLookupTable["ge11"]["short"][0] = 6 #VFAT0
Expand Down
42 changes: 21 additions & 21 deletions gempython/tools/optohybrid_user_functions_xhal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, cardName, link, debug=False, gemType="ge11", detType="short")
"""
# Debug flag
self.debug = debug

# Logger
self.ohlogger = logging.getLogger(__name__)

Expand All @@ -49,18 +49,18 @@ def __init__(self, cardName, link, debug=False, gemType="ge11", detType="short")
self.vfatGBTPhases = vfat3GBTPhaseLookupTable[gemType][detType]
self.typeDet = detType
self.typeGEM = gemType
self.parentAMC = HwAMC(cardName, debug)
self.parentAMC = HwAMC(cardName, debug, gemType)

# Define broadcast read
self.bRead = self.parentAMC.lib.broadcastRead
self.bRead.argtypes = [c_uint, c_char_p, c_uint, POINTER(c_uint32)]
self.bRead.argtypes = [c_uint, c_char_p, c_uint, POINTER(c_uint32), c_uint]
self.bRead.restype = c_uint

# Define broadcast write
self.bWrite = self.parentAMC.lib.broadcastWrite
self.bWrite.argtypes = [c_uint, c_char_p, c_uint, c_uint]
self.bWrite.restype = c_uint

# Define the sbit mapping scan modules
self.sbitMappingWithCalPulse = self.parentAMC.lib.checkSbitMappingWithCalPulse
self.sbitMappingWithCalPulse.restype = c_uint
Expand All @@ -80,17 +80,17 @@ def __init__(self, cardName, link, debug=False, gemType="ge11", detType="short")
self.genScan.restype = c_uint
self.genScan.argtypes = [c_uint, c_uint, c_uint, c_uint,
c_uint, c_uint, c_bool, c_bool, c_uint, c_uint,
c_char_p, c_bool, c_bool, POINTER(c_uint32)]
c_char_p, c_bool, c_bool, POINTER(c_uint32), c_uint]
self.genChannelScan = self.parentAMC.lib.genChannelScan
self.genChannelScan.restype = c_uint
self.genChannelScan.argtypes = [c_uint, c_uint, c_uint, c_uint,
c_uint, c_uint, c_bool, c_bool,
c_uint, c_bool, c_char_p, c_bool,
POINTER(c_uint32)]
POINTER(c_uint32), c_uint]

self.dacScan = self.parentAMC.lib.dacScan
self.dacScan.restype = c_uint
self.dacScan.argtypes = [ c_uint, c_uint, c_uint, c_uint, c_bool, POINTER(c_uint32) ]
self.dacScan.argtypes = [ c_uint, c_uint, c_uint, c_uint, c_bool, POINTER(c_uint32), c_uint]

# Define the known V2b electronics scan registers
self.KnownV2bElScanRegs = [
Expand All @@ -111,7 +111,7 @@ def broadcastRead(self,register,mask=0xff000000):
outData = (c_uint32 * self.nVFATs)()

try:
rpcResp = self.bRead(self.link, register, mask, outData)
rpcResp = self.bRead(self.link, register, mask, outData, self.nVFATs)
except Exception as e:
print e
pass
Expand All @@ -120,13 +120,13 @@ def broadcastRead(self,register,mask=0xff000000):
raise OHRPCException("broadcastRead failed for device %i; reg: %s; with mask %x"%(self.link,register,mask), os.EX_SOFTWARE)

return outData

def broadcastWrite(self,register,value,mask=0xff000000):
"""
Perform a broadcast RPC write on the VFATs specified by mask
Will return when operation has completed
"""

rpcResp = 0

try:
Expand Down Expand Up @@ -163,7 +163,7 @@ def checkSbitMappingWithCalPulse(self, **kwargs):
L1AInterval - Number of BX's inbetween L1A's
mask - VFAT mask to use for excluding vfats from the trigger
nevts - Number of events for each dac value in scan
outData - Pointer to an array of size (24*128*8*nevts) which
outData - Pointer to an array of size (self.nVFATs*128*8*nevts) which
stores the results of the scan:
bits [0,7] channel pulsed,
bits [8:15] sbit observed,
Expand Down Expand Up @@ -334,15 +334,15 @@ def getTriggerSource(self):
else:
print("HwOptoHybrid.getTriggerSource() - No support for v3 electronics, exiting")
sys.exit(os.EX_USAGE)

def getType(self):
return (self.typeGEM,self.typeDet)

def getVFATMask(self):
"""
V3 electronics only
Returns a 24 bit number that should be used as the VFAT Mask
Returns a self.nVFATs bit number that should be used as the VFAT Mask
"""

return self.parentAMC.getLinkVFATMask(self.link)
Expand Down Expand Up @@ -370,7 +370,7 @@ def performCalibrationScan(self, **kwargs):
mask - VFAT mask to use
nevts - Number of events for each dac value in scan
outData - Array of type c_uint32, if chan >= 0 array size
must be: ((dacMax - dacMin + 1) / stepSize) * 24.
must be: ((dacMax - dacMin + 1) / stepSize) * self.nVFATs.
The first ((dacMax - dacMin + 1) / stepSize)
array positions are for VFAT0, the next
((dacMax - dacMin + 1) / stepSize) are for VFAT1,
Expand Down Expand Up @@ -454,9 +454,9 @@ def performCalibrationScan(self, **kwargs):
useExtTrig = kwargs["useExtTrig"]

if chan < 0:
return self.genChannelScan(nevts, self.link, mask, dacMin, dacMax, stepSize, enableCal, currentPulse, calSF, useExtTrig, scanReg, useUltra, kwargs["outData"])
return self.genChannelScan(nevts, self.link, mask, dacMin, dacMax, stepSize, enableCal, currentPulse, calSF, useExtTrig, scanReg, useUltra, kwargs["outData"], self.nVFATs)
else:
return self.genScan(nevts, self.link, dacMin, dacMax, stepSize, chan, enableCal, currentPulse, calSF, mask, scanReg, useUltra, useExtTrig, kwargs["outData"])
return self.genScan(nevts, self.link, dacMin, dacMax, stepSize, chan, enableCal, currentPulse, calSF, mask, scanReg, useUltra, useExtTrig, kwargs["outData"], self.nVFATs)

def performDacScan(self, outData, dacSelect, dacStep=1, mask=0x0, useExtRefADC=False):
"""
Expand All @@ -483,12 +483,12 @@ def performDacScan(self, outData, dacSelect, dacStep=1, mask=0x0, useExtRefADC=F
exit(os.EX_USAGE)

#Check length of results container
lenExpected = (maxVfat3DACSize[dacSelect][0] - 0+1)*24 / dacStep
lenExpected = (maxVfat3DACSize[dacSelect][0] - 0+1)*self.nVFATs / dacStep
if (len(outData) != lenExpected):
print("HwOptoHybrid::performDacScan(): I expected container of lenght {0} but provided 'outData' has length {1}",format(lenExpected, len(outData)))
exit(os.EX_USAGE)

return self.dacScan(self.link, dacSelect, dacStep, mask, useExtRefADC, outData)
return self.dacScan(self.link, dacSelect, dacStep, mask, useExtRefADC, outData, self.nVFATs)

def setDebug(self, debug):
self.debug = debug
Expand All @@ -500,7 +500,7 @@ def setSBitMask(self, sbitMask):
Sets the sbit mask in the OH FPGA
"""

if self.parentAMC.fwVersion < 3:
print("Parent AMC Major FW Version: %i"%(self.parentAMC.fwVersion))
print("Only implemented for v3 electronics, exiting")
Expand Down Expand Up @@ -530,7 +530,7 @@ def setTriggerThrottle(self,throttle):
"""
Set the trigger throttle
"""

if self.parentAMC.fwVersion < 3:
return self.parentAMC.writeRegister("GEM_AMC.OH.OH%d.CONTROL.TRIGGER.THROTTLE"%(self.link),throttle)
else:
Expand All @@ -539,7 +539,7 @@ def setTriggerThrottle(self,throttle):

def setType(self, gemType, detType):
"""
Sets the GEM type and detector type, updates the number of VFATs expected
Sets the GEM type and detector type, updates the number of VFATs expected
and changes the VFAT GBT Phase lookup table
gemType - string specifying gemType, expexted to be a key in gemVariants dictionary
Expand Down
Loading

0 comments on commit 0dedd40

Please sign in to comment.