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__ = "Program to merge data from ancillary and LDF data files"
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:33:25 $").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 logging as log
00022 import sys
00023 import time
00024
00025 from LATTE.merger.geb import Geb
00026
00027 from ancillaryFile import AncillaryContributor
00028 from ldfFile import LdfContributor
00029
00030
00031 class Merger(Geb):
00032 def __init__(self, contributors, filename):
00033 Geb.__init__(self, contributors)
00034 self.__file = file(filename, 'wb')
00035
00036 def dispose(self, (statuses, event)):
00037 """!\brief Method called by the base class to dispose of an event.
00038 """
00039 self.__file.write(event)
00040
00041 def close(self):
00042 """!\brief Method called by the base class to close the output file.
00043 """
00044 self.__file.close()
00045
00046
00047 def main(options):
00048 ancillaryContributor = AncillaryContributor(options.ancillaryFile)
00049 ldfContributor = LdfContributor(options.ldfFile)
00050 merger = Merger([ancillaryContributor, ldfContributor], options.outFile)
00051 #merger = Merger([ancillaryContributor], options.outFile)
00052
00053 try:
00054 merger.start()
00055
00056 # Wait until an error occurs or the user kills us
00057 while(True): time.sleep(24*3600)
00058
00059 except KeyboardInterrupt:
00060 pass
00061 except Exception, e:
00062 log.exception(sys.argv[0] + ":\n" + str(e))
00063
00064 # Shutdown the builder
00065 merger.shutdown()
00066
00067
00068 def usage():
00069 """!\brief Return a program usage message
00070 """
00071 return "\n\n%s merges, or builds, events from files\n" % (sys.argv[0])
00072
00073
00074 if __name__ == "__main__":
00075 # Options, first list mandatory, second list optional
00076 from LATTE.tools.gOptions import Options
00077
00078 options = Options(["ancillaryFile", "ldfFile", "outFile"])
00079 try:
00080 options.parse()
00081 except Exception, msg:
00082 options.usage(usage())
00083 raise Exception, msg
00084
00085 main(options)