Skip to content

Commit dbda3f2

Browse files
author
f-schmitt-zih
committed
Merge pull request #203 from slizzered/topic-readMeta_cc
ReadMeta function to get the CollectionType
2 parents 1c03967 + 17d808e commit dbda3f2

18 files changed

Lines changed: 608 additions & 7 deletions

src/DCGroup.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright 2013 Felix Schmitt
3+
* 2015 Carlchristian Eckert
34
*
45
* This file is part of libSplash.
56
*
@@ -25,8 +26,11 @@
2526
#include <sstream>
2627
#include <cassert>
2728
#include <string.h>
29+
#include <typeinfo>
2830

2931
#include "splash/core/DCGroup.hpp"
32+
#include "splash/basetypes/basetypes.hpp"
33+
#include <splash/basetypes/generateCollectionType.hpp>
3034

3135
#define H5_TRUE 1
3236
#define H5_FALSE 0
@@ -196,8 +200,16 @@ namespace splash
196200
if (obj_info.type == H5O_TYPE_DATASET)
197201
{
198202
if (param->entries)
203+
{
199204
param->entries[param->count].name = currentBaseName;
200205

206+
hid_t dataset_id = H5Oopen_by_idx(base, ".", H5_INDEX_NAME, H5_ITER_INC, i, H5P_DEFAULT);
207+
hid_t datatype_id = H5Dget_type(dataset_id);
208+
param->entries[param->count].colType = generateCollectionType(datatype_id);
209+
H5Dclose(datatype_id);
210+
H5Oclose(dataset_id);
211+
}
212+
201213
param->count++;
202214
}
203215
}

src/ParallelDataCollector.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,20 @@ namespace splash
558558
localSize, globalOffset, sizeRead, ndims, buf);
559559
}
560560

561+
CollectionType* ParallelDataCollector::readMeta(int32_t id,
562+
const char* name,
563+
const Dimensions dstBuffer,
564+
const Dimensions dstOffset,
565+
Dimensions& sizeRead) throw (DCException)
566+
{
567+
if (fileStatus != FST_READING && fileStatus != FST_WRITING)
568+
throw DCException(getExceptionString("readMeta", "this access is not permitted"));
569+
570+
uint32_t ndims = 0;
571+
return readDataSetMeta(handles.get(id), id, name, dstBuffer, dstOffset,
572+
Dimensions(0, 0, 0), sizeRead, ndims);
573+
}
574+
561575
void ParallelDataCollector::write(int32_t id, const CollectionType& type, uint32_t ndims,
562576
const Selection select, const char* name, const void* buf)
563577
throw (DCException)
@@ -957,6 +971,40 @@ namespace splash
957971
dataset.close();
958972
}
959973

974+
CollectionType* ParallelDataCollector::readDataSetMeta(H5Handle h5File,
975+
int32_t id,
976+
const char* name,
977+
const Dimensions dstBuffer,
978+
const Dimensions dstOffset,
979+
const Dimensions srcOffset,
980+
Dimensions &sizeRead,
981+
uint32_t& srcDims)
982+
throw (DCException)
983+
{
984+
log_msg(2, "readDataSetMeta");
985+
986+
std::string group_path, dset_name;
987+
DCDataSet::getFullDataPath(name, SDC_GROUP_DATA, id, group_path, dset_name);
988+
989+
DCGroup group;
990+
group.open(h5File, group_path);
991+
992+
DCDataSet dataset(dset_name.c_str());
993+
dataset.open(group.getHandle());
994+
995+
size_t entrySize;
996+
getEntriesForID(id, NULL, &entrySize);
997+
std::vector<DataCollector::DCEntry> entries(entrySize);
998+
999+
getEntriesForID(id, &(*entries.begin()), NULL);
1000+
1001+
Dimensions src_size(dataset.getSize() - srcOffset);
1002+
dataset.read(dstBuffer, dstOffset, src_size, srcOffset, sizeRead, srcDims, NULL);
1003+
dataset.close();
1004+
1005+
return entries[0].colType;
1006+
}
1007+
9601008
void ParallelDataCollector::writeDataSet(H5Handle group,
9611009
const Dimensions globalSize,
9621010
const Dimensions globalOffset,

src/SerialDataCollector.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "splash/core/DCHelper.hpp"
3838
#include "splash/core/SDCHelper.hpp"
3939
#include "splash/core/logging.hpp"
40+
#include "splash/basetypes/basetypes.hpp"
4041

4142
namespace splash
4243
{
@@ -428,6 +429,21 @@ namespace splash
428429
Dimensions(0, 0, 0), sizeRead, ndims, data);
429430
}
430431

