示例#1
0
    def __init__(self, port):
        self._subscribed = set()
        self.reloadmaster = False

        self._batch_mode = bool(_argparser.parse_args().batch_mode)
        if self._batch_mode:
            return

        self._state = backend.worker.Worker.state
        self._zmq_key = bytes('hummingbird')
        self._context = zmq.Context()
        self._ctrl_socket = self._context.socket(zmq.REP)
        self._ctrl_port = self._state.get('zmq_ctrl_port', port)
        self._broker_pub_socket = self._context.socket(zmq.XPUB)
        self._broker_pub_port = self._state.get('zmq_data_port',
                                                self._ctrl_port + 1)
        self._broker_sub_socket = self._context.socket(zmq.XSUB)
        self._broker_sub_port = self._state.get('zmq_xsub_port',
                                                self._broker_pub_port + 1)

        self._data_socket = self._context.socket(zmq.PUB)
        ## Does not match intent according to http://stackoverflow.com/questions/23800442/why-wont-zmq-drop-messages
        self._broker_sub_socket.setsockopt(zmq.RCVHWM, eventLimit)
        self._broker_pub_socket.setsockopt(zmq.SNDHWM, eventLimit)
        self._broker_pub_socket.setsockopt(zmq.SNDTIMEO, 0)
        self._data_socket.setsockopt(zmq.SNDHWM, eventLimit)
        self._data_socket.setsockopt(zmq.SNDTIMEO, 0)
        self._ctrl_socket.bind("tcp://*:%d" % (self._ctrl_port))
        self._broker_pub_socket.bind("tcp://*:%d" % (self._broker_pub_port))
        self._broker_sub_socket.bind("tcp://*:%d" % (self._broker_sub_port))
        self._data_socket.connect("tcp://127.0.0.1:%d" %
                                  (self._broker_sub_port))

        zmq.eventloop.ioloop.install()
        # We are installing event handlers for those sockets
        # but also for data stream, since a PUB socket actually
        # can leak data if it never is asked to process its events.
        # (According to some vague discussions.)
        # (e.g. https://github.com/zeromq/libzmq/issues/1256 )
        self._data_stream = zmq.eventloop.zmqstream.ZMQStream(
            self._data_socket)
        self._ctrl_stream = zmq.eventloop.zmqstream.ZMQStream(
            self._ctrl_socket)
        self._ctrl_stream.on_recv_stream(self._answer_command)

        self._xpub_stream = zmq.eventloop.zmqstream.ZMQStream(
            self._broker_pub_socket)
        self._xpub_stream.on_recv_stream(self._forward_xpub)

        self._xsub_stream = zmq.eventloop.zmqstream.ZMQStream(
            self._broker_sub_socket)
        self._xsub_stream.on_recv_stream(self._forward_xsub)

        ipc.uuid = ipc.hostname + ':' + str(self._broker_pub_port)
        t = threading.Thread(target=self._ioloop)
        # Make sure the program exists even when the thread exists
        t.daemon = True
        t.start()
示例#2
0
def main():
    """The entry point of the program"""

    if len(sys.argv) == 1:
        argparser.print_help()

    if "-b" in sys.argv and (sys.argv.index("-b") + 1 < len(sys.argv)):
        config_file = sys.argv[sys.argv.index("-b") + 1]
        imp.load_source("__config_file", config_file)

    args = argparser.parse_args()

    level = logging.WARNING
    if args.verbose:
        level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    logging.basicConfig(format="%(filename)s:%(lineno)d %(message)s", level=level)

    if args.port < PORT_RANGE[0] or args.port > PORT_RANGE[1]:
        print "The port must be from {0} to {1}".format(PORT_RANGE[0], PORT_RANGE[1])
        exit(0)

    if args.backend is not None:
        if args.influxdb is not None:
            from ipc import influx

            influx.init(args.influxdb)
        from backend import Worker

        if args.backend != True:
            worker = Worker(args.backend, args.port)
        else:
            worker = Worker(None, args.port)
        if not args.profile:
            worker.start()
        else:
            from pycallgraph import PyCallGraph
            from pycallgraph.output import GraphvizOutput
            import ipc.mpi
            import os

            graphviz = GraphvizOutput()
            graphviz.output_file = "pycallgraph_%d.png" % (ipc.mpi.rank)
            with PyCallGraph(output=graphviz):
                worker.start()
    elif args.interface is not False:
        import interface

        interface.start_interface(args.no_restore)
    elif args.reload is not False:
        import os, signal

        with open(".pid", "r") as file:
            pid = int(file.read())
        os.kill(pid, signal.SIGUSR1)
