Skip to content
Snippets Groups Projects
Commit e34512d0 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Add some logging around constant injection

parent c8fc4255
No related branches found
No related tags found
1 merge request!1026Feat[Jungfrau]: Inject CCVs using RESTful API
import binascii
import logging
import time
from dataclasses import asdict, dataclass
from datetime import datetime, timezone
from hashlib import md5
from pathlib import Path
......@@ -21,6 +21,8 @@ from cal_tools.calcat_interface2 import (
CONDITION_NAME_MAX_LENGTH = 60
log = logging.getLogger(__name__)
class InjectionError(Exception):
...
......@@ -80,7 +82,7 @@ def create_unique_cc_name(det_type, calibration, condition_name):
def create_unique_ccv_name(start_idx):
# Generate unique name if it doesn't exist
datetime_str = datetime_str = datetime.now(
datetime_str = datetime.now(
timezone.utc).strftime('%Y%m%d_%H%M%S')
return f'{datetime_str}_sIdx={start_idx}'
......@@ -243,11 +245,13 @@ def get_or_create_calibration_constant(
cc_id = client.get(
f"calibrations/{cal_id}/get_calibration_constant",
calibration_constant
)
)['id']
log.debug("Retrieved existing calibration constant ID %s", cc_id)
except CalCatAPIError as e:
if e.status_code != 404:
raise
cc_id = client.post("calibration_constants", calibration_constant)['id']
log.debug("Created calibration constant ID %s", cc_id)
return cc_id
......@@ -344,6 +348,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None):
try:
condition_id, condition_name = create_condition(
client, detector_type, pdu_name, pdu_uuid, cond_params)
log.debug("Condition ID: %s & name: %r", condition_id, condition_name)
# Create Calibration Constant in database, if not available.
cc_id = get_or_create_calibration_constant(
......@@ -360,6 +365,7 @@ def inject_ccv(const_src, ccv_root, report_to=None, client=None):
description="",
))
report_id = resp['id']
log.debug("CalCat report ID: %s", report_id)
# Get PDU ID before creating new CCV.
pdu_id = client.pdu_by_name(pdu_name)['id']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment