diff --git a/ess/TraceWin.py b/ess/TraceWin.py index e6842124532e22058fd44998b9562754ae7cadb9..0ee742e9ef9df3cdad13058c509ebebb782906e0 100644 --- a/ess/TraceWin.py +++ b/ess/TraceWin.py @@ -1536,16 +1536,10 @@ class project: self._dict[key] = o[-1][vals.index(True)] else: current = "".join(hexlist[o[0] : o[0] + o[2]]) - if o[1] == "bool": - # TODO I think we can simplify here by using unpack of type "?" - if current == o[3]: - self._dict[key] = False - elif current == o[4]: - self._dict[key] = True - else: - raise ValueError(f"Wrong setting found for {key}, found {current}, expected one of {o[3:]}") - elif o[1] in ["d", "f", "i"]: + if o[1] in ["d", "f", "i", "?"]: self._dict[key] = struct.unpack(o[1], b"".fromhex(current))[0] + else: + raise TypeError(f"Unknown type for {key}: {o[1]}") def print_settings(self, settings=None): """ @@ -1626,14 +1620,7 @@ class project: t = False hexlist[i] = struct.pack("?", t).hex() else: - if isinstance(v, bool): - # TODO Think we can simplify this by using pack of type ? - if v: - v = [o[-1]] - else: - v = [o[-2]] - else: - v = wrap(struct.pack(o[1], v).hex(), 2) + v = wrap(struct.pack(o[1], v).hex(), 2) for i in range(len(v)): hexlist[o[0] + i] = v[i] diff --git a/ess/data/tw_project_file_reverse_engineered.json b/ess/data/tw_project_file_reverse_engineered.json index f953f852bc34fe0b57920583e5fbd53fc4dd6edc..5b9baf6ab06ea74000b7f03135deac2d2cdf9ecc 100644 --- a/ess/data/tw_project_file_reverse_engineered.json +++ b/ess/data/tw_project_file_reverse_engineered.json @@ -1,38 +1,28 @@ { "partran": [ 109, - "bool", - 1, - "00", - "01" + "?", + 1 ], "toutatis": [ 135, - "bool", - 1, - "00", - "01" + "?", + 1 ], "match:input_matched_beam": [ 128, - "bool", - 1, - "00", - "01" + "?", + 1 ], "match:family_twiss": [ 113, - "bool", - 1, - "00", - "01" + "?", + 1 ], "match:diag": [ 118, - "bool", - 1, - "00", - "01" + "?", + 1 ], "match:limit_criterion": [ 12260, @@ -119,5 +109,130 @@ 9876, "i", 4 + ], + "match:input_matched_beam_wpartran": [ + 20200, + "?", + 1 + ], + "match:family_twiss_wpartran": [ + 20201, + "?", + 1 + ], + "match:diag_wpartran": [ + 20202, + "?", + 1 + ], + "mp:partr_sc_picnir_mesh_long": [ + 12032, + "i", + 4 + ], + "mp:partr_sc_picnir_mesh_transv": [ + 12028, + "i", + 4 + ], + "mp:partr_sc_picnic_mesh_transv": [ + 12036, + "i", + 4 + ], + "mp:partr_sc_picnic_mesh_long": [ + 12040, + "i", + 4 + ], + "mp:partr_sc_picnic_weight": [ + 12052, + "i", + 4 + ], + "mp:partr_sc_picnic_meshrms": [ + 12244, + "d", + 8 + ], + "mp:partr_sc_picnic_skip": [ + 12056, + "i", + 4 + ], + "err:study_envelope": [ + 114, + "?", + 1 + ], + "err:study_multipart": [ + 111, + "?", + 1 + ], + "err:beamref": [ + 8737, + "?", + 1 + ], + "mp:input_distr": [ + 8732, + "i", + 4 + ], + "mp:input_distr_mask_transv": [ + 8728, + "i", + 4 + ], + "mp:input_distr_mask_long": [ + 8724, + "i", + 4 + ], + "mp:partr_enerphase_lost_eesynchr": [ + 12632, + "d", + 8 + ], + "mp:partr_enerphase_lost_p-psynchr": [ + 12640, + "d", + 8 + ], + "mp:partr_enerphase_excl_e-esynchr": [ + 12672, + "d", + 8 + ], + "mp:partr_enerphase_excl_p-psynchr": [ + 12680, + "d", + 8 + ], + "mp:plt_includedistr_lastelmt": [ + 120, + "?", + 1 + ], + "mp:plt_includedistr_eachperiod": [ + 121, + "?", + 1 + ], + "mp:plt_includedistr_lossfile": [ + 22768, + "?", + 1 + ], + "mp:plt_includedistr_stoplost": [ + 23275, + "?", + 1 + ], + "mp:multithread": [ + 20248, + "?", + 1 ] }