예제 #1
0
    def execute(self):
        self.outCont = None
        self.nProcessed += 1
        self.msg.debug('==> execute %s on %r. event...' %
                       (self.name(), self.nProcessed))

        # Get the input collections from StoreGate and add each to the list of containers for this event
        nInputElements = 0
        inContList = []
        for i in xrange(self.inputContainerNames.__len__()):
            inCont = None
            try:
                inCont = self.storeGateSvc.retrieve(
                    self.inputContainerType, self.inputContainerNames[i])
            except LookupError:
                if self.nProcessed < 100:
                    self.msg.warning(
                        'Collection of type %s with key %s not found' %
                        (self.inputContainerType, self.inputContainerNames[i]))
                    pass  #continue
                pass
            if inCont:
                inContList.append(inCont)
                nInputElements += inCont.size()
            pass
        self.msg.debug('Found %s input containers.' % len(inContList))

        self.msg.debug('allocating containers')
        # Create the new output container
        # for now, we only create view containers, because deep copies are not yet supported
        self.outCont = PyAthena.DataVector(self.particleType)(1)
        self.outCont.reserve(nInputElements)

        self.msg.debug('recording containers')
        # Record the merged output container into StoreGate so that they can be retrieved by other algorithms
        if self.storeGateSvc.record(
                self.outCont, self.outputContainerName) != StatusCode.Success:
            self.msg.error(
                'Could not record the output container into StoreGate with the key = '
                % self.outputContainerName)
            pass

        #Then... here we go!

        # Get the input collections from StoreGate
        for inCont in inContList:
            self.msg.verbose('Processing input container with %s elements...' %
                             len(inCont))

            # Loop over all objects in the input container and add them to the output
            for obj in inCont:
                self.nObjectsProcessed += 1
                self.msg.verbose('  Processing object in input container...')
                # TODO: maybe reimplement removeIdentical/removeNearby functionality here
                self.outCont.push_back(obj)
            pass

        # Determine if this events passes the minimum/maximum number of required objects
        nPassedObject = self.outCont.size()
        self.nObjectsPassed += nPassedObject
        if nPassedObject >= self.minNumberPassed and nPassedObject <= self.maxNumberPassed:
            self.msg.debug('Found %s objects in this event... passing it.' %
                           nPassedObject)
            self.nEventAccepted += 1
            self.setFilterPassed(True)
            pass
        else:
            self.setFilterPassed(False)
            pass

        self.msg.debug('returning')
        if gc.isenabled():
            self.msg.debug('garbage collection is enabled')
        else:
            self.msg.debug('garbage collection is disabled')
        return StatusCode.Success
예제 #2
0
    def execute(self):
        self.nProcessed += 1
        self.msg.debug('==> execute %s on %r. event...' %
                       (self.name(), self.nProcessed))

        # Get the input collections from StoreGate and add each to the list of containers for this event
        nInputElements = 0
        inContList = []
        for i in xrange(self.inputContainerNames.__len__()):
            inCont = None
            try:
                inCont = self.storeGateSvc.retrieve(
                    self.inputContainerType, self.inputContainerNames[i])
            except LookupError:
                if self.nProcessed < 100:
                    self.msg.warning(
                        'Collection of type %s with key %s not found' %
                        (self.inputContainerType, self.inputContainerNames[i]))
                    pass  #continue
                pass
            if inCont:
                inContList.append(inCont)
                nInputElements += inCont.size()
            pass
        self.msg.debug('Found %s input containers.' % len(inContList))

        # Create the new output container and reserve some memory for it
        try:
            VIEW_ELEMENTS = 1
            outCont = PyAthena.DataVector(
                getattr(PyAthena.xAOD,
                        self.inputContainerParticleType))(VIEW_ELEMENTS)
        except TypeError:
            outCont = PyAthena.DataVector(
                getattr(PyAthena.xAOD, self.inputContainerParticleType))()
            pass
        outCont.reserve(nInputElements)

        #Then... here we go!

        # Get the input collections from StoreGate
        for inCont in inContList:
            self.msg.verbose('Processing input container with %s elements...' %
                             len(inCont))

            # Loop over all objects in the input container and add them to the output
            for obj in inCont:
                self.nObjectsProcessed += 1
                self.msg.verbose('  Processing object in input container...')
                if self.removeIdentical:
                    if not obj in outCont:
                        outCont.push_back(obj)
                        pass
                    pass
                else:
                    if self.removeNearby:
                        if not self.isOverlapping(obj, outCont):
                            outCont.push_back(obj)
                            pass
                        pass
                    else:
                        outCont.push_back(obj)
                        pass
                    pass
                pass

            pass

        # Determine if this events passes the minimum/maximum number of required objects
        nPassedObject = outCont.size()
        self.nObjectsPassed += nPassedObject
        if nPassedObject >= self.minNumberPassed and nPassedObject <= self.maxNumberPassed:
            self.msg.debug('Found %s objects in this event... passing it.' %
                           nPassedObject)
            self.nEventAccepted += 1
            self.setFilterPassed(True)
            pass
        else:
            self.setFilterPassed(False)
            pass

        # Record the merged output container into StoreGate so that they can be retrieved by other algorithms
        if self.storeGateSvc.record(
                outCont, self.outputContainerName) != StatusCode.Success:
            self.msg.error(
                'Could not record the output container into StoreGate with the key = '
                % self.outputContainerName)
            pass

        return StatusCode.Success