summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Mastbaum <mastbaum@hep.upenn.edu>2013-01-03 17:57:15 -0500
committertlatorre <tlatorre@uchicago.edu>2021-05-09 08:42:39 -0700
commit5e68ad9aec8f623a7cc75f61c3e9355dafcb41c3 (patch)
treed7111d82999fb15035b54f633997966e799af752
parent07dcc0971c435f7e0068a6c28dbeaf14349e1beb (diff)
downloadchroma-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
-rwxr-xr-xbin/chroma-server57
-rw-r--r--setup.py3
2 files changed, 59 insertions, 1 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()
+
diff --git a/setup.py b/setup.py
index 21b3eb8..dacd868 100644
--- a/setup.py
+++ b/setup.py
@@ -31,7 +31,8 @@ setup(
include_package_data=True,
scripts = ['bin/chroma-sim', 'bin/chroma-cam',
- 'bin/chroma-geo', 'bin/chroma-bvh'],
+ 'bin/chroma-geo', 'bin/chroma-bvh',
+ 'bin/chroma-server'],
ext_modules = [
Extension('chroma.generator._g4chroma',
['src/G4chroma.cc'],