diff options
author | Andy Mastbaum <mastbaum@hep.upenn.edu> | 2013-01-03 17:57:15 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:39 -0700 |
commit | 5e68ad9aec8f623a7cc75f61c3e9355dafcb41c3 (patch) | |
tree | d7111d82999fb15035b54f633997966e799af752 /bin/chroma-server | |
parent | 07dcc0971c435f7e0068a6c28dbeaf14349e1beb (diff) | |
download | chroma-5e68ad9aec8f623a7cc75f61c3e9355dafcb41c3.tar.gz chroma-5e68ad9aec8f623a7cc75f61c3e9355dafcb41c3.tar.bz2 chroma-5e68ad9aec8f623a7cc75f61c3e9355dafcb41c3.zip |
add chroma server script
chroma-server starts a ZeroMQ socket server which listens for Photons objects,
propagates them in the given Detector, and returns the final Photons.
Usage:
$ chroma-server DETECTOR [--address ADDRESS]
DETECTOR is a detector string, e.g. @chroma_sno.sno or sno
ADDRESS is a ZeroMQ socket address, default tcp://*:5024
Diffstat (limited to 'bin/chroma-server')
-rwxr-xr-x | bin/chroma-server | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/chroma-server b/bin/chroma-server new file mode 100755 index 0000000..9cd8e47 --- /dev/null +++ b/bin/chroma-server @@ -0,0 +1,57 @@ +#!/usr/bin/env python +#--*-python-*- + +import sys +import optparse +import zmq +from chroma import Simulation +from chroma.tools import enable_debug_on_crash +from chroma.loader import load_geometry_from_string + +class ChromaServer(object): + '''A ZeroMQ socket server which listens for incoming Photons objects + and replies with propagated Photons. + + :param address: Socket address on which to listen + :param detector: Detector to progagate photons in + ''' + def __init__(self, address, detector): + # set up zeromq socket + self.address = address + self.context = zmq.Context() + self.socket = self.context.socket(zmq.REP) + self.socket.bind(address) + + # set up simulation + self.detector = detector + self.sim = Simulation(self.detector) + + def serve_forever(self): + '''Listen for photons, propagate them, and return the final states.''' + while True: + photons_in = self.socket.recv_pyobj() + print 'Processing', len(photons_in), 'photons' + + # propagate in chroma simulation + photons_end = self.sim.simulate(photons_in, keep_photons_end=True).next() + + # return final photon vertices to client + self.socket.send_pyobj(photons_end) + + +if __name__ == '__main__': + enable_debug_on_crash() + parser = optparse.OptionParser('%prog <detector> <options>') + parser.add_option('--address', dest='address', default='tcp://*:5024') + options, args = parser.parse_args() + + if len(args) < 1: + sys.exit(parser.format_help()) + + print 'reticulating splines...' + detector = load_geometry_from_string(args[0]) + + print 'starting chroma server listening on', options.address + server = ChromaServer(options.address, detector) + server.serve_forever() + |