1 #include "h5helper_v1_1.h"
3 #include "QDaqObject.h"
7 #define DYNAMIC_PROPERTY_TAG "DYNAMIC_PROPERTY"
9 void h5helper_v1_1::write(CommonFG* h5obj,
const char* name,
const QDaqObject* obj)
12 h5helper_v1_0::write(h5obj,name,QString(
"0"));
16 QString path(obj->objectName());
20 while(p && p!=top && p!=r) {
24 path.push_front(p->objectName());
27 if (p==top) h5helper_v1_0::write(h5obj,name,path);
29 h5helper_v1_0::write(h5obj,name,QString(
"0"));
30 pushWarning(QString(
"QDaqObject* property named: %1 of %2 could not be saved. Pointed object is outside of file scope.").arg(name).arg(path));
34 void h5helper_v1_1::write(CommonFG *h5obj,
const char *name,
const QDaqObjectList &objList)
36 if (objList.isEmpty()) {
37 h5helper_v1_0::write(h5obj,name,QString(
"0"));
47 QString path(p->objectName());
48 while(p && p!=top && p!=r) {
52 path.push_front(p->objectName());
55 if (p==top) pathList << path;
57 pathList << QString(
"0");
58 pushWarning(QString(
"A ptr in QDaqObjectList property named: %1 of %2 could not be saved. Pointed object is outside of file scope.").arg(name).arg(path));
61 h5helper_v1_0::write(h5obj,name,pathList);
64 void h5helper_v1_1::connectDeferedPointers()
66 foreach(
const deferedPtrData& d, deferedPtrs) {
70 foreach(
const QString& path, d.pathList) {
72 if (path.isEmpty() || path==
"0") {
77 QStringList splitPath = path.split(QChar(
'.'));
79 QString objName = splitPath.front(); splitPath.pop_front();
81 if (objName != p->objectName()) {
82 pushWarning(QString(
"Error reading %1.%2 from file: Path %3 not found.")
83 .arg(d.obj->objectName())
92 objName = splitPath.front();
93 splitPath.pop_front();
96 while (!splitPath.isEmpty() && p);
100 pushWarning(QString(
"Error reading %1.%2 from file: Unknown error.")
101 .arg(d.obj->objectName())
111 if (!p) { noNulls =
false;
break; }
113 if (noNulls) d.obj->setProperty(d.propName,QVariant::fromValue(objList));
116 if (!objList.isEmpty()) p = objList.at(0);
117 d.obj->setProperty(d.propName,QVariant::fromValue(p));
123 Group h5helper_v1_1::createGroup(CommonFG* loc,
const char* name)
125 hid_t group_creation_plist;
126 group_creation_plist = H5Pcreate(H5P_GROUP_CREATE);
127 herr_t status = H5Pset_link_creation_order(group_creation_plist,
128 H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
130 if (status<0)
throw PropListIException(
"H5Pset_link_creation_order");
133 group_id = H5Gcreate(loc->getLocId(),
136 group_creation_plist,
141 H5Pclose(group_creation_plist);
147 QByteArrayList h5helper_v1_1::getGroupNames(CommonFG* h5g,
bool isRoot)
149 QByteArrayList names;
151 int n = h5g->getNumObjs();
154 for(
int i=0; i<n; ++i) {
155 H5G_obj_t typ = h5g->getObjTypeByIdx(i);
158 QByteArray groupName;
159 groupName.fill(
'\0',256);
160 h5g->getObjnameByIdx(i,groupName.data(),256);
161 names.push_back(groupName);
165 for(
int i=0; i<n; ++i) {
166 QByteArray groupName;
167 groupName.fill(
'\0',256);
169 herr_t ret = H5Lget_name_by_idx(h5g->getLocId(),
".", H5_INDEX_CRT_ORDER, H5_ITER_INC,
170 i, groupName.data(), 256, 0);
172 H5O_info_t object_info;
173 ret = H5Oget_info_by_name(h5g->getLocId(), groupName, &object_info, 0);
174 if (object_info.type == H5O_TYPE_GROUP) names.push_back(groupName);
194 void h5helper_v1_1::writeDynamicProperties(CommonFG* h5obj,
const QDaqObject* m_object)
196 if (m_object->dynamicPropertyNames().isEmpty())
return;
199 foreach(
const QByteArray& propName, m_object->dynamicPropertyNames())
201 if (lockedPropertyList_.contains(propName))
continue;
203 QVariant v = m_object->property(propName.constData());
205 if (QDaqTypes::isBool(v)) h5helper_v1_0::write(h5obj,propName.constData(),(int)v.toBool());
206 else if (QDaqTypes::isNumeric(v)) h5helper_v1_0::write(h5obj,propName.constData(),v.toDouble());
207 else if (QDaqTypes::isString(v)) h5helper_v1_0::write(h5obj,propName.constData(),v.toString());
208 else if (QDaqTypes::isStringList(v)) h5helper_v1_0::write(h5obj,propName.constData(),QDaqTypes::toStringList(v));
209 else if (QDaqTypes::isVector(v)) h5helper_v1_0::write(h5obj,propName.constData(),QDaqTypes::toVector(v));
213 DataSet ds = h5obj->openDataSet(propName.constData());
214 DataSpace dspace(H5S_SCALAR);
215 Attribute attr = ds.createAttribute(DYNAMIC_PROPERTY_TAG,PredType::NATIVE_INT,dspace);
217 attr.write(PredType::NATIVE_INT,&va);
219 catch(FileIException& e)
221 qDebug() <<
"File exception writing dynamic property " << propName;
224 catch(GroupIException& e)
226 qDebug() <<
"Group exception writing dynamic property " << propName;
228 catch(AttributeIException& e)
230 qDebug() <<
"Attribute exception writing dynamic property " << propName;
238 void h5helper_v1_1::readDynamicProperties(CommonFG* h5g,
QDaqObject* m_object)
240 int n = h5g->getNumObjs();
242 for(
int i=0; i<n; ++i) {
243 H5G_obj_t typ = h5g->getObjTypeByIdx(i);
244 if (typ==H5G_DATASET)
247 propName.fill(
'\0',256);
248 h5g->getObjnameByIdx(i,propName.data(),256);
250 DataSet ds = h5g->openDataSet(propName.constData());
252 if (ds.attrExists(DYNAMIC_PROPERTY_TAG))
254 H5T_class_t type_class = ds.getTypeClass();
255 DataSpace dspace = ds.getSpace();
257 if (type_class==H5T_INTEGER) {
258 int sz = dspace.getSimpleExtentNpoints();
260 qDebug() <<
"Invalid dynamic prop in HDF5";
263 ds.read(&val, ds.getDataType());
265 m_object->setProperty(propName.constData(),QVariant::fromValue(b));
267 }
else if (type_class==H5T_FLOAT) {
268 int sz = dspace.getSimpleExtentNpoints();
272 ds.read(val.
data(), ds.getDataType());
273 m_object->setProperty(propName.constData(),QVariant::fromValue(val));
276 ds.read(&val, ds.getDataType());
277 m_object->setProperty(propName.constData(),QVariant::fromValue(val));
279 }
else if (type_class==H5T_STRING) {
281 StrType st = ds.getStrType();
282 int ncols = st.getSize();
284 dspace.getSimpleExtentDims(&sz);
286 QByteArray buff(nrows*ncols,
'0');
287 ds.read(buff.data(),st,dspace);
290 for(
int i=0; i<nrows; i++)
292 QByteArray ba(buff.constData() + i*ncols, ncols);
295 m_object->setProperty(propName.constData(),QVariant::fromValue(val));
298 m_object->setProperty(propName.constData(),QVariant::fromValue(val));
301 qDebug() <<
"Invalid dynamic prop in HDF5";
Base class of all QDaq objects.
void setCapacity(int c)
Set the capacity.
static QDaqRoot * root()
Obtain a pointer to the one-and-only QDaqRoot object.
QDaqObject * findChild(const QString &name) const
Find the first child QDaqObject with objectName equal to name.
A buffer for storing double numbers.
QList< QDaqObject * > QDaqObjectList
A QList of QDaqObject pointers.
double * data()
Return a pointer to the data.
QDaqObject * parent() const