Skip to content
Snippets Groups Projects
Commit 9ac9c5f4 authored by Andrey Samartsev's avatar Andrey Samartsev
Browse files

Merge branch 'fix/DAQoldformatCorr' into 'master'

Fix/da qoldformat corr

See merge request detectors/pycalibration!432
parents 5db3cca5 5e7b7ce3
No related branches found
No related tags found
1 merge request!432Fix/da qoldformat corr
...@@ -14,7 +14,7 @@ def get_pulseid_checksum(fname, h5path, h5path_idx): ...@@ -14,7 +14,7 @@ def get_pulseid_checksum(fname, h5path, h5path_idx):
with h5py.File(fname, "r") as infile: with h5py.File(fname, "r") as infile:
count = np.squeeze(infile[f"{h5path_idx}/count"]) count = np.squeeze(infile[f"{h5path_idx}/count"])
first = np.squeeze(infile[f"{h5path_idx}/first"]) first = np.squeeze(infile[f"{h5path_idx}/first"])
last_index = int(first[count != 0][-1]+count[count != 0][-1]) last_index = int(first[count != 0][-1] + count[count != 0][-1])
first_index = int(first[count != 0][0]) first_index = int(first[count != 0][0])
pulseids = infile[f"{h5path}/pulseId"][first_index: pulseids = infile[f"{h5path}/pulseId"][first_index:
int(first[count != 0][1])] int(first[count != 0][1])]
...@@ -26,7 +26,7 @@ def get_pulseid_checksum(fname, h5path, h5path_idx): ...@@ -26,7 +26,7 @@ def get_pulseid_checksum(fname, h5path, h5path_idx):
def _extr_gainparam_conffilename(fileName: str) -> Tuple[int]: def _extr_gainparam_conffilename(fileName: str) -> Tuple[int]:
"""extracts target gain from config filename, if provided.""" """extracts target gain from config filename, if provided."""
vals = re.search(".*_TG(?P<TG>\d+.?\d+)", fileName) vals = re.search(".*_TG(?P<TG>\\d+.?\\d+)", fileName)
if vals: if vals:
return vals.group('TG') return vals.group('TG')
...@@ -55,7 +55,7 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern, ...@@ -55,7 +55,7 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
encodedGainAll = {} encodedGainAll = {}
operatingFreqAll = {} operatingFreqAll = {}
for i in range(16): for i in range(16):
qm = 'Q{}M{}'.format(i//4+1, i % 4+1) qm = 'Q{}M{}'.format(i // 4 + 1, i % 4 + 1)
targetGainAll[qm] = None targetGainAll[qm] = None
encodedGainAll[qm] = None encodedGainAll[qm] = None
operatingFreqAll[qm] = None operatingFreqAll[qm] = None
...@@ -67,59 +67,78 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern, ...@@ -67,59 +67,78 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
f = os.path.join(in_folder, quad_sd_pattern) f = os.path.join(in_folder, quad_sd_pattern)
if os.path.exists(f): if os.path.exists(f):
ctrlDataFiles[quadrant+1] = f ctrlDataFiles[quadrant + 1] = f
if len(ctrlDataFiles) == 0: if len(ctrlDataFiles) == 0:
print("No Control Slow Data found!") print("ERROR: no Slow Control Data found!")
return targetGainAll, encodedGainAll, operatingFreqAll return targetGainAll, encodedGainAll, operatingFreqAll
ctrlloc = h5py.File(next(iter(ctrlDataFiles.values())), 'r')[ daq_format = None
'/METADATA/dataSources/deviceId'][0]
ctrlloc = None
filename = next(iter(ctrlDataFiles.values()))
with h5py.File(filename, 'r') as ctlrh5file:
if '/METADATA/dataSources/deviceId' in ctlrh5file:
ctrlloc = ctlrh5file['/METADATA/dataSources/deviceId'][0]
daq_format = ctlrh5file['/METADATA/dataFormatVersion'][0].decode(
"utf-8")
elif '/METADATA/deviceId' in ctlrh5file:
ctrlloc = ctlrh5file['/METADATA/deviceId'][0]
else:
print("ERROR: no Slow Control Data found in files!")
return targetGainAll, encodedGainAll, operatingFreqAll
ctrlloc = ctrlloc.decode("utf-8") ctrlloc = ctrlloc.decode("utf-8")
ctrlloc = ctrlloc[:ctrlloc.find('/')] ctrlloc = ctrlloc[:ctrlloc.find('/')]
tGain = {} tGain = {}
encodedGain = {} encodedGain = {}
operatingFreqs = {} operatingFreqs = {}
for quadrant, file in ctrlDataFiles.items(): for quadrant in range(1,5):
if len(file): if quadrant in ctrlDataFiles.keys():
h5file = h5py.File(file) file = ctrlDataFiles[quadrant]
if not f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value' in h5file: with h5py.File(file) as h5file:
print(f"Slow control data file {file} is not usable") iramp_path = f"/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value"
continue if not daq_format:
epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\ tGain[quadrant] = 0.0 # 0.0 is default value for TG
.decode("utf-8")
epcConfig = epcConfig[epcConfig.rfind('/') + 1:] if iramp_path in h5file:
irampSettings = h5file[iramp_path][0]
print(f"EPC configuration: {epcConfig}") else:
irampSettings = "Various"
targGain = _extr_gainparam_conffilename(epcConfig) else:
epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
tGain[quadrant] = float(targGain) if targGain is not None else 0.0 .decode("utf-8")
# 0.0 is default value for TG epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
gainSettingsMap = {} print(f"EPC configuration: {epcConfig}")
for coarseParam in ['fcfEnCap', 'csaFbCap', 'csaResistor']: targGain = _extr_gainparam_conffilename(epcConfig)
gainSettingsMap[coarseParam] = int( tGain[quadrant] = float(
h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/{coarseParam}/value'][0]) targGain) if targGain is not None else 0.0
irampSettings = h5file[iramp_path][0].decode("utf-8")
irampSettings = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value'][0]\
.decode("utf-8") gainSettingsMap = {}
for coarseParam in ['fcfEnCap', 'csaFbCap', 'csaResistor']:
gainSettingsMap['trimmed'] = np.int64( gainSettingsMap[coarseParam] = int(
1) if irampSettings == "Various" else np.int64(0) h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/{coarseParam}/value'][0])
encodedGain[quadrant] = _get_gain_encoded_val(gainSettingsMap) gainSettingsMap['trimmed'] = np.int64(
1) if irampSettings == "Various" else np.int64(0)
opFreq = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/sequencer/cycleLength/value'][0]
# The Operating Frequency of the detector should be in MHz. encodedGain[quadrant] = _get_gain_encoded_val(gainSettingsMap)
# Here the karabo operation mode is converted to acquisition rate:
# 22 corresponds to 4.5 MHz, 44 to 2.25 MHz, etc. opFreq = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/sequencer/cycleLength/value'][0]
operatingFreqs[quadrant] = 4.5 * (22.0 / opFreq) # The Operating Frequency of the detector should be in MHz.
# Here the karabo operation mode is converted to acquisition rate:
# 22 corresponds to 4.5 MHz, 44 to 2.25 MHz, etc.
operatingFreqs[quadrant] = 4.5 * (22.0 / opFreq)
else: else:
print(f"no slow data for quadrant {quadrant} is found") print(f"ERROR: no slow data for quadrant {quadrant} is found")
for varpair in [(targetGainAll, tGain), (encodedGainAll, encodedGain), (operatingFreqAll, operatingFreqs)]: for varpair in [
(targetGainAll, tGain),
(encodedGainAll, encodedGain),
(operatingFreqAll, operatingFreqs)]:
for quadrant, value in varpair[1].items(): for quadrant, value in varpair[1].items():
for module in range(1, 5): for module in range(1, 5):
qm = f'Q{quadrant}M{module}' qm = f'Q{quadrant}M{module}'
......
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