00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2002 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 """Test script for taking AEM events 00011 """ 00012 __facility__ = "Online" 00013 __abstract__ = "Test script for AEM" 00014 __author__ = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST I&T/Online" 00015 __date__ = ("$Date: 2005/05/17 23:12:40 $").split(' ')[1] 00016 __version__ = "$Revision: 1.4 $" 00017 __release__ = "$Name: R04-12-00 $" 00018 __credits__ = "SLAC" 00019 00020 import LATTE.copyright_SLAC 00021 00022 from LATTE.client.gOptions import Options 00023 from LATTE.client.gCmdCli import CmdCli 00024 from LATTE.database.gLAT import GLAT 00025 from LATTE.database.gXBR import GXBRD 00026 from LATTE.client.gEvtCli import EvtCli 00027 from LATTE.database.gPlumber import Plumber 00028 00029 from time import sleep 00030 import time 00031 import os 00032 import gc 00033 00034 from LATTE.tests.apps.support.SimpleGasuExample import * 00035 00036 00037 aem = None 00038 glt = None 00039 00040 def test(cmd=None, debug=0, count=10000, disconnectOnExit=1, parse=1, lowlevel=0): 00041 global aem, glt, ec 00042 gc.disable() 00043 00044 options = Options(['server', 'schema'], 00045 ['fswmsglevel', 'evtdebug'], 00046 ['initforce', 'ocsverbose', 'nocommander']) 00047 try: 00048 options.parse() 00049 except Exception, msg: 00050 options.usage(str(msg)) 00051 return 00052 00053 if options.fswmsglevel is not None: 00054 msglevel = int(options.fswmsglevel) 00055 else: 00056 msglevel = 3 00057 verbose = (options.ocsverbose != None) 00058 force = (options.initforce != None) 00059 commander = not(options.nocommander != None) 00060 00061 if cmd == None: 00062 cmd = CmdCli() 00063 cmd.connect(options.server) 00064 00065 if options.evtdebug is not None: 00066 debug = options.evtdebug 00067 ec = EvtCli(debug) 00068 ec.connect(options.server, force) 00069 00070 lat = GLAT(cmd) 00071 lat.readSchema(options.schema) 00072 00073 xbrd = GXBRD(cmd) 00074 xbrd = xbrd.readSchema(options.schema) 00075 00076 plumber = Plumber(lat, xbrd) 00077 plumber.initialize(msglevel, verbose, force, commander) 00078 00079 lat.applyConfig() 00080 00081 try: 00082 lat.LCB.setEvtEnable(True) 00083 except Exception, e: 00084 log.error(e) 00085 raise 00086 00087 trigger = SimpleGasuExample() 00088 trigger.GEM(lat.GEM) 00089 trigger.commit() 00090 00091 aem = lat.downAEM() 00092 00093 arc0 = aem.downARC(11) 00094 arc0.cmd_reset = 1 00095 00096 # configure the AEM 00097 aem.configuration = 0x208ff 00098 00099 # The FREE-sim simulates 4 ADCs with fixed outputs of 1112, 1113, 1114, 1115 (decimal). 00100 # The FREE-sim simulates 4 ADCs with fixed outputs of 0x458, 0x459, 0x45a, 0x45b (hex). 00101 # adjust the PHA thresholds to turn these on/off. 00102 00103 # config all PHAs on 00104 00105 thresh_on = 0x20 00106 thresh_off = 0xFFF 00107 00108 arc0.PHA_THRESHOLD_0 = thresh_on 00109 arc0.PHA_THRESHOLD_1 = thresh_on 00110 arc0.PHA_THRESHOLD_2 = thresh_on 00111 arc0.PHA_THRESHOLD_3 = thresh_on 00112 arc0.PHA_THRESHOLD_4 = thresh_on 00113 arc0.PHA_THRESHOLD_5 = thresh_on 00114 arc0.PHA_THRESHOLD_6 = thresh_on 00115 arc0.PHA_THRESHOLD_7 = thresh_on 00116 arc0.PHA_THRESHOLD_8 = thresh_on 00117 arc0.PHA_THRESHOLD_9 = thresh_on 00118 arc0.PHA_THRESHOLD_10 = thresh_on 00119 arc0.PHA_THRESHOLD_11 = thresh_on 00120 arc0.PHA_THRESHOLD_12 = thresh_on 00121 arc0.PHA_THRESHOLD_13 = thresh_on 00122 arc0.PHA_THRESHOLD_14 = thresh_on 00123 arc0.PHA_THRESHOLD_15 = thresh_on 00124 arc0.PHA_THRESHOLD_16 = thresh_on 00125 arc0.PHA_THRESHOLD_17 = thresh_on 00126 arc0.veto_width = 5 00127 00128 # set MAX_PHA 00129 arc0.MAX_PHA = 18 00130 00131 # set PHA ENABLE bits 00132 arc0.PHA_EN_0 = 0xffff 00133 arc0.PHA_EN_1 = 0x3 00134 00135 # set VETO ENABLE bits 00136 arc0.VETO_EN_0 = 0xffff 00137 arc0.VETO_EN_1 = 0x3 00138 00139 afeb = arc0.allAFE() 00140 afeb.CONFIGURATION = 0x0032 00141 afeb.VETO_DAC = 0x20 00142 afeb.HLD_DAC = 0x30 00143 afeb.TCI_DAC = 0x20 00144 afeb.bias_dac = 3 00145 00146 aem.TRGSEQ = 0x5f 00147 00148 trigger.enable() 00149 00150 cnt=0 00151 ces=0 00152 start = time.time() 00153 for i in range(count): 00154 cnt+=1 00155 trigger.solicit() 00156 00157 if lowlevel==1: 00158 (header, ec.dat) = ec.read() 00159 else: 00160 ec.readEvent() 00161 00162 if parse: 00163 if ec.setCurrentContribution(ec.AEM) != -1: 00164 ec.evDumpEventAEM() 00165 # print "AEM Veto Hit Vectors:" 00166 # j = 0 00167 # for hitVect in ec.evt.aem.vetoHitVectors: 00168 # print "\tCable %2d Raw Data 0x%05x" % (j, hitVect) 00169 # j+=1 00170 # print "\nAEM Accept Hit Vectors:" 00171 # j = 0 00172 # for hitVect in ec.evt.aem.acceptHitVectors: 00173 # print "\tCable %2d Raw Data 0x%05x" % (j, hitVect) 00174 # j+=1 00175 # print "\nAEM PHA Values:" 00176 # j = 0 00177 # for (cbl, phas) in ec.evt.aem.PHA.items(): 00178 # for pha in phas: 00179 # print "\tCable: %02d - PHA Value: 0x%04x" % (cbl, pha.ui) 00180 if cnt % 500 == 0: print cnt 00181 ces = ces + len(ec.dat) 00182 end = time.time() 00183 et = end-start 00184 if et == 0: et = 0.000001 00185 print "Finished in %f seconds (%d events/second), average event size is %d" %(et,(cnt/et),(ces/cnt)) 00186 00187 if disconnectOnExit == 1: 00188 cmd.disconnect() 00189 00190 ec.disconnect() 00191 00192 #if __name__ == '__main__': 00193 # test()