| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

iStatsSvc.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # DayaBay wrapper class for IStatisticsSvc
00004 #
00005 # dandwyer@caltech.edu  2009-05-28
00006 
00007 # Wrapper class for IStatisticSvc
00008 class iStatsSvc:
00009     "Python Interface to IStatisticsSvc"
00010     _statsSvc = None   # Reference to IStatisticsSvc
00011     def __init__(self, alg, path = ""):
00012         self.alg = alg # Reference to the algorithm which created this handle
00013         self.defaultPath = path   # Default path for this algorithm
00014         self.data = {}  # Shortcuts to items in StatisticsSvc for this alg
00015         return
00016 
00017     def isInitialized(self):
00018         if self.__class__._statsSvc == None:
00019             return False
00020         return True
00021 
00022     def initialize(self):
00023         if not self.isInitialized():
00024             statsSvc = self.alg.svc("IStatisticsSvc","StatisticsSvc")
00025             if statsSvc == None:
00026                 self.alg.error("Failed to initialize statistics service")
00027             else:
00028                 # Initialize for all instances of iStatsSvc
00029                 self.__class__._statsSvc = statsSvc
00030         return
00031     
00032     def _key2path(self,key):
00033         if key[0] != '/': 
00034             key = self.defaultPath + '/' + key
00035         return key
00036 
00037     def __setitem__(self,key,value):
00038         self.alg.debug('iStatsSvc.__setitem__(%s,%s)'%(key,value))
00039         if not self.isInitialized(): self.initialize() 
00040         key = self._key2path(key)
00041         if self.data.has_key(key):
00042             raise KeyError, 'key "%s" already set'%key
00043         self.__class__._statsSvc.put(key,value)
00044         self.data[key] = value
00045         return
00046 
00047     def __getitem__(self,key):
00048         self.alg.debug('iStatsSvc.__getitem__(%s)'%(key))
00049         if not self.isInitialized(): self.initialize()
00050         key = self._key2path(key)
00051         if self.data.has_key(key):
00052             return self.data[self._key2path(key)]
00053         return self.__class__._statsSvc.get(key)
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:13:00 2011 for DybPython by doxygen 1.4.7