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