Fesapi  2.0.0.0
This project provides C++ classes which allow an easy access in import and export to the Energistics standards.
EtpHdfProxy.h
1 /*-----------------------------------------------------------------------
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"; you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 -----------------------------------------------------------------------*/
19 #pragma once
20 
21 #include "../common/HdfProxyFactory.h"
22 
23 #include "DataArrayBlockingSession.h"
24 
25 namespace ETP_NS
26 {
27  class DLL_IMPORT_OR_EXPORT EtpHdfProxy : public EML2_NS::AbstractHdfProxy
28  {
29  private:
30  std::shared_ptr<DataArrayBlockingSession> session;
31  unsigned int compressionLevel;
32 
33  std::string getUri() const;
34 
35  public:
36 
41  EtpHdfProxy(COMMON_NS::DataObjectRepository * repo, const std::string & guid, const std::string & title, const std::string & packageDirAbsolutePath, const std::string & externalFilePath, COMMON_NS::DataObjectRepository::openingMode hdfPermissionAccess) :
42  EML2_NS::AbstractHdfProxy(packageDirAbsolutePath, externalFilePath, hdfPermissionAccess) {
43  initGsoapProxy(repo, guid, title, 20);
44  }
45 
49  EtpHdfProxy(gsoap_resqml2_0_1::_eml20__EpcExternalPartReference* fromGsoap) :
50  EML2_NS::AbstractHdfProxy(fromGsoap), session(nullptr), compressionLevel(0) {}
51 
52  EtpHdfProxy(gsoap_eml2_1::_eml21__EpcExternalPartReference* fromGsoap) :
53  EML2_NS::AbstractHdfProxy(fromGsoap), session(nullptr), compressionLevel(0) {}
54 
58  EtpHdfProxy(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject) :
59  EML2_NS::AbstractHdfProxy(partialObject), session(nullptr), compressionLevel(0) {}
60 
61  EtpHdfProxy(const COMMON_NS::DataObjectReference& dor) :
62  EML2_NS::AbstractHdfProxy(dor), session(nullptr), compressionLevel(0) {}
63 
64 
69  ~EtpHdfProxy() = default;
70 
71  std::shared_ptr<DataArrayBlockingSession> getSession() { return session; }
72  void setSession(boost::asio::io_context& ioc, const std::string & host, const std::string & port, const std::string & target);
73 
78  void open();
79 
83  bool isOpened() const { return session != nullptr && !session->isWebSocketSessionClosed(); }
84 
88  void close() { session->close(); }
89 
90  /*
91  * Get the used (native) datatype in a dataset
92  */
93  COMMON_NS::AbstractObject::hdfDatatypeEnum getHdfDatatypeInDataset(const std::string & groupName);
94 
99  int getHdfDatatypeClassInDataset(const std::string & datasetName);
100 
113  void writeItemizedListOfList(const std::string & groupName,
114  const std::string & name,
115  hdf5_hid_t cumulativeLengthDatatype,
116  const void * cumulativeLength,
117  unsigned long long cumulativeLengthSize,
118  hdf5_hid_t elementsDatatype,
119  const void * elements,
120  unsigned long long elementsSize);
121 
126  unsigned int getDimensionCount(const std::string & datasetName);
127 
132  std::vector<unsigned long long> getElementCountPerDimension(const std::string & datasetName);
133 
138  signed long long getElementCount(const std::string & datasetName);
139 
144  void setCompressionLevel(unsigned int newCompressionLevel) { if (newCompressionLevel > 9) compressionLevel = 9; else compressionLevel = newCompressionLevel; }
145 
146  void writeArrayNdOfFloatValues(const std::string & groupName,
147  const std::string & name,
148  const float * floatValues,
149  const unsigned long long * numValuesInEachDimension,
150  unsigned int numDimensions);
151 
161  void writeArrayNdOfDoubleValues(const std::string & groupName,
162  const std::string & name,
163  const double * dblValues,
164  const unsigned long long * numValuesInEachDimension,
165  unsigned int numDimensions);
166 
176  void writeArrayNdOfCharValues(const std::string & groupName,
177  const std::string & name,
178  const char * intValues,
179  const unsigned long long * numValuesInEachDimension,
180  unsigned int numDimensions);
181 
191  void writeArrayNdOfIntValues(const std::string & groupName,
192  const std::string & name,
193  const int * intValues,
194  const unsigned long long * numValuesInEachDimension,
195  unsigned int numDimensions);
196 
197  void writeArrayNdOfInt64Values(const std::string & groupName,
198  const std::string & name,
199  const int64_t * values,
200  const unsigned long long * numValuesInEachDimension,
201  unsigned int numDimensions);
202 
212  void writeArrayNdOfUInt64Values(const std::string & groupName,
213  const std::string & name,
214  const uint64_t * values,
215  const unsigned long long * numValuesInEachDimension,
216  unsigned int numDimensions);
217 
228  void writeArrayNd(const std::string & groupName,
229  const std::string & name,
230  hdf5_hid_t datatype,
231  const void * values,
232  const unsigned long long * numValuesInEachDimension,
233  unsigned int numDimensions);
234 
245  const std::string& groupName,
246  const std::string& name,
247  hdf5_hid_t datatype,
248  const unsigned long long* numValuesInEachDimension,
249  unsigned int numDimensions
250  );
251 
263  const std::string& groupName,
264  const std::string& name,
265  hdf5_hid_t datatype,
266  const void* values,
267  const unsigned long long* numValuesInEachDimension,
268  const unsigned long long* offsetValuesInEachDimension,
269  unsigned int numDimensions
270  );
271 
275  void writeGroupAttributes(const std::string & groupName,
276  const std::vector<std::string> & attributeNames,
277  const std::vector<std::string> & values);
278 
282  void writeGroupAttribute(const std::string & groupName,
283  const std::string & attributeName,
284  const std::vector<std::string> & values);
285 
289  void writeGroupAttributes(const std::string & groupName,
290  const std::vector<std::string> & attributeNames,
291  const std::vector<double> & values);
292 
296  void writeGroupAttributes(const std::string & groupName,
297  const std::vector<std::string> & attributeNames,
298  const std::vector<int> & values);
299 
303  void writeDatasetAttributes(const std::string & datasetName,
304  const std::vector<std::string> & attributeNames,
305  const std::vector<std::string> & values);
306 
310  void writeDatasetAttribute(const std::string & datasetName,
311  const std::string & attributeName,
312  const std::vector<std::string> & values);
313 
317  void writeDatasetAttributes(const std::string & datasetName,
318  const std::vector<std::string> & attributeNames,
319  const std::vector<double> & values);
320 
324  void writeDatasetAttributes(const std::string & datasetName,
325  const std::vector<std::string> & attributeNames,
326  const std::vector<int> & values);
327 
328  std::string readStringAttribute(const std::string & obj_name,
329  const std::string & attr_name) const;
330 
331  std::vector<std::string> readStringArrayAttribute(const std::string & obj_name,
332  const std::string & attr_name) const;
333 
334  double readDoubleAttribute(const std::string & obj_name,
335  const std::string & attr_name) const;
336 
337  int64_t readLongAttribute(const std::string & obj_name,
338  const std::string & attr_name) const;
339 
345  void readArrayNdOfDoubleValues(const std::string & datasetName, double* values);
346 
356  const std::string & datasetName,
357  double* values,
358  unsigned long long const * numValuesInEachDimension,
359  unsigned long long const * offsetInEachDimension,
360  unsigned int numDimensions
361  );
362 
374  const std::string & datasetName, double* values,
375  unsigned long long const * blockCountPerDimension,
376  unsigned long long const * offsetInEachDimension,
377  unsigned long long const * strideInEachDimension,
378  unsigned long long const * blockSizeInEachDimension,
379  unsigned int numDimensions);
380 
382  const std::string & datasetName,
383  unsigned long long const * blockCountPerDimension,
384  unsigned long long const * offsetInEachDimension,
385  unsigned long long const * strideInEachDimension,
386  unsigned long long const * blockSizeInEachDimension,
387  unsigned int numDimensions,
388  bool newSelection,
389  hdf5_hid_t & dataset,
390  hdf5_hid_t & filespace);
391 
400  hdf5_hid_t dataset,
401  hdf5_hid_t filespace,
402  void* values,
403  unsigned long long slabSize);
404 
410  void readArrayNdOfFloatValues(const std::string & datasetName, float* values);
411 
421  const std::string & datasetName,
422  float* values,
423  unsigned long long const * numValuesInEachDimension,
424  unsigned long long const * offsetInEachDimension,
425  unsigned int numDimensions
426  );
427 
433  void readArrayNdOfInt64Values(const std::string & datasetName, int64_t* values);
434 
444  const std::string & datasetName,
445  int64_t* values,
446  unsigned long long const * numValuesInEachDimension,
447  unsigned long long const * offsetInEachDimension,
448  unsigned int numDimensions
449  );
450 
456  void readArrayNdOfUInt64Values(const std::string & datasetName, uint64_t* values);
457 
463  void readArrayNdOfIntValues(const std::string & datasetName, int* values);
464 
474  const std::string & datasetName,
475  int* values,
476  unsigned long long const * numValuesInEachDimension,
477  unsigned long long const * offsetInEachDimension,
478  unsigned int numDimensions
479  );
480 
486  void readArrayNdOfUIntValues(const std::string & datasetName, unsigned int* values);
487 
494  void readArrayNdOfShortValues(const std::string & datasetName, short* values);
495 
501  void readArrayNdOfUShortValues(const std::string & datasetName, unsigned short* values);
502 
508  void readArrayNdOfCharValues(const std::string & datasetName, char* values);
509 
514  void readArrayNdOfUCharValues(const std::string & datasetName, unsigned char* values);
515 
520  std::vector<unsigned long long> readArrayDimensions(const std::string & datasetName);
521 
525  bool exist(const std::string & absolutePathInHdfFile) const;
526 
530  bool isCompressed(const std::string & datasetName);
531 
535  static const char* XML_NS;
536 
540  std::string getXmlNamespace() const { return XML_NS; }
541  };
542 
543  class DLL_IMPORT_OR_EXPORT EtpHdfProxyFactory : public COMMON_NS::HdfProxyFactory
544  {
545  public:
549  EML2_NS::AbstractHdfProxy* make(gsoap_resqml2_0_1::eml20__DataObjectReference* partialObject) {
550  return new EtpHdfProxy(partialObject);
551  }
552  EML2_NS::AbstractHdfProxy* make(const COMMON_NS::DataObjectReference& dor) {
553  return new EtpHdfProxy(dor);
554  }
555 
559  EML2_NS::AbstractHdfProxy* make(gsoap_resqml2_0_1::_eml20__EpcExternalPartReference* fromGsoap) {
560  return new EtpHdfProxy(fromGsoap);
561  }
562 
563  EML2_NS::AbstractHdfProxy* make(COMMON_NS::DataObjectRepository * repo, const std::string & guid, const std::string & title,
564  const std::string & packageDirAbsolutePath, const std::string & externalFilePath,
565  COMMON_NS::DataObjectRepository::openingMode hdfPermissionAccess = COMMON_NS::DataObjectRepository::openingMode::READ_ONLY) {
566  return new EtpHdfProxy(repo, guid, title, packageDirAbsolutePath, externalFilePath, hdfPermissionAccess);
567  }
568  };
569 }
Definition: EtpHdfProxy.h:544
eml2::AbstractHdfProxy * make(gsoap_resqml2_0_1::eml20__DataObjectReference *partialObject)
Definition: EtpHdfProxy.h:549
eml2::AbstractHdfProxy * make(const common::DataObjectReference &dor)
Creates an instance of HDF5 file proxy. Only to be used in partial transfer context.
Definition: EtpHdfProxy.h:552
eml2::AbstractHdfProxy * make(common::DataObjectRepository *repo, const std::string &guid, const std::string &title, const std::string &packageDirAbsolutePath, const std::string &externalFilePath, common::DataObjectRepository::openingMode hdfPermissionAccess=common::DataObjectRepository::openingMode::READ_ONLY)
Creates an instance of HDF5 file proxy for serialization purpose.
Definition: EtpHdfProxy.h:563
eml2::AbstractHdfProxy * make(gsoap_resqml2_0_1::_eml20__EpcExternalPartReference *fromGsoap)
Definition: EtpHdfProxy.h:559
Definition: EtpHdfProxy.h:28
int getHdfDatatypeClassInDataset(const std::string &datasetName)
void writeArrayNdOfFloatValues(const std::string &groupName, const std::string &name, const float *floatValues, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void writeArrayNd(const std::string &groupName, const std::string &name, hdf5_hid_t datatype, const void *values, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
std::vector< std::string > readStringArrayAttribute(const std::string &obj_name, const std::string &attr_name) const
void writeItemizedListOfList(const std::string &groupName, const std::string &name, hdf5_hid_t cumulativeLengthDatatype, const void *cumulativeLength, unsigned long long cumulativeLengthSize, hdf5_hid_t elementsDatatype, const void *elements, unsigned long long elementsSize)
EtpHdfProxy(common::DataObjectRepository *repo, const std::string &guid, const std::string &title, const std::string &packageDirAbsolutePath, const std::string &externalFilePath, common::DataObjectRepository::openingMode hdfPermissionAccess)
Definition: EtpHdfProxy.h:41
std::vector< unsigned long long > getElementCountPerDimension(const std::string &datasetName)
void writeDatasetAttributes(const std::string &datasetName, const std::vector< std::string > &attributeNames, const std::vector< int > &values)
void setCompressionLevel(unsigned int newCompressionLevel)
Definition: EtpHdfProxy.h:144
void readArrayNdOfDoubleValues(const std::string &datasetName, double *values, unsigned long long const *numValuesInEachDimension, unsigned long long const *offsetInEachDimension, unsigned int numDimensions)
void readArrayNdOfInt64Values(const std::string &datasetName, int64_t *values, unsigned long long const *numValuesInEachDimension, unsigned long long const *offsetInEachDimension, unsigned int numDimensions)
void writeGroupAttributes(const std::string &groupName, const std::vector< std::string > &attributeNames, const std::vector< double > &values)
void readArrayNdOfDoubleValues(const std::string &datasetName, double *values)
void writeDatasetAttribute(const std::string &datasetName, const std::string &attributeName, const std::vector< std::string > &values)
std::string readStringAttribute(const std::string &obj_name, const std::string &attr_name) const
void writeArrayNdOfCharValues(const std::string &groupName, const std::string &name, const char *intValues, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void writeArrayNdOfIntValues(const std::string &groupName, const std::string &name, const int *intValues, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void readArrayNdOfFloatValues(const std::string &datasetName, float *values, unsigned long long const *numValuesInEachDimension, unsigned long long const *offsetInEachDimension, unsigned int numDimensions)
void writeDatasetAttributes(const std::string &datasetName, const std::vector< std::string > &attributeNames, const std::vector< std::string > &values)
static const char * XML_NS
Definition: EtpHdfProxy.h:535
void writeGroupAttributes(const std::string &groupName, const std::vector< std::string > &attributeNames, const std::vector< std::string > &values)
void writeDatasetAttributes(const std::string &datasetName, const std::vector< std::string > &attributeNames, const std::vector< double > &values)
void writeArrayNdOfUInt64Values(const std::string &groupName, const std::string &name, const uint64_t *values, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void writeArrayNdOfDoubleValues(const std::string &groupName, const std::string &name, const double *dblValues, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void readArrayNdOfIntValues(const std::string &datasetName, int *values, unsigned long long const *numValuesInEachDimension, unsigned long long const *offsetInEachDimension, unsigned int numDimensions)
void readArrayNdOfShortValues(const std::string &datasetName, short *values)
void readArrayNdOfDoubleValues(const std::string &datasetName, double *values, unsigned long long const *blockCountPerDimension, unsigned long long const *offsetInEachDimension, unsigned long long const *strideInEachDimension, unsigned long long const *blockSizeInEachDimension, unsigned int numDimensions)
void readArrayNdOfFloatValues(const std::string &datasetName, float *values)
std::string getXmlNamespace() const
Definition: EtpHdfProxy.h:540
signed long long getElementCount(const std::string &datasetName)
void readArrayNdOfInt64Values(const std::string &datasetName, int64_t *values)
void writeGroupAttributes(const std::string &groupName, const std::vector< std::string > &attributeNames, const std::vector< int > &values)
void readArrayNdOfIntValues(const std::string &datasetName, int *values)
unsigned int getDimensionCount(const std::string &datasetName)
void readArrayNdOfUInt64Values(const std::string &datasetName, uint64_t *values)
bool isCompressed(const std::string &datasetName)
void writeGroupAttribute(const std::string &groupName, const std::string &attributeName, const std::vector< std::string > &values)
void writeArrayNdSlab(const std::string &groupName, const std::string &name, hdf5_hid_t datatype, const void *values, const unsigned long long *numValuesInEachDimension, const unsigned long long *offsetValuesInEachDimension, unsigned int numDimensions)
void writeArrayNdOfInt64Values(const std::string &groupName, const std::string &name, const int64_t *values, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
void readArrayNdOfUShortValues(const std::string &datasetName, unsigned short *values)
void close()
Definition: EtpHdfProxy.h:88
void createArrayNd(const std::string &groupName, const std::string &name, hdf5_hid_t datatype, const unsigned long long *numValuesInEachDimension, unsigned int numDimensions)
~EtpHdfProxy()=default
void readArrayNdOfUIntValues(const std::string &datasetName, unsigned int *values)
EtpHdfProxy(gsoap_resqml2_0_1::eml20__DataObjectReference *partialObject)
Definition: EtpHdfProxy.h:58
bool isOpened() const
Definition: EtpHdfProxy.h:83
void selectArrayNdOfValues(const std::string &datasetName, unsigned long long const *blockCountPerDimension, unsigned long long const *offsetInEachDimension, unsigned long long const *strideInEachDimension, unsigned long long const *blockSizeInEachDimension, unsigned int numDimensions, bool newSelection, hdf5_hid_t &dataset, hdf5_hid_t &filespace)
bool exist(const std::string &absolutePathInHdfFile) const
std::vector< unsigned long long > readArrayDimensions(const std::string &datasetName)
common::AbstractObject::hdfDatatypeEnum getHdfDatatypeInDataset(const std::string &groupName)
void readArrayNdOfCharValues(const std::string &datasetName, char *values)
int64_t readLongAttribute(const std::string &obj_name, const std::string &attr_name) const
void readArrayNdOfUCharValues(const std::string &datasetName, unsigned char *values)
void readArrayNdOfDoubleValues(hdf5_hid_t dataset, hdf5_hid_t filespace, void *values, unsigned long long slabSize)
double readDoubleAttribute(const std::string &obj_name, const std::string &attr_name) const
EtpHdfProxy(gsoap_resqml2_0_1::_eml20__EpcExternalPartReference *fromGsoap)
Definition: EtpHdfProxy.h:49