#!/usr/bin/python import sys, string, os, time import SvtSim from SvtVme import * def stripEE(d): out=[] j = 0 while len(d)>j: if d[j]&0x400000: out = out + [d[j]] j = j + 1 return out def countEE(d): i = 0; j = 0; while len(d)>j : if d[j]&0x400000: i = i + 1 j = j +1 return i def EEpointer(d, n): #return pointer to n-th EE word i = 0; j = 0; while len(d)>j : if d[j]&0x400000: if i==n: return j i = i + 1 j = j +1 return -1 def fixEE(x): if (x&0x400000): return x&0x7fc0ff else: return x class VstFlow: def __init__(self): self.wedge = 5 self.hwset = "fakehits_nobypass" self.mapset = "fakehits" def setupSim(self): self.maps = SvtSim.WedgeMaps() self.maps.useHwSet(self.wedge, self.hwset) self.maps.initFromMapSet(self.wedge, self.mapset) self.incable = SvtSim.Cable() self.tfpps = SvtSim.SimTF(self.wedge) self.tfpps.plugInput(self.incable) for bs in [self.tfpps]: bs.useMaps(self.maps) def procEvent(self, d): self.incable.copyWords(d) for x in [(self.amsrws, "amsrw"), (self.hbpps, "hbpp ")]: bs, bn = x bs.procEvent() nroads = len(self.amsrws.outputCable().data())-1 def splitByEvent(self, din): d = [] i=0 self.tfout = [] while len(din)>0: d = d + [din.pop(0)] if d[len(d)-1]&0x400000: self.incable.copyWords(d) self.tfpps.procEvent() i=i+1 # if (not i%100): # print "Simulating event # %d"%(i) self.tfout = self.tfout + map(lambda x: (x&0x7fffff), self.tfpps.outputCable().data()) d = [] # print "Simulated %d events"%(i) return self.tfout def main(): if len(sys.argv)<2: print "usage: TFsim.py infile " return -1 # prepare board simulation vst = VstFlow() vst.setupSim() f_hbout = open(sys.argv[1], "r") hbout = map(lambda x: string.atoi(x,16), f_hbout.readlines()) if not (hbout[len(hbout)-1])&0x400000: print "WARNING last HB output word is not EE" >> stderr hbout = roads[0: 1+EEpointer(hbout, countEE(hbout)-1)] s_tfout = vst.splitByEvent(hbout) print string.join(map(lambda x: "%6.6x\n"%(x), s_tfout), "") f_hbout.close() if __name__=="__main__": main()