Skip to content
Snippets Groups Projects

Fix/da qoldformat corr

Merged Andrey Samartsev requested to merge fix/DAQoldformatCorr into master
4 unresolved threads
@@ -72,8 +72,21 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
print("No Control Slow Data found!")
return targetGainAll, encodedGainAll, operatingFreqAll
ctrlloc = h5py.File(next(iter(ctrlDataFiles.values())), 'r')[
'/METADATA/dataSources/deviceId'][0]
daq_format = ''
ctrlloc = None
filename = next(iter(ctrlDataFiles.values()))
ctlrh5file = h5py.File(filename, 'r')
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("No Slow Control Data found in files!")
return targetGainAll, encodedGainAll, operatingFreqAll
ctrlloc = ctrlloc.decode("utf-8")
ctrlloc = ctrlloc[:ctrlloc.find('/')]
@@ -83,27 +96,31 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
for quadrant, file in ctrlDataFiles.items():
if len(file):
h5file = h5py.File(file)
if not f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value' in h5file:
print(f"Slow control data file {file} is not usable")
continue
epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
.decode("utf-8")
epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
print(f"EPC configuration: {epcConfig}")
targGain = _extr_gainparam_conffilename(epcConfig)
tGain[quadrant] = float(targGain) if targGain is not None else 0.0
# 0.0 is default value for TG
if daq_format != '':
    • Please do the check before opening the file.
      The use a context manager to open and close the file (with h5py.File(filename) as f:...)

      • I would have written this bit as

        Suggested change
        96 for quadrant, file in ctrlDataFiles.items():
        97 if len(file):
        98 h5file = h5py.File(file)
        99 if daq_format != '':
        100 epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
        101 .decode("utf-8")
        102 epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
        103
        104 print(f"EPC configuration: {epcConfig}")
        105 targGain = _extr_gainparam_conffilename(epcConfig)
        106 tGain[quadrant] = float(
        107 targGain) if targGain is not None else 0.0
        108 # 0.0 is default value for TG
        109 else:
        110 tGain[quadrant] = 0.0
        96 for quadrant, filename in ctrlDataFiles.items():
        97 if filename:
        98 if not daq_format:
        99 tGain[quadrant] = 0.0
        100 else:
        101 with h5file.File(filename) as h5file:
        102 epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0].decode("utf-8")
        103 epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
        104
        105 print(f"EPC configuration: {epcConfig}")
        106 targGain = _extr_gainparam_conffilename(epcConfig)
        107 tGain[quadrant] = float(targGain) if targGain is not None else 0.0

        With this in mind, I'm wondering whether the topmost if could be if not daq_formant or not filename:? Then this block is even simpler so:

        Suggested change
        96 for quadrant, file in ctrlDataFiles.items():
        97 if len(file):
        98 h5file = h5py.File(file)
        99 if daq_format != '':
        100 epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
        101 .decode("utf-8")
        102 epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
        103
        104 print(f"EPC configuration: {epcConfig}")
        105 targGain = _extr_gainparam_conffilename(epcConfig)
        106 tGain[quadrant] = float(
        107 targGain) if targGain is not None else 0.0
        108 # 0.0 is default value for TG
        109 else:
        110 tGain[quadrant] = 0.0
        96 for quadrant, filename in ctrlDataFiles.items():
        97 if not filename or not daq_format:
        98 tGain[quadrant] = 0.0
        99 else:
        100 with h5file.File(filename) as h5file:
        101 epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0].decode("utf-8")
        102 epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
        103
        104 print(f"EPC configuration: {epcConfig}")
        105 targGain = _extr_gainparam_conffilename(epcConfig)
        106 tGain[quadrant] = float(targGain) if targGain is not None else 0.0
        Edited by Cyril Danilevski
      • changed this line in version 2 of the diff

      • Author Contributor

        Added exception handling, changed order in branching.

        Edited by Andrey Samartsev
      • Author Contributor
        Edited by Andrey Samartsev
      • Please register or sign in to reply
Please register or sign in to reply
epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
.decode("utf-8")
epcConfig = epcConfig[epcConfig.rfind('/') + 1:]
print(f"EPC configuration: {epcConfig}")
targGain = _extr_gainparam_conffilename(epcConfig)
tGain[quadrant] = float(
targGain) if targGain is not None else 0.0
# 0.0 is default value for TG
else:
tGain[quadrant] = 0.0
gainSettingsMap = {}
for coarseParam in ['fcfEnCap', 'csaFbCap', 'csaResistor']:
gainSettingsMap[coarseParam] = int(
h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/{coarseParam}/value'][0])
irampSettings = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value'][0]\
.decode("utf-8")
iramp_path = f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value'
if daq_format != '':
irampSettings = h5file[iramp_path][0].decode("utf-8")
elif iramp_path in h5file:
irampSettings = h5file[iramp_path][0]
else:
irampSettings = "Various"
gainSettingsMap['trimmed'] = np.int64(
1) if irampSettings == "Various" else np.int64(0)
@@ -118,7 +135,10 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
else:
print(f"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 module in range(1, 5):
qm = f'Q{quadrant}M{module}'
Loading