Skip to content

Instantly share code, notes, and snippets.

@berezovskyi
Created February 4, 2016 19:21
Show Gist options
  • Save berezovskyi/10004d5fcf00a3d4477e to your computer and use it in GitHub Desktop.
Save berezovskyi/10004d5fcf00a3d4477e to your computer and use it in GitHub Desktop.
import tables
def main():
class Particle(tables.IsDescription):
name = tables.StringCol(16) # 16-character String
idnumber = tables.Int64Col() # Signed 64-bit integer
ADCcount = tables.UInt16Col() # Unsigned short integer
TDCcount = tables.UInt8Col() # unsigned byte
grid_i = tables.Int32Col() # 32-bit integer
grid_j = tables.Int32Col() # 32-bit integer
pressure = tables.Float32Col() # float (single-precision)
energy = tables.Float64Col() # double (double-precision)
h5file = tables.open_file("test.h5", mode="a")
if "/detector" not in h5file:
group = h5file.create_group("/", 'detector', 'Detector information')
else:
group = h5file.root.detector
if "readout" not in group:
table = h5file.create_table(group, 'readout', Particle, "Readout example")
else:
table = h5file.root.detector.readout
particle = table.row
for i in range(200000):
particle['name'] = 'Particle: %6d' % i
particle['TDCcount'] = i % 256
particle['ADCcount'] = (i * 256) % (1 << 16)
particle['grid_i'] = i
particle['grid_j'] = 10 - i
particle['pressure'] = float(i * i)
particle['energy'] = float(particle['pressure'] ** 4)
particle['idnumber'] = i * (2 ** 34)
# Insert a new particle record
particle.append()
h5file.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment