Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions daq_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import bluesky.plan_stubs as bps
import logging
from utils import validation
import requests
logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -446,6 +447,14 @@ def runDCQueue(): #maybe don't run rasters from here???
logger.info("running queue in daq server")
while (1):
currentRequest = db_lib.popNextRequest(daq_utils.beamline)
if (currentRequest == {}):
break
elif currentRequest is None:
gui_message("Queue contains collection requests from different proposals"
"and not using commissioning directory."
"Please remove invalid requests or switch to"
"commissioning directory to continue")
break
if (getBlConfig("queueCollect") == 1):
if (getBlConfig(BEAM_CHECK) == 1):
waitBeam()
Expand All @@ -462,14 +471,6 @@ def runDCQueue(): #maybe don't run rasters from here???
if (abort_flag):
abort_flag = 0 #careful about when to reset this
return
if (currentRequest == {}):
break
elif currentRequest is None:
gui_message("Queue contains collection requests from different proposals"
"and not using commissioning directory."
"Please remove invalid requests or switch to"
"commissioning directory to continue")
break
logger.info("processing request " + str(time.time()))
reqObj = currentRequest["request_obj"]
gov_lib.set_detz_in(gov_robot, reqObj["detDist"])
Expand Down Expand Up @@ -753,8 +754,22 @@ def collectData(currentRequest):
node = getBlConfig(nodeName)
dimpleNode = getBlConfig("dimpleNode")
if (daq_utils.detector_id == "EIGER-16"):
with open(f"{os.environ['CONFIGDIR']}/autoproc_blacklist.json") as autoproc_blacklist_file:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be moved somewhere so that the file does not have to be json.loaded every time the check is performed?

autoproc_proposal_data = json.load(autoproc_blacklist_file)
run_autoproc = 0
try:
r = requests.get(f"{os.environ['NSLS2_API_URL']}/v1/proposal/{currentRequest['proposalID']}")
r.raise_for_status()
response = r.json()['proposal']
if ("proprietary" in response["type"].lower()
or int(currentRequest["proposalID"]) in autoproc_proposal_data["blacklist"]):
run_autoproc = 0
else:
run_autoproc = 1
except Exception as e:
run_autoproc = 0
seqNum = flyer.detector.cam.sequence_id.get()
comm_s = os.environ["LSDCHOME"] + "/runFastDPH5.py " + data_directory_name + " " + str(seqNum) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + " " + str(currentIspybDCID)+ "&"
comm_s = os.environ["LSDCHOME"] + "/runFastDPH5.py " + data_directory_name + " " + str(seqNum) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + " " + str(currentIspybDCID)+ " " + str(run_autoproc) + " &"
else:
comm_s = os.environ["LSDCHOME"] + "/runFastDP.py " + data_directory_name + " " + file_prefix + " " + str(file_number_start) + " " + str(int(round(range_degrees/img_width))) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + "&"
logger.info(f'Running fastdp command: {comm_s}')
Expand Down
65 changes: 50 additions & 15 deletions runFastDPH5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import os
import sys
import db_lib
from daq_utils import getBlConfig
from daq_utils import getBlConfig, setBlConfig
import xmltodict
import json
import logging
import subprocess
logger = logging.getLogger()
logging.getLogger().setLevel(logging.INFO)
handler1 = logging.FileHandler('fast_dp.txt')
Expand Down Expand Up @@ -32,26 +34,59 @@
runDimple = int(sys.argv[6])
dimpleNode = sys.argv[7]
ispybDCID = 1 #int(sys.argv[8])
runAutoProc = int(sys.argv[9])
# runAutoProc = 0

comm_s = f"ssh -q {node} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}fast_dp.sh {request_id} {numstart}\""
logger.info(comm_s)
os.system(comm_s)
try:
comm_s = f"ssh -q {node} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}fast_dp.sh {request_id} {numstart}\""
logger.info(comm_s)
os.system(comm_s)
fastDPResultFile = runningDir+"/fast_dp.xml"
fd = open(fastDPResultFile)
resultObj = xmltodict.parse(fd.read())
logger.info(f"finished fast_dp {request_id}")
resultID = db_lib.addResultforRequest("fastDP",request_id,owner,resultObj,beamline=os.environ["BEAMLINE_ID"])
newResult = db_lib.getResult(resultID)
visitName = getBlConfig("visitName")
except Exception as e:
logger.error("runfastdph5 error running fastdp: %s" % e)

fastDPResultFile = runningDir+"/fast_dp.xml"
fd = open(fastDPResultFile)
resultObj = xmltodict.parse(fd.read())
logger.info(f"finished fast_dp {request_id}")
resultID = db_lib.addResultforRequest("fastDP",request_id,owner,resultObj,beamline=os.environ["BEAMLINE_ID"])
newResult = db_lib.getResult(resultID)
visitName = getBlConfig("visitName")
try:
ispybLib.insertResult(newResult,"fastDP",request,visitName,ispybDCID,fastDPResultFile)
except Exception as e:
logger.error("runfastdph5 insert result ispyb error: %s" % e)

if (runFastEP):
os.system("fast_ep") #looks very bad! running on ca1!

if (runDimple):
dimpleComm = getBlConfig("dimpleComm")
comm_s = f"ssh -q {dimpleNode} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}dimple.sh {request_id} {numstart}\""
logger.info(f"running dimple: {comm_s}")
os.system(comm_s)
try:
dimpleComm = getBlConfig("dimpleComm")
comm_s = f"ssh -q {dimpleNode} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}dimple.sh {request_id} {numstart}\""
logger.info(f"running dimple: {comm_s}")
# os.system(comm_s)
subprocess.Popen(comm_s, shell=True)
except Exception as e:
logger.error("runfastdph5 error running dimple: %s" % e)

if runAutoProc:
logger.info("Running AUTO-AUTOPROC...")
setBlConfig("auto_proc_lock", True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find that this locking was necessary to prevent breaking the queue?

try:
queue = getBlConfig("auto_proc_queue")
queue.append((directory, request_id))
setBlConfig("auto_proc_queue", queue)
except Exception as e:
logger.exception("Could not add request to autoproc queue")
finally:
setBlConfig("auto_proc_lock", False)
start_in_proc = None
autoproc_processor_list = json.loads(getBlConfig("autoprocNodes"))
for proc_num in autoproc_processor_list:
if not getBlConfig(proc_num):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the BlConfig flag for proc_num is set, then cleared in the autoproc.py file in lsdc_processing.

All the more reason to make sure the changes related to autoproc are put into a PR for lsdc_processing!

start_in_proc = proc_num
break
if start_in_proc:
comm_s = f"ssh {start_in_proc} \"nohup {os.environ['MXPROCESSINGSCRIPTSDIR']}autoproc.sh {start_in_proc} {os.environ['BEAMLINE_ID']} & \" "
logger.info(f"Initializing AUTO-AUTOPROC {comm_s} \n In ({directory}, {request_id})")
subprocess.Popen(comm_s, shell=True)