Files
katrin-plasma/src/mc_electron/h5_particles.h
T
2019-06-17 13:22:57 +02:00

121 lines
2.6 KiB
C++

//
// h5_particles.h
// mc_electron
//
// Created by Christian Reiling on 18.05.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef h5_particles_h
#define h5_particles_h
#include "read_system.h"
#include <string>
#include <sstream>
#include "hdf5.h"
#include "hdf5_hl.h"
#include "katrin_geo.hpp"
class H5_Particles {
int numberZBins;
bool logging;
double *zValues;
hid_t *h5_file;
hid_t *h5g_particles;
hid_t *h5g_z;
public:
H5_Particles() {};
H5_Particles(hid_t *h5_file);
int get_numberZBins() {return(numberZBins);}
bool get_logging() {return(logging);}
double *get_zValues() {return(zValues);}
hid_t *get_h5g_z() {return(h5g_z);}
private:
void set_logging();
void set_zValues();
void print_logInfo();
void create_h5gs();
};
inline H5_Particles::H5_Particles(hid_t *h5_file) {
this->h5_file = h5_file;
numberZBins = load_parameter("numberZBins");
set_logging();
set_zValues();
print_logInfo();
create_h5gs();
}
inline void H5_Particles::set_logging() {
if (numberZBins == 0) {
logging = false;
} else if (numberZBins == -1 || numberZBins > 0){
logging = true;
} else {
std::stringstream ss;
ss<<"H5_Logger::Parameter numberZBins invalid value.\nnumberZBins:\t"<<numberZBins<<"\n";
throw MyException (ss.str());
}
}
inline void H5_Particles::set_zValues() {
if (logging) {
zValues = new double[numberZBins];
double start_m = Katrin_Geo::get_z_RW_m();
double length_m = Katrin_Geo::get_z_WGTSend_m() - start_m;
double stepLength_m = length_m/(numberZBins-1);
double z_m;
for (int i = 0;i<numberZBins;i++) {
z_m = start_m + stepLength_m*i;
zValues[i] = z_m;
}
}
}
inline void H5_Particles::print_logInfo() {
std::stringstream ss;
if (!logging) {
ss<<"Logging disabled.\n";
} else if (numberZBins == -1) {
ss<<"Logging after every Interaction to one file.\n";
} else if (numberZBins == 1) {
ss<<"Only Logging Rearwall Output.\n";
} else {
ss<<"Logging at "<<numberZBins<<" z values.\n";
}
std::cout<<ss.str();
}
inline void H5_Particles::create_h5gs() {
h5g_particles = new hid_t;
*h5g_particles = H5Gcreate(*h5_file, "/Particles", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if (numberZBins == -1) {
h5g_z = new hid_t[1];
h5g_z[0] = H5Gcreate(*h5_file, "/Particles/z=all", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
} else {
h5g_z = new hid_t [numberZBins];
for (int i = 0; i < numberZBins; i++)
{
std::stringstream ss;
ss << "/Particles/" << zValues[i];
std::cout<< ss.str()<<"\n";
h5g_z[i] = H5Gcreate(*h5_file, ss.str().c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
}
}
#endif /* h5_particles_h */