Пример #1
0
class CombinedMonitor(Monitor):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._name = name
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition
        self._monitors = {}
        self._done = set()

    def _extra_config(self, seq):
        for n, m in self._config['monitors'].iteritems():
            self._monitors[n] = SubMonitor(m.child_type(),
                                           '_'.join([n, self.name()]))

        opts = set( self._config.keys() ) - set( self._monitors.keys() ) \
               - set( [ 'monitors' ] )

        for n, sub in self._monitors.iteritems():
            mon = sub.monitor()
            for key, val in self._config[n].iteritems():
                mon._config[key] = val
            for key in opts:
                mon._config[key] = self._config[key]
            mon._extra_config(seq)

    def initialize(self):
        # Configure the app by instantiating the AppMgr
        self._appMgr = AppMgr()

        # Get the EventDataSvc for later use
        self._evtSvc = self._appMgr.evtSvc()

        # Initialize
        for sub in self._monitors.values():
            mon = sub.monitor()
            mon._appMgr = self._appMgr
            mon._evtSvc = self._evtSvc
            mon._pre_init()

        if not self._appMgr.state() == 2:
            self._appMgr.initialize()

        for sub in self._monitors.values():
            mon = sub.monitor()
            mon._post_init()

        self._condition.acquire()
        self._condition.notify()
        self._condition.release()

    def run(self):

        nEvents = self._config['EvtMax']
        event = 1
        while True:
            self._condition.acquire()
            self._appMgr.run(1)
            # Get the ODIN
            if not self._evtSvc['DAQ']:
                self.done()
                break

            info = {}
            for n, sub in self._monitors.iteritems():
                # Get the sub infos
                infos = []
                sub_mon = sub.monitor()
                sub_info = sub_mon.make_info()
                if sub_info: infos.append(sub_info)
                sub_info = None
                try:
                    sub_info = sub.outQueue().get(False)
                except IOError:
                    pass
                except Queue.Empty:
                    pass
                if sub_info: infos.append(sub_info)
                if len(infos) != 0:
                    info[n] = infos

            event += 1
            if len(info) != 0: self._outQueue.put(info)
            if event == nEvents:
                self.done()
                break
            else:
                ## self._condition.wait()
                self._condition.release()
            try:
                message = self._inQueue.get(False)
                if message == "BREAK":
                    for sub in self._monitors.itervalues():
                        sub.inQueue().put(message)
                self._condition.release()
                break
            except Queue.Empty:
                pass
Пример #2
0
#
# Stolen from I. Belyaev at http://indico.cern.ch/getFile.py/access?contribId=1&sessionId=7&resId=2&materialId=0&confId=25000
#
from Gaudi.Configuration import *

importOptions('demo2.opts')

import GaudiKernel.SystemOfUnits as Units

from GaudiPython import AppMgr

gaudi = AppMgr()

from LoKiPhys.decorators import *
from LoKiCore.functions import monitor

evtSvc = gaudi.evtSvc()

minPT = MINTREE('mu+' == ABSID, PT) / Units.GeV
# minPT = monitor(MINTREE( 'mu+' ==ABSID , PT ) / Units.GeV )

for i in range(1, 100):
    gaudi.run(1)
    psis = evtSvc['Phys/Psi2MuMu/Particles']

    for psi in psis:
        print ' Mass=%s, ptMin=%s' % (M(psi), minPT(psi))
Пример #3
0
class Monitor(Task):
    def __init__(self, name, queues, condition):
        Task.__init__(self, name)
        self._config = dict()
        self._name = name
        self._inQueue = queues[0]
        self._outQueue = queues[1]
        self._condition = condition

    def configure(self, configuration):
        from Configurables import LHCbApp
        app = LHCbApp()
        for (attr, value) in configuration.items():
            if hasattr(app, attr):
                setattr(app, attr, value)
            self._config[attr] = value

        EventSelector().Input = self._config['Input']
        if 'Catalogs' in self._config.keys():
            FileCatalog().Catalogs = self._config['Catalogs']

        from Configurables import DecodeRawEvent
        importOptions("$L0DUOPTS/L0DUConfig.opts")
        EventPersistencySvc().CnvServices.append('LHCb::RawDataCnvSvc')

        EventSelector().PrintFreq = 1000

        from Configurables import CondDB
        CondDB().Online = True

        from Configurables import GaudiSequencer as Sequence
        from Configurables import createODIN, HltRoutingBitsFilter
        seq = Sequence("MonitorSequence")
        physFilter = HltRoutingBitsFilter("PhysFilter",
                                          RequireMask=[0x0, 0x4, 0x0])
        co = createODIN()
        seq.Members = [co, physFilter]

        from DAQSys.Decoders import DecoderDB
        from itertools import product
        for stage, t in product(('Hlt1', 'Hlt2'), ('Dec', 'Sel', 'Vertex')):
            an = "{0}{1}ReportsDecoder".format(stage, t)
            seq.Members += [
                DecoderDB["Hlt%sReportsDecoder/%s" % (t, an)].setup()
            ]

        ApplicationMgr().TopAlg = [seq]
        self._extra_config(seq)

    def _extra_config(self, seq):
        pass

    def _pre_init(self):
        pass

    def _post_init(self):
        self._filter = self._appMgr.algorithm('PhysFilter')._ialg

    def initialize(self):
        # Configure the app by instantiating the AppMgr
        self._appMgr = AppMgr()

        # Get the EventDataSvc for later use
        self._evtSvc = self._appMgr.evtSvc()

        # Initialize
        self._pre_init()
        self._appMgr.initialize()
        self._post_init()

        self._condition.acquire()
        self._condition.notify()
        self._condition.release()

    def run(self):

        nEvents = self._config['EvtMax']
        event = 1
        while True:
            self._condition.acquire()
            self._appMgr.run(1)
            # Get the ODIN
            if not self._evtSvc['DAQ']:
                self.done()
                break
            # Get the event time
            info = self.make_info()
            if not info:
                self._condition.release()
                continue

            event += 1
            if info: self._outQueue.put(info)
            if event == nEvents:
                self.done()
                break
            else:
                ## self._condition.wait()
                self._condition.release()
            try:
                message = self._inQueue.get(False)
                if message == "BREAK":
                    self._condition.release()
                    break
            except Queue.Empty:
                pass

    def make_info(self):
        pass

    def finalize(self):
        self._appMgr.stop()
        self._appMgr.finalize()

    def done(self):
        # Max events reached, signal done to the main process
        self._outQueue.put('DONE')
        self._condition.release()

    def name(self):
        return self._name

    def filterPassed(self):
        return self._filter.filterPassed()