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

test_evt_exttrg.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 external trigger functionality.
00011 """
00012 __facility__ = "Online"
00013 __abstract__ = "Test script for external trigger"
00014 __author__   = "Jim Panetta <panetta@slac.stanford.edu> SLAC - GLAST I&T/Online"
00015 __date__     = ("$Date: 2004/11/18 18:31:39 $").split(' ')[1]
00016 __version__  = "$Revision: 1.2 $"
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.client.gEvtCli  import EvtCli
00025 from LATTE.database.gLAT   import GLAT
00026 from LATTE.database.gGLT   import GGLT
00027 from LATTE.database.gOCS   import GOCS
00028 
00029 from time import sleep
00030 import gc
00031 import os
00032 import time
00033 import logging as log
00034 
00035 
00036 from LATTE.tests.apps.support.SimpleGasuExample import *
00037 from LATTE.tests.apps.support.MiniGLTExample    import *
00038 
00039 tem = None
00040 
00041 # Define a GASU impl of an external trigger engine
00042 class GasuExtTrg(SimpleGasuExample):
00043   def __init__(self):
00044     SimpleGasuExample.__init__(self)
00045     self.__cond = GasuExtTrgCond()
00046     self.engines().replaceEngine(0, GasuExtTrgEngine())
00047   def conditions(self): return self.__cond
00048 
00049 class GasuExtTrgCond(TrgConditionsValue):
00050   def __init__(self):
00051     TrgConditionsValue.__init__(self)
00052   def external(self): return True
00053 
00054 class GasuExtTrgEngine(TrgEngine):
00055   def __init__(self):
00056     TrgEngine.__init__(self)
00057     self.__request = TrgReadout()
00058     cond = GasuExtTrgCond()
00059     self.__cv = cond.value()
00060   def participate(self,conditionsValue):
00061     if conditionsValue & self.__cv:
00062       return True
00063     return False
00064   def prescale(self):   return 0
00065   def request(self):    return self.__request
00066 
00067 # define a MiniGLT impl of an external trigger
00068 class MiniGltExtTrg(MiniGLTExample):
00069   def __init__(self):
00070     MiniGLTExample.__init__(self)
00071     self.__cond = MiniGltExtTrgCond()
00072     self.engines().replaceEngine(0, MiniGltTrgEngine())
00073   def conditions(self): return self.__cond
00074 
00075 class MiniGltExtTrgCond(MiniGLTTrgConditionsValue):
00076   def __init__(self):
00077     MiniGLTTrgConditionsValue.__init__(self)
00078   def external(self): return True
00079 
00080 class MiniGltTrgEngine(TrgEngine):
00081   def __init__(self):
00082     TrgEngine.__init__(self)
00083     self.__request = TrgReadout()
00084     cond = MiniGltExtTrgCond()
00085     self.__cv = cond.value()
00086   def participate(self,conditionsValue):
00087     if conditionsValue & self.__cv:
00088       return True
00089     return False
00090   def prescale(self):   return 0
00091   def request(self):    return self.__request
00092   
00093 
00094 def test(cmd=None, debug=0, disconnectOnExit=1, parse=1, lowlevel=0):
00095   global tem , glt
00096   gc.disable()
00097   
00098   print "Test of external trigger."
00099   print "External trigger should be triggering at ~100Hz"
00100   
00101   log.getLogger().setLevel(log.INFO)
00102 
00103   options = Options(['server', 'schema'], ['evtdebug'])
00104   try:
00105     options.parse()
00106   except Exception, msg:
00107     options.usage(str(msg))
00108     return
00109 
00110   if cmd == None:
00111     cmd = CmdCli()
00112     cmd.connect(options.server)
00113   lat = GLAT(cmd)
00114   lat.readSchema(options.schema)
00115   lat.applyConfig()
00116 
00117   try:
00118     lat.LCB.setEvtEnable(True)
00119   except Exception, e:
00120     log.error(e)
00121     raise
00122 
00123   if lat.GEM is not None:
00124     trigger = GasuExtTrg()
00125     trigger.GEM(lat.GEM)
00126   else:
00127     glt = GGLT(cmd)
00128     glt.initialize()
00129     trigger = MiniGltExtTrg()
00130     trigger.GLT(glt)
00131   trigger.commit()
00132 
00133   trigger.disable()
00134 
00135   if options.evtdebug is not None:
00136     debug = options.evtdebug
00137   ec = EvtCli(debug)
00138   ec.connect(options.server)
00139   ec.socket().settimeout(1)
00140   
00141   ocs = GOCS(cmd)
00142   # ocs.evtHandlerSetVerbosity(0xf)
00143   ocs.evtHandlerSendAll()
00144 
00145   # Make sure counters are reset
00146   trigger.triggerCounters().reset()
00147   
00148   # Take 1 second of events
00149   trigger.enable()
00150   time.sleep(1)
00151   trigger.disable()
00152   time.sleep(1)
00153   
00154   # get stats
00155   trgStats = trigger.triggerCounters().stats()
00156   nSent    = trgStats.sent()
00157   nDisc    = trgStats.discarded()
00158   nPre     = trgStats.prescaled()
00159 
00160   
00161   # loop over "sent"
00162   nSeen = 0
00163   for i in range(nSent):
00164     if lowlevel==1:
00165       (header, ec.dat) = ec.read()
00166     else:
00167       try:
00168         ec.readEvent()
00169       except IOError, e:
00170         pass
00171         print e
00172     if parse==1:
00173       ec.setCurrentContribution(ec.GEM)
00174       if ec.getContributionStatus() == 0:
00175         ec.evDumpGEM()
00176         if (ec.evt.gem.triggerSummary & 0x80):
00177           nSeen += 1
00178 
00179   if nSent != nSeen:
00180     print
00181     print "  !!!!FAILED!!!!"
00182     print "  nSent (%d) not equal to nSeen (%d)" % ( nSent, nSeen )
00183     print "  GEM stats: nDiscarded= %d" % (nDisc)
00184     print "             nPrescaled= %d" % (nPre )    
00185   else:
00186     print
00187     print "  TEST PASSED"    
00188   
00189   if disconnectOnExit:
00190     cmd.disconnect()
00191   ec.disconnect()
00192 
00193 if __name__ == '__main__':
00194   test()
00195 

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