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 Trigger Object class" 00012 __author__ = "M. Huffer <mehsys@slac.stanford.edu> SLAC - GLAST LAT Electronics" 00013 __date__ = "1/14/04" 00014 __version__ = "$Revision: 2.1 $" 00015 __release__ = "$Name: R04-12-00 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 """TrgRoiAsTiles: Map coincidences to Regions of Interest 00021 """ 00022 00023 from TrgCoincidences import * 00024 from NullObjects import NullCoincidence 00025 00026 class TrgRoiAsTiles(TrgCoincidences): 00027 """\brief Class TrgRoiAsTiles 00028 LATTE provided class to map coincidences to ROIs 00029 """ 00030 def __init__(self): 00031 TrgCoincidences.__init__(self) 00032 self.__coincidenceList = [] 00033 for i in range(TrgObject.COINCIDENCE_NUMBER_MAX + 1): 00034 self.__coincidenceList.append(NullCoincidence()) 00035 self.__roiList = [] 00036 for i in range(TrgObject.ROI_NUMBER_MAX+1): 00037 self.__roiList.append(AddableRoi()) 00038 00039 def coincidence(self, coincidenceNumber): 00040 if coincidenceNumber < TrgObject.COINCIDENCE_NUMBER_MIN or \ 00041 coincidenceNumber > TrgObject.COINCIDENCE_NUMBER_MAX: 00042 raise IndexError, "coincidenceNumber is out of range" 00043 return self.__coincidenceList[coincidenceNumber] 00044 00045 def roi(self, roiNumber): 00046 if roiNumber < TrgObject.ROI_NUMBER_MIN or \ 00047 roiNumber > TrgObject.ROI_NUMBER_MAX: 00048 raise IndexError, "roiNumber is out of range" 00049 return self.__roiList[roiNumber] 00050 00051 def addCoincidence(self, cNumber, coinc): 00052 self.__coincidenceList[cNumber] = coinc 00053 self.__fillRoiList(cNumber) 00054 00055 def __fillRoiList(self, cNumber): 00056 """This function fills the list of ROIs by using the defined 00057 list of coincident tiles. Each coincidence pair defines 00058 tiles in two ROIs. Coincidence pair 0 maps to ROI 0 and 1, 00059 and so on. 00060 """ 00061 rList = self.__roiList 00062 coin = self.coincidence(cNumber) 00063 for tileA in range(TrgObject.TILE_NUMBER_MAX+1): 00064 tileB = coin.inCoincidence(tileA) 00065 if tileB >= 0: 00066 c2 = cNumber * 2 00067 rList[c2].addTile(tileA) 00068 rList[c2+1].addTile(tileB) 00069 00070 class AddableRoi(TrgRoi): 00071 """The main purpose of this class is to add the member function 00072 addTile(tile). 00073 This function appends a tile to the list of tiles in the ROI 00074 """ 00075 def __init__(self): 00076 TrgRoi.__init__(self) 00077 self.__tileList = [] 00078 00079 def addTile(self,tile): 00080 if tile not in self.__tileList: 00081 if tile >= TrgObject.TILE_NUMBER_MIN and tile <= TrgObject.TILE_NUMBER_MAX: 00082 self.__tileList.append(tile) 00083 00084 def tile(self, tileNumber): 00085 if tileNumber < TrgObject.TILE_NUMBER_MIN or tileNumber > TrgObject.TILE_NUMBER_MAX: 00086 raise IndexError, "tileNumber is out of range" 00087 if tileNumber in self.__tileList: 00088 return True 00089 return False 00090