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
ResizableField::setSize
void setSize(const V3i &size)
Resizes the object.
Definition: Field.h:913
Field3DFileHDF5Base::m_groupMembership
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
Definition: Field3DFileHDF5.h:403
Field3DFileHDF5Base::m_metadata
FieldMetadata m_metadata
metadata
Definition: Field3DFileHDF5.h:406
FileHDF5::Partition::name
std::string name
Name of the partition.
Definition: Field3DFileHDF5.h:201
Field3DFileHDF5Base::m_partitionNames
std::vector< std::string > m_partitionNames
This stores partition names.
Definition: Field3DFileHDF5.h:394
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
Field3DInputFileHDF5::readScalarLayer
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.
Definition: Field3DFileHDF5.h:1359
ClassFactory::createFieldIO
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
Definition: ClassFactory.cpp:165
Hdf5Util::writeAttribute
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
FileHDF5::Partition::class_type
Partition class_type
Definition: Field3DFileHDF5.h:157
Field3DFileHDF5Base::m_partitionCount
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
Definition: Field3DFileHDF5.h:398
FileHDF5::Partition::mapping
FieldMapping::Ptr mapping
Pointer to the mapping object.
Definition: Field3DFileHDF5.h:203
Field3DInputFileHDF5::readVectorLayers
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.
Definition: Field3DFileHDF5.h:981
Field3DOutputFile
Provides writing of .f3d (internally, hdf5 or Ogawa) files.
Definition: Field3DFile.h:637
Field3DFileHDF5Base::GroupMembershipMap
std::map< std::string, std::string > GroupMembershipMap
Definition: Field3DFileHDF5.h:257
Field3DFileHDF5Base::getScalarLayerNames
void getScalarLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the scalar layers in a given partition.
Definition: Field3DFileHDF5.cpp:403
Field3DOutputFile::writeMapping
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 ...
Definition: Field3DFile.cpp:1013
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
FileHDF5::Partition::staticClassType
static const char * staticClassType()
Definition: Field3DFileHDF5.h:160
ClassFactory
Definition: ClassFactory.h:72
FieldBase::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field.h:155
Field3DOutputFile::create
bool create(const std::string &filename, CreateMode cm=OverwriteMode)
Creates a .f3d file on disk.
Definition: Field3DFile.cpp:977
EmptyField::Vec
std::vector< Ptr > Vec
Definition: EmptyField.h:94
Field::Ptr
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:395
Field3DOutputFileHDF5::CreateMode
CreateMode
Definition: Field3DFileHDF5.h:773
FieldMetadata.h
Basic container for metedata.
Field3DFileHDF5Base::LayerInfo::name
std::string name
Definition: Field3DFileHDF5.h:247
Field3DOutputFile::writeVectorLayer
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
InputFileHDF5::ParseLayersInfo::file
Field3DInputFileHDF5 * file
Definition: Field3DFileHDF5.h:886
Field3DInputFile
Provides reading of .f3d (internally, hdf5 or Ogawa) files.
Definition: Field3DFile.h:414
Hdf5Util::H5ScopedGcreate
Scoped object - creates a group on creation and closes it on destruction.
Definition: Hdf5Util.h:166
Hdf5Util::H5Base::id
hid_t id() const
Query the hid_t value.
Definition: Hdf5Util.h:100
FileHDF5::Layer::name
std::string name
The name of the layer (always available)
Definition: Field3DFileHDF5.h:124
Field3DFileHDF5Base::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName)
Returns a pointer to the given partition.
Field3DFileHDF5Base::LayerInfo::LayerInfo
LayerInfo(std::string par, std::string nm, int cpt)
Definition: Field3DFileHDF5.h:250
InputFileHDF5::parsePartitions
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....
Definition: Field3DFileHDF5.cpp:1130
InputFileHDF5::ParseLayersInfo
struct used to pass the class and partition info back to the parseLayers() callback
Definition: Field3DFileHDF5.h:885
Field3DFileHDF5Base::removeUniqueId
std::string removeUniqueId(const std::string &partitionName) const
Strips any unique identifiers from the partition name and returns the original name.
Definition: Field3DFileHDF5.cpp:373
Field3DInputFileHDF5::readVectorLayer
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.
Definition: Field3DFileHDF5.h:1369
DataTypeEnum
DataTypeEnum
Definition: Traits.h:108
Field3DInputFileHDF5::readScalarLayersAs
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...
Definition: Field3DFileHDF5.h:525
Field3DFileHDF5Base::m_file
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFileHDF5.h:390
FieldCache::singleton
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition: FieldCache.h:135
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
EmptyField::Ptr
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:93
Field3DFileHDF5Base
Definition: Field3DFileHDF5.h:237
MetadataCallback
Definition: FieldMetadata.h:71
FileHDF5::Layer
Definition: Field3DFileHDF5.h:121
Field3DOutputFileHDF5::writeLayer
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.
Definition: Field3DFileHDF5.h:1447
FieldBase::name
std::string name
Optional name of the field.
Definition: Field.h:171
InputFileHDF5::parseLayers
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....
Definition: Field3DFileHDF5.cpp:1170
Field3DOutputFile::writeScalarLayer
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:715
Field3DFileHDF5Base::getIntVectorLayerNames
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 ...
Definition: Field3DFileHDF5.cpp:470
FieldBase::Ptr
boost::intrusive_ptr< FieldBase > Ptr
Definition: Field.h:97
FieldRes::setMapping
void setMapping(FieldMapping::Ptr mapping)
Sets the field's mapping.
Definition: Field.h:347
Hdf5Util::H5ScopedGopen
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:195
FileHDF5::Layer::parent
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFileHDF5.h:127
FileHDF5::Partition::Partition
Partition()
Ctor.
Definition: Field3DFileHDF5.h:168
Field3DFileHDF5Base::partition
FileHDF5::Partition::Ptr partition(const std::string &partitionName) const
Returns a pointer to the given partition.
Field3DFileHDF5Base::getIntScalarLayerNames
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 ...
Definition: Field3DFileHDF5.cpp:452
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition: ClassFactory.cpp:278
FieldRes::mapping
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:263
Field3DFileHDF5Base::LayerInfo
Definition: Field3DFileHDF5.h:246
ns.h
Field3DInputFileHDF5::readScalarLayers
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.
Definition: Field3DFileHDF5.h:910
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition: Field.h:213
Field3DOutputFileHDF5::OverwriteMode
@ OverwriteMode
Definition: Field3DFileHDF5.h:774
FileHDF5::Partition::DEFINE_FIELD_RTTI_CONCRETE_CLASS
DEFINE_FIELD_RTTI_CONCRETE_CLASS
Definition: Field3DFileHDF5.h:158
Hdf5Util.h
Contains various utility functions for Hdf5.
FieldMetadata::setIntMetadata
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
Definition: FieldMetadata.cpp:91
Field3DFileHDF5Base::m_partitions
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFileHDF5.h:392
FieldBase::attribute
std::string attribute
Optional name of the attribute the field represents.
Definition: Field.h:173
Field3DFileHDF5Base::PartitionList
std::vector< FileHDF5::Partition::Ptr > PartitionList
Definition: Field3DFileHDF5.h:346
Field3DOutputFile::OverwriteMode
@ OverwriteMode
Definition: Field3DFile.h:643
Field3DOutputFile::FailOnExisting
@ FailOnExisting
Definition: Field3DFile.h:644
FileHDF5::Partition::m_scalarLayers
ScalarLayerList m_scalarLayers
The scalar-valued layers belonging to this partition.
Definition: Field3DFileHDF5.h:210
DataTypeTraits::typeEnum
static DataTypeEnum typeEnum()
Field::Vec
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:403
Field3DInputFileHDF5::readProxyScalarLayers
EmptyField< Data_T >::Vec readProxyScalarLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each scalar layer.
Definition: Field3DFileHDF5.h:1289
Field3DOutputFileHDF5::writeScalarLayer
bool writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFileHDF5.h:795
FieldMetadata
Definition: FieldMetadata.h:85
writeFieldMapping
FIELD3D_API bool writeFieldMapping(hid_t mappingGroup, FieldMapping::Ptr mapping)
This function creates a FieldMappingIO instance based on mapping->className() which then writes Field...
Definition: Field3DFileHDF5.cpp:1645
FileHDF5::Partition::VectorLayerList
std::vector< Layer > VectorLayerList
Definition: Field3DFileHDF5.h:150
Field3DInputFileHDF5::readMetadata
bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const
Read metadata for this layer.
Definition: Field3DFileHDF5.cpp:837
Field.h
Contains Field, WritableField and ResizableField classes.
FileHDF5::Partition::m_vectorLayers
VectorLayerList m_vectorLayers
The vector-valued layers belonging to this partition.
Definition: Field3DFileHDF5.h:212
Field3DOutputFile::writeMetadata
bool writeMetadata(OgOGroup &metadataGroup, FieldBase::Ptr layer)
Writes metadata for this layer.
Definition: Field3DFile.cpp:1045
Field3DInputFileHDF5::readVectorLayersAs
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.
Definition: Field3DFileHDF5.h:560
g_hdf5Mutex
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
Field3DFileHDF5Base::metadata
FieldMetadata & metadata()
accessor to the m_metadata class
Definition: Field3DFileHDF5.h:321
EmptyField
This subclass of Field does not store any data.
Definition: EmptyField.h:88
InputFileHDF5::ParseLayersInfo::partitionName
std::string partitionName
Definition: Field3DFileHDF5.h:887
Field3DInputFileHDF5::readVectorLayersAs
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...
Definition: Field3DFileHDF5.h:595
Field3DOutputFileHDF5
Provides writing of .f3d (internally, hdf5) files.
Definition: Field3DFileHDF5.h:765
Field3DFileHDF5Base::LayerInfo::components
int components
Definition: Field3DFileHDF5.h:249
Field3DFileHDF5Base::Field3DFileHDF5Base
Field3DFileHDF5Base(const Field3DFileHDF5Base &)
Exc
Namespace for Exception objects.
Definition: Exception.h:57
Field3DFileBase::GroupMembershipMap
std::map< std::string, std::string > GroupMembershipMap
Definition: Field3DFile.h:228
Field3DOutputFile::writeLayer
bool writeLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:687
GlobalLock
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
Field3DFileHDF5Base::PartitionCountMap
std::map< std::string, int > PartitionCountMap
Definition: Field3DFileHDF5.h:347
FieldCache.h
Contains the FieldCache class.
Hdf5Util::readAttribute
FIELD3D_API bool readAttribute(hid_t location, const std::string &attrName, std::string &value)
Reads a string attribute.
Field3DFileHDF5Base::intPartitionName
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 ...
Definition: Field3DFileHDF5.cpp:316
Hdf5Util
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
Field3DFileHDF5Base::getIntPartitionNames
void getIntPartitionNames(std::vector< std::string > &names) const
Gets the names of all the -internal- partitions in the file.
Definition: Field3DFileHDF5.cpp:439
Field3DInputFileHDF5::m_filename
std::string m_filename
Filename, only to be set by open().
Definition: Field3DFileHDF5.h:736
FieldCache::getCachedField
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
Definition: FieldCache.h:148
Field3DInputFileHDF5::readScalarLayersAs
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.
Definition: Field3DFileHDF5.h:491
FileHDF5::Partition::base
RefBase base
Convenience typedef for referring to base class.
Definition: Field3DFileHDF5.h:217
Field3DFileHDF5Base::LayerInfo::parentName
std::string parentName
Definition: Field3DFileHDF5.h:248
FileHDF5::Partition::ScalarLayerList
std::vector< Layer > ScalarLayerList
Definition: Field3DFileHDF5.h:149
EmptyField.h
Contains the EmptyField class.
Field3DFileHDF5Base::getPartitionNames
void getPartitionNames(std::vector< std::string > &names) const
Gets the names of all the partitions in the file.
Definition: Field3DFileHDF5.cpp:386
Field3DFileHDF5Base::metadata
const FieldMetadata & metadata() const
Read only access to the m_metadata class.
Definition: Field3DFileHDF5.h:325
InputFileHDF5
Namespace for file input specifics.
Definition: Field3DFileHDF5.h:879
Field3DOutputFile::CreateMode
CreateMode
Definition: Field3DFile.h:642
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:91
readField
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...
Definition: Field3DFileHDF5.h:1644
FIELD3D_API
#define FIELD3D_API
Definition: ns.h:77
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
Box3i
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
FileHDF5::Partition
Definition: Field3DFileHDF5.h:146
Field3DFileHDF5Base::metadataHasChanged
virtual void metadataHasChanged(const std::string &)
This function should implemented by concrete classes to get the callback when metadata changes.
Definition: Field3DFileHDF5.h:330
FileHDF5::Partition::CPtr
boost::intrusive_ptr< const Partition > CPtr
Definition: Field3DFileHDF5.h:153
Field3DFileBase::intPartitionName
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 ...
Definition: Field3DFile.cpp:422
FieldCache::cacheField
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
Definition: FieldCache.h:169
Msg::print
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
Field3DFileHDF5Base::m_layerInfo
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition: Field3DFileHDF5.h:387
Field3DInputFileHDF5::readProxyVectorLayers
EmptyField< Data_T >::Vec readProxyVectorLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each vector layer.
Definition: Field3DFileHDF5.h:1324
Field
Definition: Field.h:390
Field3DFileHDF5Base::getVectorLayerNames
void getVectorLayerNames(std::vector< std::string > &names, const std::string &partitionName) const
Gets the names of all the vector layers in a given partition.
Definition: Field3DFileHDF5.cpp:421
Field3DFileHDF5Base::getPartition
FileHDF5::Partition::Ptr getPartition(const std::string &partitionName) const
Returns a pointer to the given partition.
Definition: Field3DFileHDF5.h:294
RefBase
Definition: RefCount.h:107
FieldCache
Definition: FieldCache.h:81
FileHDF5
Namespace for file I/O specifics.
Definition: Field3DFileHDF5.h:111
Field3DOutputFile::createNewPartition
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, FieldRes::Ptr field)
Create newPartition given the input config.
Definition: Field3DFile.cpp:1355
Field3DOutputFileHDF5::createNewPartition
FileHDF5::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
create newPartition given the input config
Definition: Field3DFileHDF5.h:1381
Field3DInputFileHDF5::readProxyLayer
EmptyField< Data_T >::Vec readProxyLayer(const std::string &partitionName, const std::string &layerName, bool isVectorLayer) const
Retrieves a proxy version (EmptyField) of each layer .
Definition: Field3DFileHDF5.h:1157
Field3DInputFileHDF5::readLayer
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...
Definition: Field3DFileHDF5.h:1052
Field3DInputFileHDF5
Provides reading of .f3d (internally, hdf5) files.
Definition: Field3DFileHDF5.h:438
readFieldMapping
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
Definition: Field3DFileHDF5.cpp:1613
ClassFactory.h
Contains the ClassFactory class for registering Field3D classes.
FileHDF5::Partition::Ptr
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFileHDF5.h:152
Field3DOutputFile::writeGlobalMetadata
bool writeGlobalMetadata()
This routine is call if you want to write out global metadata to disk.
Definition: Field3DFile.cpp:1234
Field3DOutputFile::writeGroupMembership
bool writeGroupMembership()
This routine is called just before closing to write out any group membership to disk.
Definition: Field3DFile.cpp:1252
writeField
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...
Definition: Field3DFileHDF5.cpp:1589
Field3DOutputFileHDF5::writeVectorLayer
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a vector layer to the "Default" partition.
Definition: Field3DFileHDF5.h:801
Field3DOutputFile::incrementPartitionName
std::string incrementPartitionName(std::string &pname)
Increment the partition or make it zero if there's not an integer suffix.
Definition: Field3DFile.cpp:1302