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 Housekeeping system base class" 00012 __author__ = "Jim Panetta <panetta@slac.stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = ("$Date: 2005/03/31 01:12:19 $").split(' ')[1] 00014 __version__ = "$Revision: 1.8 $" 00015 __release__ = "$Name: R04-12-00 $" 00016 __credits__ = "SLAC" 00017 00018 import LATTE.copyright_SLAC 00019 00020 import gAttr 00021 from LATTE.client.gNode import Node 00022 from LATTE.database.gDb import _regList 00023 00024 00025 class GattrHsk(gAttr.Gattr): 00026 """\brief Class which is instantiated for each housekeeping quantity 00027 """ 00028 class __AttrHsk(object): 00029 """Helper class for private use in this file only. 00030 """ 00031 def __init__(self, node, attr): 00032 self.__attr = attr 00033 self.__node = node 00034 00035 self.__data = None 00036 00037 #print id(self), id(attr), node.getName(), attr.getName(), attr.flags() 00038 if attr.flags() == (gAttr.ATTR_READ | gAttr.ATTR_NO_DIRECT_ACCESS): 00039 self.set = self.__badSet 00040 self.get = self.__badGet 00041 else: 00042 self.set = self.__set 00043 self.get = self.__get 00044 00045 # Callthroughs to 'parent' class 00046 self.setEGU = self.__attr.setEGU 00047 self.setRule = self.__attr.setRule 00048 self.setConstraint = self.__attr.setConstraint 00049 self.getEGU = self.__attr.getEGU 00050 self.getRule = self.__attr.getRule 00051 self.getConstraint = self.__attr.getConstraint 00052 00053 self.id = attr.id 00054 00055 def __set(self, val, bypass=0, node=None): 00056 if node is not None: 00057 self.__data = self.__attr.set(node, val, bypass) 00058 else: # For backward compatibility 00059 self.__data = self.__attr.set(self.__node, val, bypass) 00060 00061 def __get(self, bypass=0, node=None): 00062 if node is not None: 00063 val = self.__attr.get(node, self.__data, bypass) 00064 else: # For backward compatibility 00065 val = self.__attr.get(self.__node, self.__data, bypass) 00066 return val 00067 00068 def __badSet(self, node, val, bypass=0): 00069 return -1 # revisit 00070 #raise LATInterfaceException(1) 00071 00072 def __badGet(self, node, val, bypass=0): 00073 return -1 # revisit 00074 #raise LATInterfaceException(1) 00075 00076 def getNode(self): 00077 return self.__node 00078 00079 def __init__(self, name, id, 00080 rule = gAttr.Gattr.defaultRule, 00081 constraint = gAttr.Gattr.defaultConstraint, 00082 egu = gAttr.Gattr.defaultEgu): 00083 """GattrHsk constructor 00084 00085 \param name The name of the attribute. 00086 \param id Positional identifier. 00087 \param rule Optional. Attribute rule. 00088 \param constraint Optional. Attribute constraint. 00089 \param egu Optional. Attribute EGU 00090 """ 00091 # instantiate the Gattr. 00092 gAttr.Gattr.__init__( self, 00093 name=name, id=id, size=0, flags=gAttr.REG_READ_WRITE, 00094 rule=rule, constraint=constraint, egu=egu ) 00095 00096 def create(self, node): 00097 return GattrHsk.__AttrHsk(node, self) 00098 00099 def set(self, node, val, bypass=True): 00100 """ 00101 Method for setting the value of an attribute. 00102 Calls the functions in the attribute's node for setting values. 00103 00104 \param val Register value to be set 00105 \param bypass Optional. Flag for bypassing EGU conversion 00106 Default is to *not* convert to EGU. 00107 """ 00108 if bypass or val == None: 00109 raw = val 00110 else: 00111 (val, rejected) = self._Gattr__constraint.evaluate(val) 00112 if rejected: 00113 return None 00114 raw = self._Gattr__egu.raw(val) 00115 00116 return raw 00117 00118 def get(self, node, raw, bypass=False): 00119 """ 00120 Method for getting the value of an attribute. 00121 If bypass=0 (the default), the value will be returned in EU. 00122 If bypass=1, the raw value will be returned. 00123 """ 00124 00125 if bypass or raw == None: 00126 return raw 00127 else: 00128 egu = self._Gattr__egu.egu(raw) 00129 self._Gattr__rule.evaluate(egu, self, node) 00130 return egu 00131