1 #ifndef RAYTRACE_API_HH 2 #define RAYTRACE_API_HH 5 #include <openPMD/openPMD.hpp> 58 Record(): _vals(), _min(), _max() { clear(); }
59 const std::vector<T>& vals(
void)
const {
return _vals; };
60 std::vector<T>& vals(
void) {
return _vals; };
61 T min(
void)
const {
return _min; };
62 T max(
void)
const {
return _max; };
65 void push_back(T val) {
67 if (_min > val) (_min) = val;
68 if (_max < val) (_max) = val;
72 void store(
const T* vec,
size_t n,
float min,
float max) {
74 _vals.insert(_vals.begin(), vec, vec + n);
79 void clear_chunk(
void) { _vals.clear(); }
82 std::numeric_limits<T> lim;
87 const T operator[](
size_t i)
const {
return _vals[i]; };
99 _sPolAx, _sPolAy, _sPolAz, _sPolPh,
100 _pPolAx, _pPolAy, _pPolAz, _pPolPh,
119 void push(
const Ray& this_ray);
127 Ray pop(
bool next =
true);
130 void clear_chunk(
void) {
146 _sPolAx.clear_chunk();
147 _sPolAy.clear_chunk();
148 _sPolAz.clear_chunk();
149 _pPolAx.clear_chunk();
150 _pPolAy.clear_chunk();
151 _pPolAz.clear_chunk();
153 _sPolPh.clear_chunk();
154 _pPolPh.clear_chunk();
156 _wavelength.clear_chunk();
159 _weight.clear_chunk();
162 _status.clear_chunk();
201 size_t size()
const {
return _size; };
204 void size(
size_t s) {
206 if (_x.vals().size() != s)
207 throw std::runtime_error(
208 "size of stored Rays and one of its records is different");
215 bool is_chunk_finished(
void) {
return _read == _size; }
226 const std::string& filename,
227 const std::string mc_code_name =
229 const std::string mc_code_version =
"",
230 const std::string instrument_name =
"",
231 const std::string name_current_component =
247 unsigned long long int n_rays,
249 unsigned int iter = 1
260 init_rays(std::string particle_species,
unsigned long long int n_rays,
unsigned int iter);
276 unsigned long long int 278 unsigned int iter = 1,
279 unsigned long long int n_rays = 0,
280 unsigned int repeat =
294 void set_gravity_direction(
float x,
float y,
float z);
296 void get_gravity_direction(
float* x,
float* y,
float* z);
297 void get_horizontal_direction(
float* x,
float* y,
float* z);
298 void set_horizontal_direction(
float* x,
float* y,
float* z);
301 void load_chunk(
void);
306 std::string _mc_code_name;
307 std::string _mc_code_version;
308 std::string _instrument_name;
309 std::string _name_current_component;
310 unsigned int _i_repeat, _n_repeat;
311 unsigned long long int _nrays, _max_allowed_rays;
315 openPMD::Offset _offset;
317 std::unique_ptr<openPMD::Series> _series;
321 std::string _particle_species;
324 inline openPMD::Iteration& iter_pmd(
unsigned int iter) {
return _series->iterations[iter]; }
327 inline openPMD::ParticleSpecies& rays_pmd(
void) {
328 auto i = iter_pmd(_iter);
329 return i.particles[_particle_species];
333 inline openPMD::ParticleSpecies& rays_pmd(std::string particle_species) {
334 _particle_species = particle_species;
335 auto i = iter_pmd(_iter);
336 return i.particles[particle_species];
344 void init_ray_prop(std::string name,
345 openPMD::Dataset& dataset,
347 std::map<openPMD::UnitDimension, double>
const& dims =
348 {{openPMD::UnitDimension::L, 0.}},
I/O API for the ray trace extension of the openPMD format.
void init_write(std::string particle_species, unsigned long long int n_rays, unsigned int iter=1)
initializes the "series" object from the openPMD API in WRITE MODE
template utility class to simplify implementation It is a vector that also stores min and max values ...
Generic ray, containing all the ray information being stored by the API into the openPMD file...
defines the maximum number of rays that can be stored in memory before dumping to file ...
void trace_write(Ray this_ray)
save ray properties for further writing to file by save_write()
void init_rays(std::string particle_species, unsigned long long int n_rays, unsigned int iter)
declare the ray particle species in the file
Ray trace_read(void)
Read rays from file and returns the next in the list.
unsigned long long int init_read(std::string pdgId, unsigned int iter=1, unsigned long long int n_rays=0, unsigned int repeat=1)
initializes the "series" object from the openPMD API in READ MODE
void save_write(void)
Flushes the output to file before closing it.
openPMD_io(const std::string &filename, const std::string mc_code_name="", const std::string mc_code_version="", const std::string instrument_name="", const std::string name_current_component="")
constructor