psana_examples/src/dump_evr.py

Go to the documentation of this file.
00001 #--------------------------------------------------------------------------
00002 # File and Version Information:
00003 #  $Id: dump_evr.py 6920 2013-10-07 22:09:39Z salnikov@SLAC.STANFORD.EDU $
00004 #
00005 # Description:
00006 #  Psana user analysis module dump_evr...
00007 #
00008 #------------------------------------------------------------------------
00009 
00010 """Psana python module which dumps EVR data.
00011 
00012 This software was developed for the LCLS project.  If you use all or 
00013 part of it, please give an appropriate acknowledgment.
00014 
00015 @version $Id: dump_evr.py 6920 2013-10-07 22:09:39Z salnikov@SLAC.STANFORD.EDU $
00016 
00017 @author Andy Salnikov
00018 """
00019 
00020 #------------------------------
00021 #  Module's version from SVN --
00022 #------------------------------
00023 __version__ = "$Revision: 6920 $"
00024 # $Source$
00025 
00026 #--------------------------------
00027 #  Imports of standard modules --
00028 #--------------------------------
00029 import sys
00030 import logging
00031 
00032 #-----------------------------
00033 # Imports for other modules --
00034 #-----------------------------
00035 from psana import *
00036 
00037 #----------------------------------
00038 # Local non-exported definitions --
00039 #----------------------------------
00040 
00041 def _dumpfields(obj, fields):
00042     """ generic method to dump values of object attributes """
00043     return ' '.join(["{0}={1}".format(f, getattr(obj, f)()) for f in fields])
00044 
00045 
00046 def _pulseConfigV0(i, cfg):
00047     fields = ['pulse', 'polarity', 'prescale', 'delay', 'width']
00048     return "  pulse config #{0}: {1}".format(i, _dumpfields(cfg, fields))
00049 
00050 def _pulseConfigV3(i, cfg):
00051     fields = ['pulseId', 'polarity', 'prescale', 'delay', 'width']
00052     return "  pulse config #{0}: {1}".format(i, _dumpfields(cfg, fields))
00053 
00054 def _pulseConfig(i, cfg):
00055     if isinstance(cfg, EvrData.PulseConfig): return _pulseConfigV0(i, cfg)
00056     if isinstance(cfg, EvrData.PulseConfigV3): return _pulseConfigV3(i, cfg)
00057 
00058 
00059 def _outputMapConfigV0(i, cfg):
00060     fields = ['source', 'source_id', 'conn', 'conn_id', 'map']
00061     return "  output config #{0}: {1}".format(i, _dumpfields(cfg, fields))
00062 
00063 def _outputMapConfigV2(i, cfg):
00064     fields = ['source', 'source_id', 'conn', 'conn_id', 'module', 'map']
00065     return "  output config #{0}: {1}".format(i, _dumpfields(cfg, fields))
00066 
00067 def _outputMapConfig(i, cfg):
00068     if isinstance(cfg, EvrData.OutputMap): return _outputMapConfigV0(i, cfg)
00069     if isinstance(cfg, EvrData.OutputMapV2): return _outputMapConfigV2(i, cfg)
00070 
00071 
00072 def _eventCodeConfigV3(i, cfg):
00073     fields = ['code', 'isReadout', 'isTerminator', 'maskTrigger', 'maskSet', 'maskClear']
00074     return "  event code #{0}: {1}".format(i, _dumpfields(cfg, fields))
00075         
00076 def _eventCodeConfigV4(i, cfg):
00077     fields = ['code', 'isReadout', 'isTerminator', 'reportDelay', 'reportWidth', 'maskTrigger', 'maskSet', 'maskClear']
00078     return "  event code #{0}: {1}".format(i, _dumpfields(cfg, fields))
00079 
00080 def _eventCodeConfigV5(i, cfg):
00081     fields = ['code', 'isReadout', 'isCommand', 'isLatch', 'reportDelay', 'reportWidth', 'maskTrigger', 'maskSet', 'maskClear', 'desc']
00082     return "  event code #{0}: {1}".format(i, _dumpfields(cfg, fields))
00083 
00084 def _eventCodeConfigV6(i, cfg):
00085     fields = ['code', 'isReadout', 'isCommand', 'isLatch', 'reportDelay', 'reportWidth', 'maskTrigger', 'maskSet', 'maskClear', 'readoutGroup', 'desc']
00086     return "  event code #{0}: {1}".format(i, _dumpfields(cfg, fields))
00087 
00088 def _eventCodeConfig(i, cfg):
00089     if isinstance(cfg, EvrData.EventCodeV3): return _eventCodeConfigV3(i, cfg)
00090     if isinstance(cfg, EvrData.EventCodeV4): return _eventCodeConfigV4(i, cfg)
00091     if isinstance(cfg, EvrData.EventCodeV5): return _eventCodeConfigV5(i, cfg)
00092     if isinstance(cfg, EvrData.EventCodeV6): return _eventCodeConfigV6(i, cfg)
00093 
00094 def _sequencerConfig(cfg):
00095     fields = ['sync_source', 'beam_source', 'length', 'cycles']
00096     return "  seq_config: {0}".format(_dumpfields(cfg, fields))
00097 
00098 def _fifoevent(i, fifo):
00099     fields = ['timestampHigh', 'timestampLow', 'eventCode']
00100     return "  fifo event #{0}: {1}".format(i, _dumpfields(fifo, fields))
00101 
00102 #---------------------
00103 #  Class definition --
00104 #---------------------
00105 class dump_evr (object) :
00106     '''Class whose instance will be used as a user analysis module.'''
00107 
00108     #----------------
00109     #  Constructor --
00110     #----------------
00111     def __init__(self):
00112         '''Class constructor. Does not need any parameters'''
00113 
00114         self.m_src = self.configSrc('source', 'DetInfo(:Evr)')
00115 
00116     #-------------------
00117     #  Public methods --
00118     #-------------------
00119 
00120     def beginRun( self, evt, env ) :
00121         """This optional method is called if present at the beginning 
00122         of the new run.
00123 
00124         @param evt    event data object
00125         @param env    environment object
00126         """
00127 
00128         config = env.configStore().get(EvrData.Config, self.m_src)
00129         if config:
00130         
00131             print "%s: %s" % (config.__class__.__name__, self.m_src)
00132 
00133             for tup in enumerate(config.pulses()): print _pulseConfig(*tup)
00134             for tup in enumerate(config.output_maps()): print _outputMapConfig(*tup)
00135             try:
00136                 for tup in enumerate(config.eventcodes()): print _eventCodeConfig(*tup)
00137             except:
00138                 pass
00139             try:
00140                 print _sequencerConfig(config.seq_config())
00141             except:
00142                 pass
00143 
00144     def event( self, evt, env ) :
00145         """This method is called for every L1Accept transition.
00146 
00147         @param evt    event data object
00148         @param env    environment object
00149         """
00150 
00151         data = evt.get(EvrData.Data, self.m_src)
00152         if data:
00153             print "{0}: numFifoEvents={1}".format(data.__class__.__name__, data.numFifoEvents())
00154             for tup in enumerate(data.fifoEvents()): print _fifoevent(*tup)
00155 

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7