11/* *
2- * Copyright 2013-2015 Felix Schmitt, Axel Huebl
2+ * Copyright 2013-2016 Felix Schmitt, Axel Huebl, Alexander Grund
33 *
44 * This file is part of libSplash.
55 *
3535#include " splash/core/DCAttribute.hpp"
3636#include " splash/core/DCDataSet.hpp"
3737#include " splash/core/DCGroup.hpp"
38- #include " splash/core/DCHelper.hpp"
3938#include " splash/core/SDCHelper.hpp"
4039#include " splash/core/logging.hpp"
4140#include " splash/basetypes/basetypes.hpp"
@@ -70,8 +69,18 @@ namespace splash
7069 return (stat (filename.c_str (), &fileInfo) == 0 );
7170 }
7271
73- std::string SerialDataCollector::getFullFilename (const Dimensions mpiPos, std::string baseFilename) const
72+ std::string SerialDataCollector::getFullFilename (const Dimensions mpiPos, std::string baseFilename,
73+ bool isFullNameAllowed) const throw (DCException)
7474 {
75+ // Check for existing extension
76+ if (baseFilename.find (" .h5" ) == baseFilename.length () - 3 )
77+ {
78+ if (isFullNameAllowed)
79+ return baseFilename;
80+ else
81+ throw DCException (" Full filename is not allowed!" );
82+ }
83+
7584 std::stringstream serial_filename;
7685 serial_filename << baseFilename << " _" << mpiPos[0 ] << " _" << mpiPos[1 ] <<
7786 " _" << mpiPos[2 ] << " .h5" ;
@@ -97,7 +106,7 @@ namespace splash
97106 *******************************************************************************/
98107
99108 SerialDataCollector::SerialDataCollector (uint32_t maxFileHandles) :
100- handles (maxFileHandles, HandleMgr::FNS_MPI ),
109+ handles (maxFileHandles, HandleMgr::FNS_FULLNAME ),
101110 fileStatus (FST_CLOSED),
102111 maxID (-1 ),
103112 mpiTopology (1 , 1 , 1 )
@@ -113,7 +122,7 @@ namespace splash
113122 " failed to initialize/open HDF5 library" ));
114123
115124#ifndef SPLASH_VERBOSE_HDF5
116- // surpress automatic output of HDF5 exception messages
125+ // Suppress automatic output of HDF5 exception messages
117126 if (H5Eset_auto2 (H5E_DEFAULT, NULL , NULL ) < 0 )
118127 throw DCException (getExceptionString (" SerialDataCollector" ,
119128 " failed to disable error printing" ));
@@ -125,6 +134,7 @@ namespace splash
125134
126135 SerialDataCollector::~SerialDataCollector ()
127136 {
137+ close ();
128138 }
129139
130140 void SerialDataCollector::open (const char * filename, FileCreationAttr &attr)
@@ -157,16 +167,19 @@ namespace splash
157167
158168 void SerialDataCollector::close ()
159169 {
170+ if (fileStatus == FST_CLOSED)
171+ return ;
172+
160173 log_msg (1 , " closing serial data collector" );
161174
162- if (fileStatus == FST_CREATING || fileStatus == FST_WRITING)
175+ if ((fileStatus == FST_CREATING || fileStatus == FST_WRITING) &&
176+ maxID >= 0 )
163177 {
164- DCGroup group;
165- group.open (handles.get (0 ), SDC_GROUP_HEADER);
166-
167178 // write number of iterations
168179 try
169180 {
181+ DCGroup group;
182+ group.open (handles.get (0 ), SDC_GROUP_HEADER);
170183 ColTypeInt32 ctInt32;
171184 DCAttribute::writeAttribute (SDC_ATTR_MAX_ID, ctInt32.getDataType (),
172185 group.getHandle (), &maxID);
@@ -746,9 +759,8 @@ namespace splash
746759 {
747760 this ->fileStatus = FST_CREATING;
748761
749- // appends the mpiPosition to the filename (e.g. myfile_0_1_0.h5)
750- std::string full_filename = getFullFilename (attr.mpiPosition , filename);
751- DCHelper::testFilename (full_filename);
762+ std::string full_filename = getFullFilename (attr.mpiPosition , filename,
763+ attr.mpiSize .getScalarSize () == 1 );
752764
753765 this ->enableCompression = attr.enableCompression ;
754766
@@ -779,11 +791,8 @@ namespace splash
779791 {
780792 fileStatus = FST_WRITING;
781793
782- std::string full_filename = filename;
783- if (full_filename.find (" .h5" ) == std::string::npos)
784- full_filename = getFullFilename (attr.mpiPosition , filename);
785-
786- DCHelper::testFilename (full_filename);
794+ std::string full_filename = getFullFilename (attr.mpiPosition , filename,
795+ attr.mpiSize .getScalarSize () == 1 );
787796
788797 this ->enableCompression = attr.enableCompression ;
789798
@@ -805,9 +814,7 @@ namespace splash
805814 this ->fileStatus = FST_MERGING;
806815
807816 // open reference file to get mpi information
808- std::string full_filename = getFullFilename (Dimensions (0 , 0 , 0 ), filename);
809-
810- DCHelper::testFilename (full_filename);
817+ std::string full_filename = getFullFilename (Dimensions (0 , 0 , 0 ), filename, true );
811818
812819 if (!fileExists (full_filename))
813820 {
@@ -821,6 +828,7 @@ namespace splash
821828 // no compression for in-memory datasets
822829 this ->enableCompression = false ;
823830
831+ handles.setFileNameScheme (HandleMgr::FNS_MPI);
824832 handles.open (mpiTopology, filename, fileAccProperties, H5F_ACC_RDONLY);
825833 }
826834
@@ -829,11 +837,7 @@ namespace splash
829837 {
830838 this ->fileStatus = FST_READING;
831839
832- std::string full_filename = filename;
833- if (full_filename.find (" .h5" ) == std::string::npos)
834- full_filename = getFullFilename (attr.mpiPosition , filename);
835-
836- DCHelper::testFilename (full_filename);
840+ std::string full_filename = getFullFilename (attr.mpiPosition , filename, true );
837841
838842 if (!fileExists (full_filename))
839843 {
0 commit comments