summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/DataProcessing/DataSource.py.old
diff options
context:
space:
mode:
Diffstat (limited to 'Monitoring/src/main/python/DataProcessing/DataSource.py.old')
-rw-r--r--Monitoring/src/main/python/DataProcessing/DataSource.py.old91
1 files changed, 91 insertions, 0 deletions
diff --git a/Monitoring/src/main/python/DataProcessing/DataSource.py.old b/Monitoring/src/main/python/DataProcessing/DataSource.py.old
new file mode 100644
index 0000000..ae3aba0
--- /dev/null
+++ b/Monitoring/src/main/python/DataProcessing/DataSource.py.old
@@ -0,0 +1,91 @@
+'''
+Created on Dec 10, 2012
+
+@author: steger
+'''
+from DataProcessing.DataHeader import DataError
+from DataProcessing.DataError import SamplerError
+
+class DataSource(object):
+ def __init__(self, datasource):
+ self._readers = set()
+ self._source = datasource
+ self._data = None
+ self.um = datasource.um
+
+ @property
+ def source(self):
+ return self._source
+
+ @property
+ def data(self):
+ self.process()
+ return self._data
+
+ @property
+ def name(self):
+ raise DataError("%s must implement name property" % self)
+
+ @property
+ def readlock(self):
+ return self.source.readlock
+
+ @property
+ def writelock(self):
+ return self.source.writelock
+
+ def __len__(self):
+ raise DataError("%s must implement __len__ method" % self)
+
+ def __getitem__(self, k):
+ raise DataError("%s must implement __getitem__ method" % self)
+
+ def process(self):
+ '''
+ @summary: recursively process data records of the source chain
+ '''
+ if self != self.source:
+ self.source.process()
+ self._process()
+
+ def _process(self):
+ raise DataError("%s must implement _process method" % self)
+
+ def _onclear(self):
+ for r in self._readers:
+ r.sourcecleared()
+
+ def _onexpand(self):
+ for r in self._readers:
+ r.sourceexpanded()
+
+ def registerReader(self, reader):
+ '''
+ @summary: registers a reader to catch clear and update events
+ @param reader: data consumer
+ @type reader: DataReader
+ @raise DataError: wrong argument
+ '''
+ try:
+ self._readers.add(reader)
+ try:
+ if len(self):
+ self._onexpand()
+ else:
+ self._onclear()
+ except SamplerError:
+ pass
+ except AttributeError:
+ self._readers.remove(reader)
+ raise DataError("Expecting a DataReader, got %s" % reader)
+
+ def deregisterReader(self, reader):
+ '''
+ @summary: removes a registered reader
+ @param reader: data consumer
+ @type reader: DataReader
+ '''
+ try:
+ self._readers.remove(reader)
+ except KeyError:
+ pass