Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

test_evt_tkr.py

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 TKR events
00011 """
00012 __facility__ = "Online"
00013 __abstract__ = "Test script for TKR"
00014 __author__   = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST I&T/Online"
00015 __date__     = ("$Date: 2005/05/17 23:42:18 $").split(' ')[1]
00016 __version__  = "$Revision: 1.8 $"
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.gGLT   import GGLT
00028 from LATTE.database.gPlumber import Plumber
00029 
00030 from LATTE.tests.apps.support.MiniGLTExample import *
00031 from LATTE.tests.apps.support.SimpleGasuExample import *
00032 
00033 import gc
00034 import os
00035 import time
00036 import logging as log
00037 
00038 lat = None
00039 tem = None
00040 
00041 # redefine SolicitedEngine
00042 class ZsupSolicitedEngine(TrgEngine):
00043   """This class defines an engine which reads out the detector
00044      whenever there is a solicited trigger.  Zero suppression is on.
00045      This engine is not prescaled.
00046   """
00047   def __init__(self):
00048     TrgEngine.__init__(self)
00049     self.__request = ZsupTrgReadout()
00050   def participate(self,conditionsValue):
00051     # This function relies on the programmer's knowledge that the
00052     # conditionsValue is a bitfield.
00053     cond = SolicitedCondition()
00054     if conditionsValue & cond.value():
00055       return True
00056     return False
00057   def prescale(self):
00058     return 0
00059   def request(self):
00060     return self.__request
00061 
00062 def test(cmd=None, debug=0, count=10000, disconnectOnExit=1, parse=1, lowlevel=0):
00063   global tem, glt
00064   gc.disable()
00065 
00066   log.getLogger().setLevel(log.DEBUG)
00067 
00068   options = Options(['server', 'schema'],
00069                     ['fswmsglevel', 'evtdebug'],
00070                     ['initforce', 'ocsverbose', 'nocommander'])
00071   try:
00072     options.parse()
00073   except Exception, msg:
00074     options.usage(str(msg))
00075     return
00076 
00077   if options.fswmsglevel is not None:
00078     msglevel = int(options.fswmsglevel)
00079   else:
00080     msglevel = 3
00081   verbose = (options.ocsverbose != None)
00082   force = (options.initforce != None)
00083   commander = not(options.nocommander != None)
00084 
00085   if cmd == None:
00086     cmd = CmdCli()
00087     cmd.connect(options.server)
00088 
00089   if options.evtdebug is not None:
00090     debug = options.evtdebug
00091   ec = EvtCli(debug)
00092   ec.connect(options.server, force)
00093 
00094   lat = GLAT(cmd)
00095   lat.readSchema(options.schema)
00096 
00097   xbrd = GXBRD(cmd)
00098   xbrd = xbrd.readSchema(options.schema)
00099 
00100   plumber = Plumber(lat, xbrd)
00101   plumber.initialize(msglevel, verbose, force, commander)
00102 
00103   lat.applyConfig()
00104 
00105   # Get a TEM instance
00106   if lat.TEMcnt() == 1:
00107     tem = lat.TEM[lat.TEM.keys()[0]]
00108   elif lat.TEMcnt() > 1:
00109     tem = lat.TEM.all()
00110   else:
00111     log.fatal("No TEM(s) found in the schema")
00112     if disconnectOnExit:
00113       cmd.disconnect()
00114     ec.disconnect()
00115     return -1
00116     
00117   try:
00118     lat.LCB.setEvtEnable(True)
00119   except Exception, e:
00120     log.error(e)
00121     raise    
00122 
00123   # TEM needs to be reset before DATA_MASKS can be set
00124   #tem.CMD_RESET = 1
00125 
00126   if lat.GEM is not None:
00127     trigger = SimpleGasuExample()
00128 
00129     trigger.engines().replaceEngine(0,ZsupSolicitedEngine())
00130     trigger.GEM(lat.GEM)
00131   else:
00132     glt = GGLT(cmd)
00133     glt.initialize()
00134     trigger = MiniGLTExample()
00135     trigger.GLT(glt)
00136   trigger.commit()
00137 
00138   trigger.disable()
00139 
00140   #
00141   # Configure TEM
00142   #
00143   # TEM config reg # set TEM timeout
00144   #tem.CONFIGURATION = 0
00145 
00146   #ccc = tem.allCCC()
00147   # enable output in our GCCCs
00148   # broadcast load of GCCC_REG_CONFIGURATION
00149   #ccc.CONFIGURATION = 0x80000000L
00150 
00151   #  disable all GCRCs in all GCCCs via broadcast
00152   #ccc.LAYER_MASK_0 = 0xFFFFFFFFL
00153   #ccc.LAYER_MASK_1 = 0xFFFFFFFFL
00154 
00155   # config TEM TKR calstrobe delay for ~ 5usec
00156   #tem.TKR_TRGSEQ = 0x3C
00157 
00158   # enable TKR, disable CAL, no diag #  0x1FF3 for diag
00159   # only enable GTCC 3
00160   #tem.DATA_MASKS = 0x0FF3
00161 
00162   tcc = tem.allTCC()
00163 
00164   # broadcast load of GTCC_REG_CONFIGURATION
00165   # enable controller output and set cable length to 1
00166   # 0xC0000000 is for one layer
00167   # 0x80000000 is for two layers
00168   #tcc.CONFIGURATION = 0xC0000000L
00169   #x_tcc = tem.downTCC(0)
00170   # enable all masks
00171   #tcc.INPUT_MASK = 0x0
00172 
00173   # set maximum event timeout
00174   #tcc.EVENT_TIMEOUTS = 0x03F
00175 
00176   #
00177   # Configure GTRCs
00178   #
00179 
00180   # our board is connected CC = 2, RC = 0 and CC = 3, RC = 0
00181   # reset GTRC # required before all triggers
00182 
00183   trc = tcc.allTRC()
00184 
00185   trc.CMD_RESET = 1
00186 
00187   # number of GTFE to readout left
00188   nGTFEsLeft  = 7
00189   nGTFEsRight = 0
00190 
00191   # max hits per GTRC # 31 max
00192   maxHits = 31
00193 
00194   enMask  = 0x6
00195 
00196   dLO = (enMask << 28) | ((nGTFEsRight << 7)& 0xF80) | (maxHits & 0x7F);
00197   print "dLO=", dLO, hex(dLO)
00198 
00199   # cable controller 2, readout controller 0
00200   tcc = tem.downTCC(2)
00201   trc = tcc.downTRC(1)
00202 
00203   trc.CSR = dLO
00204 
00205   dLO = (enMask << 28) | ((nGTFEsLeft << 7)& 0xF80) | (maxHits & 0x7F);
00206   print "dLO=", dLO, hex(dLO)
00207 
00208   # cable controller 3, readout controller 0
00209   tcc = tem.downTCC(3)
00210   trc = tcc.downTRC(1)
00211 
00212   trc.CSR = dLO
00213 
00214   #
00215   # Configure GTFEs
00216   #
00217 
00218   tfe = trc.allTFE()
00219   tfe.TRIG_MASK = 0x0
00220   tfe.DATA_MASK = 0x0
00221   tfe.CALIB_MASK = 0x0
00222   tfe.DAC = 0x00001902
00223   # configure front ends # all listen to left
00224   tfe.MODE = 0
00225   #tfe = trc.downTFE(0)
00226 
00227 # configure default DACs for threshold and calibration
00228 # Calibration DAC Range and Resolution
00229 # Low Range (B6=0):  DAC output voltage in mV = 1.57 + 1.53*DAC_Value
00230 # High Range (B6=1): DAC output voltage in mV = 15.0 + 14.6*DAC_Value
00231 # Discriminator Threshold DAC Range and Resolution
00232 # Low Range (B6=0):  DAC output voltage in mV = 4.5 + 4.5*DAC_Value
00233 # High Range (B6=1): DAC output voltage in mV = 12.9 + 12.9*DAC_Value
00234 
00235 
00236   # calRng = 1
00237   # thrRng = 0
00238   # calDAC = 60
00239   # thrDAC = 10
00240 
00241   tfe.DAC = 0x00001952  # based on the above Rng and DAC values
00242 
00243   # enable GTFE for data taking # all channels
00244   tfe.TRIG_MASK = 0xffffffffffffffff
00245   tfe.DATA_MASK = 0xffffffffffffffff
00246 
00247   # Cal strobe channels 4 and 48 only
00248   tfe.CALIB_MASK = 0x0001000000000010
00249 
00250   #~ #Mask of the following Registers
00251   #~ tfe = trc.downTFE(13)
00252   #~ tfe.DATA_MASK = 0x0L
00253   #~ tfe.CALIB_MASK = 0x0L
00254   #~ tfe.TRIG_MASK = 0x0L
00255 
00256   #~ tfe = trc.downTFE(14)
00257   #~ tfe.DATA_MASK = 0x0L
00258   #~ tfe.CALIB_MASK = 0x0L
00259   #~ tfe.TRIG_MASK = 0x0L
00260 
00261   #~ tfe = trc.downTFE(19)
00262   #~ #tfe.DATA_MASK = 0x0L
00263   #~ tfe.CALIB_MASK = 0x0L
00264   #~ tfe.TRIG_MASK = 0x0L
00265 
00266   #~ tfe = trc.downTFE(20)
00267   #~ #tfe.DATA_MASK = 0x0L
00268   #~ tfe.CALIB_MASK = 0x0L
00269   #~ tfe.TRIG_MASK = 0x0L
00270 
00271   trigger.enable()
00272 
00273   cnt=0
00274   ces=0
00275   start = time.time()
00276   for i in range(count):
00277     cnt=cnt+1
00278     trigger.solicit()
00279     if lowlevel==1:
00280       (header, ec.dat) = ec.read()
00281     else:
00282       ec.readEvent()
00283     if parse:
00284       ec.setCurrentContribution(ec.TEM0)
00285       if ec.getContributionStatus() == 0:
00286         ec.evDumpTKR()
00287     if cnt % 100 == 0: print cnt
00288     ces += len(ec.dat)
00289     #sleep(0.000300)
00290   end = time.time()
00291   et = end-start
00292   if et == 0: et = 0.000001
00293   print "Finished in %f seconds (%d events/second), average event size is %d" %(et,(cnt/et),(ces/cnt))
00294   if disconnectOnExit:
00295     cmd.disconnect()
00296   ec.disconnect()
00297 
00298 #if __name__ == '__main__':
00299 #  test()
00300 
00301 # 10/22/04
00302 #   server    : gitot / LCBD / XBRD based with TEM0 attached (Zero-Suppression on).
00303 #   teststand : COLUMBA
00304 #   event size: 96 bytes
00305 #     test():                     939 events/second
00306 #     test(parse=0):             1338 events/second
00307 #     test(lowlevel=1, parse=0): 1580 events/second
00308 # 05/17/05
00309 #   server    : gitot / LCBD / GASU based with TEM0 attached (Zero-Suppression on).
00310 #   teststand : COLUMBA
00311 #   event size: 176 bytes
00312 #     test():                     909 events/second
00313 #     test(parse=0):             1366 events/second
00314 #     test(lowlevel=1, parse=0): 1664 events/second

Generated on Fri Jul 21 13:26:32 2006 for LATTE R04-12-00 by doxygen 1.4.3