summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/DataProcessing/DataIndex.py
blob: 84d8390a482ff6a12318cb920d2b6cbfd507db8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
Created on Dec 31, 2012

@author: steger
'''
from DataProcessing.DataReader import DataReader

class DataIndex(DataReader):
    '''
    classdocs
    '''

    def __init__(self, datasource, key):
        '''
        Constructor
        '''
        DataReader.__init__(self, datasource)
        self.indexmap = {}
        self.extract(cellrequest = key)
    
    def buildindex(self):
        i = len(self.indexmap)
        for k in self:
            self.indexmap[tuple(k)] = i
            i += 1
    
    def __getitem__(self, k):
        if self.sourceCleared.isSet():
            self.sourceCleared.clear()
            self.indexmap.clear()
            self.buildindex()
        try:
            iter(k)
        except TypeError:
            k = (k,)
        if not self.indexmap.has_key(k) and self.sourceExpanded.isSet():
            self.sourceExpanded.clear()
            self.buildindex()
        return self.source._rawrecords[ self.indexmap[k] ]