summaryrefslogtreecommitdiffstats
path: root/Monitoring/src/main/python/DataProcessing/AggregatorManager.py
blob: 7a2df8f491fcec01482b623b75e30cf1cfb5d281 (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
40
from __future__ import with_statement
'''
Created on Dec 10, 2012

@author: steger
'''
from DataProcessing.Aggregator import AggregatorError, Aggregator
from DataProcessing.Sampler import Sampler

class AggregatorManager(object):
    def __init__(self):
        self._id = 0;
        self._aggregators = {}

    def newAggregator(self, dataSource, cellrequest, commandflow):
        for c, ca in commandflow:
            if issubclass(c, Aggregator):
                dataSource = c(dataSource, cellrequest)
                for k, v in ca.iteritems():
                    dataSource.__setattr__(k, v)
            elif issubclass(c, Sampler):
                dataSource = c(dataSource)
                for k, v in ca.iteritems():
                    dataSource.__setattr__(k, v)
        self._id += 1
        self._aggregators[ self._id ] = dataSource
        return self._id

    def __getitem__(self, aggregatorid):
        try:
            return self._aggregators[ aggregatorid ]
        except:
            raise AggregatorError("Aggregator with id %s not found" % aggregatorid)

    def pop(self, aggregatorid):
        try:
            self._aggregators.pop( aggregatorid )
        except KeyError:
            print "WW: Aggregator with id %s not found" % aggregatorid