Skip to content
Snippets Groups Projects

[Generic] Injection code for DynamicFF corrections

Merged Philipp Schmidt requested to merge feat/shimadzu-injection into feat/shimadzu-correction
All threads resolved!
+ 20
11
@@ -137,7 +137,7 @@ def inject_ccv(const_src, ccv_root, report_to):
unique_name = detector_type[:detector_type.index('-Type')] + ' Def'
cond_hash = md5(pdu_name.encode())
cond_hash.update(pdu_uuid.to_bytes(
length=8, byteorder='little', signed=False))3
length=8, byteorder='little', signed=False))
for param_dict in cond_params:
cond_hash.update(str(param_dict['parameter_name']).encode())
@@ -184,19 +184,24 @@ def inject_ccv(const_src, ccv_root, report_to):
}
}
resp = CalibrationClient.inject_new_calibration_constant_version(calibration_client(), inject_h)
if not resp['success']:
raise RuntimeError(resp)
const_dest = _get_default_caldb_root() / const_rel_path / const_filename
const_dest.parent.mkdir(parents=True, exist_ok=True)
copyfile(const_src, const_dest)
resp = CalibrationClient.inject_new_calibration_constant_version(
calibration_client(), inject_h)
if not resp['success']:
const_dest.unlink() # Delete already copied CCV file.
raise RuntimeError(resp)
def inject_ccv_legacy(in_folder, metadata_folder, runs, calibration, cond, pdu, const_input, begin_at):
def inject_ccv_legacy(in_folder, metadata_folder, runs, calibration, cond,
pdu, const_input, begin_at):
"""Inject new CCV into CalCat.
LEGACY VERSION - DO NOT USE
(from before most details were saved in CCV file itself)
metadata_folder
calibration -> in file, but pass anyway as there could be multiple
@@ -209,13 +214,15 @@ def inject_ccv_legacy(in_folder, metadata_folder, runs, calibration, cond, pdu,
metadata_folder, # Same as notebook parameter
[run_high, run_mid, run_low],
'Offset',
current_pdu, # Element of calibration_client.from get_all_phy_det_units_from_detector
current_pdu, # Element of calibration_client.from
# get_all_phy_det_units_from_detector
out_folder / 'my-constant-file.h5',
get_dir_creation_date(in_folder, run_high)
)
Args:
in_folder (str or Path): Root for input data, i.e. *not* containing r{run:04d} folder
in_folder (str or Path): Root for input data, i.e. *not*
containing r{run:04d} folder
metadata_folder (str or Path): Metadata location
runs (Iterable of str or int): Run number(s) used for characterization.
calibration (str): Calibration name, e.g. 'Offset', must exist in CalCat.
@@ -246,7 +253,8 @@ def inject_ccv_legacy(in_folder, metadata_folder, runs, calibration, cond, pdu,
# Generate condition name.
unique_name = detector_type[:detector_type.index('-Type')] + ' Def'
cond_hash = hashlib.md5(pdu_name.encode())
cond_hash.update(pdu['uuid'].to_bytes(length=8, byteorder='little', signed=False))
cond_hash.update(pdu['uuid'].to_bytes(
length=8, byteorder='little', signed=False))
for key, value in cond_dict.items():
cond_hash.update(str(key).encode())
@@ -305,7 +313,8 @@ def inject_ccv_legacy(in_folder, metadata_folder, runs, calibration, cond, pdu,
}
}
resp = CalibrationClient.inject_new_calibration_constant_version(calibration_client(), inject_h)
resp = CalibrationClient.inject_new_calibration_constant_version(
calibration_client(), inject_h)
if not resp['success']:
raise RuntimeError(resp)
Loading