Field3D
Field3DFileHDF5.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
45 //----------------------------------------------------------------------------//
46 
47 #ifndef _INCLUDED_Field3D_Field3DFileHDF5_H_
48 #define _INCLUDED_Field3D_Field3DFileHDF5_H_
49 
50 //----------------------------------------------------------------------------//
51 
52 #include <list>
53 #include <string>
54 #include <vector>
55 
56 #include <hdf5.h>
57 
58 #include <boost/intrusive_ptr.hpp>
59 
60 #include "EmptyField.h"
61 #include "Field.h"
62 #include "FieldCache.h"
63 #include "FieldMetadata.h"
64 #include "ClassFactory.h"
65 #include "Hdf5Util.h"
66 
67 //----------------------------------------------------------------------------//
68 
69 #include "ns.h"
70 
72 
73 
74 
75 //----------------------------------------------------------------------------//
76 // Function Declarations
77 //----------------------------------------------------------------------------//
78 
80 // \{
81 
84 template <class Data_T>
85 typename Field<Data_T>::Ptr
86 readField(const std::string &className, hid_t layerGroup,
87  const std::string &filename, const std::string &layerPath);
88 
91 FIELD3D_API bool writeField(hid_t layerGroup, FieldBase::Ptr field);
92 
96 
100 FIELD3D_API bool writeFieldMapping(hid_t mappingGroup,
101  FieldMapping::Ptr mapping);
102 
104 
105 //----------------------------------------------------------------------------//
106 // Layer
107 //----------------------------------------------------------------------------//
108 
111 namespace FileHDF5 {
112 
120 class Layer
121 {
122 public:
124  std::string name;
127  std::string parent;
128 };
129 
130 } // namespace FileHDF5
131 
132 //----------------------------------------------------------------------------//
133 // Partition
134 //----------------------------------------------------------------------------//
135 
136 namespace FileHDF5 {
137 
146 {
147 public:
148 
149  typedef std::vector<Layer> ScalarLayerList;
150  typedef std::vector<Layer> VectorLayerList;
151 
152  typedef boost::intrusive_ptr<Partition> Ptr;
153  typedef boost::intrusive_ptr<const Partition> CPtr;
154 
155  // RTTI replacement ----------------------------------------------------------
156 
159 
160  static const char *staticClassType()
161  {
162  return "Partition";
163  }
164 
165  // Ctors, dtor ---------------------------------------------------------------
166 
169  : RefBase()
170  { }
171 
172  // From RefBase --------------------------------------------------------------
173 
176 
177  virtual std::string className() const;
178 
180 
181  // Main methods --------------------------------------------------------------
182 
184  void addScalarLayer(const FileHDF5::Layer &layer);
186  void addVectorLayer(const FileHDF5::Layer &layer);
187 
189  const FileHDF5::Layer* scalarLayer(const std::string &name) const;
191  const FileHDF5::Layer* vectorLayer(const std::string &name) const;
192 
194  void getScalarLayerNames(std::vector<std::string> &names) const;
196  void getVectorLayerNames(std::vector<std::string> &names) const;
197 
198  // Public data members -------------------------------------------------------
199 
201  std::string name;
204 
205 private:
206 
207  // Private data members ------------------------------------------------------
208 
213 
214  // Typedefs ------------------------------------------------------------------
215 
217  typedef RefBase base;
218 
219 };
220 
221 } // namespace FileHDF5
222 
223 //----------------------------------------------------------------------------//
224 // Field3DFileHDF5Base
225 //----------------------------------------------------------------------------//
226 
234 //----------------------------------------------------------------------------//
235 
237 {
238 public:
239 
240  friend class Field3DInputFile;
241  friend class Field3DOutputFile;
242 
243  // Structs -------------------------------------------------------------------
244 
245  struct LayerInfo
246  {
247  std::string name;
248  std::string parentName;
250  LayerInfo(std::string par, std::string nm, int cpt)
251  : name(nm), parentName(par), components(cpt)
252  { /* Empty */ }
253  };
254 
255  // Typedefs ------------------------------------------------------------------
256 
257  typedef std::map<std::string, std::string> GroupMembershipMap;
258 
259  // Ctor, dtor ----------------------------------------------------------------
260 
263 
266  virtual ~Field3DFileHDF5Base() = 0;
267 
269 
270  // Main methods --------------------------------------------------------------
271 
273  void clear();
274 
278  bool close();
279 
282 
284  void getPartitionNames(std::vector<std::string> &names) const;
286  void getScalarLayerNames(std::vector<std::string> &names,
287  const std::string &partitionName) const;
289  void getVectorLayerNames(std::vector<std::string> &names,
290  const std::string &partitionName) const;
291 
294  FileHDF5::Partition::Ptr getPartition(const std::string &partitionName) const
295  { return partition(partitionName); }
296 
298 
301 
305  std::string intPartitionName(const std::string &partitionName,
306  const std::string &layerName,
307  FieldRes::Ptr field);
308 
311  std::string removeUniqueId(const std::string &partitionName) const;
312 
314  void addGroupMembership(const GroupMembershipMap &groupMembers);
315 
317 
318  // Access to metadata --------------------------------------------------------
319 
322  { return m_metadata; }
323 
325  const FieldMetadata& metadata() const
326  { return m_metadata; }
327 
330  virtual void metadataHasChanged(const std::string &/* name */)
331  { /* Empty */ }
332 
333  // Debug ---------------------------------------------------------------------
334 
337 
338  void printHierarchy() const;
339 
341 
342 protected:
343 
344  // Internal typedefs ---------------------------------------------------------
345 
346  typedef std::vector<FileHDF5::Partition::Ptr> PartitionList;
347  typedef std::map<std::string, int> PartitionCountMap;
348 
349  // Convenience methods -------------------------------------------------------
350 
353 
355  void closeInternal();
358  FileHDF5::Partition::Ptr partition(const std::string &partitionName);
361  FileHDF5::Partition::Ptr partition(const std::string &partitionName) const;
362 
364  void getIntPartitionNames(std::vector<std::string> &names) const;
367  void getIntScalarLayerNames(std::vector<std::string> &names,
368  const std::string &intPartitionName) const;
371  void getIntVectorLayerNames(std::vector<std::string> &names,
372  const std::string &intPartitionName) const;
373 
375  int numIntPartitions(const std::string &partitionName) const;
376 
379  std::string makeIntPartitionName(const std::string &partitionsName,
380  int i) const;
381 
383 
384  // Data members --------------------------------------------------------------
385 
387  std::vector<LayerInfo> m_layerInfo;
388 
390  hid_t m_file;
394  std::vector<std::string> m_partitionNames;
395 
399 
404 
407 
408 private:
409 
410  // Private member functions --------------------------------------------------
411 
413  void operator =(const Field3DFileHDF5Base&);
414 
415 
416 };
417 
418 //----------------------------------------------------------------------------//
419 // Field3DInputFileHDF5
420 //----------------------------------------------------------------------------//
421 
435 //----------------------------------------------------------------------------//
436 
438 {
439 public:
440 
441  friend class Field3DInputFile;
442  friend class Field3DOutputFile;
443 
444  // Ctors, dtor ---------------------------------------------------------------
445 
448 
450  virtual ~Field3DInputFileHDF5();
451 
453 
454  // Main interface ------------------------------------------------------------
455 
458 
463  template <class Data_T>
464  typename Field<Data_T>::Vec
465  readScalarLayers(const std::string &layerName = std::string("")) const;
466 
468  template <class Data_T>
469  typename Field<Data_T>::Vec
470  readScalarLayers(const std::string &partitionName,
471  const std::string &layerName) const;
472 
477  template <class Data_T>
478  typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
479  readVectorLayers(const std::string &layerName = std::string("")) const;
480 
482  template <class Data_T>
483  typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
484  readVectorLayers(const std::string &partitionName,
485  const std::string &layerName) const;
486 
489  template <template <typename T> class Field_T, class Data_T>
490  typename Field_T<Data_T>::Vec
491  readScalarLayersAs(const std::string &layerName = std::string("")) const
492  {
493  typedef typename Field<Data_T>::Vec FieldList;
494  typedef typename Field_T<Data_T>::Vec TypedFieldList;
495 
496  // First, read the layers as-is
497  FieldList originals;
498  originals = readScalarLayers<Data_T>(layerName);
499 
500  // Loop over fields, converting if needed
501  TypedFieldList output;
502  typename FieldList::iterator i = originals.begin();
503  for (; i != originals.end(); ++i) {
504  typename Field_T<Data_T>::Ptr targetField;
505  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
506  if (targetField) {
507  output.push_back(targetField);
508  } else {
509  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
510  newTarget->name = (*i)->name;
511  newTarget->attribute = (*i)->attribute;
512  newTarget->copyMetadata(**i);
513  newTarget->copyFrom(*i);
514  output.push_back(newTarget);
515  }
516  }
517 
518  return output;
519  }
520 
523  template <template <typename T> class Field_T, class Data_T>
524  typename Field_T<Data_T>::Vec
525  readScalarLayersAs(const std::string &partitionName,
526  const std::string &layerName) const
527  {
528  typedef typename Field<Data_T>::Vec FieldList;
529  typedef typename Field_T<Data_T>::Vec TypedFieldList;
530 
531  // First, read the layers as-is
532  FieldList originals;
533  originals = readScalarLayers<Data_T>(partitionName, layerName);
534 
535  // Loop over fields, converting if needed
536  TypedFieldList output;
537  typename FieldList::iterator i = originals.begin();
538  for (; i != originals.end(); ++i) {
539  typename Field_T<Data_T>::Ptr targetField;
540  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
541  if (targetField) {
542  output.push_back(targetField);
543  } else {
544  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
545  newTarget->name = (*i)->name;
546  newTarget->attribute = (*i)->attribute;
547  newTarget->copyMetadata(**i);
548  newTarget->copyFrom(*i);
549  output.push_back(newTarget);
550  }
551  }
552 
553  return output;
554  }
555 
558  template <template <typename T> class Field_T, class Data_T>
559  typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec
560  readVectorLayersAs(const std::string &layerName = std::string("")) const
561  {
562  typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
563  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
564  typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
565 
566  // First, read the layers as-is
567  FieldList originals;
568  originals = readVectorLayers<Data_T>(layerName);
569 
570  // Loop over fields, converting if needed
571  TypedFieldList output;
572  typename FieldList::iterator i = originals.begin();
573  for (; i != originals.end(); ++i) {
574  typename TypedVField::Ptr targetField;
575  targetField = field_dynamic_cast<TypedVField>(*i);
576  if (targetField) {
577  output.push_back(targetField);
578  } else {
579  typename TypedVField::Ptr newTarget(new TypedVField);
580  newTarget->name = (*i)->name;
581  newTarget->attribute = (*i)->attribute;
582  newTarget->copyMetadata(**i);
583  newTarget->copyFrom(*i);
584  output.push_back(newTarget);
585  }
586  }
587 
588  return output;
589  }
590 
593  template <template <typename T> class Field_T, class Data_T>
594  typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec
595  readVectorLayersAs(const std::string &partitionName,
596  const std::string &layerName) const
597  {
598  typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
599  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
600  typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
601 
602  // First, read the layers as-is
603  FieldList originals;
604  originals = readVectorLayers<Data_T>(partitionName, layerName);
605 
606  // Loop over fields, converting if needed
607  TypedFieldList output;
608  typename FieldList::iterator i = originals.begin();
609  for (; i != originals.end(); ++i) {
610  typename TypedVField::Ptr targetField;
611  targetField = field_dynamic_cast<TypedVField>(*i);
612  if (targetField) {
613  output.push_back(targetField);
614  } else {
615  typename TypedVField::Ptr newTarget(new TypedVField);
616  newTarget->name = (*i)->name;
617  newTarget->attribute = (*i)->attribute;
618  newTarget->copyMetadata(**i);
619  newTarget->copyFrom(*i);
620  output.push_back(newTarget);
621  }
622  }
623 
624  return output;
625  }
626 
628 
631 
637  template <class Data_T>
638  typename EmptyField<Data_T>::Vec
639  readProxyLayer(const std::string &partitionName,
640  const std::string &layerName,
641  bool isVectorLayer) const;
642 
647  template <class Data_T>
648  typename EmptyField<Data_T>::Ptr
649  readProxyLayer(hid_t location, const std::string &name,
650  const std::string &attribute,
651  FieldMapping::Ptr mapping) const;
652 
658  template <class Data_T>
659  typename EmptyField<Data_T>::Vec
660  readProxyScalarLayers(const std::string &name = std::string("")) const;
661 
667  template <class Data_T>
668  typename EmptyField<Data_T>::Vec
669  readProxyVectorLayers(const std::string &name = std::string("")) const;
670 
672 
673  // File IO ---
674 
677  bool open(const std::string &filename);
678 
679  // Callback convenience methods ----------------------------------------------
680 
683 
685  herr_t parsePartition(hid_t loc_id, const std::string partitionName);
686 
688  herr_t parseLayer(hid_t loc_id, const std::string &partitionName,
689  const std::string &layerName);
690 
692 
693  // Convenience methods -------------------------------------------------------
694 
696  bool readGroupMembership(GroupMembershipMap &gpMembershipMap);
697 
698 private:
699 
700  // Convenience methods -------------------------------------------------------
701 
704  template <class Data_T>
705  typename Field<Data_T>::Ptr
706  readScalarLayer(const std::string &intPartitionName,
707  const std::string &layerName) const;
708 
711  template <class Data_T>
712  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr
713  readVectorLayer(const std::string &intPartitionName,
714  const std::string &layerName) const;
715 
718  template <class Data_T>
719  typename Field<Data_T>::Ptr
720  readLayer(const std::string &intPartitionName,
721  const std::string &layerName,
722  bool isVectorLayer) const;
723 
725  bool readPartitionAndLayerInfo();
726 
728  bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const;
729 
731  bool readMetadata(hid_t metadata_id);
732 
733  // Data members --------------------------------------------------------------
734 
736  std::string m_filename;
737 
738 };
739 
740 //----------------------------------------------------------------------------//
741 // Utility functions
742 //----------------------------------------------------------------------------//
743 
744 
745 //----------------------------------------------------------------------------//
746 // Field3DOutputFileHDF5
747 //----------------------------------------------------------------------------//
748 
762 //----------------------------------------------------------------------------//
763 
765 {
766 public:
767 
768  friend class Field3DInputFile;
769  friend class Field3DOutputFile;
770 
771  // Enums ---------------------------------------------------------------------
772 
773  enum CreateMode {
776  };
777 
778  // Ctors, dtor ---------------------------------------------------------------
779 
782 
784  virtual ~Field3DOutputFileHDF5();
785 
787 
788  // Main interface ------------------------------------------------------------
789 
792 
794  template <class Data_T>
795  bool writeScalarLayer(const std::string &layerName,
796  typename Field<Data_T>::Ptr layer)
797  { return writeScalarLayer<Data_T>(layerName, std::string("default"), layer); }
798 
800  template <class Data_T>
801  bool writeVectorLayer(const std::string &layerName,
802  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
803  { return writeVectorLayer<Data_T>(layerName, std::string("default"), layer); }
804 
807  template <class Data_T>
808  bool writeScalarLayer(const std::string &partitionName,
809  const std::string &layerName,
810  typename Field<Data_T>::Ptr layer);
811 
814  template <class Data_T>
815  bool writeScalarLayer(typename Field<Data_T>::Ptr layer);
816 
819  template <class Data_T>
820  bool writeVectorLayer(const std::string &partitionName,
821  const std::string &layerName,
822  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer);
823 
826  template <class Data_T>
827  bool writeVectorLayer(typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer);
828 
830 
832  bool create(const std::string &filename, CreateMode cm = OverwriteMode);
833 
835  bool writeGlobalMetadata();
836 
839  bool writeGroupMembership();
840 
842  std::string incrementPartitionName(std::string &pname);
843 
845  template <class Data_T>
847  createNewPartition(const std::string &partitionName,
848  const std::string &layerName,
849  typename Field<Data_T>::Ptr field);
850  private:
851 
852  // Convenience methods -------------------------------------------------------
853 
857  bool writeMapping(hid_t partitionLocation, FieldMapping::Ptr mapping);
858 
860  template <class Data_T>
861  bool writeLayer(const std::string &partitionName,
862  const std::string &layerName,
863  bool isVectorLayer,
864  typename Field<Data_T>::Ptr layer);
865 
867  bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer);
868 
870  bool writeMetadata(hid_t metadataGroup);
871 
872 };
873 
874 //----------------------------------------------------------------------------//
875 // Field3DInputFileHDF5-related callback functions
876 //----------------------------------------------------------------------------//
877 
879 namespace InputFileHDF5 {
880 
885 {
887  std::string partitionName;
888 };
889 
893 FIELD3D_API herr_t parsePartitions(hid_t loc_id, const char *partitionName,
894  const H5L_info_t *linfo, void *opdata);
895 
899 FIELD3D_API herr_t parseLayers(hid_t loc_id, const char *partitionName,
900  const H5L_info_t *linfo, void *opdata);
901 
902 } // namespace InputFileHDF5
903 
904 //----------------------------------------------------------------------------//
905 // Field3DInputFileHDF5
906 //----------------------------------------------------------------------------//
907 
908 template <class Data_T>
909 typename Field<Data_T>::Vec
910 Field3DInputFileHDF5::readScalarLayers(const std::string &name) const
911 {
912  using namespace std;
913 
914  typedef typename Field<Data_T>::Ptr FieldPtr;
915  typedef typename Field<Data_T>::Vec FieldList;
916 
917  FieldList ret;
918  std::vector<std::string> parts;
919  getIntPartitionNames(parts);
920 
921  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
922  std::vector<std::string> layers;
923  getIntScalarLayerNames(layers, *p);
924  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
925  // Only read if it matches the name
926  if ((name.length() == 0) || (*l == name)) {
927  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
928  if (mf) {
929  ret.push_back(mf);
930  }
931  }
932  }
933  }
934 
935  return ret;
936 }
937 
938 //----------------------------------------------------------------------------//
939 
940 template <class Data_T>
941 typename Field<Data_T>::Vec
942 Field3DInputFileHDF5::readScalarLayers(const std::string &partitionName,
943  const std::string &layerName) const
944 {
945  using namespace std;
946 
947  typedef typename Field<Data_T>::Ptr FieldPtr;
948  typedef typename Field<Data_T>::Vec FieldList;
949 
950  FieldList ret;
951 
952  if ((layerName.length() == 0) || (partitionName.length() == 0))
953  return ret;
954 
955  std::vector<std::string> parts;
956  getIntPartitionNames(parts);
957 
958  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
959  std::vector<std::string> layers;
960  getIntScalarLayerNames(layers, *p);
961  if (removeUniqueId(*p) == partitionName) {
962  for (vector<string>::iterator l = layers.begin();
963  l != layers.end(); ++l) {
964  // Only read if it matches the name
965  if (*l == layerName) {
966  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
967  if (mf)
968  ret.push_back(mf);
969  }
970  }
971  }
972  }
973 
974  return ret;
975 }
976 
977 //----------------------------------------------------------------------------//
978 
979 template <class Data_T>
980 typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
981 Field3DInputFileHDF5::readVectorLayers(const std::string &name) const
982 {
983  using namespace std;
984 
985  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
986  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
987 
988  FieldList ret;
989 
990  std::vector<std::string> parts;
991  getIntPartitionNames(parts);
992 
993  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
994  std::vector<std::string> layers;
995  getIntVectorLayerNames(layers, *p);
996  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
997  // Only read if it matches the name
998  if ((name.length() == 0) || (*l == name)) {
999  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
1000  if (mf)
1001  ret.push_back(mf);
1002  }
1003  }
1004  }
1005 
1006  return ret;
1007 }
1008 
1009 //----------------------------------------------------------------------------//
1010 
1011 template <class Data_T>
1012 typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
1013 Field3DInputFileHDF5::readVectorLayers(const std::string &partitionName,
1014  const std::string &layerName) const
1015 {
1016  using namespace std;
1017 
1018  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
1019  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
1020 
1021  FieldList ret;
1022 
1023  if ((layerName.length() == 0) || (partitionName.length() == 0))
1024  return ret;
1025 
1026  std::vector<std::string> parts;
1027  getIntPartitionNames(parts);
1028 
1029  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1030  std::vector<std::string> layers;
1031  getIntVectorLayerNames(layers, *p);
1032  if (removeUniqueId(*p) == partitionName) {
1033  for (vector<string>::iterator l = layers.begin();
1034  l != layers.end(); ++l) {
1035  // Only read if it matches the name
1036  if (*l == layerName) {
1037  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
1038  if (mf)
1039  ret.push_back(mf);
1040  }
1041  }
1042  }
1043  }
1044 
1045  return ret;
1046 }
1047 
1048 //----------------------------------------------------------------------------//
1049 
1050 template <class Data_T>
1051 typename Field<Data_T>::Ptr
1053  const std::string &layerName,
1054  bool isVectorLayer) const
1055 {
1056  using namespace boost;
1057  using namespace std;
1058  using namespace Hdf5Util;
1059 
1060  typedef typename Field<Data_T>::Ptr FieldPtr;
1061 
1062  // Instantiate a null pointer for easier code reading
1063  FieldPtr nullPtr;
1064 
1065  GlobalLock lock(g_hdf5Mutex);
1066 
1067  // Find the partition
1069  if (!part) {
1070  Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
1071  return nullPtr;
1072  }
1073 
1074  // Find the layer in the partition
1075  const FileHDF5::Layer *l;
1076  if (isVectorLayer)
1077  l = part->vectorLayer(layerName);
1078  else
1079  l = part->scalarLayer(layerName);
1080  if (!l) {
1081  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName );
1082  return nullPtr;
1083  }
1084 
1085  // Open the layer group
1086  string layerPath = l->parent + "/" + l->name;
1087  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
1088 
1089  if (layerGroup.id() < 0) {
1090  Msg::print(Msg::SevWarning, "Couldn't find layer group " + layerName
1091  + " in .f3d file ");
1092  return nullPtr;
1093  }
1094 
1095  // Get the class name
1096  string className;
1097  if (!readAttribute(layerGroup.id(), "class_name", className)) {
1098  Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
1099  layerName);
1100  return nullPtr;
1101  }
1102 
1103  // Check the cache
1104 
1106  FieldPtr cachedField = cache.getCachedField(m_filename, layerPath);
1107 
1108  if (cachedField) {
1109  return cachedField;
1110  }
1111 
1112  // Construct the field and load the data
1113 
1114  // Unlock the g_hdf5Mutex while calling readField() so that other threads
1115  // have a chance to pre-empt loading in between (prevents deadlocks with
1116  // sparse reader)
1117  lock.unlock();
1118 
1119  typename Field<Data_T>::Ptr field;
1120  field = readField<Data_T>(className, layerGroup.id(), m_filename, layerPath);
1121 
1122  if (!field) {
1123 #if 0 // This isn't really an error
1124  Msg::print(Msg::SevWarning, "Couldn't read the layer data of layer: "
1125  + layerName);
1126 #endif
1127  return nullPtr;
1128  }
1129 
1130  // Now we need to use Hdf5 again, so re-aquire the lock.
1131  lock.lock();
1132 
1133  // read the metadata
1134  string metadataPath = layerPath + "/metadata";
1135  H5ScopedGopen metadataGroup(m_file, metadataPath.c_str());
1136  if (metadataGroup.id() > 0) {
1137  readMetadata(metadataGroup.id(), field);
1138  }
1139 
1140  // Set the name of the field so it's possible to re-create the file
1142  field->attribute = layerName;
1143  field->setMapping(part->mapping);
1144 
1145  // Cache the field for future use
1146  if (field) {
1147  cache.cacheField(field, m_filename, layerPath);
1148  }
1149 
1150  return field;
1151 }
1152 
1153 //----------------------------------------------------------------------------//
1154 
1155 template <class Data_T>
1156 typename EmptyField<Data_T>::Vec
1157 Field3DInputFileHDF5::readProxyLayer(const std::string &partitionName,
1158  const std::string &layerName,
1159  bool isVectorLayer) const
1160 {
1161  using namespace boost;
1162  using namespace std;
1163  using namespace Hdf5Util;
1164 
1165  GlobalLock lock(g_hdf5Mutex);
1166 
1167  // Instantiate a null pointer for easier code reading
1168  typename EmptyField<Data_T>::Vec emptyList, output;
1169 
1170  if ((layerName.length() == 0) || (partitionName.length() == 0))
1171  return emptyList;
1172 
1173  std::vector<std::string> parts, layers;
1174  getIntPartitionNames(parts);
1175 
1176  bool foundPartition = false;
1177 
1178  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1179  if (removeUniqueId(*p) == partitionName) {
1180  foundPartition = true;
1181  if (isVectorLayer) {
1182  getIntVectorLayerNames(layers, *p);
1183  } else {
1184  getIntScalarLayerNames(layers, *p);
1185  }
1186  for (vector<string>::iterator l = layers.begin();
1187  l != layers.end(); ++l) {
1188  if (*l == layerName) {
1189  // Find the partition
1191  if (!part) {
1192  Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
1193  return emptyList;
1194  }
1195  // Find the layer
1196  const FileHDF5::Layer *layer;
1197  if (isVectorLayer)
1198  layer = part->vectorLayer(layerName);
1199  else
1200  layer = part->scalarLayer(layerName);
1201  if (!layer) {
1202  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1203  return emptyList;
1204  }
1205  // Open the layer group
1206  string layerPath = layer->parent + "/" + layer->name;
1207  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
1208  if (layerGroup.id() < 0) {
1209  Msg::print(Msg::SevWarning, "Couldn't find layer group "
1210  + layerName + " in .f3d file ");
1211  return emptyList;
1212  }
1213 
1214  // Make the proxy representation
1215  typename EmptyField<Data_T>::Ptr field =
1216  readProxyLayer<Data_T>(layerGroup, partitionName, layerName,
1217  part->mapping);
1218 
1219  // Read MIPField's number of mip levels
1220  int numLevels = 0;
1221  H5ScopedGopen mipGroup(layerGroup, "mip_levels");
1222  if (mipGroup.id() >= 0)
1223  readAttribute(mipGroup, "levels", 1, numLevels);
1224  field->metadata().setIntMetadata("mip_levels", numLevels);
1225 
1226  // Add field to output
1227  output.push_back(field);
1228  }
1229  }
1230  }
1231  }
1232 
1233  if (!foundPartition) {
1234  Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
1235  return emptyList;
1236  }
1237 
1238  return output;
1239 }
1240 
1241 //----------------------------------------------------------------------------//
1242 
1243 template <class Data_T>
1244 typename EmptyField<Data_T>::Ptr
1246  const std::string &name,
1247  const std::string &attribute,
1248  FieldMapping::Ptr mapping) const
1249 {
1250  using namespace boost;
1251  using namespace std;
1252  using namespace Hdf5Util;
1253 
1254  typename EmptyField<Data_T>::Ptr null;
1255 
1256  GlobalLock lock(g_hdf5Mutex);
1257 
1258  // Read the extents and data window
1259  Box3i extents, dataW;
1260  if (!readAttribute(location, "extents", 6, extents.min.x)) {
1261  return null;
1262  }
1263  if (!readAttribute(location, "data_window", 6, dataW.min.x)) {
1264  return null;
1265  }
1266 
1267  // Construct the field and load the data
1268  typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
1269  field->setSize(extents, dataW);
1270 
1271  // Read the metadata
1272  H5ScopedGopen metadataGroup(location, "metadata");
1273  if (metadataGroup.id() > 0) {
1274  readMetadata(metadataGroup.id(), field);
1275  }
1276 
1277  // Set field properties
1278  field->name = name;
1279  field->attribute = attribute;
1280  field->setMapping(mapping);
1281 
1282  return field;
1283 }
1284 
1285 //----------------------------------------------------------------------------//
1286 
1287 template <class Data_T>
1288 typename EmptyField<Data_T>::Vec
1289 Field3DInputFileHDF5::readProxyScalarLayers(const std::string &name) const
1290 {
1291  using namespace std;
1292 
1293  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1294  typedef std::vector<FieldPtr> FieldList;
1295 
1296  FieldList ret;
1297 
1298  std::vector<std::string> parts;
1299  getPartitionNames(parts);
1300 
1301  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1302  std::vector<std::string> layers;
1303  getScalarLayerNames(layers, *p);
1304  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1305  // Only read if it matches the name
1306  if ((name.length() == 0) || (*l == name)) {
1307  FieldList f = readProxyLayer<Data_T>(*p, *l, false);
1308  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1309  if (*i) {
1310  ret.push_back(*i);
1311  }
1312  }
1313  }
1314  }
1315  }
1316 
1317  return ret;
1318 }
1319 
1320 //----------------------------------------------------------------------------//
1321 
1322 template <class Data_T>
1323 typename EmptyField<Data_T>::Vec
1324 Field3DInputFileHDF5::readProxyVectorLayers(const std::string &name) const
1325 {
1326  using namespace std;
1327 
1328  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1329  typedef std::vector<FieldPtr> FieldList;
1330 
1331  FieldList ret;
1332 
1333  std::vector<std::string> parts;
1334  getPartitionNames(parts);
1335 
1336  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1337  std::vector<std::string> layers;
1338  getVectorLayerNames(layers, *p);
1339  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1340  // Only read if it matches the name
1341  if ((name.length() == 0) || (*l == name)) {
1342  FieldList f = readProxyLayer<Data_T>(*p, *l, true);
1343  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1344  if (*i) {
1345  ret.push_back(*i);
1346  }
1347  }
1348  }
1349  }
1350  }
1351 
1352  return ret;
1353 }
1354 
1355 //----------------------------------------------------------------------------//
1356 
1357 template <class Data_T>
1358 typename Field<Data_T>::Ptr
1360  const std::string &layerName) const
1361 {
1362  return readLayer<Data_T>(intPartitionName, layerName, false);
1363 }
1364 
1365 //----------------------------------------------------------------------------//
1366 
1367 template <class Data_T>
1368 typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr
1370  const std::string &layerName) const
1371 {
1372  return readLayer<FIELD3D_VEC3_T<Data_T> >(intPartitionName, layerName, true);
1373 }
1374 
1375 //----------------------------------------------------------------------------//
1376 // Field3DOutputFileHDF5
1377 //----------------------------------------------------------------------------//
1378 
1379 template <class Data_T>
1381 Field3DOutputFileHDF5::createNewPartition(const std::string &partitionName,
1382  const std::string & /* layerName */,
1383  typename Field<Data_T>::Ptr field)
1384 {
1385  using namespace Hdf5Util;
1386  using namespace Exc;
1387 
1388  GlobalLock lock(g_hdf5Mutex);
1389 
1391 
1392  newPart->name = partitionName;
1393 
1394  H5ScopedGcreate partGroup(m_file, newPart->name.c_str());
1395  if (partGroup.id() < 0) {
1397  "Error creating partition: " + newPart->name);
1398  return FileHDF5::Partition::Ptr();
1399  }
1400 
1401  m_partitions.push_back(newPart);
1402 
1403  // Pick up new pointer
1404  FileHDF5::Partition::Ptr part = partition(partitionName);
1405 
1406  // Add mapping group to the partition
1409  try {
1410  if (!writeMapping(partGroup.id(), field->mapping())) {
1412  "writeMapping returned false for an unknown reason ");
1413  return FileHDF5::Partition::Ptr();
1414  }
1415  }
1416  catch (WriteMappingException &e) {
1417  Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
1418  + partitionName);
1419  return FileHDF5::Partition::Ptr();
1420  }
1421  catch (...) {
1423  "Unknown error when writing mapping for partition: "
1424  + partitionName);
1425  return FileHDF5::Partition::Ptr();
1426  }
1427 
1428  // Set the mapping of the partition. Since all layers share their
1429  // partition's mapping, we can just pick this first one. All subsequent
1430  // additions to the same partition are checked to have the same mapping
1431  part->mapping = field->mapping();
1432 
1433  // Tag node as partition
1434  // Create a version attribute on the root node
1435  if (!writeAttribute(partGroup.id(), "is_field3d_partition", "1")) {
1436  Msg::print(Msg::SevWarning, "Adding partition string.");
1437  return FileHDF5::Partition::Ptr();
1438  }
1439 
1440  return part;
1441 }
1442 
1443 //----------------------------------------------------------------------------//
1444 
1445 template <class Data_T>
1446 bool
1447 Field3DOutputFileHDF5::writeLayer(const std::string &userPartitionName,
1448  const std::string &layerName,
1449  bool isVectorLayer,
1450  typename Field<Data_T>::Ptr field)
1451 {
1452  using namespace std;
1453  using namespace Exc;
1454  using namespace Hdf5Util;
1455 
1456  GlobalLock lock(g_hdf5Mutex);
1457 
1458  if (!field) {
1460  "Called writeLayer with null pointer. Ignoring...");
1461  return false;
1462  }
1463 
1464  if (m_file < 0) {
1466  "Attempting to write layer without opening file first. ");
1467  return false;
1468  }
1469 
1470  string partitionName = intPartitionName(userPartitionName, layerName, field);
1471 
1472  // See if the partition already exists or if we need to make it ---
1473 
1474  FileHDF5::Partition::Ptr part = partition(partitionName);
1475 
1476  if (!part) {
1477  part = createNewPartition<Data_T>(partitionName,layerName,field);
1478  if (!part)
1479  return false;
1480  } else {
1481 
1482  if (!field->mapping()) {
1484  "Couldn't add layer \"" + layerName + "\" to partition \""
1485  + partitionName + "\" because the layer's mapping is null.");
1486  return false;
1487  }
1488 
1489  // If the partition already existed, we need to make sure that the layer
1490  // doesn't also exist
1491  if (!isVectorLayer) {
1492  if (part->scalarLayer(layerName)) {
1493  //need to create a new partition and then add the layer to that
1494  std::string newPartitionName = incrementPartitionName(partitionName);
1495  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1496  if (!part)
1497  return false;
1498  }
1499  } else {
1500  if (part->vectorLayer(layerName)) {
1501  //need to create a new partition and then add the layer to that
1502  std::string newPartitionName = incrementPartitionName(partitionName);
1503  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1504  if (!part)
1505  return false;
1506  }
1507  }
1508  }
1509 
1510  if (!part->mapping) {
1511  Msg::print(Msg::SevWarning, "Severe error - partition mapping is null: "
1512  + partitionName);
1513  return false;
1514  }
1515 
1516  // Check that the mapping matches what's already in the Partition
1517  if (!field->mapping()->isIdentical(part->mapping)) {
1518  Msg::print(Msg::SevWarning, "Couldn't add layer \"" + layerName
1519  + "\" to partition \"" + partitionName
1520  + "\" because mapping doesn't match");
1521  return false;
1522  }
1523 
1524  // Open the partition
1525  H5ScopedGopen partGroup(m_file, part->name.c_str(), H5P_DEFAULT);
1526 
1527  // Build a Layer object ---
1528 
1529  FileHDF5::Layer layer;
1530  layer.name = layerName;
1531  layer.parent = partitionName;
1532 
1533  // Add Layer to file ---
1534 
1535  H5ScopedGcreate layerGroup(partGroup.id(), layerName.c_str(),
1536  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1537 
1538  if (layerGroup.id() < 0) {
1539  Msg::print(Msg::SevWarning, "Error creating layer: " + layerName);
1540  return false;
1541  }
1542 
1543  // Tag as layer
1544  if (!writeAttribute(layerGroup.id(), "class_type", "field3d_layer")) {
1545  Msg::print(Msg::SevWarning, "Error adding layer string.");
1546  return false;
1547  }
1548 
1549  // Add metadata group and write it out
1550  H5ScopedGcreate metadataGroup(layerGroup.id(), "metadata");
1551  if (metadataGroup.id() < 0) {
1552  Msg::print(Msg::SevWarning, "Error creating group: metadata");
1553  return false;
1554  }
1555  if (!writeMetadata(metadataGroup.id(), field)) {
1556  Msg::print(Msg::SevWarning, "Error writing metadata.");
1557  return false;
1558  }
1559 
1560  if (!writeField(layerGroup.id(), field)) {
1561  Msg::print(Msg::SevWarning, "Error writing layer: " + layer.name);
1562  return false;
1563  }
1564 
1565  // Add layer to partition ---
1566 
1567  if (isVectorLayer)
1568  part->addVectorLayer(layer);
1569  else
1570  part->addScalarLayer(layer);
1571 
1572  return true;
1573 }
1574 
1575 //----------------------------------------------------------------------------//
1576 
1577 template <class Data_T>
1578 bool
1579 Field3DOutputFileHDF5::writeScalarLayer(const std::string &partitionName,
1580  const std::string &layerName,
1581  typename Field<Data_T>::Ptr field)
1582 {
1583  return writeLayer<Data_T>(partitionName, layerName, false, field);
1584 }
1585 
1586 //----------------------------------------------------------------------------//
1587 
1588 template <class Data_T>
1589 bool
1591 {
1592  if (layer->name.size() == 0) {
1593  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
1594  "Tried to write a scalar layer with no name");
1595  return false;
1596  }
1597  if (layer->attribute.size() == 0) {
1598  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeScalarLayer: "
1599  "Tried to write a scalar layer with no attribute name");
1600  return false;
1601  }
1602  return writeScalarLayer<Data_T>(layer->name, layer->attribute, layer);
1603 }
1604 
1605 //----------------------------------------------------------------------------//
1606 
1607 template <class Data_T>
1608 bool
1610 writeVectorLayer(const std::string &partitionName,
1611  const std::string &layerName,
1612  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr field)
1613 {
1614  return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName,
1615  true, field);
1616 }
1617 
1618 //----------------------------------------------------------------------------//
1619 
1620 template <class Data_T>
1621 bool
1623  (typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
1624 {
1625  if (layer->name.size() == 0) {
1626  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
1627  "Tried to write a vector layer with no name");
1628  return false;
1629  }
1630  if (layer->attribute.size() == 0) {
1631  Msg::print(Msg::SevWarning, "Field3DOutputFileHDF5::writeVectorLayer: "
1632  "Tried to write a vector layer with no attribute name");
1633  return false;
1634  }
1635  return writeVectorLayer<Data_T>(layer->name, layer->attribute, layer);
1636 }
1637 
1638 //----------------------------------------------------------------------------//
1639 // Template Function Implementations
1640 //----------------------------------------------------------------------------//
1641 
1642 template <class Data_T>
1643 typename Field<Data_T>::Ptr
1644 readField(const std::string &className, hid_t layerGroup,
1645  const std::string &filename, const std::string &layerPath)
1646 {
1647 
1649 
1650  typedef typename Field<Data_T>::Ptr FieldPtr;
1651 
1652  FieldIO::Ptr io = factory.createFieldIO(className);
1653  if (!io) {
1654  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1655  className);
1656  return FieldPtr();
1657  }
1658 
1660  FieldBase::Ptr field = io->read(layerGroup, filename, layerPath, typeEnum);
1661 
1662  if (!field) {
1663  // We don't need to print a message, because it could just be that
1664  // a layer of the specified data type and name couldn't be found
1665  return FieldPtr();
1666  }
1667 
1668  FieldPtr result = field_dynamic_cast<Field<Data_T> >(field);
1669 
1670  if (result)
1671  return result;
1672 
1673  return FieldPtr();
1674 }
1675 
1676 //----------------------------------------------------------------------------//
1677 
1679 
1680 //----------------------------------------------------------------------------//
1681 
1682 #endif
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
Field_T::Ptr field_dynamic_cast(RefBase::Ptr field)
Dynamic cast that uses string-comparison in order to be safe even after an object crosses a shared li...
Definition: RefCount.h:256
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
std::vector< Layer > ScalarLayerList
Field_T< Data_T >::Vec readScalarLayersAs(const std::string &layerName=std::string("")) const
Retrieves all layers for all partitions. Converts it to the given template type if needed.
bool writeGroupMembership()
This routine is called just before closing to write out any group membership to disk.
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
FIELD3D_API bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
This function creates a FieldMappingIO instance based on mapping->className() which then writes Field...
bool writeGlobalMetadata()
This routine is call if you want to write out global metadata to disk.
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Create newPartition given the input config.
FIELD3D_API herr_t parsePartitions(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file....
FIELD3D_API bool writeField(hid_t layerGroup, FieldBase::Ptr field)
This function creates a FieldIO instance based on field->className() which then writes the field data...
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Namespace for Exception objects.
Definition: Exception.h:57
Field< Data_T >::Vec readScalarLayers(const std::string &layerName=std::string("")) const
Retrieves all the layers of scalar type and maintains their on-disk data types.
FIELD3D_API herr_t parseLayers(hid_t loc_id, const char *partitionName, const H5L_info_t *linfo, void *opdata)
Gets called from readPartitionAndLayerInfo to check each group found under the root of the file....
std::map< std::string, std::string > GroupMembershipMap
Definition: Field3DFile.h:228
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
std::map< std::string, int > PartitionCountMap
FileHDF5::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
create newPartition given the input config
std::vector< LayerInfo > m_layerInfo
This stores layer info.
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
Provides writing of .f3d (internally, hdf5 or Ogawa) files.
Definition: Field3DFile.h:636
Definition: Field.h:389
RefBase base
Convenience typedef for referring to base class.
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
boost::intrusive_ptr< FieldBase > Ptr
Definition: Field.h:97
boost::intrusive_ptr< Partition > Ptr
ScalarLayerList m_scalarLayers
The scalar-valued layers belonging to this partition.
Contains the FieldCache class.
static ClassFactory & singleton()
}
Field< Data_T >::Ptr readLayer(const std::string &intPartitionName, const std::string &layerName, bool isVectorLayer) const
This call does the actual reading of a layer. Notice that it expects a unique -internal- partition na...
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
Contains the EmptyField class.
void getIntScalarLayerNames(std::vector< std::string > &names, const std::string &intPartitionName) const
Gets the names of all the scalar layers in a given partition, but assumes that partition name is the ...
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition: Log.cpp:70
void getIntVectorLayerNames(std::vector< std::string > &names, const std::string &intPartitionName) const
Gets the names of all the vector layers in a given partition, but assumes that partition name is the ...
bool writeMapping(OgOGroup &partitionGroup, FieldMapping::Ptr mapping)
Writes the mapping to the given Og node. Mappings are assumed to be light-weight enough to be stored ...
bool writeLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer, typename Field< Data_T >::Ptr layer)
Performs the actual writing of the layer to disk.
boost::intrusive_ptr< FieldRes > Ptr
Definition: Field.h:213
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
Definition: FieldCache.h:148
Field< Data_T >::Ptr readField(const std::string &className, hid_t layerGroup, const std::string &filename, const std::string &layerPath)
This function creates a FieldIO instance based on className which then reads the field data from laye...
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:715
bool create(const std::string &filename, CreateMode cm=OverwriteMode)
Creates a .f3d file on disk.
static DataTypeEnum typeEnum()
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
std::string intPartitionName(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Returns a unique partition name given the requested name. This ensures that partitions with matching ...
FieldMetadata & metadata()
accessor to the m_metadata class
Field_T< FIELD3D_VEC3_T< Data_T > >::Vec readVectorLayersAs(const std::string &layerName=std::string("")) const
Retrieves a layers for all partitions. Converts it to the given template type if needed.
Contains various utility functions for Hdf5.
Scoped object - creates a group on creation and closes it on destruction.
Definition: Hdf5Util.h:165
static const char * staticClassType()
FieldMetadata m_metadata
metadata
std::vector< std::string > m_partitionNames
This stores partition names.
EmptyField< Data_T >::Vec readProxyLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer) const
Retrieves a proxy version (EmptyField) of each layer .
struct used to pass the class and partition info back to the parseLayers() callback
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a vector layer to the "Default" partition.
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
std::string name
Name of the partition.
Namespace for file input specifics.
std::string parent
The name of the parent partition. We need this in order to open its group.
std::vector< Ptr > Vec
Definition: EmptyField.h:94
FileHDF5::Partition::Ptr getPartition(const std::string &partitionName) const
Returns a pointer to the given partition.
Field< FIELD3D_VEC3_T< Data_T > >::Ptr readVectorLayer(const std::string &intPartitionName, const std::string &layerName) const
Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
PartitionList m_partitions
Vector of partitions.
void setSize(const V3i &size)
Resizes the object.
Definition: Field.h:913
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
Definition: FieldCache.h:169
void getScalarLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the scalar layers in a given partition.
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
VectorLayerList m_vectorLayers
The vector-valued layers belonging to this partition.
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition: Field.h:347
const FieldMetadata & metadata() const
Read only access to the m_metadata class.
Provides reading of .f3d (internally, hdf5) files.Refer to using_files for examples of how to use thi...
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
std::string m_filename
Filename, only to be set by open().
virtual void metadataHasChanged(const std::string &)
This function should implemented by concrete classes to.
This subclass of Field does not store any data.
Definition: EmptyField.h:86
Provides writing of .f3d (internally, hdf5) files.
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:403
Provides reading of .f3d (internally, hdf5 or Ogawa) files.Refer to using_files for examples of how t...
Definition: Field3DFile.h:413
std::vector< FileHDF5::Partition::Ptr > PartitionList
#define FIELD3D_API
Definition: ns.h:77
Field_T< Data_T >::Vec readScalarLayersAs(const std::string &partitionName, const std::string &layerName) const
Retrieves a layers given their and its parent partition's name. Converts it to the given template typ...
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:93
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Namespace for file I/O specifics.
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field.h:155
bool writeLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:687
LayerInfo(std::string par, std::string nm, int cpt)
FieldMapping::Ptr mapping
Pointer to the mapping object.
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition: FieldCache.h:135
Field< Data_T >::Ptr readScalarLayer(const std::string &intPartitionName, const std::string &layerName) const
Retrieves a single layer given its and its parent partition's name. Maintains the on-disk data types.
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
std::string attribute
Optional name of the attribute the field represents.
Definition: Field.h:173
Contains Field, WritableField and ResizableField classes.
Contains the ClassFactory class for registering Field3D classes.
std::vector< Layer > VectorLayerList
Basic container for metedata.
Field< FIELD3D_VEC3_T< Data_T > >::Vec readVectorLayers(const std::string &layerName=std::string("")) const
Retrieves all the layers of vector type and maintains their on-disk data types.
boost::intrusive_ptr< const Partition > CPtr
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:91
hid_t id() const
Query the hid_t value.
Definition: Hdf5Util.h:100
DataTypeEnum
Definition: Traits.h:108
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:194
Field3DInputFileHDF5 * file
EmptyField< Data_T >::Vec readProxyScalarLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each scalar layer.
Field_T< FIELD3D_VEC3_T< Data_T > >::Vec readVectorLayersAs(const std::string &partitionName, const std::string &layerName) const
Retrieves a layers given their and its parent partition's name. Converts it to the given template typ...
std::string incrementPartitionName(std::string &pname)
Increment the partition or make it zero if there's not an integer suffix.
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
EmptyField< Data_T >::Vec readProxyVectorLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each vector layer.
std::map< std::string, std::string > GroupMembershipMap
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:395
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:263
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:750
std::string name
Optional name of the field.
Definition: Field.h:171
std::string name
The name of the layer (always available)