# Tai Sakuma <tai.sakuma@cern.ch>

##__________________________________________________________________||
class MPEventLoopRunner(object):
    def __init__(self, communicationChannel):
        self.communicationChannel = communicationChannel

    def begin(self):
        self._allReaders = { }

    def run(self, eventLoop):

        # add id so can collect later
        reader = eventLoop.reader
        reader.id = id(reader)
        self._allReaders[id(reader)] = reader

        self.communicationChannel.put(eventLoop)

    def end(self):

        readers = self.communicationChannel.receive()
        for reader in readers:
            self._allReaders[reader.id].setResults(reader.results())

##__________________________________________________________________||

# Tai Sakuma <tai.sakuma@cern.ch>

##__________________________________________________________________||
class MPEventLoopRunner(object):
    def __init__(self, communicationChannel):
        self.communicationChannel = communicationChannel
        self._original_readers = [ ]

    def begin(self): pass

    def run(self, eventLoop):
        self._original_readers.append(eventLoop.reader)
        self.communicationChannel.put(eventLoop)

    def end(self):
        returned_readers = self.communicationChannel.receive()
        for original, returned in zip(self._original_readers, returned_readers):
            if original is returned: continue
            original.setResults(returned.results())

##__________________________________________________________________||

stop MPEventLoopRunner setting results if returned readers are the same as the original. clean up code