432+
CollectionType* SerialDataCollector::readMeta(int32_t id,
433+
const char* name,
434+
const Dimensions dstBuffer,
435+
const Dimensions dstOffset,
436+
Dimensions &sizeRead)
437+
throw (DCException)
438+
{
439+
if (fileStatus != FST_READING && fileStatus != FST_WRITING && fileStatus != FST_MERGING)
440+
throw DCException(getExceptionString("readMeta", "this access is not permitted"));
441+
442+
uint32_t ndims = 0;
443+
return readDataSetMeta(handles.get(id), id, name, dstBuffer, dstOffset,
444+
Dimensions(0, 0, 0), sizeRead, ndims);
445+
}
446+
431447
void SerialDataCollector::write(int32_t id, const CollectionType& type, uint32_t ndims,
432448
const Selection select, const char* name, const void* data)
433449
throw (DCException)
@@ -960,6 +976,40 @@ namespace splash
960976
dataset.close();
961977
}
962978

979+
CollectionType* SerialDataCollector::readDataSetMeta(H5Handle h5File,
980+
int32_t id,
981+
const char* name,
982+
const Dimensions dstBuffer,
983+
const Dimensions dstOffset,
984+
const Dimensions srcOffset,
985+
Dimensions &sizeRead,
986+
uint32_t& srcDims)
987+
throw (DCException)
988+
{
989+
log_msg(2, "readDataSetMeta");
990+
991+
std::string group_path, dset_name;
992+
DCDataSet::getFullDataPath(name, SDC_GROUP_DATA, id, group_path, dset_name);
993+
994+
DCGroup group;
995+
group.open(h5File, group_path);
996+
997+
DCDataSet dataset(dset_name.c_str());
998+
dataset.open(group.getHandle());
999+
1000+
size_t entrySize;
1001+
getEntriesForID(id, NULL, &entrySize);
1002+
std::vector<DataCollector::DCEntry> entries(entrySize);
1003+
1004+
getEntriesForID(id, &(*entries.begin()), NULL);
1005+
1006+
Dimensions src_size(dataset.getSize() - srcOffset);
1007+
dataset.read(dstBuffer, dstOffset, src_size, srcOffset, sizeRead, srcDims, NULL);
1008+
dataset.close();
1009+
1010+
return entries[0].colType;
1011+
}
1012+
9631013
void SerialDataCollector::readSizeInternal(H5Handle h5File,
9641014
int32_t id,
9651015
const char* name,

src/include/splash/CollectionType.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright 2013 Felix Schmitt
3+
* 2015 Carlchristian Eckert
34
*
45
* This file is part of libSplash.
56
*
@@ -25,6 +26,7 @@
2526
#define COLLECTIONTYPE_H
2627

2728
#include <hdf5.h>
29+
#include <string>
2830

2931
#define H5DataType hid_t
3032

@@ -55,6 +57,13 @@ namespace splash
5557
*/
5658
virtual size_t getSize() const = 0;
5759

60+
/**
61+
* Returns a human-readable representation of the datatype.
62+
*
63+
* @return the name of the datatype as a string
64+
*/
65+
virtual std::string toString() const = 0;
66+
5867
/**
5968
* Destructor
6069
*/

src/include/splash/DataCollector.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "splash/CollectionType.hpp"
5353
#include "splash/Dimensions.hpp"
5454
#include "splash/Selection.hpp"
55+
#include "splash/core/DCDataSet.hpp"
5556

5657
namespace splash
5758
{
@@ -113,6 +114,10 @@ namespace splash
113114
* Fully-qualified name of this dataset.
114115
*/
115116
std::string name;
117+
/**
118+
* Pointer to an instance of the CollectionType of this dataset
119+
*/
120+
CollectionType* colType;
116121
} DCEntry;
117122

118123
/**
@@ -424,6 +429,25 @@ namespace splash
424429
const Dimensions dstOffset,
425430
Dimensions &sizeRead,
426431
void* buf) = 0;
432+
433+
/**
434+
* Reads meta data from HDF5 file.
435+
*
436+
* @param id ID of iteration.
437+
* @param name Name of the dataset.
438+
* @param dstBuffer Size of the dataset.
439+
* @param dstOffset Offset in destination dataset.
440+
* @param sizeRead Returns the size of the data in the file.
441+
*
442+
* @return The CollectionType of the dataset as a heap allocated
443+
* object. The object must be freed by the caller at the
444+
* end of the object's lifetime.
445+
*/
446+
virtual CollectionType* readMeta(int32_t id,
447+
const char* name,
448+
const Dimensions dstBuffer,
449+
const Dimensions dstOffset,
450+
Dimensions &sizeRead) = 0;
427451
};
428452

