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);
@@ -759,9 +772,8 @@ namespace splash
759772 {
760773 this ->fileStatus = FST_CREATING;
761774
762- // appends the mpiPosition to the filename (e.g. myfile_0_1_0.h5)
763- std::string full_filename = getFullFilename (attr.mpiPosition , filename);
764- DCHelper::testFilename (full_filename);
775+ std::string full_filename = getFullFilename (attr.mpiPosition , filename,
776+ attr.mpiSize .getScalarSize () == 1 );
765777
766778 this ->enableCompression = attr.enableCompression ;
767779
@@ -792,11 +804,8 @@ namespace splash
792804 {
793805 fileStatus = FST_WRITING;
794806
795- std::string full_filename = filename;
796- if (full_filename.find (" .h5" ) == std::string::npos)
797- full_filename = getFullFilename (attr.mpiPosition , filename);
798-
799- DCHelper::testFilename (full_filename);
807+ std::string full_filename = getFullFilename (attr.mpiPosition , filename,
808+ attr.mpiSize .getScalarSize () == 1 );
800809
801810 this ->enableCompression = attr.enableCompression ;
802811
@@ -818,9 +827,7 @@ namespace splash
818827 this ->fileStatus = FST_MERGING;
819828
820829 // open reference file to get mpi information
821- std::string full_filename = getFullFilename (Dimensions (0 , 0 , 0 ), filename);
822-
823- DCHelper::testFilename (full_filename);
830+ std::string full_filename = getFullFilename (Dimensions (0 , 0 , 0 ), filename, true );
824831
825832 if (!fileExists (full_filename))
826833 {
@@ -834,6 +841,7 @@ namespace splash
834841 // no compression for in-memory datasets
835842 this ->enableCompression = false ;
836843
844+ handles.setFileNameScheme (HandleMgr::FNS_MPI);
837845 handles.open (mpiTopology, filename, fileAccProperties, H5F_ACC_RDONLY);
838846 }
839847
@@ -842,11 +850,7 @@ namespace splash
842850 {
843851 this ->fileStatus = FST_READING;
844852
845- std::string full_filename = filename;
846- if (full_filename.find (" .h5" ) == std::string::npos)
847- full_filename = getFullFilename (attr.mpiPosition , filename);
848-
849- DCHelper::testFilename (full_filename);
853+ std::string full_filename = getFullFilename (attr.mpiPosition , filename, true );
850854
851855 if (!fileExists (full_filename))
852856 {
0 commit comments