// // h5tb_particle_interface.cpp // mc_electron // // Created by Christian Reiling on 19.05.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #include #include "h5tb_particle_interface.hpp" using namespace std; logParticle samplelogParticle = {0,0,0,0,0,0,0,0}; const size_t H5TB_Particle_Interface::size = sizeof(logParticle); const char *H5TB_Particle_Interface::fieldNames[8] = { "Id","ParentId", "x_m", "y_m", "z_m", "vx_ms", "vy_ms", "vz_ms" }; const size_t H5TB_Particle_Interface::offset[8] = { HOFFSET(logParticle, Id), HOFFSET(logParticle, parentId), HOFFSET(logParticle, x_m), HOFFSET(logParticle, y_m), HOFFSET(logParticle, z_m), HOFFSET(logParticle, vx_ms), HOFFSET(logParticle, vy_ms), HOFFSET(logParticle, vz_ms)}; const hid_t H5TB_Particle_Interface::fieldTypes[8] = { H5T_NATIVE_INT, H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE, H5T_NATIVE_DOUBLE}; const hsize_t H5TB_Particle_Interface::chunkSize = 145; const size_t H5TB_Particle_Interface::sizes[8] = { sizeof( samplelogParticle.Id), sizeof( samplelogParticle.parentId), sizeof( samplelogParticle.x_m), sizeof( samplelogParticle.y_m), sizeof( samplelogParticle.z_m), sizeof( samplelogParticle.vx_ms), sizeof( samplelogParticle.vy_ms), sizeof( samplelogParticle.vz_ms)}; void H5TB_Particle_Interface::create() { herr_t state = H5TBmake_table(table_name.c_str(), *loc_id, table_name.c_str(), 8, 0, size, fieldNames, offset, fieldTypes, chunkSize, nullptr, 0, nullptr); if (state < 0) { stringstream ss; ss<<"H5TB_Particle_Interface::create: Error creating.\n"; throw MyException(ss.str()); } } void H5TB_Particle_Interface::write(const Particle &logPart) { buffer[buffer_count] = transform(logPart); buffer_count = buffer_count + 1; if (buffer_count == buffer_size) { H5TBappend_records(*loc_id, table_name.c_str() , buffer_size, size, offset, sizes, &buffer); buffer_count = 0; } } void H5TB_Particle_Interface::flush() { H5TBappend_records(*loc_id, table_name.c_str() , buffer_count, size, offset, sizes, &buffer); buffer_count = 0; } H5TB_Particle_Interface::~H5TB_Particle_Interface() { flush(); } loggerParticle H5TB_Particle_Interface::transform(const Particle &logPart) { logParticle res; res.Id = logPart.get_Id(); res.parentId = logPart.get_PId(); res.x_m = logPart.get_x_m()[0]; res.y_m = logPart.get_x_m()[1]; res.z_m = logPart.get_x_m()[2]; res.vx_ms = logPart.get_v_ms()[0]; res.vy_ms = logPart.get_v_ms()[1]; res.vz_ms = logPart.get_v_ms()[2]; return res; }