OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
H5PartWrapper.h
Go to the documentation of this file.
1#ifndef OPAL_H5PARTWRAPPER_H
2#define OPAL_H5PARTWRAPPER_H
3
4//
5// Copyright & License: See Copyright.readme in src directory
6//
7
12template <class T, unsigned Dim>
13class PartBunchBase;
14
15#include "Utility/IpplInfo.h"
16
17#include "H5hut.h"
18
19#include <map>
20#include <string>
21
22#define REPORTONERROR(rc) H5PartWrapper::reportOnError(rc, __FILE__, __LINE__)
23#define READFILEATTRIB(type, file, name, value) REPORTONERROR(H5ReadFileAttrib##type(file, name, value));
24#define WRITESTRINGFILEATTRIB(file, name, value) REPORTONERROR(H5WriteFileAttribString(file, name, value));
25#define WRITEFILEATTRIB(type, file, name, value, length) REPORTONERROR(H5WriteFileAttrib##type(file, name, value, length));
26
27#define READSTEPATTRIB(type, file, name, value) REPORTONERROR(H5ReadStepAttrib##type(file, name, value));
28#define WRITESTRINGSTEPATTRIB(file, name, value) REPORTONERROR(H5WriteStepAttribString(file, name, value));
29#define WRITESTEPATTRIB(type, file, name, value, length) REPORTONERROR(H5WriteStepAttrib##type(file, name, value, length));
30
31#define READDATA(type, file, name, value) REPORTONERROR(H5PartReadData##type(file, name, value));
32#define WRITEDATA(type, file, name, value) REPORTONERROR(H5PartWriteData##type(file, name, value));
33
35public:
36 virtual ~H5PartWrapper();
37
38 void close();
39
40 double getLastPosition();
41 virtual void readHeader() = 0;
42 virtual void readStep(PartBunchBase<double, 3>*, h5_ssize_t firstParticle, h5_ssize_t lastParticle) = 0;
43
44 virtual void writeHeader() = 0;
45 virtual void writeStep(PartBunchBase<double, 3>*, const std::map<std::string, double> &) = 0;
46
47 virtual bool predecessorIsSameFlavour() const = 0;
48
50
51 size_t getNumParticles() const;
52protected:
53 H5PartWrapper(const std::string &fileName, h5_int32_t flags = H5_O_WRONLY);
54 H5PartWrapper(const std::string &fileName, int restartStep, std::string sourceFile, h5_int32_t flags = H5_O_RDWR);
55
56 void open(h5_int32_t flags);
57
58 void copyFile(const std::string &sourceFile, int lastStep = -1, h5_int32_t flags = H5_O_WRONLY);
59 void copyFileSystem(const std::string &sourceFile);
60 void copyHeader(h5_file_t source);
61 void copyStep(h5_file_t source, int step);
62 void copyStepHeader(h5_file_t source);
63 void copyStepData(h5_file_t source);
64 void sendFailureMessage(bool failed,
65 const std::string &where,
66 const std::string &what);
67 void receiveFailureMessage(int sourceNode,
68 const std::string &where,
69 const std::string &what);
70
71 static void reportOnError(h5_int64_t rc, const char* file, int line);
72
73 h5_file_t file_m;
74 std::string fileName_m;
76 h5_int64_t numSteps_m;
78
79 static std::string copyFilePrefix_m;
80};
81
82inline
83void H5PartWrapper::reportOnError(h5_int64_t rc, const char* file, int line) {
84 if (rc != H5_SUCCESS)
85 ERRORMSG("H5 rc= " << rc << " in " << file << " @ line " << line << endl);
86}
87
88inline
90 if (!file_m) open(H5_O_RDONLY);
91
92 h5_ssize_t numStepsInSource = H5GetNumSteps(file_m);
93 h5_ssize_t readStep = numStepsInSource - 1;
94 REPORTONERROR(H5SetStep(file_m, readStep));
95
96 h5_float64_t pathLength;
97 READSTEPATTRIB(Float64, file_m, "SPOS", &pathLength);
98
99 return pathLength;
100}
101
102#endif //OPAL_H5PARTWRAPPER_H
#define REPORTONERROR(rc)
Definition: H5PartWrapper.h:22
#define READSTEPATTRIB(type, file, name, value)
Definition: H5PartWrapper.h:27
PETE_TTTree< OpWhere, typename Cond_t::PETE_Expr_t, typename True_t::PETE_Expr_t, PETE_Scalar< Vektor< T, Dim > > > where(const PETE_Expr< Cond_t > &c, const PETE_Expr< True_t > &t, const Vektor< T, Dim > &f)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
#define ERRORMSG(msg)
Definition: IpplInfo.h:350
bool startedFromExistingFile_m
Definition: H5PartWrapper.h:77
virtual void writeStep(PartBunchBase< double, 3 > *, const std::map< std::string, double > &)=0
size_t getNumParticles() const
virtual void readStep(PartBunchBase< double, 3 > *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)=0
void receiveFailureMessage(int sourceNode, const std::string &where, const std::string &what)
virtual bool predecessorIsSameFlavour() const =0
virtual ~H5PartWrapper()
void copyStepData(h5_file_t source)
void copyFile(const std::string &sourceFile, int lastStep=-1, h5_int32_t flags=H5_O_WRONLY)
void open(h5_int32_t flags)
h5_int64_t numSteps_m
Definition: H5PartWrapper.h:76
virtual void readHeader()=0
void copyFileSystem(const std::string &sourceFile)
H5PartWrapper(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
void copyHeader(h5_file_t source)
std::string predecessorOPALFlavour_m
Definition: H5PartWrapper.h:75
void storeCavityInformation()
double getLastPosition()
Definition: H5PartWrapper.h:89
virtual void writeHeader()=0
std::string fileName_m
Definition: H5PartWrapper.h:74
void copyStepHeader(h5_file_t source)
h5_file_t file_m
Definition: H5PartWrapper.h:73
void copyStep(h5_file_t source, int step)
static std::string copyFilePrefix_m
Definition: H5PartWrapper.h:79
void sendFailureMessage(bool failed, const std::string &where, const std::string &what)
static void reportOnError(h5_int64_t rc, const char *file, int line)
Definition: H5PartWrapper.h:83