00001 #!/usr/bin/env 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 __facility__ = "Online" 00011 __abstract__ = "Sweep handler class" 00012 __author__ = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = ("$Date: 2005/03/04 21:32:00 $").split(' ')[1] 00014 __version__ = "$Revision: 2.13 $" 00015 __release__ = "$Name: R04-12-00 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 import sys 00021 00022 from LATTE.database import gLAT 00023 from LATTE.client import gException 00024 00025 class LATsweep(object): 00026 """Saves the current values of the registers, sets the TEM to a 00027 valid and known state for reliable event data taking. Triggers the event and 00028 then restores the registers to their prior values. This is done to make sure 00029 the sweep events that are retrieved from the TEM are good events. 00030 00031 \param lat The LAT object hierarchy 00032 \param trigger The trigger object 00033 \param sweepEvent Event() object passed to the trigger 00034 00035 """ 00036 00037 def __init__(self, lat, trigger, shut): 00038 self.__lat = lat 00039 self.__trigger = trigger 00040 self.__shut = shut 00041 00042 def shut(self, sweepEvent, progress = None): 00043 # Disable the trigger since we are going to access registers 00044 self.__trigger.disable() 00045 00046 # Use a temporary LAT hierarchy in case the current lat 00047 # doesn't define what we need to access. 00048 tempLAT = gLAT.GLAT(self.__lat.client()) 00049 tkrTimeouts = {} 00050 tkrConfig = {} 00051 calConfig = {} 00052 for (temId, tem) in self.__lat.TEM.items(): 00053 try: 00054 tem.configuration # Check to see if this TEM really exists 00055 tempTEM = tempLAT._GLAT__addTEM(temId) 00056 except gException.LATInterfaceException: 00057 if sys.exc_info()[1].errstr()[0] in ('LCB_RTOERR', 'LCBD_RTOERR') \ 00058 and self.__lat.getDeclarations()['options']['ignorehardwaretimeouts']: 00059 continue 00060 else: 00061 raise gException.LATInterfaceException(sys.exc_info()[1].status) 00062 00063 # Save the configuration register values of the CCCs and TCCCs 00064 # that are defined in the schema 00065 tkrConfig[temId] = {} 00066 tkrTimeouts[temId] = {} 00067 for cc in range(8): 00068 tempTCC = tempTEM._GTEM__addTCC(cc) 00069 timeouts = tempTCC.event_timeouts 00070 if timeouts != 0: 00071 tkrTimeouts[temId][cc] = timeouts 00072 tkrConfig[temId][cc] = tempTCC.configuration 00073 calConfig[temId] = {} 00074 for cc in range(4): 00075 tempCCC = tempTEM._GTEM__addCCC(cc) 00076 calConfig[temId][cc] = tempCCC.configuration 00077 # Broadcast to all TEMS 00078 if self.__lat.TEMcnt() > 0: 00079 tempTEMall = tempLAT._GLAT__addTEM(255) 00080 allTCC = tempTEMall._GTEM__addTCC(255) 00081 allTCC.event_timeouts = (1L << 14) - 1 00082 allTCC.configuration = (1L << 31) 00083 tempTEMall._GTEM__addCCC(255).configuration = (1L << 31) 00084 # Put back the timeouts that werent zero. 00085 for temId in tkrTimeouts.keys(): 00086 for cc in tkrTimeouts[temId]: 00087 tempLAT.TEM[temId].TCC[cc].event_timeouts = tkrTimeouts[temId][cc] 00088 # Put back the configuration values that we saved ORing with (1<<31) 00089 for temId in tkrConfig.keys(): 00090 tempTEM = tempLAT.TEM[temId] 00091 for cc in tkrConfig[temId]: 00092 tempTEM.TCC[cc].configuration = (tkrConfig[temId][cc] | (1L << 31)) 00093 for cc in calConfig[temId]: 00094 tempTEM.CCC[cc].configuration = (calConfig[temId][cc] | (1L << 31)) 00095 00096 #self.__trigger._shut(sweepEvent, progress) 00097 swept = self.__shut(sweepEvent, progress) 00098 00099 # Finally restore the configuration register values to their initial settings. 00100 for temId in tkrConfig.keys(): 00101 tempTEM = tempLAT.TEM[temId] 00102 for cc in tkrConfig[temId].keys(): 00103 tempTEM.TCC[cc].configuration = tkrConfig[temId][cc] 00104 for cc in calConfig[temId].keys(): 00105 tempTEM.CCC[cc].configuration = calConfig[temId][cc] 00106 00107 return swept