22 const h5_int64_t H5TypesCHAR = H5_STRING_T;
23 const h5_int64_t H5TypesFLOAT = H5_FLOAT32_T;
24 const h5_int64_t H5TypesDOUBLE = H5_FLOAT64_T;
25 const h5_int64_t H5TypesINT32 = H5_INT32_T;
26 const h5_int64_t H5TypesINT64 = H5_INT64_T;
34 predecessorOPALFlavour_m(
"NOT SET"),
36 startedFromExistingFile_m(false)
44 predecessorOPALFlavour_m(
"NOT SET"),
46 startedFromExistingFile_m(true)
48 if (sourceFile.empty()) {
52 copyFile(sourceFile, restartStep, flags);
74 h5_prop_t props = H5CreateFileProp ();
76 h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
89 h5_int64_t nFormerlySavedAutoPhaseCavities = 0;
90 bool fileWasClosed = (
file_m == 0);
92 if (nAutoPhaseCavities == 0)
return;
93 if (fileWasClosed)
open(H5_O_APPENDONLY);
94 if (!H5HasFileAttrib(
file_m,
"nAutoPhaseCavities") ||
95 H5ReadFileAttribInt64(
file_m,
"nAutoPhaseCavities", &nFormerlySavedAutoPhaseCavities) != H5_SUCCESS) {
96 nFormerlySavedAutoPhaseCavities = 0;
98 if (nFormerlySavedAutoPhaseCavities == nAutoPhaseCavities) {
99 if (fileWasClosed)
close();
105 unsigned int elementNumber = 1;
108 for(; it <
end; ++
it, ++ elementNumber) {
109 if (elementNumber <= nFormerlySavedAutoPhaseCavities)
continue;
111 std::string nameAttributeName =
"Cav-" + std::to_string(elementNumber) +
"-name";
112 std::string valueAttributeName =
"Cav-" + std::to_string(elementNumber) +
"-value";
114 std::string elementName = (*it).first;
115 h5_float64_t elementPhase = (*it).second;
120 INFOMSG(
"Saved phases in the h5 file: "
121 << nameAttributeName <<
" -> " << elementName <<
" --- "
122 << valueAttributeName <<
" -> " << elementPhase <<
endl);
125 if (fileWasClosed)
close();
130 namespace fs = std::filesystem;
131 if (!fs::exists(sourceFile)) {
133 "source file '" + sourceFile +
"' does not exist");
137 h5_prop_t props = H5CreateFileProp ();
139 h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
144 h5_file_t source = H5OpenFile (sourceFile.c_str(), H5_O_RDONLY, props);
145 PAssert (source != (h5_file_t)H5_ERR);
147 h5_ssize_t numStepsInSource = H5GetNumSteps(source);
149 if (lastStep == -1 || lastStep >= numStepsInSource) {
152 char opalFlavour[128];
168 fs::rename(fileName_m, sourceFileName);
174 props = H5CreateFileProp ();
176 h5err = H5SetPropFileMPIOCollective (props, &comm);
178 source = H5OpenFile (sourceFileName.c_str(), H5_O_RDONLY, props);
179 PAssert (source != (h5_file_t)H5_ERR);
184 if (-lastStep > numStepsInSource) {
187 lastStep = numStepsInSource + lastStep;
198 fs::remove(sourceFileName);
206 h5_prop_t props = H5CreateFileProp ();
208 h5_err_t h5err = H5SetPropFileMPIOCollective (props, &comm);
213 h5_file_t source = H5OpenFile (sourceFile.c_str(), H5_O_RDONLY, props);
214 PAssert (source != (h5_file_t)H5_ERR);
216 h5_ssize_t numStepsInSource = H5GetNumSteps(source);
218 if (lastStep == -1 || lastStep >= numStepsInSource) {
221 char opalFlavour[128];
236 if (-lastStep > numStepsInSource) {
239 lastStep = numStepsInSource + lastStep;
269 std::ifstream source(sourceFile, std::ios::binary);
270 std::ofstream dest(
fileName_m, std::ios::binary);
272 std::istreambuf_iterator<char> begin_source(source);
273 std::istreambuf_iterator<char> end_source;
274 std::ostreambuf_iterator<char> begin_dest(dest);
275 std::copy(begin_source, end_source, begin_dest);
280 "H5PartWrapper::copyFile",
281 "could not copy file " + sourceFile);
285 "H5PartWrapper::copyFile",
286 "received message to throw exception from node 0");
293 h5_int64_t numFileAttributes = H5GetNumFileAttribs(source);
295 const h5_size_t lengthAttributeName = 256;
297 h5_int64_t attributeType;
298 h5_size_t numAttributeElements;
299 std::vector<char> buffer(256);
300 h5_float32_t *f32buffer =
reinterpret_cast<h5_float32_t*
>(&buffer[0]);
301 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
302 h5_int32_t *i32buffer =
reinterpret_cast<h5_int32_t*
>(&buffer[0]);
303 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(&buffer[0]);
305 for (h5_int64_t i = 0; i < numFileAttributes; ++ i) {
311 &numAttributeElements));
313 if (attributeType == H5_STRING_T) {
314 if (buffer.size() < numAttributeElements) {
315 buffer.resize(numAttributeElements);
321 }
else if (attributeType == H5_FLOAT32_T) {
322 if (buffer.size() < numAttributeElements *
sizeof(h5_float32_t)) {
323 buffer.resize(numAttributeElements *
sizeof(h5_float32_t));
329 }
else if (attributeType == H5_FLOAT64_T) {
330 if (buffer.size() < numAttributeElements *
sizeof(h5_float64_t)) {
331 buffer.resize(numAttributeElements *
sizeof(h5_float64_t));
337 }
else if (attributeType == H5_INT32_T) {
338 if (buffer.size() < numAttributeElements *
sizeof(h5_int32_t)) {
339 buffer.resize(numAttributeElements *
sizeof(h5_int32_t));
345 }
else if (attributeType == H5_INT64_T) {
346 if (buffer.size() < numAttributeElements *
sizeof(h5_int64_t)) {
347 buffer.resize(numAttributeElements *
sizeof(h5_int64_t));
355 "unknown data type: " + std::to_string(attributeType));
374 h5_int64_t numStepAttributes = H5GetNumStepAttribs(source);
376 h5_size_t lengthAttributeName = 256;
378 h5_int64_t attributeType;
379 h5_size_t numAttributeElements;
381 std::vector<char> buffer(256);
382 h5_float32_t *f32buffer =
reinterpret_cast<h5_float32_t*
>(&buffer[0]);
383 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(&buffer[0]);
384 h5_int32_t *i32buffer =
reinterpret_cast<h5_int32_t*
>(&buffer[0]);
385 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(&buffer[0]);
390 for (h5_int64_t i = 0; i < numStepAttributes; ++ i) {
396 &numAttributeElements));
398 if (attributeType == H5TypesCHAR) {
399 if (buffer.size() < numAttributeElements) {
400 buffer.resize(numAttributeElements);
406 }
else if (attributeType == H5TypesFLOAT) {
407 if (buffer.size() < numAttributeElements *
sizeof(h5_float32_t)) {
408 buffer.resize(numAttributeElements *
sizeof(h5_float32_t));
414 }
else if (attributeType == H5TypesDOUBLE) {
415 if (buffer.size() < numAttributeElements *
sizeof(h5_float64_t)) {
416 buffer.resize(numAttributeElements *
sizeof(h5_float64_t));
422 }
else if (attributeType == H5TypesINT32) {
423 if (buffer.size() < numAttributeElements *
sizeof(h5_int32_t)) {
424 buffer.resize(numAttributeElements *
sizeof(h5_int32_t));
430 }
else if (attributeType == H5TypesINT64) {
431 if (buffer.size() < numAttributeElements *
sizeof(h5_int64_t)) {
432 buffer.resize(numAttributeElements *
sizeof(h5_int64_t));
440 "unknown data type: " + std::to_string(attributeType));
448 h5_size_t lengthSetName = 256;
449 char setName[lengthSetName];
451 h5_size_t numSetElements;
453 h5_ssize_t numParticles = H5PartGetNumParticles(source);
456 h5_ssize_t firstParticle = numParticlesPerNode *
Ippl::myNode();
457 h5_ssize_t lastParticle = firstParticle + numParticlesPerNode - 1;
459 lastParticle = numParticles - 1;
461 REPORTONERROR(H5PartSetView(source, firstParticle, lastParticle));
463 numParticles = lastParticle - firstParticle + 1;
466 std::vector<char> buffer(numParticles *
sizeof(h5_float64_t));
468 h5_float32_t *f32buffer =
reinterpret_cast<h5_float32_t*
>(buffer_ptr);
469 h5_float64_t *f64buffer =
reinterpret_cast<h5_float64_t*
>(buffer_ptr);
470 h5_int32_t *i32buffer =
reinterpret_cast<h5_int32_t*
>(buffer_ptr);
471 h5_int64_t *i64buffer =
reinterpret_cast<h5_int64_t*
>(buffer_ptr);
473 h5_ssize_t numDatasets = H5PartGetNumDatasets(source);
475 for (h5_ssize_t i = 0; i < numDatasets; ++ i) {
476 REPORTONERROR(H5PartGetDatasetInfo(source, i, setName, lengthSetName, &setType, &numSetElements));
478 if (setType == H5TypesFLOAT) {
479 READDATA(Float32, source, setName, f32buffer);
481 }
else if (setType == H5TypesDOUBLE) {
482 READDATA(Float64, source, setName, f64buffer);
484 }
else if (setType == H5TypesINT32) {
485 READDATA(Int32, source, setName, i32buffer);
487 }
else if (setType == H5TypesINT64) {
488 READDATA(Int64, source, setName, i64buffer);
492 "unknown data type: " + std::to_string(setType));
496 numParticles = H5PartGetNumParticles(
file_m);
501 const std::string &
where,
502 const std::string &what) {
513 const std::string &
where,
514 const std::string &what) {
531 h5_ssize_t numParticles = H5PartGetNumParticles(
file_m);
static OpalData * getInstance()
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
void copyFile(const std::string &sourceFile, int lastStep=-1, h5_int32_t flags=H5_O_WRONLY)
void getMessage(Message &m, T &t)
size_t getNumParticles() const
#define WRITEFILEATTRIB(type, file, name, value, length)
void copyStepData(h5_file_t source)
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent we have made it clear that any patent must be licensed for everyone s free use or not licensed at all The precise terms and conditions for distribution and modification follow GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The refers to any such program or and a work based on the Program means either the Program or any derivative work under copyright a work containing the Program or a portion of it
void copyHeader(h5_file_t source)
Message * receive_block(int &node, int &tag)
std::map< AttributeType, std::string > attributeName
static MPI_Comm getComm()
static std::string copyFilePrefix_m
void copyStep(h5_file_t source, int step)
void sendFailureMessage(bool failed, const std::string &where, const std::string &what)
#define WRITESTRINGSTEPATTRIB(file, name, value)
H5PartWrapper(const std::string &fileName, h5_int32_t flags=H5_O_WRONLY)
int getNumberOfMaxPhases()
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
T * c_data(std::vector< T, A > &v)
Inform & endl(Inform &inf)
#define REPORTONERROR(rc)
void copyStepHeader(h5_file_t source)
std::vector< MaxPhasesT >::iterator getLastMaxPhases()
#define READDATA(type, file, name, value)
std::string::iterator iterator
#define WRITEDATA(type, file, name, value)
static Communicate * Comm
The base class for all OPAL exceptions.
void storeCavityInformation()
std::string predecessorOPALFlavour_m
#define READFILEATTRIB(type, file, name, value)
#define READSTEPATTRIB(type, file, name, value)
virtual int broadcast_all(Message *, int)
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)
std::vector< MaxPhasesT >::iterator getFirstMaxPhases()
#define WRITESTRINGFILEATTRIB(file, name, value)
#define WRITESTEPATTRIB(type, file, name, value, length)
void copyFileSystem(const std::string &sourceFile)
void putMessage(Message &m, const T &t)
void open(h5_int32_t flags)
void receiveFailureMessage(int sourceNode, const std::string &where, const std::string &what)