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 file" 00012 __author__ = "R. Claus <Claus@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "3/30/2006" 00014 __updated__ = ("$Date: 2006/07/19 16:08:50 $").split(' ')[1] 00015 __version__ = "$Revision: 1.2 $" 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 00028 00029 class LdfContributor(geb.GebContributor): 00030 def __init__(self, filename, offset = 1): 00031 geb.GebContributor.__init__(self) 00032 self.__filename = filename 00033 self.__fakeEvent = struct.pack(">3L", LDF.EBFevent.ID, 3*4, 0xabadcafeL) 00034 self.__offset = offset 00035 00036 def name(self): 00037 return "LDF" 00038 00039 def offset(self): 00040 return self.__offset 00041 00042 def open(self): 00043 self.__file = file(self.__filename, 'rb') 00044 print "LdfContrib.open: %s opened" % (self.__filename) 00045 00046 def close(self): 00047 self.__file.close() 00048 00049 def read(self): 00050 """!\brief Method to read an LDF contribution from a file. 00051 """ 00052 data = self.__file.read(8) 00053 if len(data) == 0: raise EOFError, "LdfContrib.read: End of file on %s" % (self.__filename) 00054 (typeId, length) = struct.unpack('>2L', data) 00055 if typeId != LDF.LATdatagram.ID: 00056 # Don't try to continue if bad typeId: we're lost or it's undefined 00057 raise KeyError, "ldfContrib.read: Unrecognized contribution %08x"%(typeId) 00058 #print "ldfContrib.read: id = %08x, len = %08x" % (typeId, length) 00059 data = self.__file.read(length - 8) # Only the LATcontribution(s) portion 00060 00061 status = 0 00062 return geb.Geb.Build, status, LdfContribution(self, data) 00063 00064 def fake(self): 00065 return self.__fakeEvent 00066