示例#3
0
    def __init__(self, port):
        self._subscribed = set()
        self.reloadmaster = False
        
        self._batch_mode = bool(_argparser.parse_args().batch_mode)
        if self._batch_mode:
            return

        self._state = backend.worker.Worker.state
        self._zmq_key = bytes('hummingbird')
        self._context = zmq.Context()
        self._ctrl_socket = self._context.socket(zmq.REP)
        self._ctrl_port = self._state.get('zmq_ctrl_port', port)
        self._broker_pub_socket = self._context.socket(zmq.XPUB)
        self._broker_pub_port = self._state.get('zmq_data_port',
                                                self._ctrl_port+1)
        self._broker_sub_socket = self._context.socket(zmq.XSUB)
        self._broker_sub_port = self._state.get('zmq_xsub_port', 
                                                self._broker_pub_port+1)

        self._data_socket = self._context.socket(zmq.PUB)
        ## Does not match intent according to http://stackoverflow.com/questions/23800442/why-wont-zmq-drop-messages
        self._broker_sub_socket.setsockopt(zmq.RCVHWM, eventLimit)
        self._broker_pub_socket.setsockopt(zmq.SNDHWM, eventLimit)
        self._broker_pub_socket.setsockopt(zmq.SNDTIMEO, 0)
        self._data_socket.setsockopt(zmq.SNDHWM, eventLimit)
        self._data_socket.setsockopt(zmq.SNDTIMEO, 0)
        self._ctrl_socket.bind("tcp://*:%d" % (self._ctrl_port))
        self._broker_pub_socket.bind("tcp://*:%d" % (self._broker_pub_port))
        self._broker_sub_socket.bind("tcp://*:%d" % (self._broker_sub_port))
        self._data_socket.connect("tcp://127.0.0.1:%d" % (self._broker_sub_port))

        zmq.eventloop.ioloop.install()
        # We are installing event handlers for those sockets
        # but also for data stream, since a PUB socket actually
        # can leak data if it never is asked to process its events.
        # (According to some vague discussions.)
        # (e.g. https://github.com/zeromq/libzmq/issues/1256 )
        self._data_stream = zmq.eventloop.zmqstream.ZMQStream(self._data_socket)
        self._ctrl_stream = zmq.eventloop.zmqstream.ZMQStream(self._ctrl_socket)
        self._ctrl_stream.on_recv_stream(self._answer_command)

        self._xpub_stream = zmq.eventloop.zmqstream.ZMQStream(self._broker_pub_socket)
        self._xpub_stream.on_recv_stream(self._forward_xpub)

        self._xsub_stream = zmq.eventloop.zmqstream.ZMQStream(self._broker_sub_socket)
        self._xsub_stream.on_recv_stream(self._forward_xsub)

        ipc.uuid = ipc.hostname+':'+str(self._broker_pub_port)
        t = threading.Thread(target=self._ioloop)
        # Make sure the program exists even when the thread exists
        t.daemon = True
        t.start()
def main():
    """The entry point of the program"""

    if(len(sys.argv) == 1):
        argparser.print_help()

    if "-b" in sys.argv and (sys.argv.index("-b")+1 < len(sys.argv)):
        config_file = sys.argv[sys.argv.index("-b")+1]
        imp.load_source('__config_file', config_file)
        
    args = argparser.parse_args()
    
    level = logging.WARNING
    if args.verbose:
        level = logging.INFO
    if args.debug:
        level = logging.DEBUG
    logging.basicConfig(format='%(filename)s:%(lineno)d %(message)s', level=level)

    if args.port < PORT_RANGE[0] or args.port > PORT_RANGE[1]:
        print "The port must be from {0} to {1}".format(PORT_RANGE[0], PORT_RANGE[1])
        exit(0)

    if(args.backend is not None):
        if (args.influxdb is not None):
            from ipc import influx
            influx.init(args.influxdb)
        from backend import Worker
        if(args.backend != True):
            worker = Worker(args.backend, args.port)
        else:
            worker = Worker(None, args.port)
        if not args.profile:
            worker.start()
        else:
            from pycallgraph import PyCallGraph
            from pycallgraph.output import GraphvizOutput
            import ipc.mpi
            import os
            graphviz = GraphvizOutput()
            graphviz.output_file = 'pycallgraph_%d.png' % (ipc.mpi.rank)
            with PyCallGraph(output=graphviz):
                worker.start()
    elif(args.interface is not False):
        import interface
        interface.start_interface(args.no_restore)
    elif(args.reload is not False):
        import os, signal
        with open('.pid', 'r') as file:
            pid = int(file.read())
        os.kill(pid, signal.SIGUSR1)
示例#5
0
    help=
    'Output level (0: dry run, 1: small data for all events, 2: tof data for hits, \
                               3: pnccd data for hits, 4: all data for multiple hits)',
    default=3)
add_config_file_argument(
    '--outdir',
    metavar='STR',
    help='output directory different from default (optional)',
    type=str)
add_config_file_argument('--nr-frames',
                         type=int,
                         help='Number of frames',
                         default=None)
add_config_file_argument('--skip-tof', action='store_true')
add_config_file_argument('--only-save-multiples', action='store_true')
args = argparser.parse_args()

this_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(this_dir)

from conf import *

# Read in parameters from a csv file
import params
p = params.read_params('params.csv', args.run_nr)
gap_top = p['pnccdGapTopMM'] * 1E-3
gap_bottom = p['pnccdGapBottomMM'] * 1E-3
gap_total = gap_top + gap_bottom
center_shift = int((gap_top - gap_bottom) / pixel_size)

# Dark file