429453
}

src/include/splash/ParallelDataCollector.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ namespace splash
312312
Dimensions &sizeRead,
313313
void* buf) throw (DCException);
314314

315+
CollectionType* readMeta(int32_t id,
316+
const char* name,
317+
const Dimensions dstBuffer,
318+
const Dimensions dstOffset,
319+
Dimensions &sizeRead) throw (DCException);
320+
315321
/**
316322
* Reads data from HDF5 file.
317323
* If data is to be read (instead of only its size in the file),
@@ -408,6 +414,20 @@ namespace splash
408414
Dimensions /*count*/,
409415
Dimensions /*offset*/,
410416
Dimensions /*stride*/) throw (DCException);
417+
418+
419+
/**
420+
* Internal meta data reading method.
421+
*/
422+
CollectionType* readDataSetMeta(H5Handle h5File,
423+
int32_t id,
424+
const char* name,
425+
const Dimensions dstBuffer,
426+
const Dimensions dstOffset,
427+
const Dimensions srcOffset,
428+
Dimensions &sizeRead,
429+
uint32_t& srcDims)
430+
throw (DCException);
411431
};
412432

413433
}

src/include/splash/SerialDataCollector.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ namespace splash
175175
uint32_t& srcDims,
176176
void* dst) throw (DCException);
177177

178+
/**
179+
* Internal meta data reading method.
180+
*/
181+
CollectionType* readDataSetMeta(H5Handle h5File,
182+
int32_t id,
183+
const char* name,
184+
const Dimensions dstBuffer,
185+
const Dimensions dstOffset,
186+
const Dimensions srcOffset,
187+
Dimensions &sizeRead,
188+
uint32_t& srcDims) throw (DCException);
189+
178190
void readSizeInternal(H5Handle h5File,
179191
int32_t id,
180192
const char* name,
@@ -321,6 +333,12 @@ namespace splash
321333
const Dimensions dstOffset,
322334
Dimensions &sizeRead,
323335
void* data) throw (DCException);
336+
337+
CollectionType* readMeta(int32_t id,
338+
const char* name,
339+
const Dimensions dstBuffer,
340+
const Dimensions dstOffset,
341+
Dimensions &sizeRead) throw (DCException);
324342
};
325343

326344
} // namespace DataCollector

src/include/splash/basetypes/ColTypeBool.hpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* Copyright 2013, 2015 Felix Schmitt, René Widera, Axel Huebl
2+
* Copyright 2013, 2015 Felix Schmitt, René Widera, Axel Huebl,
3+
* Carlchristian Eckert
34
*
45
* This file is part of libSplash.
56
*
@@ -26,6 +27,9 @@
2627

2728
#include "splash/CollectionType.hpp"
2829

30+
#include <string>
31+
#include <cstring>
32+
2933
namespace splash
3034
{
3135

@@ -55,6 +59,34 @@ class ColTypeBool : public CollectionType
5559
{
5660
return sizeof (bool);
5761
}
62+
63+
static CollectionType* genType(hid_t datatype_id)
64+
{
65+
bool found = false;
66+
H5T_class_t h5_class = H5Tget_class(datatype_id);
67+
if(h5_class == H5T_ENUM)
68+
{
69+
if(H5Tget_nmembers(datatype_id) == 2)
70+
{
71+
char* m0 = H5Tget_member_name(datatype_id,0);
72+
char* m1 = H5Tget_member_name(datatype_id,1);
73+
if(strcmp("true" , m0) == 0 && strcmp("false", m1) == 0)
74+
found = true;
75+
free(m1);
76+
free(m0);
77+
}
78+
}
79+
80+
if(found)
81+
return new ColTypeBool;
82+
else
83+
return NULL;
84+
}
85+
86+
std::string toString() const
87+
{
88+
return "Bool";
89+
}
5890
};
5991

6092
}

0 commit comments

Comments
 (0)