diff --git a/CHANGELOG.md b/CHANGELOG.md index 1adf67a..5ff352f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Also possible, but for this project less relevant, is `Deprecated` for soon-to-b ## Unreleased +* :heavy_plus_sign: New binary reader version due to added strangeness output ## SMASH-analysis-3.0 Date: 2023-04-28 diff --git a/python_scripts/read_binary_output.py b/python_scripts/read_binary_output.py index 0530b4b..00ce278 100755 --- a/python_scripts/read_binary_output.py +++ b/python_scripts/read_binary_output.py @@ -324,6 +324,10 @@ def _read_binary_block_v8(bfile): """Read one output block from SMASH binary file.""" return _read_binary_block_v7(bfile) # Nothing has changed for non-extended +def _read_binary_block_v9(bfile): + """Read one output block from SMASH binary file.""" + return _read_binary_block_v7(bfile) # Nothing has changed for non-extended + def _read_binary_block_v4_extended(bfile): """Read one output block from SMASH binary file.""" particle_data_type = np.dtype([('r','d',4),('mass','d'),('p','d',4),('pdgid','i4'),('id','i4'),('Ncoll','i4'),('formation_time','d'),('cross_section_scaling_factor','f'),('process_ID_origin','i4'),('process_type_origin', 'i4'),('time_of_origin','f'),('PDG_mother1','i4'),('PDG_mother2','i4')]) @@ -621,6 +625,68 @@ def _read_binary_block_v8_extended(bfile): return else: raise ValueError('This is not the start of a block.') + +def _read_binary_block_v9_extended(bfile): + """Read one output block from SMASH binary file.""" + particle_data_type = np.dtype([('r','d',4),('mass','d'),('p','d',4),('pdgid','i4'),('id','i4'),('charge','i4'),('Ncoll','i4'),('formation_time','d'),('cross_section_scaling_factor','d'),('process_ID_origin','i4'),('process_type_origin', 'i4'),('time_of_origin','d'),('PDG_mother1','i4'),('PDG_mother2','i4'),('baryon_number','i4'),('strangeness','i4')]) + + block_type = bfile.read(1).decode(encoding) + if (block_type == 'p'): + # got particles block + npart = np.fromfile(bfile, dtype='i4', count=1)[0] + particles = np.fromfile(bfile, dtype=particle_data_type, count=npart) + try: + tmp_type = bfile.read(1).decode(encoding) + if ((tmp_type == 'p') or (tmp_type == 'f') or (tmp_type == 'i')): + bfile.seek(-1, 1) + return {'type': block_type, + 'npart': npart, + 'part': particles + } + else: + return None + except: + return None + elif (block_type == 'i'): + # got interaction block + n_inout = np.fromfile(bfile, dtype='i4', count=2) + rho = np.fromfile(bfile, dtype='d', count=1)[0] + sigma = np.fromfile(bfile, dtype='d', count=1)[0] + sigma_p = np.fromfile(bfile, dtype='d', count=1)[0] + process = np.fromfile(bfile, dtype='i4', count=1)[0] + incoming = np.fromfile(bfile, dtype=particle_data_type, count=n_inout[0]) + outgoing = np.fromfile(bfile, dtype=particle_data_type, count=n_inout[1]) + try: + tmp_type = bfile.read(1).decode(encoding) + if ((tmp_type == 'p') or (tmp_type == 'f') or (tmp_type == 'i')): + bfile.seek(-1, 1) + return {'type': block_type, + 'nin': n_inout[0], + 'nout': n_inout[1], + 'incoming': incoming, + 'outgoing': outgoing, + 'density': rho, + 'total_cross_section': sigma, + 'partial_cross_section': sigma_p, + 'process_type': process + } + else: + return None + except: + return None + elif (block_type == 'f'): + n_event = np.fromfile(bfile, dtype='i4', count=1)[0] + impact_parameter = np.fromfile(bfile, dtype='d', count=1)[0] + empty_event = np.fromfile(bfile, dtype='B', count=1)[0] + return {'type': block_type, + 'nevent': n_event, + 'b' : impact_parameter, + 'empty_event': bool(empty_event)} + elif (block_type == ''): + # got eof + return + else: + raise ValueError('This is not the start of a block.') class BinaryReader: """A reader for SMASH binary files. @@ -636,7 +702,12 @@ class BinaryReader: def __init__(self, path): self.__file = open(path, 'rb') self.smash_version, self.format_extended, self.format_version = _read_binary_header(self.__file) - if self.format_version == 8: + if self.format_version == 9: + if self.format_extended == 1: + self.__read_block = _read_binary_block_v9_extended + elif self.format_extended == 0: + self.__read_block = _read_binary_block_v9 + elif self.format_version == 8: if self.format_extended == 1: self.__read_block = _read_binary_block_v8_extended elif self.format_extended == 0: