00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2006 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__ = "Read LDF event contributions from a socket" 00012 __author__ = "R. Claus <Claus@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "3/30/2006" 00014 __updated__ = ("$Date: 2006/07/14 22:34:28 $").split(' ')[1] 00015 __version__ = "$Revision: 1.1 $" 00016 __release__ = "$Name: R04-12-00 $" 00017 __credits__ = "SLAC" 00018 00019 import LATTE.copyright_SLAC 00020 00021 import struct 00022 import logging as log 00023 import LDF 00024 00025 import LATTE.merger.geb as geb 00026 from LATTE.merger.ldfContribution import LdfContribution 00027 from LATTE.client.gSocket import Socket 00028 00029 00030 class LdfContributor(geb.GebContributor): 00031 def __init__(self, (host, port), offset = 1): 00032 geb.GebContributor.__init__(self) 00033 self.__socket = Socket(port) 00034 self.__host = host 00035 self.__fakeEvent = struct.pack(">3L", LDF.EBFevent.ID, 3*4, 0xabadcafeL) 00036 self.__offset = offset 00037 00038 def name(self): 00039 return "LDF" 00040 00041 def offset(self): 00042 return self.__offset 00043 00044 def open(self): 00045 self.__socket.connect(self.__host) 00046 self.__socket.settimeout(9999) 00047 print "LdfContrib.open: socket opened" 00048 00049 def read(self): 00050 """!\brief Method to read an LDF contribution from a socket. 00051 """ 00052 data = self.__socket.recvall(8) 00053 (typeId, length) = struct.unpack('>2L', data) 00054 if typeId != LDF.LATdatagram.ID: 00055 # Don't try to continue if bad typeId: we're lost or it's undefined 00056 raise KeyError, "Unrecognized contribution %08x"%(typeId) 00057 #print "ldfContrib.read: id = %08x, len = %08x" % (typeId, length) 00058 data = self.__socket.recvall(length - 8) # Only the LATcontribution(s) portion 00059 00060 status = 0 00061 return geb.Geb.Build, status, LdfContribution(self, data) 00062 00063 def close(self): 00064 self.__socket.disconnect() 00065 00066 def fake(self): 00067 return self.__fakeEvent 00068