def __init__(self, datadir="data", outlabel="gainMeasurement"): self.outpathlabel = os.path.join(datadir, outlabel) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.cppfr = CPP_FILE_RUNNER() #misc variables self.gain = 0 self.shape = 0 self.base = 0 #json output, note module version number defined here self.jsondict = {'type':'quadFeAsic_gain_fpgadac'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date)
def __init__(self, master=None, forceLong=False): Frame.__init__(self, master) self.pack() self.config = CONFIG() self.forceLong = forceLong self.timestamp = None self.iTry_david_adams = 1 self.iTry_configure = 1 self.waveform_window = None # for live waveform self.waveform_root_windows = [] # for ROOT files self.waveform_root_viewers = [] # for ROOT files self.result_labels = [] self.display_procs = [] #Define general commands column self.define_test_details_column() self.reset() self.master.protocol("WM_DELETE_WINDOW", self.exit) self.data_base_dir = "/dsk/1/tmp" #changed from data -> tmp try: self.data_base_dir = os.environ["FEMB_DATA_DIR"] except KeyError: pass
def reset(self, iTrace=None): self.femb = FEMB_UDP() self.femb_config = CONFIG() self.figure.clf() self.subgs = [None] * 16 * 4 self.ax = [None] * 16 * 4 self.plot = [None] * 16 * 4 # 4x4x4 grid, one cell per channel self.gs = gridspec.GridSpec(4, 16) self.gs.update(wspace=0.2, hspace=0.2) # 1 plots per channel for row in range(4): for col in range(16): self.subgs[col + 16 * row] = gridspec.GridSpecFromSubplotSpec( 1, 1, subplot_spec=self.gs[col + 16 * row], hspace=0.0) self.ax[col + 16 * row] = self.figure.add_subplot( self.subgs[col + 16 * row][0]) self.ax[col + 16 * row].tick_params(axis='x', colors='black', labelsize='medium') self.ax[col + 16 * row].tick_params(axis='y', colors='black', labelsize='smaller') if iTrace is None: self.ani = animation.FuncAnimation(self.figure, self.plotData, interval=100, blit=True) else: self.plotData(0, iTrace) self.canvas.draw()
def __init__(self, datadir="data", outlabel="simpleMeasurement", wib=0, fembNum=0): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_femb_") + str(fembNum + 4 * wib) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.fembNum = int(fembNum) print("Test type\t" + str(self.outlabel)) print("Data path\t" + str(datadir)) print("FEMB #\t" + str(self.fembNum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 9014 self.cppfr = CPP_FILE_RUNNER() #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 #json output, note module version number defined here self.jsondict = {'type': 'fembTest_simple'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date)
def main(): #initialize board femb_config = CONFIG() femb_config.COLD = True femb_config.doSpiWrite = False print("\n") print("Running ADC synchronization process") print("Configuration parameters:") femb_config.printParameters() #check if register interface still working regVal = femb_config.femb.read_reg(femb_config.REG_FIRMWARE_VERSION) if regVal == None : print( "Register interface error, could not synchronize ASIC " ) return #do sync asicStatus = [1,1,1,1] for asic in [0,1,2,3]: asicNum = int(asic) if (asicNum < 0) or (asicNum>3) : continue femb_config.doAdcAsicConfig(asicNum) if femb_config.adcSyncStatus == False : femb_config.fixUnsync(asicNum) if femb_config.adcSyncStatus == False : print( "Could not synchronize ASIC ", asicNum ) asicStatus[asicNum] = 0 print("ASIC SYNC STATUS","\t",asicStatus)
def __init__(self, datadir="data", outlabel="simpleMeasurement", asicnum=0, isCold=False): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_asic_") + str(asicnum) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.asicnum = int(asicnum) print("Test type\t" + str(self.outlabel)) print("Data path\t" + str(datadir)) print("ASIC socket #\t" + str(self.asicnum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) self.cppfr = CPP_FILE_RUNNER() #set appropriate UDP packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 #should be larger than largest expected packet size #set test module status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.isCold = isCold #define json output self.jsondict = {'type': 'quadAdcTest_simple'} #self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date) self.jsondict['asicnum'] = str(self.asicnum)
def __init__(self, datadir="data", outlabel="OscillatorTesting"): self.outpathlabel = os.path.join(datadir, outlabel) self.femb_config = CONFIG() self.nFlashes = 4 self.nPages = 10 self.nTriesWrite = 3 self.printData = False
def __init__(self): self.sbnd = FEMB_DAQ() self.femb = FEMB_UDP() self.config = CONFIG() self.FunctionGenerator = None self.analyze = Data_Analysis() self.analyze2 = Data_Analysis2() self.analyze3 = Data_Analysis3()
def __init__(self, datadir="data", outlabel="funcgenMeasurement", asicnum=0, doReconfig=True, doLongRamp=False, isExternalClock=True, is1MHzSAMPLERATE=True, isCold=False): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_asic_") + str(asicnum) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.asicnum = int(asicnum) print("Test type\t" + str(self.outlabel)) print("Data path\t" + str(datadir)) print("ASIC socket #\t" + str(self.asicnum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) self.cppfr = CPP_FILE_RUNNER() self.funcgen = Keysight_33600A("/dev/usbtmc0", 1) #hardcoded to usbtmc0 #set appropriate UDP packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 #should be larger than largest expected packet size #set test module status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 #assign input to test and config module internal variables self.doReconfig = doReconfig self.doLongRamp = doLongRamp self.isExternalClock = isExternalClock self.is1MHzSAMPLERATE = is1MHzSAMPLERATE self.isCold = isCold self.femb_config.isExternalClock = self.isExternalClock #False = internal monostable, True = external self.femb_config.is1MHzSAMPLERATE = self.is1MHzSAMPLERATE #False = 1MHz, True = 2MHz self.femb_config.COLD = self.isCold self.femb_config.enableTest = 1 # 0 = no test input, 1 = enabled #define json output self.jsondict = {'type': 'quadAdcTest_funcgen'} #self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date) self.jsondict['asicnum'] = str(self.asicnum) self.jsondict['doreconfig'] = str(self.doReconfig) self.jsondict['extclock'] = str(self.isExternalClock) self.jsondict['is1MHz'] = str(self.is1MHzSAMPLERATE) self.jsondict['iscold'] = str(self.isCold)
def __init__(self, datadir="data", outlabel="OscillatorTesting"): self.outpathlabel = os.path.join(datadir, outlabel) self.femb_config = CONFIG() self.nFlashes = 4 self.nPages = 20 self.nWriteTries = 3 self.nTimeToErase = 180 #Erase bulk cycle time for EPCS64 is 160s max self.powerSupplyDevice = None self.printData = False
class FEMB_CONTROL_POWER(object): def __init__(self): #import femb_udp modules from femb_udp package self.femb_config = CONFIG() def power_off(self): print("Powering down all four ASICs") self.femb_config.turnOffAsics() def power_on(self): print("Powering up all four ASICs") self.femb_config.turnOnAsics()
def __init__(self, datadir="data", outlabel="check_current"): #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.config = CONFIG() self.results_current = {} self.fullresults_current = {} self.datadir = datadir self.outlabel = outlabel self.outpathlabel = os.path.join(self.datadir, self.outlabel)
def main(): femb_config = CONFIG() #initialize readout to known working state print("Turn off ASICs") femb_config.turnOffAsics() #ideally check if function generator exists here... #initialize funciton generator funcgen = Keysight_33600A("/dev/usbtmc0", 1) #hardcoded to usbtmc0 funcgen.stop()
def __init__(self, master=None, forceQuick=False, forceLong=False): Frame.__init__(self, master) self.pack() self.config = CONFIG() self.result_labels = [] self.display_procs = [] #Define general commands column self.define_test_details_column() self.reset() self.master.protocol("WM_DELETE_WINDOW", self.exit)
def __init__(self, datadir="data"): #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.cppfr = CPP_FILE_RUNNER()
def __init__(self): self.xmlshapingtimeval = 0 self.xmlgainval = 0 self.configshapingtimeval = 0 self.configgainval = 0 self.femb_config = CONFIG() self.feasicLeakage = self.femb_config.feasicLeakage self.feasicLeakagex10 = self.femb_config.feasicLeakagex10 self.feasicAcdc = self.femb_config.feasicAcdc self.feasicBaseline = self.femb_config.feasicBaseline self.feasicEnableTestInput = self.femb_config.feasicEnableTestInput self.feasicGain = self.femb_config.feasicGain self.feasicShape = self.femb_config.feasicShape self.feasicBuf = self.femb_config.feasicBuf self.femb_config.useLArIATmap = True
def __init__(self, datadir="data", outlabel="syncData"): self.outpathlabel = os.path.join(datadir, outlabel) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #set appropriate packet size self.plotting = plot_functions() self.write_data.femb.MAX_PACKET_SIZE = 8000 self.cppfr = CPP_FILE_RUNNER() #json output, note module version number defined here self.jsondict = {'type': 'sync_adcs'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date)
def __init__(self, master=None, forceQuick=False, forceLong=False): Frame.__init__(self, master) self.pack() self.config = CONFIG() if forceQuick and forceLong: raise Exception("Can't forceQuick and forceLong at the same time") self.forceQuick = forceQuick self.forceLong = forceLong self.timestamp = None self.result_labels = [] self.display_procs = [] #Define general commands column self.define_test_details_column() self.reset() self.master.protocol("WM_DELETE_WINDOW", self.exit) self.data_base_dir = "/dsk/1/data" try: self.data_base_dir = os.environ["FEMB_DATA_DIR"] except KeyError: pass
def __init__(self, datadir="data", outlabel="baselineTest"): #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #import data analysis and plotting objects self.plotting = plot_functions() self.analyze = Data_Analysis() #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 self.cppfr = CPP_FILE_RUNNER() #json output, note module version number defined here self.jsondict = {'type':'baseline_test'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date)
def __init__(self, datadir="data", outlabel="summary"): #set status variables self.status_check_setup = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.config = CONFIG() self.datadir = datadir self.topdir = "" self.subdirs = [] self.outlabel = outlabel self.outpathlabel = os.path.join(self.datadir, self.outlabel)
def __init__(self, datadir="data", outlabel="xtalk", fembNum=0): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_femb_") + str(fembNum) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.fembNum = int(fembNum) print("FEMB # " + str(self.fembNum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(self.datadir) #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 self.cppfr = CPP_FILE_RUNNER() #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 #misc variables self.gain = 0 self.shape = 0 self.base = 0 self.leakage = 0 self.leakagex10 = 0 self.buffer = 1 self.acdc = 0 self.useInternalPulser = False self.useExtAdcClock = False self.isRoomTemp = False self.isAPA = False self.useDefaultGainFactor = False #json output, note module version number defined here self.jsondict = {'type': 'fembTest_xtalk'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date)
class FEMB_POWER_CYCLE_TEST(object): def __init__(self): self.config = CONFIG() self.ntries = 5 def callit(self, params): wibslots = params['wibslots'] isRoomTemp = params['isRoomTemp'] for icycle in range(0, self.ntries): if (icycle == 0): self.config.initWib() for ifemb in wibslots: self.config.powerOffFemb(ifemb) datadir = params['datadir'] label = "simpleMeasurement_cycle_" + str(icycle) femb_test = FEMB_TEST_SIMPLE(datadir, label, ifemb) femb_test.isRoomTemp = isRoomTemp femb_test.check_setup() femb_test.record_data() femb_test.do_analysis() femb_test.archive_results() for ifemb in wibslots: self.config.powerOffFemb(ifemb)
def __init__(self, master=None): Frame.__init__(self,master) self.pack() #Define configuration object self.femb_config = CONFIG() #Define general commands column self.define_general_commands_column() #Define configuration commands column self.define_config_commands_column() #Define fe-asic configuration column self.define_feasic_config_commands_column() #Define adc asic configuration column self.define_adcasic_config_commands_column() self.trace_fft_window = None #self.trace_fft_allchan_window = None self.trace_fft = None
def main(): #initialize board femb_config = CONFIG() #femb_config.isExternalClock = True #femb_config.is1MHzSAMPLERATE = False #COOL #initialize readout to known working state print("Initializing board") initStatus = femb_config.initBoard() if initStatus == False : #setup in bad state completeFailure() return asicStatus = [1,1,1] initStatus = femb_config.initAsic(0) if initStatus == False : print( "Could not initialize ASIC ", 0 ) asicStatus[0] = 0 initStatus = femb_config.initAsic(1) if initStatus == False : print( "Could not initialize ASIC ", 1 ) asicStatus[1] = 0 initStatus = femb_config.initAsic(2) if initStatus == False : print( "Could not initialize ASIC ", 2 ) asicStatus[2] = 0 #use external pulser femb_config.setFPGADac(0,1,0,0) # write regs 4 and 5 #ideally check if function generator exists here... #initialize funciton generator funcgen = Keysight_33600A("/dev/usbtmc0",1) #hardcoded to usbtmc0 xLow = 0.1 xHigh = 1.3 offsetV = (xLow + xHigh)*0.5 amplitudeV = (xHigh - xLow)*0.5 freq = 20173 funcgen.startSin(freq,amplitudeV,offsetV) #setup is in good state totalVictory() print("ASIC STATUS","\t",asicStatus)
class QUADADC_TEST_SIMPLE(object): def __init__(self, datadir="data", outlabel="simpleMeasurement", asicnum=0, isCold=False): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_asic_") + str(asicnum) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.asicnum = int(asicnum) print("Test type\t" + str(self.outlabel)) print("Data path\t" + str(datadir)) print("ASIC socket #\t" + str(self.asicnum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) self.cppfr = CPP_FILE_RUNNER() #set appropriate UDP packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 #should be larger than largest expected packet size #set test module status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.isCold = isCold #define json output self.jsondict = {'type': 'quadAdcTest_simple'} #self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date) self.jsondict['asicnum'] = str(self.asicnum) def check_setup(self): #CHECK STATUS AND INITIALIZATION print("SIMPLE MEASUREMENT - CHECKING READOUT STATUS") self.status_check_setup = 0 #make sure output directory exists (should catch permissions issues etc) isDir = self.write_data.assure_filedir() if isDir == None: print("Error running test - Output data directory note created.") return #check if register interface is working print("Checking register interface") regVal = self.femb_config.femb.read_reg( self.femb_config.REG_FIRMWARE_VERSION) if (regVal == None): print("Error running test - register interface is not working.") print(" Turn on or debug UDP readout.") return if (regVal < 0): print("Error running test - register interface is not working.") print(" Turn on or debug UDP readout.") return print("Read register 6, value = " + str(hex(regVal))) #check for any problems in input variables #check that input ASIC # is correct if self.asicnum == None: print( "Error running test - Invalid ASIC socket # specified, ending test" ) return if (self.asicnum < 0) or (self.asicnum > self.femb_config.NASICS): print( "Error running test - Invalid ASIC socket # specified, ending test" ) return #initialize readout to known working state #initialization may identify problem that cancels test print("Initializing board") initStatus = self.femb_config.initBoard() if initStatus == False: print( "Error running test - Could not initialize board, ending test") return initStatus = self.femb_config.initAsic(self.asicnum) if initStatus == False: print( "Error running test - Could not initialize ASIC, ending test") return #firmware version check should be done in initialize, otherwise do here #if self.femb_config.checkFirmwareVersion() == False: # print('Error running doFembTest - Invalid firmware and/or register read error') # return #check if data streaming is working, assume it's ON after board + ASIC initialize print("Checking data streaming") testData = self.write_data.femb.get_data_packets(1) if testData == None: print("Error running test - board is not streaming data.") print(" Turn on and initialize FEMB UDP readout.") return if len(testData) == 0: print("Error running test - board is not streaming data.") print(" Turn on and initialize FEMB UDP readout.") return print("Received data packet " + str(len(testData[0])) + " bytes long") #check for analysis executables if not self.cppfr.exists( 'test_measurements/quadAdcTester/code/parseBinaryFile'): print( 'Error running test - parseBinaryFile executable not found, run setup.sh' ) return if not self.cppfr.exists( 'test_measurements/quadAdcTester/code/processNtuple_simpleMeasurement' ): print( 'Error running test - processNtuple_simpleMeasurement executable not found, run setup.sh' ) return #Setup is ok print("SIMPLE MEASUREMENT - READOUT STATUS OK" + "\n") self.status_check_setup = 1 def record_data(self): if self.status_check_setup == 0: print( "Error running test - Please run check_setup method before trying to take data" ) return if self.status_record_data == 1: print( "Error running test - Data already recorded. Reset/restat GUI to begin a new measurement" ) return #MEASUREMENT SECTION print("SIMPLE MEASUREMENT - RECORDING DATA") #wait to make sure HS link is back on after check_setup function sleep(1.) #setup output file and record data self.write_data.filename = self.outlabel + ".bin" print("Recording " + self.write_data.filename) isOpen = self.write_data.open_file() if isOpen == 0: print( "Error running test - Could not open output data file for writing, ending test" ) #record data self.write_data.numpacketsrecord = 10 self.write_data.run = 0 self.write_data.runtype = 0 self.write_data.runversion = 0 #loop over each ASIC, record some data subrun = 0 asic = self.asicnum asicCh = 0 self.femb_config.selectAsic(asic) self.write_data.record_data(subrun, asic, asicCh) self.write_data.close_file() #Power off ASIC #self.femb_config.turnOffAsics() print("SIMPLE MEASUREMENT - DONE RECORDING DATA" + "\n") self.status_record_data = 1 def do_analysis(self): if self.status_record_data == 0: print("Error running test - Please record data before analysis") return if self.status_do_analysis == 1: print("Error running test - Analysis already complete") return #ANALYSIS SECTION print("SIMPLE MEASUREMENT - ANALYZING AND SUMMARIZING DATA") #parse binary self.cppfr.run("test_measurements/quadAdcTester/code/parseBinaryFile", [self.write_data.data_file_path]) #check for parsed file here if os.path.isfile("output_parseBinaryFile.root") == False: print("Error running test - parsed data file not found.") return #run analysis program parseBinaryFile = "output_parseBinaryFile.root" self.cppfr.run( "test_measurements/quadAdcTester/code/processNtuple_simpleMeasurement", [parseBinaryFile]) #check for online analysis result files here if os.path.isfile( "output_processNtuple_simpleMeasurement.root") == False: print("Error running test - parsed data file not found.") return #update output file names parseBinaryFile = self.outpathlabel + "-parseBinaryFile.root" call(["mv", "output_parseBinaryFile.root", parseBinaryFile]) processNtupleFile = self.outpathlabel + "-processNtupleFile.root" call([ "mv", "output_processNtuple_simpleMeasurement.root", processNtupleFile ]) summaryPlot = self.outpathlabel + "-summaryPlot.png" call(["mv", "summaryPlot_simpleMeasurement.png", summaryPlot]) print("SIMPLE MEASUREMENT - DONE ANALYZING AND SUMMARIZING DATA" + "\n") self.status_do_analysis = 1 def archive_results(self): #NOTE: GENERALLY ALLOW ARCHIVE PROCESS TO RUN EVEN IF OTHER STEPS FAIL #if self.status_check_setup == 0 : # print("Check setup status is 0, not archiving data") # return #if self.status_do_analysis == 0: # print("Please analyze data before archiving results") # return if self.status_archive_results == 1: print("Error running test - Results already archived") return #ARCHIVE SECTION print("SIMPLE MEASUREMENT - ARCHIVE") #add summary variables to output self.jsondict['filedir'] = str(self.write_data.filedir) self.jsondict['status_check_setup'] = str(self.status_check_setup) self.jsondict['status_record_data'] = str(self.status_record_data) self.jsondict['status_do_analysis'] = str(self.status_do_analysis) self.jsondict['status_archive_results'] = str(1) #dump results into json jsonFile = self.outpathlabel + "-results.json" with open(jsonFile, 'w') as outfile: json.dump(self.jsondict, outfile, indent=4) print("SIMPLE MEASUREMENT - DONE ARCHIVING" + "\n") self.status_archive_results = 1
class FEMB_CHECK_CURRENT(object): def __init__(self, datadir="data", outlabel="check_current"): #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 self.config = CONFIG() self.results_current = {} self.fullresults_current = {} self.datadir = datadir self.outlabel = outlabel self.outpathlabel = os.path.join(self.datadir, self.outlabel) def check_setup(self): #CHECK STATUS AND INITIALIZATION print("CHECK SETUP") self.status_check_setup = 0 #check if register interface is working print("Checking register interface") regVal = self.config.femb.read_reg(6) if (regVal == None): print( "Error running doFembTest - FEMB register interface is not working." ) print(" Turn on or debug FEMB UDP readout.") return if (regVal < 0): print( "Error running doFembTest - FEMB register interface is not working." ) print(" Turn on or debug FEMB UDP readout.") return print("Read register 6, value = " + str(hex(regVal))) #CHECK STATUS SUCCEEDED print("CHECK SETUP - STATUS OK" + "\n") self.status_check_setup = 1 def record_data(self, ifemb, wibslots=[]): if self.status_check_setup == 0: print( "RECORD DATA - Please run check_setup method before trying to take data" ) return #check that femb number is valid if ("all" not in ifemb and "off" not in ifemb): if ((int(ifemb) < 0) or (int(ifemb) >= self.config.NFEMBS)): print( "Error running current check - Invalid FEMB # specified.") return print("Checking current for: ", ifemb) for j in range(0, 4, 1): self.config.powerOffFemb(j) if ("off" in ifemb): #All off time.sleep(60) curr_measured = self.config.readCurrent() self.results_current["none_on"] = curr_measured elif ("all" not in ifemb): #Single slot on self.config.powerOnFemb(ifemb) time.sleep(30) curr_measured = self.config.readCurrent() self.results_current["femb" + str(ifemb) + "on"] = curr_measured self.config.powerOffFemb(ifemb) #elif len(wibslots)>1: #All on else: for i in wibslots: self.config.powerOnFemb(i) time.sleep(30) curr_measured = self.config.readCurrent() self.results_current["all_on"] = curr_measured for j in wibslots: self.config.powerOffFemb(j) self.status_record_data = 1 def do_analysis(self): if self.status_record_data == 0: print("DO ANALYSIS - Please record data before analysis") return if self.status_do_analysis == 1: print("DO ANALYSIS - Analysis already complete") return print("DO ANALYSIS") rsense = 0.1 for key, resultlist in self.results_current.items(): print(key, resultlist) i = 0 for val in resultlist: if (i < 25): jfemb = int(i / 6) val1 = ((val >> 16) & 0xFFFF) val2 = (val & 0xFFFF) if i % 6 == 0: v1 = val1 & 0x3FFF vcc1 = v1 * 305.18e-6 + 2.5 self.fullresults_current[key + "_femb" + str(jfemb) + "_vcc1"] = vcc1 v2 = val2 & 0x3FFF temp1 = v2 * 0.0625 self.fullresults_current[key + "_femb" + str(jfemb) + "_temp1"] = temp1 else: v1 = val1 & 0x3FFF vi = v1 * 305.18e-6 self.fullresults_current[key + "_femb" + str(jfemb) + "_v" + str(i % 6)] = vi v2 = val2 & 0x3FFF ii = v2 * 19.075e-6 / rsense if ii > 3.1: ii = 0 self.fullresults_current[key + "_femb" + str(jfemb) + "_i" + str(i % 6)] = ii i += 1 def unpack(self, val, i): i -= 1 rsense = 0.1 unpacked_results = [] if (i < 25): jfemb = int(i / 6) val1 = ((val >> 16) & 0xFFFF) val2 = (val & 0xFFFF) if i % 6 == 0: v1 = val1 & 0x3FFF vcc1 = v1 * 305.18e-6 + 2.5 unpacked_results.append(vcc1) v2 = val2 & 0x3FFF temp1 = v2 * 0.0625 unpacked_results.append(temp1) else: v1 = val1 & 0x3FFF vi = v1 * 305.18e-6 unpacked_results.append(vi) v2 = val2 & 0x3FFF ii = v2 * 19.075e-6 / rsense if ii > 3.1: ii = 0 unpacked_results.append(ii) i += 1 print(i, val, unpacked_results) return unpacked_results def archive_results(self): if self.status_record_data == 0: print( "ARCHIVE RESULTS - Please take data before archiving results") return if self.status_archive_results == 1: print("ARCHIVE RESULTS -Results already archived") return print("ARCHIVE RESULTS") jsonFile = self.outpathlabel + "-results.json" with open(jsonFile, 'w') as outfile: json.dump(self.fullresults_current, outfile, indent=4) #ARCHIVING SUCCEEDED print("ARCHIVE RESULTS - DONE" + "\n") self.status_archive_results = 1
class CONFIGURATION_WINDOW(Frame): def __init__(self, master=None): Frame.__init__(self,master) self.pack() #Define configuration object self.femb_config = CONFIG() #Define general commands column self.define_general_commands_column() #Define configuration commands column self.define_config_commands_column() #Define fe-asic configuration column self.define_feasic_config_commands_column() #Define adc asic configuration column self.define_adcasic_config_commands_column() self.trace_fft_window = None #self.trace_fft_allchan_window = None self.trace_fft = None def define_general_commands_column(self): columnbase=0 label = Label(self, text="General Commands") label.grid(row=0,column=columnbase, columnspan=2) label = Label(self,text="Register to read:") label.grid(sticky=W,row=1,column=columnbase+0) # Adding register number to read entry box self.readreg_number_entry = Entry(self,width=4) self.readreg_number_entry.grid(sticky=W,row=1,column=columnbase+1) # Adding read register result label label = Label(self,text="Register contents:") label.grid(sticky=W,row=2,column=columnbase+0) self.readreg_result = Label(self, text="",width=10) self.readreg_result.grid(sticky=W,row=2,column=columnbase+1) #Adding the read register button readreg_button = Button(self, text="Read Register", command=self.call_readRegister) readreg_button.grid(row=3,column=columnbase,columnspan=2) label = Label(self,text="Register to write:") label.grid(sticky=W,row=4,column=columnbase+0) # Adding register number to write entry box self.writereg_number_entry = Entry(self,width=4) self.writereg_number_entry.grid(sticky=W,row=4,column=columnbase+1) label = Label(self,text="Value to write:") label.grid(sticky=W,row=5,column=columnbase+0) # Adding register value to write entry box self.writereg_value_entry = Entry(self,width=15) self.writereg_value_entry.grid(sticky=W,row=5,column=columnbase+1) #Adding the write register button writereg_button = Button(self, text="Write Register", command=self.call_writeRegister) writereg_button.grid(row=6,column=columnbase,columnspan=2) # Adding write register result label self.writereg_result = Label(self, text="") self.writereg_result.grid(sticky=W,row=7,column=columnbase,columnspan=2) #Adding the reset plot button reset_plot_button = Button(self, text="Show/Reset Plots", command=self.call_reset_plot) reset_plot_button.grid(row=8,column=columnbase,columnspan=2) def define_config_commands_column(self): columnbase=10 label = Label(self, text="Configuration Commands") label.grid(row=0,column=columnbase,columnspan=2) #Adding the reset button reset_button = Button(self, text="Reset", command=self.call_reset) reset_button.grid(row=1,column=columnbase,columnspan=2) #Adding the initialization button init_button = Button(self, text="Initialize", command=self.call_initialize) init_button.grid(row=2,column=columnbase,columnspan=2) # Adding femb number to select label = Label(self,text="FEMB:") label.grid(sticky=W,row=3,column=columnbase+0) self.femb_number_entry = Spinbox(self,from_=0,to=15,insertwidth=3,width=4) self.femb_number_entry.grid(sticky=W,row=3,column=columnbase+1) # Adding asic number to select label = Label(self,text="ASIC:") label.grid(sticky=W,row=4,column=columnbase+0) self.asic_number_entry = Spinbox(self,from_=0,to=7,insertwidth=1,width=4) self.asic_number_entry.grid(sticky=W,row=4,column=columnbase+1) # Adding channel number to select label = Label(self,text="Channel:") label.grid(sticky=W,row=5,column=columnbase+0) self.channel_number_entry = Spinbox(self,values=CHAN_OPTIONS,insertwidth=3,width=4) self.channel_number_entry.grid(sticky=W,row=5,column=columnbase+1) #self.channel_number_entry = Menu(self,insertwidth=3,width=4) #self.channel_number_entry.add_command(label="1") #self.channel_number_entry.grid(sticky=W,row=5,column=columnbase+1) #Adding the select channel button selectChannel_button = Button(self, text="Select Channel", command=self.call_selectChannel) selectChannel_button.grid(row=6,column=columnbase,columnspan=2) self.selectChannel_result = Label(self, text="") self.selectChannel_result.grid(sticky=W,row=7,column=columnbase) def define_feasic_config_commands_column(self): columnbase=20 label = Label(self, text="FE ASIC Configuration Commands") label.grid(row=0,column=columnbase,columnspan=2) # FE ASIC config entry label = Label(self, text="Gain") label.grid(sticky=W,row=1,column=columnbase) self.feasic_config_gain_entry = Spinbox(self,values=GAINVALS,state="readonly") self.feasic_config_gain_entry.grid(sticky=W,row=1,column=columnbase+1) label = Label(self, text="Shape") label.grid(sticky=W,row=2,column=columnbase) self.feasic_config_shape_entry = Spinbox(self,values=SHAPEVALS,state="readonly") self.feasic_config_shape_entry.grid(sticky=W,row=2,column=columnbase+1) label = Label(self, text="Baseline") label.grid(sticky=W,row=3,column=columnbase) self.feasic_config_base_entry = Spinbox(self,values=BASEVALS,state="readonly") self.feasic_config_base_entry.grid(sticky=W,row=3,column=columnbase+1) #Adding the configure all FE-ASIC channels button feasic_config_button = Button(self, text="Config FE-ASIC", command=self.call_feasic_config) feasic_config_button.grid(row=4,column=columnbase,columnspan=2) def define_adcasic_config_commands_column(self): columnbase=30 label = Label(self, text="ADC ASIC Configuration Commands") label.grid(row=0,column=columnbase) def call_readRegister(self): regnum = self.readreg_number_entry.get() try: regnum = int(regnum) if regnum < 0: raise ValueError("regnum must be >= 0") except ValueError: self.readreg_result["text"] = "Error: Register must be a number >= 0" return message = "" regVal = self.femb_config.femb.read_reg(regnum) if regVal != None: message = "0x{:08x}".format(regVal) else: message = "Error: regVal = None" self.readreg_result["text"] = message def call_writeRegister(self): regnum = self.writereg_number_entry.get() try: regnum = int(regnum) if regnum < 0: raise ValueError("regnum must be >= 0") except ValueError: self.writereg_result["text"] = "Error: Register must be a number >= 0" return regval = self.writereg_value_entry.get() message = "value must be int literal e.g. 123, 0xF3, 0b0101" if regval[:2] == "0x": try: regval = int(regval,16) except ValueError: self.writereg_result["text"] = message return elif regval[:2] == "0b": try: regval = int(regval,2) except ValueError: self.writereg_result["text"] = message return else: try: regval = int(regval) except ValueError: self.writereg_result["text"] = message return if (regval < 0) or (regval > 0xFFFFFFFF): message = 'Value must be > 0 and < 0xFFFFFFFF' self.writereg_result["text"] = message return self.femb_config.femb.write_reg(regnum,regval) self.writereg_result["text"] = "" def call_reset(self): self.femb_config.resetBoard() def call_initialize(self): self.femb_config.initBoard() def call_selectChannel(self): femb = None asic = None chan = None try: femb = int(self.femb_number_entry.get()) except ValueError: self.selectChannel_result["text"] = "Error femb must be an int" return try: asic = int(self.asic_number_entry.get()) except ValueError: self.selectChannel_result["text"] = "Error asic must be an int" return try: if self.channel_number_entry.get() != "ALL": chan = int(self.channel_number_entry.get()) else: chan = self.channel_number_entry.get() except ValueError: self.selectChannel_result["text"] = "Error channel must be an int or ALL" return message = "" if femb < 0 or femb >=4 : self.selectChannel_result["text"] = "Error femb only from 0 to 3" return if asic < 0 or asic >= 7: self.selectChannel_result["text"] = "Error asic only from 0 to 7" return if chan != "ALL": if chan < 0 or chan >= 16: self.selectChannel_result["text"] = "Error channel only from 0 to 15 or ALL" return self.femb_config.selectFemb(femb) self.femb_config.selectChannel(asic,chan) self.selectChannel_result["text"] = "" #WIB specific if isinstance( chan, int ): self.trace_fft_window.selChan = chan self.call_reset_plot() def call_feasic_config(self): gain = GAINVALS.index(self.feasic_config_gain_entry.get()) shape = SHAPEVALS.index(self.feasic_config_shape_entry.get()) base = BASEVALS.index(self.feasic_config_base_entry.get()) self.femb_config.configFeAsic(gain,shape,base) def call_set_pulser(self): enabled = self.pulser_enable_var.get() if not(enabled == 0 or enabled == 1): raise ValueError("Pulser enabled must be 0 or 1") pulseHeight = None try: pulseHeight = int(self.pulser_height_entry.get()) except ValueError: self.pulser_result["text"] = "Error pulseHeight must be an int" return if pulseHeight < 0 or pulseHeight >= 32: self.pulser_result["text"] = "Error pulseHeight must be 0 to 31" return self.pulser_result["text"] = "" self.femb_config.setInternalPulser(enabled,pulseHeight) def call_adcasic_config(self): print("call_adcasic_config") enabled = self.adc_offset_enable_var.get() if not(enabled == 0 or enabled == 1): raise ValueError("Pulser enabled must be 0 or 1") offsetCurrent = None try: offsetCurrent = int(self.adc_offset_current_entry.get()) except ValueError: self.adc_result["text"] = "Error offsetCurrent must be an int" return if offsetCurrent < 0 or offsetCurrent >= 16: self.adc_result["text"] = "Error offsetCurrent must be 0 to 15" return self.adc_result["text"] = "" f2default = 0 clkdefault = "fifo" if hasattr(self.femb_config,"F2DEFAULT"): f2default = self.femb_config.F2DEFAULT if hasattr(self.femb_config,"CLKDEFAULT"): clkdefault = self.femb_config.CLKDEFAULT clockMonostable = False clockExternal = False clockFromFIFO = False if clkdefault=="fifo": clockFromFIFO = True elif clkdefault=="monostable": clockMonostable = True elif clkdefault=="external": clockExternal = True else: print("Error: CLKDEFAULT='{}' not one of the allowed options. Try fife, monostable, or external..".format(clkdefault)) self.femb_config.configAdcAsic(enableOffsetCurrent=enabled,offsetCurrent=offsetCurrent,f2=f2default,clockMonostable=clockMonostable,clockExternal=clockExternal,clockFromFIFO=clockFromFIFO,pdsr=1,pcsr=1) #nRetries = 5 #for iRetry in range(nRetries): # self.femb_config.configAdcAsic(enableOffsetCurrent=enabled,offsetCurrent=offsetCurrent,f2=f2default,clockMonostable=clockMonostable,clockExternal=clockExternal,clockFromFIFO=clockFromFIFO) # # Check that board streams data # data = self.femb.get_data(1) # if data == None: # print("Board not streaming data, retrying initialization...") # continue # try initializing again # self.adc_result["text"] = "" # return #self.adc_result["text"] = "Board not streaming data after {} tries".format(nRetries) def call_sync_adc(self): print("call_sync_adc") message = "Sync Error" isAlreadySynced, latchloc1, latchloc2, phase = self.femb_config.syncADC() if isAlreadySynced: message = "Already Sync'd" else: message = "Sync'd: latch latency " + str(hex(latchloc1)) + str(hex(latchloc2)) + "\tPhase " + str(hex(phase)) self.adc_sync_result["text"] = message def call_quit(self): print("call_adcasic_config") def call_reset_plot(self): selChan = self.channel_number_entry.get() if self.trace_fft_window: self.trace_fft_window.destroy() if selChan == "ALL": self.trace_fft_window = Toplevel(self) self.trace_fft_window.title("Trace FFT Window") self.trace_fft = TRACE_FFT_ALLCHAN_WINDOW(self.trace_fft_window) else: self.trace_fft_window = Toplevel(self) self.trace_fft_window.title("Trace FFT Window") self.trace_fft = TRACE_FFT_WINDOW(self.trace_fft_window)
class GUI_WINDOW(Frame): #GUI window defined entirely in init function def __init__(self, master=None, forceQuick=False, forceLong=False): Frame.__init__(self, master) self.pack() self.config = CONFIG() self.result_labels = [] self.display_procs = [] #Define general commands column self.define_test_details_column() self.reset() self.master.protocol("WM_DELETE_WINDOW", self.exit) def define_test_details_column(self): columnbase = 0 """ # Adding operator name label and read entry box self.operator_label = Label(self,text="Operator Name:",width=25) self.operator_label.grid(sticky=W,row=1,column=columnbase+0) self.operator_entry = Entry(self,width=25) self.operator_entry.grid(sticky=W,row=1,column=columnbase+1) # Adding electronics ID and read entry box self.boxid_label = Label(self,text="Electronics ID:",width=25) self.boxid_label.grid(sticky=W,row=3,column=columnbase+0) self.boxid_entry = Entry(self,width=25) self.boxid_entry.grid(sticky=W,row=3,column=columnbase+1) """ # Adding electronics ID and read entry box self.sync_button = Button(self, text="Sync ADC", command=self.adc_sync, width=25) self.sync_button.grid(row=22, column=columnbase, columnspan=2, pady=30) # self.reset_button = Button(self, text="Reset", command=self.reset, width=25, bg="#FF8000") self.reset_button.grid(row=24, column=columnbase, columnspan=2) self.runid_label = Label(self, text="") self.runid_label.grid(row=25, column=columnbase, columnspan=2, pady=20) self.status_label = Label(self, text="NOT STARTED", bd=1, relief=SUNKEN, width=50) self.status_label.grid(row=100, column=columnbase, columnspan=2) self.bkg_color = self.status_label.cget("background") """ def get_options(self,getCurrent=False): operator = self.operator_entry.get() boxid = self.boxid_entry.get() variables = [operator,boxid] for var in variables: if var == "" : return print("Operator Name: '{}'".format(operator)) print("CE Box ID: '{}'".format(boxid)) inputOptions = { "operator": operator, "box_id": boxid, } print(inputOptions) return inputOptions """ def reset(self): for i in reversed(range(len(self.display_procs))): tmp = self.display_procs.pop(i) tmp.terminate() try: tmp.wait(2) except subprocess.TimeoutExpired: tmp.kill() del tmp for i in reversed(range(len(self.result_labels))): tmp = self.result_labels.pop(i) tmp.destroy() self.status_label["text"] = "NOT STARTED" self.status_label["fg"] = "#000000" self.status_label["bg"] = self.bkg_color self.runid_label["text"] = "" self.sync_button["state"] = "normal" #self.operator_label["state"] = "normal" #self.operator_entry["state"] = "normal" #self.boxid_label["state"] = "normal" #self.boxid_entry["state"] = "normal" #self.boxid_entry.delete(0,END) self.reset_button["bg"] = "#FF9900" self.reset_button["activebackground"] = "#FFCF87" def adc_sync(self): #operator_name = self.operator_entry.get() #test_stand = self.test_stand_entry.get() #boardid = self.boardid_entry.get() #traveller = self.traveller_entry.get() #print("Operator Name: " + str( operator_name ) ) #print("Test Stand # : " + str( test_stand ) ) #print("Board/Chip ID: " + str( boardid ) ) #print("Traveller # : " + str( traveller ) ) self.config.femb.init_ports(hostIP=settings.PC_IP, destIP=settings.FPGA_IP) self.config.resetFEMBBoard() self.config.initBoard() self.config.syncADC() self.config.initFunctionGenerator() """ if self.femb_test.status_check_setup == 0: self.check_setup_result["text"] = "TERRIBLE FAILURE" else: self.check_setup_result["text"] = "SUCCESS" """ """ def start_measurements(self): params = self.get_options() if params is None: print("ENTER REQUIRED INFO") return print("BEGIN TESTS") self.status_label["text"] = "TESTS IN PROGRESS..." self.status_label["fg"] = "#000000" self.update_idletasks() run_main(self.config,**params) self.done_measuring(params) """ def done_measuring(self, params): print("TESTS COMPLETE") self.status_label["text"] = "Tests done" self.reset_button["bg"] = "#00CC00" self.reset_button["activebackground"] = "#A3CCA3" titles_made = False testNames = None columnbase = 0 rowbase = 50 def exit(self, *args, **kargs): for i in reversed(range(len(self.display_procs))): tmp = self.display_procs.pop(i) tmp.terminate() try: tmp.wait(4) except subprocess.TimeoutExpired: tmp.kill() del tmp self.destroy() self.master.destroy()
class MONITOR_TESTER(object): def __init__(self, datadir="data", outlabel="monitorTest"): self.outpathlabel = os.path.join(datadir, outlabel) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #import data analysis and plotting objects self.plotting = plot_functions() self.analyze2 = Data_Analysis2() #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 8000 self.cppfr = CPP_FILE_RUNNER() #json output, note module version number defined here self.jsondict = {'type': 'monitor_test'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date) def get_data(self): for num, i in enumerate(self.chip_list): if self.config_list[i[0]]: folder_path = os.path.join(self.datadir, i[1]) self.save_monitor_data(folder_path, chip_index=i[0], chip_name=i[1]) def save_monitor_data(self, folder_path, chip_index, chip_name): sys.stdout.flush() test_directory = os.path.join(folder_path, self.datasubdir) os.makedirs(test_directory) data_directory = os.path.join(test_directory, "Data") os.makedirs(data_directory) #Select the monitor readout self.femb_config.femb.write_reg(9, 3) #Get the ASIC to send out pulses. Bit 6 needs to be high for ASIC DAC reg17_value = (self.femb_config.monitor_freq << 16) + ( self.femb_config.monitor_delay << 8) + (0b01000000) self.femb_config.femb.write_reg(17, reg17_value) #Make sure the input to the DAC is not on self.femb_config.femb.write_reg(7, 0) #Read from test output ADCs self.femb_config.femb.write_reg(60, 1) for chn in range(self.femb_config.channels): # This was from the old code, not sure why the choice of hardcoded values # self.femb_config.set_fe_board(sts=a["test_int"][0], snc=a["200mV"], sg=a["14mV"], st=a["2us"], # smn=0, sbf=a["b_on"], slk = a["500pA"][1], stb = 0, s16=0, slkh=a["500pA"][0], sdc=0, # sdacsw2=1, sdacsw1=0, sdac=settings.monitor_amplitude) self.femb_config.fe_reg.set_fe_board( sts=0, snc=0, sg=2, st=2, smn=0, sbf=1, slk=0, stb=0, s16=0, slkh=0, sdc=0, sdacsw2=1, sdacsw1=0, sdac=self.femb_config.monitor_amplitude, remapping=True ) #remapping is to make gain/shaping times/base settings (0-3) consecutive in output and GUI self.femb_config.fe_reg.set_fe_chn(chip=chip_index, chn=chn, sts=1, snc=-1, sg=-1, st=-1, smn=1, sbf=-1) self.config_list = self.femb_config.configFeAsic(to_print=False) self.femb_config.select_chip_chn(chip=chip_index, chn=chn) filename = self.femb_config.Monitor_Naming.format(chn) rawdata = bytearray() full_filename = os.path.join(data_directory, filename) # rawdata += self.femb_config.femb.get_data_packets(data_type = "bin", num = 1, header = True) rawdata += self.femb_config.femb.get_data_packets(data_type="bin", num=1, header=False)[2:] for pack in range(self.femb_config.monitor_length): rawdata += self.femb_config.femb.get_data_packets( data_type="bin", num=1, header=False)[2:] with open(full_filename, "wb") as f: f.write(rawdata) f.close() self.femb_config.femb.write_reg(17, 0) print("Test--> Monitor check data collected for Chip {}".format( chip_name)) def analyze_data(self): for num, i in enumerate(self.chip_list): if self.config_list[i[0]]: folder_path = os.path.join(self.datadir, i[1]) self.result, self.peaks, self.differences, self.average_peak = self.analyze2.monitor_directory( folder_path, i[1], self.datasubdir, self.datadir, self.gain, self.shape, self.leak, self.buff, self.base) self.archive_results(i[1], i[0]) if (self.result == True): print("Chip {} (Socket {}) PASSED!".format(i[1], i[0])) if (self.result == False): print("Chip {} (Socket {}) FAILED!".format(i[1], i[0])) def archive_results(self, chip_name, chip_index): print("MONITOR DATA RESULTS - ARCHIVE") #add summary variables to output #add summary variables to output self.jsondict['filedir'] = str(self.write_data.filedir) self.jsondict['config_gain'] = str( self.femb_config.gainArray[self.gain]) self.jsondict['config_shape'] = str( self.femb_config.shapeArray[self.shape]) self.jsondict['config_base'] = str( self.femb_config.baseArray[self.base]) self.jsondict['config_buff'] = str( self.femb_config.buffArray[self.buff]) self.jsondict['average_peak'] = str(self.average_peak) self.jsondict['chip_name'] = str(chip_name) self.jsondict['chip_index'] = str(chip_index) self.jsondict['config_list'] = self.config_list if self.result: self.jsondict['result'] = "Pass" else: self.jsondict['result'] = "Fail" self.jsondict['average_peak'] = self.average_peak results = [] for i, ch_peak in enumerate(self.peaks): measurement = {} measurement["ch"] = str(ch_peak[0]) measurement["peak"] = str(ch_peak[1]) measurement["difference"] = str(self.differences[i]) results.append(measurement) self.jsondict['results'] = results #dump results jsonFile = os.path.join(self.datadir, chip_name, self.datasubdir, "results.json") with open(jsonFile, 'w') as outfile: json.dump(self.jsondict, outfile, indent=4)
class FEMB_TEST_SIMPLE(object): def __init__(self, datadir="data", outlabel="simpleMeasurement", wib=0, fembNum=0): #set internal variables self.datadir = datadir self.outlabel = outlabel + str("_femb_") + str(fembNum + 4 * wib) self.outpathlabel = os.path.join(self.datadir, self.outlabel) self.fembNum = int(fembNum) print("Test type\t" + str(self.outlabel)) print("Data path\t" + str(datadir)) print("FEMB #\t" + str(self.fembNum)) #import femb_udp modules from femb_udp package self.femb_config = CONFIG() self.write_data = WRITE_DATA(datadir) #set appropriate packet size self.write_data.femb.MAX_PACKET_SIZE = 9014 self.cppfr = CPP_FILE_RUNNER() #set status variables self.status_check_setup = 0 self.status_record_data = 0 self.status_do_analysis = 0 self.status_archive_results = 0 #json output, note module version number defined here self.jsondict = {'type': 'fembTest_simple'} self.jsondict['version'] = '1.0' self.jsondict['timestamp'] = str(self.write_data.date) def check_setup(self): #CHECK STATUS AND INITIALIZATION print("SIMPLE MEASUREMENT - CHECKING READOUT STATUS") self.status_check_setup = 0 #make sure output directory exists self.write_data.assure_filedir() #check if register interface is working print("Checking register interface") regVal = self.femb_config.femb.read_reg(6) if (regVal == None): print( "Error running test - FEMB register interface is not working.") print(" Turn on or debug FEMB UDP readout.") return if (regVal < 0): print( "Error running test - FEMB register interface is not working.") print(" Turn on or debug FEMB UDP readout.") return print("Read register 6, value = " + str(hex(regVal))) #check that femb number is valid if (int(self.fembNum) < 0) or (int(self.fembNum) >= self.femb_config.NFEMBS): print("Error running doFembTest - Invalid FEMB # specified.") return #DO NOT CONFIGURE, except to enable streaming self.femb_config.wib_reg_enable() self.femb_config.femb.write_reg(20, 3) self.femb_config.femb.write_reg(20, 3) time.sleep(0.001) self.femb_config.femb.write_reg(20, 0) self.femb_config.femb.write_reg(20, 0) time.sleep(0.001) # start streaming data from ASIC 0 in initialization self.femb_config.femb.write_reg(7, 0x80000000) self.femb_config.femb.write_reg(7, 0x80000000) femb_asic = 0 & 0x0F wib_asic = (((self.fembNum << 16) & 0x000F0000) + ((femb_asic << 8) & 0xFF00)) self.femb_config.femb.write_reg(7, wib_asic | 0x80000000) self.femb_config.femb.write_reg(7, wib_asic | 0x80000000) self.femb_config.femb.write_reg(7, wib_asic) self.femb_config.femb.write_reg(7, wib_asic) self.femb_config.selectFemb(self.fembNum) #Enable Streaming self.femb_config.femb.write_reg(9, 9) self.femb_config.femb.write_reg(9, 9) time.sleep(0.1) #test firmware versions if self.femb_config.checkFirmwareVersion() == False: print( 'Error running doFembTest - Invalid firmware and/or register read error' ) return if self.femb_config.syncStatus != 0: print('Error running doFembTest - ADC SYNC failed') return if self.femb_config.spiStatus != 0: print('Error running doFembTest - ADC SPI failed') return #check if data streaming is working print("Checking data streaming") testData = self.write_data.femb.get_data_packets(1) if testData == None: print("Error running doFembTest - FEMB is not streaming data.") print(" Turn on and initialize FEMB UDP readout.") return if len(testData) == 0: print("Error running doFembTest - FEMB is not streaming data.") print(" Turn on and initialize FEMB UDP readout.") return print("Received data packet " + str(len(testData[0])) + " bytes long") #check for analysis executables if not self.cppfr.exists( 'test_measurements/fembTest/code/parseBinaryFile'): print('parseBinaryFile not found, run setup.sh') return print("SIMPLE MEASUREMENT - READOUT STATUS OK" + "\n") self.status_check_setup = 1 def record_data(self): if self.status_check_setup == 0: print("Please run check_setup method before trying to take data") return if self.status_record_data == 1: print( "Data already recorded. Reset/restat GUI to begin a new measurement" ) return #MEASUREMENT SECTION print("SIMPLE MEASUREMENT - RECORDING DATA") #wait to make sure HS link is back on after check_setup sleep(5) self.femb_config.printParameters() #setup output file and record data self.write_data.filename = self.outlabel + ".bin" print("Recording " + self.write_data.filename) isOpen = self.write_data.open_file() if isOpen == 0: print( "Error running doFembTest - Could not open output data file for writing, ending test" ) subrun = 0 #record data self.write_data.numpacketsrecord = 100 self.write_data.run = 0 self.write_data.runtype = 0 self.write_data.runversion = 0 asicCh = 0 for asic in range(0, 8, 1): self.femb_config.selectChannel(asic, asicCh) self.write_data.record_data(subrun, asic, asicCh) self.write_data.close_file() print("SIMPLE MEASUREMENT - DONE RECORDING DATA" + "\n") self.status_record_data = 1 def do_analysis(self): if self.status_record_data == 0: print("Please record data before analysis") return if self.status_do_analysis == 1: print("Analysis already complete") return #ANALYSIS SECTION print("SIMPLE MEASUREMENT - ANALYZING AND SUMMARIZING DATA") #parse binary self.cppfr.run("test_measurements/fembTest/code/parseBinaryFile", [self.write_data.data_file_path]) #run analysis program parseBinaryFile = self.outpathlabel + "-parseBinaryFile.root" call(["mv", "output_parseBinaryFile.root", parseBinaryFile]) self.cppfr.run( "test_measurements/fembTest/code/processNtuple_simpleMeasurement", [parseBinaryFile]) processNtupleFile = self.outpathlabel + "-processNtupleFile.root" call([ "mv", "output_processNtuple_simpleMeasurement.root", processNtupleFile ]) summaryPlot = self.outpathlabel + "-summaryPlot.png" call(["mv", "summaryPlot_simpleMeasurement.png", summaryPlot]) print("SIMPLE MEASUREMENT - DONE ANALYZING AND SUMMARIZING DATA" + "\n") self.status_do_analysis = 1 def archive_results(self): #if self.status_check_setup == 0 : # print("Check setup status is 0, not archiving data") # return #if self.status_do_analysis == 0: # print("Please analyze data before archiving results") # return if self.status_archive_results == 1: print("Results already archived") return #ARCHIVE SECTION print("SIMPLE MEASUREMENT - ARCHIVE") #add summary variables to output self.jsondict['femb'] = self.fembNum self.jsondict['filedir'] = str(self.write_data.filedir) self.jsondict['status_check_setup'] = str(self.status_check_setup) self.jsondict['status_record_data'] = str(self.status_record_data) self.jsondict['status_do_analysis'] = str(self.status_do_analysis) self.jsondict['status_archive_results'] = str(1) self.jsondict['syncStatus'] = str(self.femb_config.syncStatus) #dump results into json jsonFile = self.outpathlabel + "-results.json" with open(jsonFile, 'w') as outfile: json.dump(self.jsondict, outfile, indent=4) print("SIMPLE MEASUREMENT - DONE ARCHIVING" + "\n") self.status_archive_results = 1