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

rcTrgMiniGLT.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2004
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__ = "GLAST LAT Coincidence based Trigger System Interface classes"
00012 __author__   = "Jim Panetta <panetta@slac.stanford.edu> SLAC - GLAST I&T"
00013 __date__     = "2/14/04"
00014 __version__  = "$Revision: 2.8 $"
00015 __release__  = "$Name: R04-12-00 $"
00016 __credits__  = "SLAC"
00017 
00018 import LATTE.copyright_SLAC
00019 
00020 """rcTrgMiniGLT:
00021 This class implements a 'threaded' model for enabling/disabling the trigger
00022 """
00023 
00024 from TrgMiniGLT   import TrgMiniGLT
00025 from threading    import Event
00026 import logging
00027 
00028 class rcTrgMiniGLT(TrgMiniGLT):
00029   """\brief rcTrgMiniGLT class definition
00030   This class implements a 'threaded' model for enabling/disabling the trigger
00031   """
00032   __SWEEP_MARKER     = 5               # Arbitrary marker value for recognizing
00033                                        #   when the event pipeline is flushed
00034   __SWEEP_TMO        = 3.0             # Sweep timeout in floating point seconds
00035   def __init__(self):
00036     """\brief rcTrgGem constructor
00037     """
00038     self.__triggersEnabled = Event()
00039 
00040     TrgMiniGLT.__init__(self)                 # do this last
00041     self.__cacheMask       = None
00042 
00043   def commit(self):
00044     """\brief public commit function
00045     This function commits the configuration defined by this
00046     TrgGem object to the hardware.  It does *all* the registers.
00047     This function should never be called by anyone other than Run Control.
00048     """
00049     self._TrgMiniGLT__commit()
00050 
00051   def waitForMaskEnable(self, tmo = None):
00052     """Waits until the enableMask() method is called.
00053     This is usually needed by non-self-triggering scripts where
00054     the _commandSynch thread needs to wait until RunControl
00055     actually enables the mask before continuing.
00056 
00057     \param tmo  Optional parameter giving the wait timeout in seconds
00058     """
00059     self.GLT().waitForMaskEnable(tmo)
00060 
00061   def getEnableTime(self):
00062     """ Returns the VxWorks timestamp at the time the triggers are enabled
00063 
00064     \return Trigger enable time
00065     """
00066     return self.GLT().getEnableTime()
00067 
00068   def getDisableTime(self):
00069     """ Returns the VxWorks timestamp at the time the triggers are disabled
00070 
00071     \return Trigger disable time
00072     """
00073     return self.GLT().getDisableTime()
00074 
00075   def getTimeStamp(self):
00076     """ Returns the VxWorks timestamp for the last time a self-trigger
00077         was asserted.
00078     \return Trigger timestamp
00079     """
00080     return self.GLT().regs['CMD_SELF_TRIGGER'].getTimeStamp()
00081 
00082   def sweepOnShut(self):
00083     """ Returns whether or not shut() does a sweep event.  Default true.
00084     \return a boolean
00085     """
00086     return True
00087 
00088   ############### Pure virtual function reimplementation
00089 
00090   def enable(self, newMask=None):
00091     """Re-implementation of the enable() function to take advantage
00092     of threading and timestamps
00093 
00094     Adds an argument to deal with several weird masking problems
00095     Only rcTransitions should use the above argument
00096     """
00097     if self.conditions() is not None:
00098       outMask = ~self.conditions().value()          # remember the MiniGLT has ~logic
00099     else:
00100       raise AssertionError, "Attempting to enable a TrgConditionsValue of None"
00101 
00102     if newMask is not None:
00103       self.__cacheMask = newMask
00104 
00105     if self.__cacheMask is not None:
00106       outMask = self.__cacheMask
00107 
00108     self.GLT().MASK = outMask
00109     self.GLT().enableMask()
00110 
00111   def disable(self):
00112     """Re-implementation of the disable() function to take advantage
00113     of threading and timestamps
00114     """
00115     self.GLT().disableMask()
00116 
00117   def shut(self, sweepEvent, progress = None):
00118     """Re-implementation of the shut function to take advantage of the
00119     fact that in rcTrgMiniGLT, trigger engine 0 is reserved for the marker.
00120 
00121     \param sweepEvent: A sweep Event() defined by runControl
00122     \param progress:   An optional function that returns a non-zero value when
00123                        when events are passing through the system.  If omitted
00124                        a fixed timeout is used.
00125     """
00126 
00127     glt = self.GLT()
00128 
00129     #0) disable triggers
00130     if not glt.triggersDisabled():
00131       enabled = True
00132     else:
00133       enabled = False
00134     goodSolicit  = self.solicit
00135     self.solicit = self.__falseSolicit
00136 
00137     self.disable()
00138     sweepEvent.clear()
00139 
00140     #1) Set up marker logic
00141     mask           = glt.MASK           # Cache Mask, CalStrobe and Tack
00142     calStrobe      = glt.CAL_STROBE
00143     tack           = glt.TACK
00144     zeroSuppress   = glt.ZERO_SUPPRESS
00145     fourRange      = glt.FOUR_RANGE_READOUT
00146     marker         = glt.MARKER
00147 
00148     glt.MASK       = TrgMiniGLT._TrgMiniGLT__SOLICIT_MASK # Enable internal trigger only
00149     glt.MARKER     = rcTrgMiniGLT.__SWEEP_MARKER          # Signal that we're sweeping
00150     glt.CAL_STROBE = 0                  # Don't inject charge
00151     glt.TACK       = 1                  # Force a readout
00152     glt.ZERO_SUPPRESS       = 1         # Yes to zero suppression
00153     glt.FOUR_RANGE_READOUT  = 0         # No to four range readout
00154 
00155     #2) enable and solicit
00156     glt.enableMask()
00157     self.waitForMaskEnable()
00158     self.GLT().CMD_SELF_TRIGGER = 1     # Solicit a trigger
00159 
00160     #3) Block until the sweep is detected by rcTransitions then disable triggers
00161     tmo = rcTrgMiniGLT.__SWEEP_TMO
00162     while (tmo > 0.0):
00163       if sweepEvent.isSet():  break
00164       sweepEvent.wait(0.5)
00165       if progress is not None:
00166         if progress() != 0:
00167           tmo = rcTrgMiniGLT.__SWEEP_TMO
00168           continue
00169       tmo -= 0.5
00170     if tmo <= 0:
00171       sweepEvent.set()
00172       logging.fatal("Trigger sweep timed out before all events were drained")
00173       return False
00174     self.disable()
00175 
00176     #4) Put the original contents of scheduler 0x40 back, and put the TAM back
00177     glt.CAL_STROBE         = calStrobe
00178     glt.TACK               = tack
00179     glt.MARKER             = marker
00180     glt.ZERO_SUPPRESS      = zeroSuppress
00181     glt.FOUR_RANGE_READOUT = fourRange
00182     glt.MASK               = mask
00183 
00184     #5) Put the trigger conditions back
00185     if enabled:
00186       glt.enableMask()
00187     self.solicit = goodSolicit
00188     
00189     return True
00190 
00191 
00192   def __falseSolicit(self):
00193     pass
00194 
00195 

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