def ResetWfAvg(self): self.ped = Ped()
class Model: def __init__(self): self._runtime=UpTime() #rwh self.GetRunTimeF=self._runtime.GetRunTimeF #rwh self.GetRunTimeS=self._runtime.GetRunTimeS #rwh self.TimeFmt=self._runtime.TimeFmt #rwh self.mcu = busio.ProtoMcu('192.168.1.10') self.mrb2 = busio.Mrb(boardid=5+2, imrb=2) self.mrb3 = busio.Mrb(boardid=5+3, imrb=3) self.mrb = [None, None, self.mrb2, self.mrb3] self._drspedestals = {} # use [(2,0)] for MRB2 DRS0 self._drspedestals[(2,0)] = np.zeros((8,1024),dtype=np.int32) self._trigspy = [[] for i in range(24)] # # I think there must be a way to wrap the program uptime, the 'nfail' # counters, and maybe other program variables so that they have an # 'rfmt' method the GUI can use, and perhaps resemble registers in # other useful ways. But for now I'll leave this mess here. # def ClearNFail(self): self.mcu.b.nfail = 0 self.mrb2.b.nfail = 0 self.mrb3.b.nfail = 0 def GetNFail1(self): return self.mcu.b.nfail def GetNFail2(self): return self.mrb2.b.nfail def GetNFail3(self): return self.mrb3.b.nfail def ReadTrigSpy(self, which, mrb): # 0 <= which < 24 m = mrb msg = [] nmsg = 0 nw = 64 # each spy buffer is 64 words deep dlist = [] baseaddr = 0x4000 + 0x0100*which for iword in range(nw): addr = baseaddr + iword d = m.v5rd(addr) dlist.append(d) d = np.array(dlist) self._trigspy[which] = d def ResetWfAvg(self): self.ped = Ped() def AddToWfAvg(self): self.ped.addtrace(self._cellid, self._adcdata) def FinishWfAvg(self, fnam): self.ped.writepeds(fnam) print "wrote pedestal data to %s"%(fnam,) def LoadPedFile(self): for imrb in [2,3]: for idrs in range(10): fnam = "peds_mrb%d_drs%d.txt"%(imrb,idrs) try: pdat = np.loadtxt(fnam).transpose() pdat[1:8,:] -= 500 pdat[0] -= np.mean(pdat[0]) except IOError: pdat = np.zeros((8,1024)) self._drspedestals[(imrb,idrs)] = pdat def SubtractPeds(self): whichmrb = self._whichmrb whichdrs = self._whichdrs cellid = self._cellid pdat = self._drspedestals[(whichmrb,whichdrs)] adcdat = self._adcdata psdat = adcdat-np.roll(pdat,-cellid,1)[:,:adcdat.shape[-1]] self._adcdata_pedsub = psdat print "shapes:", adcdat.shape, psdat.shape def ParseRoFifoData(self, imrb): d = self._rofifodata ok = False AND = lambda x,y: x and y rc = 0 while True: if len(d)<4: # fewer than 4 words makes no sense rc = 1 break if not reduce(AND, [(x&7)==0 for x in d]): # low 3 bits of each word should be 0 padding rc = 2 break if not reduce(AND, [((x>>54)&3)==2 for x in d]): # top 2 bits of each word should be 1,0 respectively rc = 3 break d = [(x>>3 & 0x7ffffffffffff) for x in d] typecode = [(x>>48 & 7) for x in d] d = [(x & 0xffffffffffff) for x in d] if typecode[0]!=1: # header word should be (0, timestamp_go) rc = 4 break timestamp_go = d[0] if typecode[-1]!=7: # trailer word should be (7, whichdrs, cellid) rc = 5 break cellid = int(d[-1] & 0x3ff) whichdrs = int(d[-1]>>16 & 0xf) # strip off header and trailer words d = d[1:-1] typecode = typecode[1:-1] if len(d)%2!=0: # number of ADC words should be even rc = 6 break if not reduce(AND, [x==2 for x in typecode[0::2]]): # ADC words 0, 2, 4, ... should have typecode 2 rc = 7 break if not reduce(AND, [x==5 for x in typecode[1::2]]): # ADC words 1, 3, 5, ... should have typecode 5 rc = 8 break adc0 = map(int, [x>> 0 & 0xfff for x in d[1::2]]) adc1 = map(int, [x>>12 & 0xfff for x in d[1::2]]) adc2 = map(int, [x>>24 & 0xfff for x in d[1::2]]) adc3 = map(int, [x>>36 & 0xfff for x in d[1::2]]) adc4 = map(int, [x>> 0 & 0xfff for x in d[0::2]]) adc5 = map(int, [x>>12 & 0xfff for x in d[0::2]]) adc6 = map(int, [x>>24 & 0xfff for x in d[0::2]]) adc7 = map(int, [x>>36 & 0xfff for x in d[0::2]]) break print "ParseRoFifoData: rc=%d"%(rc,) if rc>0: return rc print "timestamp_go=%d whichdrs=%d cellid=%d"%( \ timestamp_go, whichdrs, cellid) if 0: print "\nadc0 =", adc0 print "\nadc1 =", adc1 print "\nadc2 =", adc2 print "\nadc3 =", adc3 print "\nadc4 =", adc4 print "\nadc5 =", adc5 print "\nadc6 =", adc6 print "\nadc7 =", adc7 self._adcdata = [adc0,adc1,adc2,adc3,adc4,adc5,adc6,adc7] self._adcdata = np.array(self._adcdata).astype(np.int32) self._whichmrb = imrb self._whichdrs = whichdrs self._cellid = cellid self._timestamp_go = timestamp_go