#!/usr/bin/env python # This example shows how to send events to a aa3d web-based event display. # The following processes are involved # - the aa3d web-display application running somewhere in a web-browser (on your laptop) # - the 'client': a script that wants to send data to the event-display; i.e. this script. # - the (rba) server which acts as a middle-man that sets up the link between the event-display and the client # # For server, both this script and the web-server are clients. Each client get's a token to # identify itself. When the event-display connects to the server, the token it receives from the # server will be shown to the user. This token can then be used in the client-script, to indicate which # event display we want to send data to. # (the client-script itself also receives a token, with is used interally to be able to send # feedback data from the event display back to the client.) import sys, aa from ROOT import WebSocket, Det, jsons, Evt, EventFile try: token = sys.argv[1] except IndexError: print "Get the token from the event-display in your browser and give it as the arugment for this script" sys.exit() # connect to the rba server w = WebSocket( "ws://www.cherenkov.nl:8088/echo", token ) # we can send some javascript to be executed; we receive a msg back with the result # w.send_rba("21+21;") # expect back a message with data = "42" # Or we can send some other javascipt # w.send_rba('alert("aanet says hi");') # popup window in aa3d evtfile = '../data/mc5.1.numuCC.ps10.aa.root' detfile = '../data/KM3NeT_-00000001_20171212.detx' det = Det(detfile) if 0 : # screw with detector so we can check update in aa3 for domid, dom, in det.doms : dom.pos.x += dom.pos.z #for p in dom.pmts : p.pos.x += dom.pos.z jsons.veto_names = aa.make_vector( "pmts rate t0 flag".split() ); # todo: move addFloor and addDoms into onNewDetector w.send_rba("setDet = function ( d ) { det = d ; callbacks.onNewDetector();callbacks.addFloor();callbacks.addDoms();}") msg = "setDet( %s ) " % (jsons(det),) w.send_rba( msg ) f = EventFile( evtfile ) import time for evt in f : print evt, evt.mc_trks[0].E w.send_rba( "setEvent( %s );" % ( jsons(evt), ) ) time.sleep(10) # for future reference: minimal event that does not crash the program looks like this # evt = { hits:[], mc_hits:[], mc_trks:[], timerange:[0,1] }