Skip to content

Commit

Permalink
Merge pull request #79 from smash-transport/roch/increase_binary_vers…
Browse files Browse the repository at this point in the history
…ion_number

Increase binary version number due to added strangeness
  • Loading branch information
Hendrik1704 authored Nov 14, 2023
2 parents a347575 + 9f02546 commit 11823db
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 72 additions & 1 deletion python_scripts/read_binary_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')])
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit 11823db

Please sign in to comment.