Skip to content

Commit

Permalink
Merge branch 'develop' into user-based-details
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikatrojanowska authored Jan 30, 2025
2 parents daa1adf + 17afd07 commit fc7522d
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 174 deletions.
18 changes: 3 additions & 15 deletions mxcubecore/HardwareObjects/ESRF/SSXICATLIMS.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,13 @@
import logging
import pathlib

from pyicat_plus.client.main import (
IcatClient,
IcatInvestigationClient,
)
from pyicat_plus.client.models.session import Session as ICATSession

from mxcubecore import HardwareRepository as HWR
from mxcubecore.BaseHardwareObjects import HardwareObject
from mxcubecore.HardwareObjects.ICATLIMS import ICATLIMS
from mxcubecore.model.lims_session import (
Lims,
LimsSessionManager,
Session,
)


class SSXICATLIMS(ICATLIMS):
"""
ICAT client.
ICAT+ client for SSX.
"""

def store_data_collection(self, parameters, bl_config=None):
Expand Down Expand Up @@ -77,5 +65,5 @@ def finalize_data_collection(self, parameters):
f.write(json.dumps(data, indent=4))
logging.getLogger("HWR").info(f"Wrote {icat_metadata_path}")

except Exception:
logging.getLogger("HWR").exception("")
except Exception as e:
logging.getLogger("HWR").exception("Failed uploading to ICAT (%s)", e)
42 changes: 30 additions & 12 deletions mxcubecore/HardwareObjects/ESRFLIMS.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import logging
from typing import List

from pyicat_plus.client.main import (
IcatClient,
IcatInvestigationClient,
)
from pyicat_plus.client.models.session import Session as ICATSession

from mxcubecore import HardwareRepository as HWR
from mxcubecore.HardwareObjects.abstract.AbstractLims import AbstractLims
from mxcubecore.model.lims_session import (
Lims,
Expand All @@ -18,7 +11,7 @@

class ESRFLIMS(AbstractLims):
"""
ESRF client.
ESRF client (ICAT+ and IPyB).
"""

def __init__(self, name):
Expand All @@ -39,13 +32,37 @@ def get_session_id(self) -> str:
)
return self.drac.get_session_id()

def is_single_session_available(self):
"""
True if there is no active session and there is
a single session available
"""
return (
self.session_manager.active_session is None
and len(self.session_manager.sessions) == 1
)

def login(self, user_name, token, is_local_host=False) -> LimsSessionManager:
self.is_local_host = is_local_host
session_manager = self.drac.login(user_name, token, is_local_host)
session_manager, lims_username, sessions = self.drac.login(
user_name, token, self.session_manager
)
logging.getLogger("HWR").debug(
"DRAC sessions=%s" % (len(self.drac.session_manager.sessions),)
"%s sessions found. user=%s" % (len(sessions), user_name)
)

self.session_manager = self.drac.session_manager
self.add_user_and_shared_sessions(lims_username, sessions)

# In case there is a single available session then it is selected automatically
if self.is_single_session_available():
single_session = self.session_manager.sessions[0]
logging.getLogger("HWR").debug(
"Single session available which will be selected automatically. session_id=%s"
% (single_session.session_id)
)
self.set_active_session_by_id(single_session.session_id)

if session_manager.active_session is None:
logging.getLogger("HWR").debug(
"DRAC no session selected then no activation of session in ISPyB"
Expand All @@ -56,8 +73,7 @@ def login(self, user_name, token, is_local_host=False) -> LimsSessionManager:
session_manager.active_session.number,
self.is_local_host,
)

return self.drac.session_manager
return self.session_manager

def is_user_login_type(self) -> bool:
return True
Expand Down Expand Up @@ -195,9 +211,11 @@ def store_beamline_setup(self, session_id, bl_config):
self.ispyb.store_beamline_setup(session_id, bl_config)

def store_energy_scan(self, energyscan_dict):
energyscan_dict["sessionId"] = self.ispyb.get_session_id()
return self.ispyb.store_energy_scan(energyscan_dict)

def store_xfe_spectrum(self, xfespectrum_dict):
xfespectrum_dict["sessionId"] = self.ispyb.get_session_id()
return self.ispyb.store_xfe_spectrum(xfespectrum_dict)

def store_workflow(self, *args, **kwargs):
Expand Down
Loading

0 comments on commit fc7522d

Please sign in to comment.