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

test_evt_cal.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 measuring event taking throughput.
00011 """
00012 __facility__ = "Online"
00013 __abstract__ = "Test script for CAL"
00014 __author__   = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST I&T/Online"
00015 __date__     = ("$Date: 2005/05/17 23:37:10 $").split(' ')[1]
00016 __version__  = "$Revision: 2.16 $"
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.gXBR     import GXBRD
00027 from LATTE.database.gGLT     import GGLT
00028 from LATTE.database.gPlumber import Plumber
00029 
00030 
00031 from time import sleep
00032 import gc
00033 import os
00034 import time
00035 import logging as log
00036 
00037 from LATTE.trigger.TrgUsingTiles      import TrgUsingTiles
00038 from LATTE.trigger.NullObjects        import NoInputsEnabled
00039 from LATTE.trigger.rcTrgFunctions     import rcTrgEngines
00040 from LATTE.trigger.TrgEngines         import *
00041 from LATTE.trigger.rcTrgMiniGLT       import rcTrgMiniGLT
00042 from LATTE.trigger.TrgMiniGLT         import MiniGLTTrgConditionsValue
00043 
00044 from LATTE.tests.apps.support.SimpleGasuExample import *
00045 
00046 
00047 tem = None
00048 
00049 
00050 class MiniGLTExample(rcTrgMiniGLT):
00051   """\brief MiniTower example interface to MiniGLT
00052   """
00053   def __init__(self):
00054     """\brief AcdTriggerExample constructor
00055     """
00056     rcTrgMiniGLT.__init__(self)
00057     self.__engines      = MiniGLTTrgEngines()
00058     self.__conditions   = MiniGLTSolicitedCondition()
00059 
00060   def engines(self):
00061     """\brief Implementation of engines 'pure virtual' method from TrgAbstract
00062     """
00063     return self.__engines
00064 
00065   def conditions(self):
00066     """\brief Implementation of conditions 'pure virtual' method from TrgAbstract
00067     """
00068     return self.__conditions
00069 
00070 # implementaions of user-level trigger classes
00071 class MiniGLTTrgEngines(rcTrgEngines):
00072   def __init__(self):
00073     rcTrgEngines.__init__(self)
00074     # There are two engines in the MiniGLT.
00075     # 0) User defined engine
00076     # 15) Marker engine
00077 
00078     eng = MiniGLTSolicitedEngine()
00079     self.replaceEngine(0,eng)
00080 
00081 class MiniGLTSolicitedEngine(TrgEngine):
00082   """This class defines an engine which reads out the detector
00083      whenever there is a solicited trigger.
00084      This engine is not prescaled.
00085   """
00086   def __init__(self):
00087     TrgEngine.__init__(self)
00088     self.__request = ZsupTrgInjectChargeReadout()
00089   def participate(self,conditionsValue):
00090     # This function relies on the programmer's knowledge that the
00091     # conditionsValue is a bitfield.
00092     cond = MiniGLTSolicitedCondition()
00093     condValue = cond.value()
00094     if conditionsValue & condValue:
00095       return True
00096     return False
00097   def prescale(self):
00098     return 0
00099   def request(self):
00100     return self.__request
00101 
00102 class MiniGLTSolicitedCondition(MiniGLTTrgConditionsValue):
00103   """ Define a condition where only the CNO trigger is asserted
00104   """
00105   def __init__(self):
00106     MiniGLTTrgConditionsValue.__init__(self)
00107   def solicited(self):
00108     return True
00109 
00110 class ZsupTrgInjectChargeReadout(TrgInjectChargeReadout):
00111   """\brief ZsupTrgReadout class definition
00112 
00113   Directs a module to send to its Front-End Electronics a command sequence
00114   which is composed only of the TACK command. This command will trigger
00115   a readout of the module's Front-End Electronics.
00116   Zero suppression is turned on.
00117   """
00118   def __init__(self):
00119     """\brief TrgReadout constructor
00120     """
00121     TrgInjectChargeReadout.__init__(self)
00122 
00123   def zeroSuppress(self):
00124     return True
00125 
00126 # redefine SolicitedEngine
00127 class ZsupSolicitedEngine(TrgEngine):
00128   """This class defines an engine which reads out the detector
00129      whenever there is a solicited trigger.  Zero suppression is on.
00130      This engine is not prescaled.
00131   """
00132   def __init__(self):
00133     TrgEngine.__init__(self)
00134     self.__request = ZsupTrgReadout()
00135   def participate(self,conditionsValue):
00136     # This function relies on the programmer's knowledge that the
00137     # conditionsValue is a bitfield.
00138     cond = SolicitedCondition()
00139     if conditionsValue & cond.value():
00140       return True
00141     return False
00142   def prescale(self):
00143     return 0
00144   def request(self):
00145     return self.__request
00146 
00147 
00148 
00149 def test(cmd=None, debug=0, count=10000, disconnectOnExit=1, parse=1, lowlevel=0):
00150   global tem , glt
00151   gc.disable()
00152 
00153   log.getLogger().setLevel(log.DEBUG)
00154 
00155   options = Options(['server', 'schema'],
00156                     ['fswmsglevel', 'evtdebug'],
00157                     ['initforce', 'ocsverbose', 'nocommander'])
00158   try:
00159     options.parse()
00160   except Exception, msg:
00161     options.usage(str(msg))
00162     return
00163 
00164   if options.fswmsglevel is not None:
00165     msglevel = int(options.fswmsglevel)
00166   else:
00167     msglevel = 3
00168   verbose = (options.ocsverbose != None)
00169   force = (options.initforce != None)
00170   commander = not(options.nocommander != None)
00171 
00172   if cmd == None:
00173     cmd = CmdCli()
00174     cmd.connect(options.server)
00175 
00176   if options.evtdebug is not None:
00177     debug = options.evtdebug
00178   ec = EvtCli(debug)
00179   ec.connect(options.server, force)
00180 
00181   lat = GLAT(cmd)
00182   lat.readSchema(options.schema)
00183 
00184   xbrd = GXBRD(cmd)
00185   xbrd = xbrd.readSchema(options.schema)
00186 
00187   plumber = Plumber(lat, xbrd)
00188   plumber.initialize(msglevel, verbose, force, commander)
00189 
00190   lat.applyConfig()
00191 
00192   # Get a TEM instance
00193   if lat.TEMcnt() == 1:
00194     tem = lat.TEM[lat.TEM.keys()[0]]
00195   elif lat.TEMcnt() > 1:
00196     tem = lat.TEM.all()
00197   else:
00198     log.fatal("No TEM(s) found in the schema")
00199     if disconnectOnExit:
00200       cmd.disconnect()
00201     ec.disconnect()
00202     return -1
00203     
00204   try:
00205     lat.LCB.setEvtEnable(True)
00206   except Exception, e:
00207     log.error(e)
00208     raise    
00209 
00210   # reset the TEM since we are going to modify DATA_MASKS
00211   #tem.CMD_RESET = 1
00212 
00213   if lat.GEM is not None:
00214     trigger = SimpleGasuExample()
00215 
00216     trigger.engines().replaceEngine(0,ZsupSolicitedEngine())
00217     trigger.GEM(lat.GEM)
00218   else:
00219     glt = GGLT(cmd)
00220     glt.initialize()
00221     trigger = MiniGLTExample()
00222     trigger.GLT(glt)
00223   trigger.commit()
00224 
00225   #glt.disableMask()
00226   trigger.disable()
00227 
00228   # clear TEM stats reg
00229   tem.COMMAND_RESPONSE = 0
00230 
00231   # clear TEM status reg
00232   tem.STATUS = 0
00233 
00234   # enable CAL, disable TKR, no diag #  0x10FF for diag
00235   #tem.DATA_MASKS = 0x10FF
00236 
00237   # TEM config reg # set TEM timeout
00238   #tem.CONFIGURATION = 0
00239   #tem.CAL_TRGSEQ = 0x40
00240 
00241   #status = gTEMread( __GT, temId, TEM_REG_CONFIGURATION, &payload);
00242   #printf("tem config reg = 0x%08x\n", payload);
00243 
00244   # enable output in our GCCCs
00245   # broadcast load of GCCC_REG_CONFIGURATION
00246 
00247   #bcast_ccc = tem.allCCC()
00248   #bcast_ccc.CONFIGURATION = 0x80000000L
00249 
00250   #  disable all GCRCs in all GCCCs via broadcast # GCCC_REG_LAYER_MASK_0, GCCC_REG_LAYER_MASK_1
00251   #bcast_ccc.LAYER_MASK_0 = 0xFFFFFFFFL
00252   #bcast_ccc.LAYER_MASK_1 = 0xFFFFFFFFL
00253   #ccc2 = tem.downCCC(2) # O$GCCC_02
00254   #ccc2.LAYER_MASK_1 = 0x3BFD3FFFL
00255 
00256   # large timeouts for all GCCCs
00257   # broadcast load of GCCC_REG_EVENT_TIMEOUTS
00258   #bcast_ccc.EVENT_TIMEOUTS = 0x0
00259   #status = gGCCCread( __GT, temId, 1, GCCC_REG_EVENT_TIMEOUTS, &payload);
00260   #printf("gccc register event timeouts = 0x%08x\n", payload);
00261 
00262 
00263 #  glt.INTERNAL_TRG = 0
00264 
00265 #  glt.DESTINATION = 5
00266 #  glt.MARKER = 0
00267 #  glt.ZERO_SUPPRESS = 1
00268 #  glt.FOUR_RANGE_READOUT = 0
00269 #  glt.TACK = 1
00270 #  glt.CAL_STROBE = 0
00271 
00272   trigger.enable()
00273 
00274   cnt=0
00275   ces=0
00276   start = time.time()
00277   for i in range(count):
00278     cnt=cnt+1
00279     trigger.solicit()
00280     if lowlevel==1:
00281       (header, ec.dat) = ec.read()
00282     else:
00283       ec.readEvent()
00284     if parse==1:
00285       ec.setCurrentContribution(ec.TEM0)
00286       if ec.getContributionStatus() == 0:
00287         ec.evDumpCAL_LogAccepts()
00288         ec.evDumpCAL_Logs()
00289     #~ #print ""
00290     #~ #ec.evDumpTKR()
00291     #~ ec.evDumpTEM_Error()
00292     #~ ec.evDumpDiagnostic()
00293     #~ sum = ec.evt.summary
00294     #~ ec.evDumpSummary()
00295     if cnt % 100 == 0: print cnt
00296     ces = ces + len(ec.dat)
00297     #sleep(0.000300)
00298   end = time.time()
00299   et = end-start
00300   if et == 0: et = 0.000001
00301   print "Finished in %f seconds (%d events/second), average event size is %d" %(et,(cnt/et),(ces/cnt))
00302   if disconnectOnExit:
00303     cmd.disconnect()
00304   ec.disconnect()
00305 
00306 #if __name__ == '__main__':
00307 #  test()
00308 
00309 # Benchmark results
00310 # 9/7/04
00311 #   server    : gitot
00312 #   teststand : COLUMBA
00313 #   event size: 80 bytes
00314 #     test():                    1327 events/second
00315 #     test(parse=0):             1491 events/second
00316 #     test(lowlevel=1, parse=0): 1823 events/second
00317 #   server    : localhost
00318 #   teststand : COLUMBA
00319 #   event size: 80 bytes
00320 #     test():                    1272 events/second
00321 #     test(parse=0):             2735 events/second
00322 #     test(lowlevel=1, parse=0): 4384 events/second
00323 # 9/30/04
00324 #   server    : gitot / GASU based with TEM0 attached.
00325 #   teststand : COLUMBA
00326 #   event size: 432 bytes
00327 #     test():                     440 events/second -- Note the slow performance is due to
00328 #                                                   -- increased event size and no zero-suppression
00329 #     test(parse=0):             1221 events/second
00330 #     test(lowlevel=1, parse=0): 1400 events/second
00331 #   server    : gitot / GASU based with TEM0 attached (Zero-Suppression on).
00332 #   teststand : COLUMBA
00333 #   event size: 304 bytes
00334 #     test():                    1035 events/second
00335 #     test(parse=0):             1285 events/second
00336 #     test(lowlevel=1, parse=0): 1485 events/second
00337 # 10/19/04
00338 #   server    : gitot / LCBD / GASU based with TEM0 attached (Zero-Suppression on).
00339 #   teststand : COLUMBA
00340 #   event size: 304 bytes
00341 #     test():                     945 events/second
00342 #     test(parse=0):             1153 events/second
00343 #     test(lowlevel=1, parse=0): 1344 events/second
00344 # 10/22/04
00345 #   server    : gitot / LCBD / XBRD based with TEM0 attached (Zero-Suppression on).
00346 #   teststand : COLUMBA
00347 #   event size: 80 bytes
00348 #     test():                    1084 events/second
00349 #     test(parse=0):             1327 events/second
00350 #     test(lowlevel=1, parse=0): 1576 events/second
00351 # 01/19/05
00352 #   server    : gitot / LCBD / GASU based with TEM0 attached (Zero-Suppression on).
00353 #               phase3 (schema driven configuration)
00354 #   teststand : COLUMBA
00355 #   event size: 304 bytes
00356 #     test():                    1023 events/second
00357 #     test(parse=0):             1301 events/second
00358 #     test(lowlevel=1, parse=0): 1503 events/second
00359 # 05/17/05
00360 #   server    : gitot / LCBD / GASU based with TEM0 attached (Zero-Suppression on).
00361 #               schema: calGasuSchemaPri.xml
00362 #   teststand : COLUMBA
00363 #   event size: 304 bytes
00364 #     test():                    1023 events/second
00365 #     test(parse=0):             1321 events/second
00366 #     test(lowlevel=1, parse=0): 1602 events/second

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