Commit 4f459f61 authored by mdurant's avatar mdurant

Major update to vizschema database plugin. Fixes several bugs and drastically...

Major update to vizschema database plugin.  Fixes several bugs and drastically restructures the code.  Equivalent to txcorp vizschema repository revision #723.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@11914 18c085ea-50e0-402c-830e-de6fd14e8384
parent d8b4d787
......@@ -15,9 +15,26 @@ VsMDServerPluginInfo.C
${COMMON_SOURCES}
avtVsFileFormat.C
VsFilter.C
VsH5Attribute.C
VsH5Dataset.C
VsH5File.C
VsH5Group.C
VsH5Object.C
VsH5Reader.C
VsLog.C
VsMDMesh.C
VsMDVariable.C
VsMesh.C
VsRectilinearMesh.C
VsSchema.C
VsStructuredMesh.C
VsUniformMesh.C
VsUnstructuredMesh.C
VsUtils.C
VsVariable.C
VsVariableWithMesh.C
VsRegistry.C
VsRegistryObject.C
)
SET(LIBE_SOURCES
......@@ -25,9 +42,26 @@ VsEnginePluginInfo.C
${COMMON_SOURCES}
avtVsFileFormat.C
VsFilter.C
VsH5Attribute.C
VsH5Dataset.C
VsH5File.C
VsH5Group.C
VsH5Object.C
VsH5Reader.C
VsLog.C
VsMDMesh.C
VsMDVariable.C
VsMesh.C
VsRectilinearMesh.C
VsSchema.C
VsStructuredMesh.C
VsUniformMesh.C
VsUnstructuredMesh.C
VsUtils.C
VsVariable.C
VsVariableWithMesh.C
VsRegistry.C
VsRegistryObject.C
)
INCLUDE_DIRECTORIES(
......
<?xml version="@VERSION@"?>
<Plugin name="Vs" type="database" label="Vs Files" version="@VERSION@" enabled="true" mdspecificcode="false" engspecificcode="false" onlyengine="false" noengine="false" dbtype="STSD" haswriter="false" hasoptions="false">
<Plugin name="Vs" type="database" label="Vs Files" version="@VERSION@" enabled="true" mdspecificcode="false" engspecificcode="false" onlyengine="false" noengine="false" dbtype="STMD" haswriter="false" hasoptions="false">
<Files components="M">
avtVsFileFormat.C
VsFilter.C
VsH5Attribute.C
VsH5Dataset.C
VsH5File.C
VsH5Group.C
VsH5Object.C
VsH5Reader.C
VsLog.C
VsMDMesh.C
VsMDVariable.C
VsMesh.C
VsRectilinearMesh.C
VsSchema.C
VsStructuredMesh.C
VsUniformMesh.C
VsUnstructuredMesh.C
VsUtils.C
VsVariable.C
VsVariableWithMesh.C
VsRegistry.C
VsRegistryObject.C
</Files>
<Files components="E">
avtVsFileFormat.C
VsFilter.C
VsH5Attribute.C
VsH5Dataset.C
VsH5File.C
VsH5Group.C
VsH5Object.C
VsH5Reader.C
VsLog.C
VsMDMesh.C
VsMDVariable.C
VsMesh.C
VsRectilinearMesh.C
VsSchema.C
VsStructuredMesh.C
VsUniformMesh.C
VsUnstructuredMesh.C
VsUtils.C
VsVariable.C
VsVariableWithMesh.C
VsRegistry.C
VsRegistryObject.C
</Files>
<CXXFLAGS>
${HDF5_INCLUDE_DIR}
</CXXFLAGS>
......
This diff is collapsed.
#include <hdf5.h>
#include <visit-hdf5.h>
#if HDF5_VERSION_GE(1, 8, 1)
/**
* @file VsFilter.h
* @file VsFilter.h
*
* @class VsFilter
*
* @brief Interface for inspecting an HDF5 file
* @brief Static class for reading an hdf5 file
*
* VsFilter is class for extracting mesh groups, variable datasets,
* varWithMeshes datasets and mesh datasets and getting their attributes.
* VsFilter contains a set of static classes that interface
* with hdf5 recursive reading routines. VsFilter creates
* VsH5Group, VsH5Dataset, and VsH5Attribute objects to
* represent the contents of the hdf5 file.
*
* Copyright &copy; 2008 by Tech-X Corporation
*/
#include <hdf5.h>
#include <visit-hdf5.h>
#if HDF5_VERSION_GE(1, 8, 1)
#ifndef VS_FILTER
#define VS_FILTER
// std includes
#include <iostream>
#include <string>
#include <vector>
// metadata
#include <VsH5Meta.h>
#include "VsH5File.h"
#include <hdf5.h>
class VsRegistry;
class VsFilter {
public:
// Constructor does nothing
VsFilter(std::ostream& dbgstrm);
// This constructor opens a file and creates generic HDF5 metadata
VsFilter(hid_t fId, std::ostream& dbgstrm);
static VsH5File* readFile(VsRegistry* registry, std::string fileName);
virtual ~VsFilter() {}
// Set a file
void setFile(hid_t fId);
// Write up
void write() const;
// Get a pointer to internal data
const VsH5Meta* getH5Meta() {
return &h5meta;
}
protected:
VsFilter();
// Visit links, group or dataset
static herr_t visitLinks(hid_t group, const char* name,
const H5L_info_t* linfo, void* opdata);
static herr_t visitLinks(hid_t group, const char* name, const H5L_info_t* linfo, void* opdata);
static herr_t visitGroup(hid_t group, const char* name, void* opdata);
static herr_t visitDataset(hid_t group, const char* name, void* opdata);
// Visit attribute
static herr_t visitAttrib(hid_t group, const char* name,
const H5A_info_t* ai, void* opdata);
// Find all groups which are meshes and all datasets that are meshes,
// variables and variables with meshes and attach their attributes to them
// Also attach datasets to the groups of interest (meshes).
// This function looks only for vsType attributes and checks if its value
// is in the schema. Then it adds the entity with the correct vsType
// to meta.
void makeH5Meta();
/** Reference to our stream for debugging information */
std::ostream& debugStrmRef;
// File id -opened once
hid_t fileId;
// List of vs entities
VsH5Meta h5meta;
static herr_t visitAttrib(hid_t group, const char* name, const H5A_info_t* ai, void* opdata);
};
#endif
......
/*
* VsH5Attribute.cpp
*
* Created on: Apr 28, 2010
* Author: mdurant
*/
#include "VsH5Attribute.h"
#include "VsLog.h"
#include <hdf5.h>
VsH5Attribute::VsH5Attribute(VsH5Object* parentObject, std::string attName, hid_t id):
VsH5Object(parentObject->registry, parentObject, attName, id) {
dataType = H5Aget_type(id);
}
VsH5Attribute::~VsH5Attribute() {
hid_t id = getId();
if (id != -1) {
H5Aclose(id);
id = -1;
}
}
void VsH5Attribute::write() {
std::string offset = "";
for (int i = 0; i < getDepth(); ++i) {
offset += " ";
}
VsLog::debugLog() << offset<< "Attribute "<< getShortName() << std::endl;
VsLog::debugLog() << offset<< " rank = " << dims.size() << std::endl;
}
// Total length
size_t VsH5Attribute::getLength() {
size_t len = 1;
for (size_t i = 0; i < dims.size(); ++i) {
len *= dims[i];
}
return len;
}
herr_t VsH5Attribute::getStringValue(std::string* val) {
hid_t atype = H5Aget_type(getId());
H5T_class_t type = H5Tget_class(atype);
hid_t aspace = H5Aget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(aspace);
if (type != H5T_STRING) {
VsLog::warningLog() <<"VsH5Attribute::getStringValue() - Requested attribute " <<getShortName()
<<" is not a string value." <<std::endl;
val->clear();
return -1;
}
//Yes, this is correct (rank != 0)
if (rank != 0) {
VsLog::warningLog() <<"VsH5Attribute::getStringValue() - Requested attribute " <<getShortName()
<<" is not a string value." <<std::endl;
val->clear();
return -1;
}
size_t len = H5Aget_storage_size(getId());
val->resize(len);
char* v = new char[len];
herr_t err = H5Aread(getId(), atype, v);
// JRC: is this right?
// err = H5Aread(id, H5T_NATIVE_CHAR, v);
for (size_t i = 0; i < len; ++i) {
if (v[i] == 0) {
//This happens when a program (IDL, HdfView) declares a string of length 5
//and uses the 5th character for the null terminator
//In h5dump this shows up as a string "mesh" being declared as 5 characters
//If dumped to a terminal, it prints like so: "mesh^@"
VsLog::warningLog() <<"VsH5Attribute::getStringValue() - Found null char inside string attribute: " <<getFullName() <<std::endl;
val->resize(i);
break;
}
(*val)[i] = v[i];
}
delete [] v;
return err;
}
// JRC: This fat interface may not scale? What about
// scalar attributes?
herr_t VsH5Attribute::getIntVectorValue(std::vector<int>* ivals) {
herr_t err;
size_t npoints;
hid_t atype = H5Aget_type(getId());
H5T_class_t type = H5Tget_class(atype);
hid_t aspace = H5Aget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(aspace);
if (type != H5T_INTEGER) {
VsLog::warningLog() <<"VsH5Attribute::getIntVectorValue() - Requested attribute " <<getShortName()
<<" is not an integer vector." <<std::endl;
ivals->resize(0);
return -1;
}
if (rank == 0) {
ivals->resize(1);
int v;
// err = H5Aread(id, atype, &v);
err = H5Aread(getId(), H5T_NATIVE_INT, &v);
(*ivals)[0] = v;
return err;
}
// rank>0
npoints = H5Sget_simple_extent_npoints(aspace);
int* v = new int[npoints];
err = H5Aread(getId(), H5T_NATIVE_INT, v);
ivals->resize(npoints);
for (size_t i = 0; i<npoints; ++i) {
(*ivals)[i] = v[i];
}
delete v;
return err;
}
// JRC: This fat interface may not scale? What about
// scalar attributes?
herr_t VsH5Attribute::getFloatVectorValue(std::vector<float>* fvals) {
herr_t err = 0;
size_t npoints;
hid_t atype = H5Aget_type(getId());
H5T_class_t type = H5Tget_class(atype);
hid_t aspace = H5Aget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(aspace);
if (type != H5T_FLOAT) {
VsLog::warningLog() <<"VsH5Attribute::getFloatVectorValue() - Requested attribute " <<getShortName()
<<" is not a floating point vector." <<std::endl;
fvals->resize(0);
return -1;
}
if (rank == 0) {
fvals->resize(1);
float v;
err = H5Aread(getId(), H5T_NATIVE_FLOAT, &v);
(*fvals)[0] = v;
return err;
}
// rank>0
npoints = H5Sget_simple_extent_npoints(aspace);
float* v = new float[npoints];
err = H5Aread(getId(), H5T_NATIVE_FLOAT, v);
fvals->resize(npoints);
for (size_t i = 0; i<npoints; ++i) {
(*fvals)[i] = v[i];
}
delete v;
return err;
}
// JRC: This fat interface may not scale? What about
// scalar attributes?
herr_t VsH5Attribute::getDoubleVectorValue(std::vector<double>* dvals) {
herr_t err = 0;
size_t npoints;
hid_t atype = H5Aget_type(getId());
H5T_class_t type = H5Tget_class(atype);
hid_t aspace = H5Aget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(aspace);
if (type != H5T_FLOAT) {
VsLog::warningLog() <<"VsH5Attribute::getDoubleVectorValue() - Requested attribute " <<getShortName()
<<" is not a floating point vector." <<std::endl;
dvals->resize(0);
return -1;
}
if (rank == 0) {
dvals->resize(1);
double v;
err = H5Aread(getId(), H5T_NATIVE_DOUBLE, &v);
(*dvals)[0] = v;
return err;
}
// rank>0
npoints = H5Sget_simple_extent_npoints(aspace);
double* v = new double[npoints];
err = H5Aread(getId(), H5T_NATIVE_DOUBLE, v);
dvals->resize(npoints);
for (size_t i = 0; i<npoints; ++i) {
(*dvals)[i] = v[i];
}
delete v;
return err;
}
/**
* @file VsH5Attribute.h
*
* @class VsH5Attribute
* @brief Represents an hdf5 attribute from an hdf5 file.
*
* Saves the name and hdf5 id of an attribute. Provides
* accessors to retrieve the actual value of the attribute
* from the file.
*
* Created on: Apr 28, 2010
* Author: mdurant
*/
#ifndef VSH5ATTRIBUTE_H_
#define VSH5ATTRIBUTE_H_
#include "VsH5Object.h"
#include <vector>
#include <string>
#include <map>
class VsH5Attribute: public VsH5Object {
public:
VsH5Attribute(VsH5Object* parentObject, std::string attName, hid_t id);
virtual ~VsH5Attribute();
void write();
hid_t getType() { return dataType; }
size_t getLength();
// Get the value of this attribute
// CAUTION: Calling the incorrect accessor will result in invalid or null data
herr_t getStringValue(std::string* val);
herr_t getIntVectorValue(std::vector<int>* ivals);
herr_t getFloatVectorValue(std::vector<float>* fvals);
herr_t getDoubleVectorValue(std::vector<double>* dvals);
private:
hid_t dataType;
std::vector<int> dims;
};
#endif /* VSH5ATTRIBUTE_H_ */
/*
* VsH5Dataset.cpp
*
* Created on: Apr 27, 2010
* Author: mdurant
*/
#include "VsH5Dataset.h"
#include "VsH5Attribute.h"
#include "VsLog.h"
#include "VsSchema.h"
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include "VsMesh.h"
#include "VsUtils.h"
#include "VsVariable.h"
#include "VsVariableWithMesh.h"
VsH5Dataset::VsH5Dataset(VsRegistry* r, VsH5Object* parentObject, std::string datasetName, hid_t id):
VsH5Object(r, parentObject, datasetName, id){
dataType = H5Tget_native_type(H5Dget_type(id), H5T_DIR_DEFAULT);
loadDims();
registry->add(this);
}
VsH5Dataset::~VsH5Dataset() {
hid_t id = this->getId();
if (id != -1) {
H5Dclose(id);
id = -1;
}
registry->remove(this);
}
// Total length
size_t VsH5Dataset::getLength() {
size_t len = 1;
for (size_t i = 0; i < dims.size(); ++i) {
len *= dims[i];
}
return len;
}
void VsH5Dataset::loadDims() {
hid_t space = H5Dget_space(getId());
size_t rank = H5Sget_simple_extent_ndims(space);
if (rank <= 0) {
VsLog::errorLog() <<"VsH5Dataset::loadDims() - Rank was <= 0 for dataset: " <<getFullName() <<std::endl;
return;
}
std::vector<hsize_t> sdim(rank);
H5Sget_simple_extent_dims(space, &sdim[0], NULL);
dims.resize(rank);
for (size_t i = 0; i < rank; ++i) {
dims[i] = sdim[i];
}
}
std::vector<int> VsH5Dataset::getDims() {
return dims;
}
void VsH5Dataset::write() {
std::string offset = "";
for (int i = 0; i < getDepth(); ++i) {
offset += " ";
}
VsLog::debugLog() << offset<<getFullName() <<"(" <<getId() <<")" <<std::endl;
}
/**
* @file VsH5Dataset.h
*
* @class VsH5Dataset
* @brief Represents a dataset from an hdf5 file.
*
* Provides accessors to retrieve attributes and data from
* the hdf5 file.
*
* Created on: Apr 27, 2010
* Author: mdurant
*/
#ifndef VSH5DATASET_H_
#define VSH5DATASET_H_
#include <string>
#include "VsH5Object.h"
#include <hdf5.h>
#include <vector>
#include <map>
class VsH5Attribute;
class VsH5Dataset : public VsH5Object {
public:
VsH5Dataset(VsRegistry* r, VsH5Object* parentObject, std::string datasetName, hid_t id);
virtual ~VsH5Dataset();
void write();
size_t getLength();
std::vector<int> getDims();
hid_t getType() { return dataType; }
private:
std::vector<int> dims;
hid_t dataType;
std::vector<VsH5Attribute*> attributes;
void loadDims();
};
#endif /* VSH5DATASET_H_ */
/*
* VsH5File.cpp
*
* Created on: Apr 27, 2010
* Author: mdurant
*/
#include "VsH5File.h"
#include "VsLog.h"
#include "VsFilter.h"
#include "hdf5.h"
#include "VsH5Dataset.h"
#include "VsH5Group.h"
#include "VsVariable.h"
#include "VsVariableWithMesh.h"
#include "VsRectilinearMesh.h"
#include "VsUniformMesh.h"
#include "VsUnstructuredMesh.h"
#include "VsStructuredMesh.h"
//#include <stdlib.h>
VsH5File::VsH5File(VsRegistry* r, std::string name, hid_t id):
VsH5Object(r, NULL, name, id) {
fileName = name;
VsLog::debugLog() <<"File name is: " <<name <<std::endl;
/* Code to determine dump number from file name
int underscoreLocation = fileName.find_last_of('_') + 1;
VsLog::debugLog() <<"dump number starts at position: " <<underscoreLocation <<std::endl;
if (underscoreLocation != -1) {
int periodLocation = fileName.find_first_of('.', underscoreLocation);
VsLog::debugLog() <<"period location is: " <<periodLocation <<std::endl;
if (periodLocation == -1) {
periodLocation = fileName.length() - 1;
}
VsLog::debugLog() <<"period location is: " <<periodLocation <<std::endl;
std::string dumpNumberString = name.substr(underscoreLocation, (periodLocation - underscoreLocation));
VsLog::errorLog() <<"DumpNumberString is: " <<dumpNumberString <<std::endl;
dumpNumber = atoi(dumpNumberString.c_str());
VsLog::errorLog() <<"Dump number is: " <<dumpNumber <<std::endl;
}
*/
}
VsH5File::~VsH5File() {
//we clear all objects that were read from this file
//so that we can close the file itself.
//Note that this does not delete the registry object
//which will be deleted in ~avtVsFileFormat
registry->deleteAllObjects();
// Check if anything is still open
int cnt = H5Fget_obj_count(getId(), H5F_OBJ_ALL);
//CNT will always be >= 1 because the FILE is still open
//So only output the error message if there is MORE than 1 open id
if (cnt > 1) {
VsLog::debugLog() << "File still has " << cnt << " open objects:" <<std::endl;
hid_t objIds[cnt];
int numObjs = H5Fget_obj_ids(getId(), H5F_OBJ_ALL, cnt, objIds);
char objName[1024];
for (int i = 0; i < numObjs; ++i) {
hid_t anobj = objIds[i];
//Don't print a warning for the file itself, we know it's still open.
if (anobj != getId()) {
H5I_type_t ot = H5Iget_type(anobj);
herr_t status = H5Iget_name(anobj, objName, 1024);
VsLog::debugLog() << "type = " << ot << ", name = " << objName <<", id = " <<anobj <<std::endl;;
}
}
VsLog::debugLog() << std::endl;
}
//VsLog::debugLog() << "Strong close should take care of this." << std::endl;
//close this file
H5Fclose(getId());
}
std::string VsH5File::getName() {
return "/";
}
void VsH5File::write() {
VsLog::debugLog() <<"File: " <<fileName <<std::endl;
}
/**
* @file VsH5File.h
*
* @class VsH5File
* @brief Represents an hdf5 data file
*
* Created on: Apr 27, 2010
* Author: mdurant
*/
#ifndef VSH5FILE_H_
#define VSH5FILE_H_
#include <string>
#include "VsH5Group.h"
#include "VsH5Object.h"
#include <hdf5.h>
class VsH5File : public VsH5Object {
public:
VsH5File(VsRegistry* r, std::string name, hid_t id);
virtual ~VsH5File();
std::string getName();
void write();
private:
std::string fileName;
};
#endif /* VSH5FILE_H_ */
/*
* VsH5Group.cpp
*
* Created on: Apr 27, 2010
* Author: mdurant
*/
#include "VsH5Group.h"
#include "VsH5Dataset.h"
#include "VsLog.h"
#include "VsSchema.h"
#include "VsMesh.h"
#include "VsUtils.h"
#include <hdf5.h>
#include <map>
#include "VsH5Attribute.h"
VsH5Group::VsH5Group(VsRegistry* r, VsH5Object* parentObject, std::string groupName, hid_t id):
VsH5Object(r, parentObject, groupName, id) {
registry->add(this);
}