def start_run(): """Check user form for completion. If it is complete, start the run. This entails saving the user configuration in couchdb and launching the data getter and emitter""" global running data = copy_form_data(run_info, request) complete = check_form_data(run_info, data) if not complete: error = "All fields in the form must be filled." return render_template('new_run.html', info=run_info, data=data, error=error, new=True, in_progress=running) # Send a start run signal to fe_master. context = zmq.Context() handshake_sck = context.socket(zmq.REQ) handshake_sck.setsockopt(zmq.LINGER, 0); start_sck = context.socket(zmq.PUSH) start_sck.setsockopt(zmq.LINGER, 0) conf = json.load(open(os.path.join(cwd, '../fast/config/.default_master.json'))) start_sck.connect(conf['trigger_port']) handshake_sck.connect(conf['handshake_port']) msg = "CONNECT" handshake_sck.send(msg) if (handshake_sck.recv() == msg): # Connection established. start_sck.send("START:%05i:" % (run_info['last_run'] + 1)) handshake_sck.close() start_sck.close() context.destroy() #save the run info db = get_db(run_info['db_name']) run_info['last_run'] += 1 data['run_number'] = run_info['last_run'] now = datetime.datetime.now() data['Start Date'] = "%02i/%02i" % (now.month, now.day) data['Start Time'] = "%02i:%02i" % (now.hour, now.minute) save_db_data(db, data) #start the run and launch the data emitter running = True data_io.begin_run() t = threading.Thread(name='emitter', target=send_events) t.start() broadcast_refresh() return redirect(url_for('home'))
def start_run(): """Check user form for completion. If it is complete, start the run. This entails saving the user configuration in couchdb and launching the data getter and emitter""" global running data = copy_form_data(run_info, request) if running: error = 'There is already a run in progress!' return render_template('new_run.html', info=run_info, last=last_run_number(), data=data, error=error, new=True, in_progress=running) complete = check_form_data(run_info, data) if not complete: error = "Please fill in all fields." return render_template('new_run.html', info=run_info, last=last_run_number(), data=data, error=error, new=True, in_progress=running) # Send a start run signal to fe_master. context = zmq.Context() handshake_sck = context.socket(zmq.REQ) handshake_sck.setsockopt(zmq.LINGER, 0); handshake_sck.setsockopt(zmq.RCVTIMEO, 200); start_sck = context.socket(zmq.PUSH) conf = json.load(open(os.path.join(cwd, '../fast/config/.default_master.json'))) start_sck.connect(conf['trigger_port']) handshake_sck.connect(conf['handshake_port']) msg = "CONNECT" handshake_sck.send(msg) reply = "" try: reply = handshake_sck.recv() except zmq.error.Again: error = "fast-daq not responding (is it running?)" return render_template('new_run.html', info=run_info, last=last_run_number(), data=data, error=error, new=True, in_progress=running) else: if reply == msg: # Connection established. start_sck.send("START:%05i:" % (last_run_number() + 1)) finally: handshake_sck.close() start_sck.close() context.destroy() #save the run info db = connect_db(run_info['db_name']) data['run_number'] = last_run_number() + 1 now = datetime.datetime.now() data['Start Date'] = "%02i/%02i/%04i" % (now.month, now.day, now.year) data['Start Time'] = "%02i:%02i" % (now.hour, now.minute) db.save(data) #start the run and launch the data emitter running = True data_io.begin_run() t = threading.Thread(name='emitter', target=send_events) t.start() broadcast_refresh() return redirect(url_for('home'))