diff --git a/FofbTool/Operation.py b/FofbTool/Operation.py index 95b3f147e87928b18cb11be710923b3737e687f4..21ceaae4c5304604b710fdbbee051ef36d79832a 100644 --- a/FofbTool/Operation.py +++ b/FofbTool/Operation.py @@ -44,19 +44,19 @@ def align_ccn(nodename): # Loop until two consecutives identical measures N=[7,3] while N[-2] != N[-1]: + if len(N) > 7: + logger.error("Could not measure sequence offset.") + return False + logger.debug("Latch two sequence numbers without offset") prx.ccnpack0_control=1 # let it roll a bit to collect data - time.sleep(2) + time.sleep(2+np.random.uniform()) prx.ccnpack0_control=2 # latch it time.sleep(2) N.append(prx.ccnpack0_latchedseq1-prx.ccnpack0_latchedseq2) logger.debug("seq ({}, {}, {})".format(prx.ccnpack0_latchedseq1, prx.ccnpack0_latchedseq2, N[-1])) - if len(N) > 5: - logger.error("Could not measure sequence offset.") - return False - N=N[-1] @@ -505,38 +505,46 @@ def electron_stop_com(bpmlist): def sync_all_bpm(): """ Synchronize all BPM electronics, Electron and Brillance Plus. - This will use the FofbManager, but add sync on LiberaBrillancePlus before and sequence alignement after. + This will use the timing system (central and local board). """ - # Get FofbManager proxy - FofbManager = tango.DeviceProxy(FofbTool.Configuration.config["tangopath"]["fofb-manager"]) + EVN=240 # Event number + + db = tango.Database() + + bpmlist = [n.split(':')[2] for n in db.get_property("FOFB", "bpmlist")['bpmlist'] if ":LIBERA:" in n] + bpmidlist = [(int(n.split(':')[0]), n.split(':')[2]) for n in db.get_property("FOFB", "bpmlist")['bpmlist'] if 'LIBERA' in n] + + tlocal = tango.Group('tlocal') + tlocal.add([n.split(':')[2] for n in db.get_property("FOFB", 'TimingBoardList')['TimingBoardList'] if "LOCAL" in n]) # Set a group of Libera Brillance Plus EVRX board, from FofbTool configuration lbpevrx = tango.Group('lbpevrx') lbpevrx.add(FofbTool.Configuration.config["tangopath"]["lbpevrx"].split()) - # --------------------------------------------------------------------------------------------------------------- - # Step 1 : Init BPMs - logger.info("Configure Libera Electron with FofbManager") + tcentral = tango.DeviceProxy(FofbTool.Configuration.config["tangopath"]["timing-central"]) - lastlog = FofbManager.logs[-1] + # --------------------------------------------------------------------------------------------------------------- + # Init BPMs, stop first and put for each the ID number - FofbManager.StartStep01ConfigLiberaCom() # Non blocking call, shame + electron_stop_com(bpmlist) - # Wait for the logs to contain the magic words... - while True: - # Read the logs, crop to get only from the last log read - readlogs = FofbManager.logs - readlogs = readlogs[readlogs.index(lastlog):] - lastlog = readlogs[-1] + electron_init_fa(bpmidlist) - if '[INFO] FOFB com. successfully configured on Libera bpms' in "".join(readlogs): - break - time.sleep(1) + # --------------------------------------------------------------------------------------------------------------- + # Write event number + logger.info("Set Event Number on local timing board, BpmTriggerEvent") + r=tlocal.write_attribute("bpm.trigEvent", EVN) + for _r in r: + if _r.has_failed(): + logger.error("Failed to set Event Number on local timing board {}, bpm.trigEvent".format(_r.dev_name())) + return # --------------------------------------------------------------------------------------------------------------- - # Step 2 : Synchronize bpm + # Prepare bpm for trigger reception + + electron_sync_next_trigger(bpmlist) logger.info("Prepare Libera Brillance Plus to start on next trigger") r=lbpevrx.write_attribute("synchronize", 0) @@ -545,36 +553,42 @@ def sync_all_bpm(): logger.error("Failed to write synchronize on LBP EVRX {}".format(_r.dev_name())) return - logger.info("Synchronize Libera Electron with FofbManager") - FofbManager.StartStep02SynchronizeLibera() # Non blocking call, shame + # --------------------------------------------------------------------------------------------------------------- + # Wait 2 seconds and Fire the soft event + + time.sleep(2) + logger.info("Fire the trigger") + + tcentral.write_attribute("softEventAdress", EVN) + tcentral.firesoftevent() - # Wait for the logs to contain the magic words... - while True: - # Read the logs, crop to get only from the last log read - readlogs = FofbManager.logs - readlogs = readlogs[readlogs.index(lastlog):] - lastlog = readlogs[-1] + time.sleep(2) - if '[INFO] Libera bpms successfully triggered' in "".join(readlogs): - break - time.sleep(1) + # --------------------------------------------------------------------------------------------------------------- + # Start electron on next trigger + electron_start_next_trigger(bpmlist) # --------------------------------------------------------------------------------------------------------------- - # Step 3 : Start communication + # Wait 2 seconds and Fire the soft event + + time.sleep(2) + logger.info("Fire the trigger") + + tcentral.write_attribute("softEventAdress", EVN) + tcentral.firesoftevent() + + time.sleep(2) - logger.info("Start Libera Electron with FofbManager") - FofbManager.StartStep03StartLiberaCom() # Non blocking call, shame - # Wait for the logs to contain the magic words... - while True: - # Read the logs, crop to get only from the last log read - readlogs = FofbManager.logs - readlogs = readlogs[readlogs.index(lastlog):] - lastlog = readlogs[-1] + # --------------------------------------------------------------------------------------------------------------- + # Write event number back to 3 - if '[INFO] FOFB com. successfully started on Libera bpms' in "".join(readlogs): - break - time.sleep(1) + logger.info("Set Event Number back to 3 on local timing board, BpmTriggerEvent") + r=tlocal.write_attribute("bpm.trigEvent", 3) + for _r in r: + if _r.has_failed(): + logger.error("Failed to set Event Number on local timing board {}, bpm.trigEvent".format(_r.dev_name())) + return