OPALX (Object Oriented Parallel Accelerator Library for Exascal) MINIorX
OPALX
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
11
12#include "OPALTypes.h"
13#include "Utility/IpplInfo.h"
14
15#include "H5hut.h"
16
17#include <map>
18#include <string>
19
20#define REPORTONERROR(rc) H5PartWrapper::reportOnError(rc, __FILE__, __LINE__)
21#define READFILEATTRIB(type, file, name, value) \
22 REPORTONERROR(H5ReadFileAttrib##type(file, name, value));
23#define WRITESTRINGFILEATTRIB(file, name, value) \
24 REPORTONERROR(H5WriteFileAttribString(file, name, value));
25#define WRITEFILEATTRIB(type, file, name, value, length) \
26 REPORTONERROR(H5WriteFileAttrib##type(file, name, value, length));
27
28#define READSTEPATTRIB(type, file, name, value) \
29 REPORTONERROR(H5ReadStepAttrib##type(file, name, value));
30#define WRITESTRINGSTEPATTRIB(file, name, value) \
31 REPORTONERROR(H5WriteStepAttribString(file, name, value));
32#define WRITESTEPATTRIB(type, file, name, value, length) \
33 REPORTONERROR(H5WriteStepAttrib##type(file, name, value, length));
34
35#define READDATA(type, file, name, value) REPORTONERROR(H5PartReadData##type(file, name, value));
36#define WRITEDATA(type, file, name, value) REPORTONERROR(H5PartWriteData##type(file, name, value));
37
39public:
40 virtual ~H5PartWrapper();
41
42 void close();
43
44 double getLastPosition();
45 virtual void readHeader() = 0;
46 virtual void readStep(PartBunch_t*, h5_ssize_t firstParticle, h5_ssize_t lastParticle) = 0;
47
48 virtual void writeHeader() = 0;
49 virtual void writeStep(PartBunch_t*, const std::map<std::string, double>&) = 0;
50
51 virtual bool predecessorIsSameFlavour() const = 0;
52
54
55 size_t getNumParticles() const;
56
57protected:
58 H5PartWrapper(const std::string& fileName, h5_int32_t flags = H5_O_WRONLY);
60 const std::string& fileName, int restartStep, std::string sourceFile,
61 h5_int32_t flags = H5_O_RDWR);
62
63 void open(h5_int32_t flags);
64
65 void copyFile(const std::string& sourceFile, int lastStep = -1, h5_int32_t flags = H5_O_WRONLY);
66 void copyFileSystem(const std::string& sourceFile);
67 void copyHeader(h5_file_t source);
68 void copyStep(h5_file_t source, int step);
69 void copyStepHeader(h5_file_t source);
70 void copyStepData(h5_file_t source);
71 void sendFailureMessage(bool failed, const std::string& where, const std::string& what);
72 void receiveFailureMessage(int sourceNode, const std::string& where, const std::string& what);
73
74 static void reportOnError(h5_int64_t rc, const char* file, int line);
75
76 h5_file_t file_m;
77 std::string fileName_m;
79 h5_int64_t numSteps_m;
81
82 static std::string copyFilePrefix_m;
83};
84
85inline void H5PartWrapper::reportOnError(h5_int64_t rc, const char* file, int line) {
86 if (rc != H5_SUCCESS)
87 *ippl::Error << "H5 rc= " << rc << " in " << file << " @ line " << line << endl;
88}
89
91 if (!file_m)
92 open(H5_O_RDONLY);
93
94 h5_ssize_t numStepsInSource = H5GetNumSteps(file_m);
95 h5_ssize_t readStep = numStepsInSource - 1;
96 REPORTONERROR(H5SetStep(file_m, readStep));
97
98 h5_float64_t pathLength;
99 READSTEPATTRIB(Float64, file_m, "SPOS", &pathLength);
100
101 return pathLength;
102}
103
104#endif // OPAL_H5PARTWRAPPER_H
PartBunch< PLayout_t< double, 3 >, double, 3 > PartBunch_t
#define REPORTONERROR(rc)
#define READSTEPATTRIB(type, file, name, value)
bool startedFromExistingFile_m
virtual void readStep(PartBunch_t *, h5_ssize_t firstParticle, h5_ssize_t lastParticle)=0
size_t getNumParticles() const
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)
virtual void writeStep(PartBunch_t *, const std::map< std::string, double > &)=0
h5_int64_t numSteps_m
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
void storeCavityInformation()
double getLastPosition()
virtual void writeHeader()=0
std::string fileName_m
void copyStepHeader(h5_file_t source)
h5_file_t file_m
void copyStep(h5_file_t source, int step)
static std::string copyFilePrefix_m
void sendFailureMessage(bool failed, const std::string &where, const std::string &what)
static void reportOnError(h5_int64_t rc, const char *file, int line)