Field3D
Field3DFile.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_Field3DFile_H_
48 #define _INCLUDED_Field3D_Field3DFile_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 "FieldMetadata.h"
63 #include "ClassFactory.h"
64 #include "Hdf5Util.h"
65 #include "FieldCache.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 File {
112 
120 class Layer
121 {
122 public:
124  std::string name;
127  std::string parent;
128 };
129 
130 } // namespace File
131 
132 //----------------------------------------------------------------------------//
133 // Partition
134 //----------------------------------------------------------------------------//
135 
136 namespace File {
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 File::Layer &layer);
186  void addVectorLayer(const File::Layer &layer);
187 
189  const File::Layer* scalarLayer(const std::string &name) const;
191  const File::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 
210  ScalarLayerList m_scalarLayers;
212  VectorLayerList m_vectorLayers;
213 
214  // Typedefs ------------------------------------------------------------------
215 
217  typedef RefBase base;
218 
219 };
220 
221 } // namespace File
222 
223 //----------------------------------------------------------------------------//
224 // Field3DFileBase
225 //----------------------------------------------------------------------------//
226 
234 //----------------------------------------------------------------------------//
235 
237 {
238 public:
239 
240  // Structs -------------------------------------------------------------------
241 
242  struct LayerInfo
243  {
244  std::string name;
245  std::string parentName;
247  LayerInfo(std::string par, std::string nm, int cpt)
248  : name(nm), parentName(par), components(cpt)
249  { /* Empty */ }
250  };
251 
252  // Typedefs ------------------------------------------------------------------
253 
254  typedef std::map<std::string, std::string> GroupMembershipMap;
255 
256  // Ctor, dtor ----------------------------------------------------------------
257 
260 
261  Field3DFileBase();
263  virtual ~Field3DFileBase() = 0;
264 
266 
267  // Main methods --------------------------------------------------------------
268 
270  void clear();
271 
275  bool close();
276 
279 
281  void getPartitionNames(std::vector<std::string> &names) const;
283  void getScalarLayerNames(std::vector<std::string> &names,
284  const std::string &partitionName) const;
286  void getVectorLayerNames(std::vector<std::string> &names,
287  const std::string &partitionName) const;
288 
291  File::Partition::Ptr getPartition(const std::string &partitionName) const
292  { return partition(partitionName); }
293 
295 
298 
302  std::string intPartitionName(const std::string &partitionName,
303  const std::string &layerName,
304  FieldRes::Ptr field);
305 
308  std::string removeUniqueId(const std::string &partitionName) const;
309 
311  void addGroupMembership(const GroupMembershipMap &groupMembers);
312 
314 
315  // Access to metadata --------------------------------------------------------
316 
319  { return m_metadata; }
320 
323  { return m_metadata; }
324 
327  virtual void metadataHasChanged(const std::string &/* name */)
328  { /* Empty */ }
329 
330  // Debug ---------------------------------------------------------------------
331 
334 
335  void printHierarchy() const;
336 
338 
339 protected:
340 
341  // Internal typedefs ---------------------------------------------------------
342 
343  typedef std::vector<File::Partition::Ptr> PartitionList;
344  typedef std::map<std::string, int> PartitionCountMap;
345 
346  // Convenience methods -------------------------------------------------------
347 
350 
352  void closeInternal();
355  File::Partition::Ptr partition(const std::string &partitionName);
358  File::Partition::Ptr partition(const std::string &partitionName) const;
359 
361  void getIntPartitionNames(std::vector<std::string> &names) const;
364  void getIntScalarLayerNames(std::vector<std::string> &names,
365  const std::string &intPartitionName) const;
368  void getIntVectorLayerNames(std::vector<std::string> &names,
369  const std::string &intPartitionName) const;
370 
372  int numIntPartitions(const std::string &partitionName) const;
373 
376  std::string makeIntPartitionName(const std::string &partitionsName,
377  int i) const;
378 
380 
381  // Data members --------------------------------------------------------------
382 
384  std::vector<LayerInfo> m_layerInfo;
385 
387  hid_t m_file;
389  PartitionList m_partitions;
391  std::vector<std::string> m_partitionNames;
392 
395  PartitionCountMap m_partitionCount;
396 
400  GroupMembershipMap m_groupMembership;
401 
404 
405 private:
406 
407  // Private member functions --------------------------------------------------
408 
410  void operator =(const Field3DFileBase&);
411 
412 
413 };
414 
415 //----------------------------------------------------------------------------//
416 // Field3DInputFile
417 //----------------------------------------------------------------------------//
418 
432 //----------------------------------------------------------------------------//
433 
435 {
436 public:
437 
438  // Ctors, dtor ---------------------------------------------------------------
439 
442 
444  virtual ~Field3DInputFile();
445 
447 
448  // Main interface ------------------------------------------------------------
449 
452 
457  template <class Data_T>
458  typename Field<Data_T>::Vec
459  readScalarLayers(const std::string &layerName = std::string("")) const;
460 
462  template <class Data_T>
463  typename Field<Data_T>::Vec
464  readScalarLayers(const std::string &partitionName,
465  const std::string &layerName) const;
466 
471  template <class Data_T>
472  typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
473  readVectorLayers(const std::string &layerName = std::string("")) const;
474 
476  template <class Data_T>
477  typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
478  readVectorLayers(const std::string &partitionName,
479  const std::string &layerName) const;
480 
483  template <template <typename T> class Field_T, class Data_T>
484  typename Field_T<Data_T>::Vec
485  readScalarLayersAs(const std::string &layerName = std::string("")) const
486  {
487  typedef typename Field<Data_T>::Vec FieldList;
488  typedef typename Field_T<Data_T>::Vec TypedFieldList;
489 
490  // First, read the layers as-is
491  FieldList originals;
492  originals = readScalarLayers<Data_T>(layerName);
493 
494  // Loop over fields, converting if needed
495  TypedFieldList output;
496  typename FieldList::iterator i = originals.begin();
497  for (; i != originals.end(); ++i) {
498  typename Field_T<Data_T>::Ptr targetField;
499  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
500  if (targetField) {
501  output.push_back(targetField);
502  } else {
503  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
504  newTarget->name = (*i)->name;
505  newTarget->attribute = (*i)->attribute;
506  newTarget->copyMetadata(**i);
507  newTarget->copyFrom(*i);
508  output.push_back(newTarget);
509  }
510  }
511 
512  return output;
513  }
514 
517  template <template <typename T> class Field_T, class Data_T>
518  typename Field_T<Data_T>::Vec
519  readScalarLayersAs(const std::string &partitionName,
520  const std::string &layerName) const
521  {
522  typedef typename Field<Data_T>::Vec FieldList;
523  typedef typename Field_T<Data_T>::Vec TypedFieldList;
524 
525  // First, read the layers as-is
526  FieldList originals;
527  originals = readScalarLayers<Data_T>(partitionName, layerName);
528 
529  // Loop over fields, converting if needed
530  TypedFieldList output;
531  typename FieldList::iterator i = originals.begin();
532  for (; i != originals.end(); ++i) {
533  typename Field_T<Data_T>::Ptr targetField;
534  targetField = field_dynamic_cast<Field_T<Data_T> >(*i);
535  if (targetField) {
536  output.push_back(targetField);
537  } else {
538  typename Field_T<Data_T>::Ptr newTarget(new Field_T<Data_T>);
539  newTarget->name = (*i)->name;
540  newTarget->attribute = (*i)->attribute;
541  newTarget->copyMetadata(**i);
542  newTarget->copyFrom(*i);
543  output.push_back(newTarget);
544  }
545  }
546 
547  return output;
548  }
549 
552  template <template <typename T> class Field_T, class Data_T>
553  typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec
554  readVectorLayersAs(const std::string &layerName = std::string("")) const
555  {
556  typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
557  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
558  typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
559 
560  // First, read the layers as-is
561  FieldList originals;
562  originals = readVectorLayers<Data_T>(layerName);
563 
564  // Loop over fields, converting if needed
565  TypedFieldList output;
566  typename FieldList::iterator i = originals.begin();
567  for (; i != originals.end(); ++i) {
568  typename TypedVField::Ptr targetField;
569  targetField = field_dynamic_cast<TypedVField>(*i);
570  if (targetField) {
571  output.push_back(targetField);
572  } else {
573  typename TypedVField::Ptr newTarget(new TypedVField);
574  newTarget->name = (*i)->name;
575  newTarget->attribute = (*i)->attribute;
576  newTarget->copyMetadata(**i);
577  newTarget->copyFrom(*i);
578  output.push_back(newTarget);
579  }
580  }
581 
582  return output;
583  }
584 
587  template <template <typename T> class Field_T, class Data_T>
588  typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec
589  readVectorLayersAs(const std::string &partitionName,
590  const std::string &layerName) const
591  {
592  typedef Field_T<FIELD3D_VEC3_T<Data_T> > TypedVField;
593  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
594  typedef typename Field_T<FIELD3D_VEC3_T<Data_T> >::Vec TypedFieldList;
595 
596  // First, read the layers as-is
597  FieldList originals;
598  originals = readVectorLayers<Data_T>(partitionName, layerName);
599 
600  // Loop over fields, converting if needed
601  TypedFieldList output;
602  typename FieldList::iterator i = originals.begin();
603  for (; i != originals.end(); ++i) {
604  typename TypedVField::Ptr targetField;
605  targetField = field_dynamic_cast<TypedVField>(*i);
606  if (targetField) {
607  output.push_back(targetField);
608  } else {
609  typename TypedVField::Ptr newTarget(new TypedVField);
610  newTarget->name = (*i)->name;
611  newTarget->attribute = (*i)->attribute;
612  newTarget->copyMetadata(**i);
613  newTarget->copyFrom(*i);
614  output.push_back(newTarget);
615  }
616  }
617 
618  return output;
619  }
620 
622 
625 
631  template <class Data_T>
632  typename EmptyField<Data_T>::Vec
633  readProxyLayer(const std::string &partitionName,
634  const std::string &layerName,
635  bool isVectorLayer) const;
636 
641  template <class Data_T>
642  typename EmptyField<Data_T>::Ptr
643  readProxyLayer(hid_t location, const std::string &name,
644  const std::string &attribute,
645  FieldMapping::Ptr mapping) const;
646 
652  template <class Data_T>
653  typename EmptyField<Data_T>::Vec
654  readProxyScalarLayers(const std::string &name = std::string("")) const;
655 
661  template <class Data_T>
662  typename EmptyField<Data_T>::Vec
663  readProxyVectorLayers(const std::string &name = std::string("")) const;
664 
666 
667  // File IO ---
668 
671  bool open(const std::string &filename);
672 
673  // Callback convenience methods ----------------------------------------------
674 
677 
679  herr_t parsePartition(hid_t loc_id, const std::string partitionName);
680 
682  herr_t parseLayer(hid_t loc_id, const std::string &partitionName,
683  const std::string &layerName);
684 
686 
687  // Convenience methods -------------------------------------------------------
688 
690  bool readGroupMembership(GroupMembershipMap &gpMembershipMap);
691 
692 private:
693 
694  // Convenience methods -------------------------------------------------------
695 
698  template <class Data_T>
699  typename Field<Data_T>::Ptr
700  readScalarLayer(const std::string &intPartitionName,
701  const std::string &layerName) const;
702 
705  template <class Data_T>
706  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr
707  readVectorLayer(const std::string &intPartitionName,
708  const std::string &layerName) const;
709 
712  template <class Data_T>
713  typename Field<Data_T>::Ptr
714  readLayer(const std::string &intPartitionName,
715  const std::string &layerName,
716  bool isVectorLayer) const;
717 
719  bool readPartitionAndLayerInfo();
720 
722  bool readMetadata(hid_t metadata_id, FieldBase::Ptr field) const;
723 
725  bool readMetadata(hid_t metadata_id);
726 
727  // Data members --------------------------------------------------------------
728 
730  std::string m_filename;
731 
732 };
733 
734 //----------------------------------------------------------------------------//
735 // Utility functions
736 //----------------------------------------------------------------------------//
737 
743 bool fileExists(const std::string &filename);
744 
745 //----------------------------------------------------------------------------//
746 // Field3DOutputFile
747 //----------------------------------------------------------------------------//
748 
762 //----------------------------------------------------------------------------//
763 
765 {
766 public:
767 
768  // Enums ---------------------------------------------------------------------
769 
770  enum CreateMode {
772  FailOnExisting
773  };
774 
775  // Ctors, dtor ---------------------------------------------------------------
776 
779 
781  virtual ~Field3DOutputFile();
782 
784 
785  // Main interface ------------------------------------------------------------
786 
789 
791  template <class Data_T>
792  bool writeScalarLayer(const std::string &layerName,
793  typename Field<Data_T>::Ptr layer)
794  { return writeScalarLayer<Data_T>(layerName, std::string("default"), layer); }
795 
797  template <class Data_T>
798  bool writeVectorLayer(const std::string &layerName,
799  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
800  { return writeVectorLayer<Data_T>(layerName, std::string("default"), layer); }
801 
804  template <class Data_T>
805  bool writeScalarLayer(const std::string &partitionName,
806  const std::string &layerName,
807  typename Field<Data_T>::Ptr layer);
808 
811  template <class Data_T>
812  bool writeScalarLayer(typename Field<Data_T>::Ptr layer);
813 
816  template <class Data_T>
817  bool writeVectorLayer(const std::string &partitionName,
818  const std::string &layerName,
819  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer);
820 
823  template <class Data_T>
824  bool writeVectorLayer(typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer);
825 
827 
829  bool create(const std::string &filename, CreateMode cm = OverwriteMode);
830 
832  bool writeGlobalMetadata();
833 
836  bool writeGroupMembership();
837 
839  std::string incrementPartitionName(std::string &pname);
840 
842  template <class Data_T>
844  createNewPartition(const std::string &partitionName,
845  const std::string &layerName,
846  typename Field<Data_T>::Ptr field);
847  private:
848 
849  // Convenience methods -------------------------------------------------------
850 
854  bool writeMapping(hid_t partitionLocation, FieldMapping::Ptr mapping);
855 
857  template <class Data_T>
858  bool writeLayer(const std::string &partitionName,
859  const std::string &layerName,
860  bool isVectorLayer,
861  typename Field<Data_T>::Ptr layer);
862 
864  bool writeMetadata(hid_t metadataGroup, FieldBase::Ptr layer);
865 
867  bool writeMetadata(hid_t metadataGroup);
868 
869 };
870 
871 //----------------------------------------------------------------------------//
872 // Field3DInputFile-related callback functions
873 //----------------------------------------------------------------------------//
874 
876 namespace InputFile {
877 
882 {
884  std::string partitionName;
885 };
886 
890 FIELD3D_API herr_t parsePartitions(hid_t loc_id, const char *partitionName,
891  const H5L_info_t *linfo, void *opdata);
892 
896 FIELD3D_API herr_t parseLayers(hid_t loc_id, const char *partitionName,
897  const H5L_info_t *linfo, void *opdata);
898 
899 } // namespace InputFile
900 
901 //----------------------------------------------------------------------------//
902 // Field3DInputFile
903 //----------------------------------------------------------------------------//
904 
905 template <class Data_T>
906 typename Field<Data_T>::Vec
907 Field3DInputFile::readScalarLayers(const std::string &name) const
908 {
909  using namespace std;
910 
911  typedef typename Field<Data_T>::Ptr FieldPtr;
912  typedef typename Field<Data_T>::Vec FieldList;
913 
914  FieldList ret;
915  std::vector<std::string> parts;
916  getIntPartitionNames(parts);
917 
918  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
919  std::vector<std::string> layers;
920  getIntScalarLayerNames(layers, *p);
921  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
922  // Only read if it matches the name
923  if ((name.length() == 0) || (*l == name)) {
924  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
925  if (mf) {
926  ret.push_back(mf);
927  }
928  }
929  }
930  }
931 
932  return ret;
933 }
934 
935 //----------------------------------------------------------------------------//
936 
937 template <class Data_T>
938 typename Field<Data_T>::Vec
939 Field3DInputFile::readScalarLayers(const std::string &partitionName,
940  const std::string &layerName) const
941 {
942  using namespace std;
943 
944  typedef typename Field<Data_T>::Ptr FieldPtr;
945  typedef typename Field<Data_T>::Vec FieldList;
946 
947  FieldList ret;
948 
949  if ((layerName.length() == 0) || (partitionName.length() == 0))
950  return ret;
951 
952  std::vector<std::string> parts;
953  getIntPartitionNames(parts);
954 
955  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
956  std::vector<std::string> layers;
957  getIntScalarLayerNames(layers, *p);
958  if (removeUniqueId(*p) == partitionName) {
959  for (vector<string>::iterator l = layers.begin();
960  l != layers.end(); ++l) {
961  // Only read if it matches the name
962  if (*l == layerName) {
963  FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
964  if (mf)
965  ret.push_back(mf);
966  }
967  }
968  }
969  }
970 
971  return ret;
972 }
973 
974 //----------------------------------------------------------------------------//
975 
976 template <class Data_T>
977 typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
978 Field3DInputFile::readVectorLayers(const std::string &name) const
979 {
980  using namespace std;
981 
982  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
983  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
984 
985  FieldList ret;
986 
987  std::vector<std::string> parts;
988  getIntPartitionNames(parts);
989 
990  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
991  std::vector<std::string> layers;
992  getIntVectorLayerNames(layers, *p);
993  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
994  // Only read if it matches the name
995  if ((name.length() == 0) || (*l == name)) {
996  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
997  if (mf)
998  ret.push_back(mf);
999  }
1000  }
1001  }
1002 
1003  return ret;
1004 }
1005 
1006 //----------------------------------------------------------------------------//
1007 
1008 template <class Data_T>
1009 typename Field<FIELD3D_VEC3_T<Data_T> >::Vec
1010 Field3DInputFile::readVectorLayers(const std::string &partitionName,
1011  const std::string &layerName) const
1012 {
1013  using namespace std;
1014 
1015  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr FieldPtr;
1016  typedef typename Field<FIELD3D_VEC3_T<Data_T> >::Vec FieldList;
1017 
1018  FieldList ret;
1019 
1020  if ((layerName.length() == 0) || (partitionName.length() == 0))
1021  return ret;
1022 
1023  std::vector<std::string> parts;
1024  getIntPartitionNames(parts);
1025 
1026  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1027  std::vector<std::string> layers;
1028  getIntVectorLayerNames(layers, *p);
1029  if (removeUniqueId(*p) == partitionName) {
1030  for (vector<string>::iterator l = layers.begin();
1031  l != layers.end(); ++l) {
1032  // Only read if it matches the name
1033  if (*l == layerName) {
1034  FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
1035  if (mf)
1036  ret.push_back(mf);
1037  }
1038  }
1039  }
1040  }
1041 
1042  return ret;
1043 }
1044 
1045 //----------------------------------------------------------------------------//
1046 
1047 template <class Data_T>
1048 typename Field<Data_T>::Ptr
1049 Field3DInputFile::readLayer(const std::string &intPartitionName,
1050  const std::string &layerName,
1051  bool isVectorLayer) const
1052 {
1053  using namespace boost;
1054  using namespace std;
1055  using namespace Hdf5Util;
1056 
1057  typedef typename Field<Data_T>::Ptr FieldPtr;
1058 
1059  GlobalLock lock(g_hdf5Mutex);
1060 
1061  // Instantiate a null pointer for easier code reading
1062  FieldPtr nullPtr;
1063 
1064  // Find the partition
1065  File::Partition::Ptr part = partition(intPartitionName);
1066  if (!part) {
1067  Msg::print(Msg::SevWarning, "Couldn't find partition: " + intPartitionName);
1068  return nullPtr;
1069  }
1070 
1071  // Find the layer in the partition
1072  const File::Layer *l;
1073  if (isVectorLayer)
1074  l = part->vectorLayer(layerName);
1075  else
1076  l = part->scalarLayer(layerName);
1077  if (!l) {
1078  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName );
1079  return nullPtr;
1080  }
1081 
1082  // Open the layer group
1083  string layerPath = l->parent + "/" + l->name;
1084  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
1085 
1086  if (layerGroup.id() < 0) {
1087  Msg::print(Msg::SevWarning, "Couldn't find layer group " + layerName
1088  + " in .f3d file ");
1089  return nullPtr;
1090  }
1091 
1092  // Get the class name
1093  string className;
1094  if (!readAttribute(layerGroup.id(), "class_name", className)) {
1095  Msg::print(Msg::SevWarning, "Couldn't find class_name attrib in layer " +
1096  layerName);
1097  return nullPtr;
1098  }
1099 
1100  // Check the cache
1101 
1103  FieldPtr cachedField = cache.getCachedField(m_filename, layerPath);
1104 
1105  if (cachedField) {
1106  return cachedField;
1107  }
1108 
1109  // Construct the field and load the data
1110 
1111  // Unlock the g_hdf5Mutex while calling readField() so that other threads
1112  // have a chance to pre-empt loading in between (prevents deadlocks with
1113  // sparse reader)
1114  lock.unlock();
1115 
1116  typename Field<Data_T>::Ptr field;
1117  field = readField<Data_T>(className, layerGroup.id(), m_filename, layerPath);
1118 
1119  if (!field) {
1120 #if 0 // This isn't really an error
1121  Msg::print(Msg::SevWarning, "Couldn't read the layer data of layer: "
1122  + layerName);
1123 #endif
1124  return nullPtr;
1125  }
1126 
1127  // Now we need to use Hdf5 again, so re-aquire the lock.
1128  lock.lock();
1129 
1130  // read the metadata
1131  string metadataPath = layerPath + "/metadata";
1132  H5ScopedGopen metadataGroup(m_file, metadataPath.c_str());
1133  if (metadataGroup.id() > 0) {
1134  readMetadata(metadataGroup.id(), field);
1135  }
1136 
1137  // Set the name of the field so it's possible to re-create the file
1138  field->name = removeUniqueId(intPartitionName);
1139  field->attribute = layerName;
1140  field->setMapping(part->mapping);
1141 
1142  // Cache the field for future use
1143  if (field) {
1144  cache.cacheField(field, m_filename, layerPath);
1145  }
1146 
1147  return field;
1148 }
1149 
1150 //----------------------------------------------------------------------------//
1151 
1152 template <class Data_T>
1153 typename EmptyField<Data_T>::Vec
1154 Field3DInputFile::readProxyLayer(const std::string &partitionName,
1155  const std::string &layerName,
1156  bool isVectorLayer) const
1157 {
1158  using namespace boost;
1159  using namespace std;
1160  using namespace Hdf5Util;
1161 
1162  GlobalLock lock(g_hdf5Mutex);
1163 
1164  // Instantiate a null pointer for easier code reading
1165  typename EmptyField<Data_T>::Vec emptyList, output;
1166 
1167  if ((layerName.length() == 0) || (partitionName.length() == 0))
1168  return emptyList;
1169 
1170  std::vector<std::string> parts, layers;
1171  getIntPartitionNames(parts);
1172 
1173  bool foundPartition = false;
1174 
1175  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1176  if (removeUniqueId(*p) == partitionName) {
1177  foundPartition = true;
1178  if (isVectorLayer) {
1179  getIntVectorLayerNames(layers, *p);
1180  } else {
1181  getIntScalarLayerNames(layers, *p);
1182  }
1183  for (vector<string>::iterator l = layers.begin();
1184  l != layers.end(); ++l) {
1185  if (*l == layerName) {
1186  // Find the partition
1187  File::Partition::Ptr part = partition(*p);
1188  if (!part) {
1189  Msg::print(Msg::SevWarning, "Couldn't find partition: " + *p);
1190  return emptyList;
1191  }
1192  // Find the layer
1193  const File::Layer *layer;
1194  if (isVectorLayer)
1195  layer = part->vectorLayer(layerName);
1196  else
1197  layer = part->scalarLayer(layerName);
1198  if (!layer) {
1199  Msg::print(Msg::SevWarning, "Couldn't find layer: " + layerName);
1200  return emptyList;
1201  }
1202  // Open the layer group
1203  string layerPath = layer->parent + "/" + layer->name;
1204  H5ScopedGopen layerGroup(m_file, layerPath.c_str());
1205  if (layerGroup.id() < 0) {
1206  Msg::print(Msg::SevWarning, "Couldn't find layer group "
1207  + layerName + " in .f3d file ");
1208  return emptyList;
1209  }
1210 
1211  // Make the proxy representation
1212  typename EmptyField<Data_T>::Ptr field =
1213  readProxyLayer<Data_T>(layerGroup, partitionName, layerName,
1214  part->mapping);
1215 
1216  // Read MIPField's number of mip levels
1217  int numLevels = 0;
1218  H5ScopedGopen mipGroup(layerGroup, "mip_levels");
1219  if (mipGroup.id() >= 0)
1220  readAttribute(mipGroup, "levels", 1, numLevels);
1221  field->metadata().setIntMetadata("mip_levels", numLevels);
1222 
1223  // Add field to output
1224  output.push_back(field);
1225  }
1226  }
1227  }
1228  }
1229 
1230  if (!foundPartition) {
1231  Msg::print(Msg::SevWarning, "Couldn't find partition: " + partitionName);
1232  return emptyList;
1233  }
1234 
1235  return output;
1236 }
1237 
1238 //----------------------------------------------------------------------------//
1239 
1240 template <class Data_T>
1241 typename EmptyField<Data_T>::Ptr
1243  const std::string &name,
1244  const std::string &attribute,
1245  FieldMapping::Ptr mapping) const
1246 {
1247  using namespace boost;
1248  using namespace std;
1249  using namespace Hdf5Util;
1250 
1251  typename EmptyField<Data_T>::Ptr null;
1252 
1253  GlobalLock lock(g_hdf5Mutex);
1254 
1255  // Read the extents and data window
1256  Box3i extents, dataW;
1257  if (!readAttribute(location, "extents", 6, extents.min.x)) {
1258  return null;
1259  }
1260  if (!readAttribute(location, "data_window", 6, dataW.min.x)) {
1261  return null;
1262  }
1263 
1264  // Construct the field and load the data
1265  typename EmptyField<Data_T>::Ptr field(new EmptyField<Data_T>);
1266  field->setSize(extents, dataW);
1267 
1268  // Read the metadata
1269  H5ScopedGopen metadataGroup(location, "metadata");
1270  if (metadataGroup.id() > 0) {
1271  readMetadata(metadataGroup.id(), field);
1272  }
1273 
1274  // Set field properties
1275  field->name = name;
1276  field->attribute = attribute;
1277  field->setMapping(mapping);
1278 
1279  return field;
1280 }
1281 
1282 //----------------------------------------------------------------------------//
1283 
1284 template <class Data_T>
1285 typename EmptyField<Data_T>::Vec
1287 {
1288  using namespace std;
1289 
1290  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1291  typedef std::vector<FieldPtr> FieldList;
1292 
1293  FieldList ret;
1294 
1295  std::vector<std::string> parts;
1296  getPartitionNames(parts);
1297 
1298  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1299  std::vector<std::string> layers;
1300  getScalarLayerNames(layers, *p);
1301  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1302  // Only read if it matches the name
1303  if ((name.length() == 0) || (*l == name)) {
1304  FieldList f = readProxyLayer<Data_T>(*p, *l, false);
1305  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1306  if (*i) {
1307  ret.push_back(*i);
1308  }
1309  }
1310  }
1311  }
1312  }
1313 
1314  return ret;
1315 }
1316 
1317 //----------------------------------------------------------------------------//
1318 
1319 template <class Data_T>
1320 typename EmptyField<Data_T>::Vec
1322 {
1323  using namespace std;
1324 
1325  typedef typename EmptyField<Data_T>::Ptr FieldPtr;
1326  typedef std::vector<FieldPtr> FieldList;
1327 
1328  FieldList ret;
1329 
1330  std::vector<std::string> parts;
1331  getPartitionNames(parts);
1332 
1333  for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1334  std::vector<std::string> layers;
1335  getVectorLayerNames(layers, *p);
1336  for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1337  // Only read if it matches the name
1338  if ((name.length() == 0) || (*l == name)) {
1339  FieldList f = readProxyLayer<Data_T>(*p, *l, true);
1340  for (typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1341  if (*i) {
1342  ret.push_back(*i);
1343  }
1344  }
1345  }
1346  }
1347  }
1348 
1349  return ret;
1350 }
1351 
1352 //----------------------------------------------------------------------------//
1353 
1354 template <class Data_T>
1355 typename Field<Data_T>::Ptr
1356 Field3DInputFile::readScalarLayer(const std::string &intPartitionName,
1357  const std::string &layerName) const
1358 {
1359  return readLayer<Data_T>(intPartitionName, layerName, false);
1360 }
1361 
1362 //----------------------------------------------------------------------------//
1363 
1364 template <class Data_T>
1365 typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr
1366 Field3DInputFile::readVectorLayer(const std::string &intPartitionName,
1367  const std::string &layerName) const
1368 {
1369  return readLayer<FIELD3D_VEC3_T<Data_T> >(intPartitionName, layerName, true);
1370 }
1371 
1372 //----------------------------------------------------------------------------//
1373 // Field3DOutputFile
1374 //----------------------------------------------------------------------------//
1375 
1376 template <class Data_T>
1378 Field3DOutputFile::createNewPartition(const std::string &partitionName,
1379  const std::string & /* layerName */,
1380  typename Field<Data_T>::Ptr field)
1381 {
1382  using namespace Hdf5Util;
1383  using namespace Exc;
1384 
1385  GlobalLock lock(g_hdf5Mutex);
1386 
1388 
1389  newPart->name = partitionName;
1390 
1391  H5ScopedGcreate partGroup(m_file, newPart->name.c_str());
1392  if (partGroup.id() < 0) {
1394  "Error creating partition: " + newPart->name);
1395  return File::Partition::Ptr();
1396  }
1397 
1398  m_partitions.push_back(newPart);
1399 
1400  // Pick up new pointer
1401  File::Partition::Ptr part = partition(partitionName);
1402 
1403  // Add mapping group to the partition
1406  try {
1407  if (!writeMapping(partGroup.id(), field->mapping())) {
1409  "writeMapping returned false for an unknown reason ");
1410  return File::Partition::Ptr();
1411  }
1412  }
1413  catch (WriteMappingException &e) {
1414  Msg::print(Msg::SevWarning, "Couldn't write mapping for partition: "
1415  + partitionName);
1416  return File::Partition::Ptr();
1417  }
1418  catch (...) {
1420  "Unknown error when writing mapping for partition: "
1421  + partitionName);
1422  return File::Partition::Ptr();
1423  }
1424 
1425  // Set the mapping of the partition. Since all layers share their
1426  // partition's mapping, we can just pick this first one. All subsequent
1427  // additions to the same partition are checked to have the same mapping
1428  part->mapping = field->mapping();
1429 
1430  // Tag node as partition
1431  // Create a version attribute on the root node
1432  if (!writeAttribute(partGroup.id(), "is_field3d_partition", "1")) {
1433  Msg::print(Msg::SevWarning, "Adding partition string.");
1434  return File::Partition::Ptr();
1435  }
1436 
1437  return part;
1438 }
1439 
1440 //----------------------------------------------------------------------------//
1441 
1442 template <class Data_T>
1443 bool
1444 Field3DOutputFile::writeLayer(const std::string &userPartitionName,
1445  const std::string &layerName,
1446  bool isVectorLayer,
1447  typename Field<Data_T>::Ptr field)
1448 {
1449  using namespace std;
1450  using namespace Exc;
1451  using namespace Hdf5Util;
1452 
1453  GlobalLock lock(g_hdf5Mutex);
1454 
1455  if (!field) {
1457  "Called writeLayer with null pointer. Ignoring...");
1458  return false;
1459  }
1460 
1461  if (m_file < 0) {
1463  "Attempting to write layer without opening file first. ");
1464  return false;
1465  }
1466 
1467  string partitionName = intPartitionName(userPartitionName, layerName, field);
1468 
1469  // See if the partition already exists or if we need to make it ---
1470 
1471  File::Partition::Ptr part = partition(partitionName);
1472 
1473  if (!part) {
1474  part = createNewPartition<Data_T>(partitionName,layerName,field);
1475  if (!part)
1476  return false;
1477  } else {
1478 
1479  if (!field->mapping()) {
1481  "Couldn't add layer \"" + layerName + "\" to partition \""
1482  + partitionName + "\" because the layer's mapping is null.");
1483  return false;
1484  }
1485 
1486  // If the partition already existed, we need to make sure that the layer
1487  // doesn't also exist
1488  if (!isVectorLayer) {
1489  if (part->scalarLayer(layerName)) {
1490  //need to create a new partition and then add the layer to that
1491  std::string newPartitionName = incrementPartitionName(partitionName);
1492  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1493  if (!part)
1494  return false;
1495  }
1496  } else {
1497  if (part->vectorLayer(layerName)) {
1498  //need to create a new partition and then add the layer to that
1499  std::string newPartitionName = incrementPartitionName(partitionName);
1500  part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1501  if (!part)
1502  return false;
1503  }
1504  }
1505  }
1506 
1507  if (!part->mapping) {
1508  Msg::print(Msg::SevWarning, "Severe error - partition mapping is null: "
1509  + partitionName);
1510  return false;
1511  }
1512 
1513  // Check that the mapping matches what's already in the Partition
1514  if (!field->mapping()->isIdentical(part->mapping)) {
1515  Msg::print(Msg::SevWarning, "Couldn't add layer \"" + layerName
1516  + "\" to partition \"" + partitionName
1517  + "\" because mapping doesn't match");
1518  return false;
1519  }
1520 
1521  // Open the partition
1522  H5ScopedGopen partGroup(m_file, part->name.c_str(), H5P_DEFAULT);
1523 
1524  // Build a Layer object ---
1525 
1526  File::Layer layer;
1527  layer.name = layerName;
1528  layer.parent = partitionName;
1529 
1530  // Add Layer to file ---
1531 
1532  H5ScopedGcreate layerGroup(partGroup.id(), layerName.c_str(),
1533  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1534 
1535  if (layerGroup.id() < 0) {
1536  Msg::print(Msg::SevWarning, "Error creating layer: " + layerName);
1537  return false;
1538  }
1539 
1540  // Tag as layer
1541  if (!writeAttribute(layerGroup.id(), "class_type", "field3d_layer")) {
1542  Msg::print(Msg::SevWarning, "Error adding layer string.");
1543  return false;
1544  }
1545 
1546  // Add metadata group and write it out
1547  H5ScopedGcreate metadataGroup(layerGroup.id(), "metadata");
1548  if (metadataGroup.id() < 0) {
1549  Msg::print(Msg::SevWarning, "Error creating group: metadata");
1550  return false;
1551  }
1552  if (!writeMetadata(metadataGroup.id(), field)) {
1553  Msg::print(Msg::SevWarning, "Error writing metadata.");
1554  return false;
1555  }
1556 
1557  if (!writeField(layerGroup.id(), field)) {
1558  Msg::print(Msg::SevWarning, "Error writing layer: " + layer.name);
1559  return false;
1560  }
1561 
1562  // Add layer to partition ---
1563 
1564  if (isVectorLayer)
1565  part->addVectorLayer(layer);
1566  else
1567  part->addScalarLayer(layer);
1568 
1569  return true;
1570 }
1571 
1572 //----------------------------------------------------------------------------//
1573 
1574 template <class Data_T>
1575 bool
1576 Field3DOutputFile::writeScalarLayer(const std::string &partitionName,
1577  const std::string &layerName,
1578  typename Field<Data_T>::Ptr field)
1579 {
1580  return writeLayer<Data_T>(partitionName, layerName, false, field);
1581 }
1582 
1583 //----------------------------------------------------------------------------//
1584 
1585 template <class Data_T>
1586 bool
1588 {
1589  if (layer->name.size() == 0) {
1590  Msg::print(Msg::SevWarning, "Field3DOutputFile::writeScalarLayer: "
1591  "Tried to write a scalar layer with no name");
1592  return false;
1593  }
1594  if (layer->attribute.size() == 0) {
1595  Msg::print(Msg::SevWarning, "Field3DOutputFile::writeScalarLayer: "
1596  "Tried to write a scalar layer with no attribute name");
1597  return false;
1598  }
1599  return writeScalarLayer<Data_T>(layer->name, layer->attribute, layer);
1600 }
1601 
1602 //----------------------------------------------------------------------------//
1603 
1604 template <class Data_T>
1605 bool
1607 writeVectorLayer(const std::string &partitionName,
1608  const std::string &layerName,
1609  typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr field)
1610 {
1611  return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName,
1612  true, field);
1613 }
1614 
1615 //----------------------------------------------------------------------------//
1616 
1617 template <class Data_T>
1618 bool
1620  (typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
1621 {
1622  if (layer->name.size() == 0) {
1623  Msg::print(Msg::SevWarning, "Field3DOutputFile::writeVectorLayer: "
1624  "Tried to write a vector layer with no name");
1625  return false;
1626  }
1627  if (layer->attribute.size() == 0) {
1628  Msg::print(Msg::SevWarning, "Field3DOutputFile::writeVectorLayer: "
1629  "Tried to write a vector layer with no attribute name");
1630  return false;
1631  }
1632  return writeVectorLayer<Data_T>(layer->name, layer->attribute, layer);
1633 }
1634 
1635 //----------------------------------------------------------------------------//
1636 // Template Function Implementations
1637 //----------------------------------------------------------------------------//
1638 
1639 template <class Data_T>
1640 typename Field<Data_T>::Ptr
1641 readField(const std::string &className, hid_t layerGroup,
1642  const std::string &filename, const std::string &layerPath)
1643 {
1644 
1646 
1647  typedef typename Field<Data_T>::Ptr FieldPtr;
1648 
1649  FieldIO::Ptr io = factory.createFieldIO(className);
1650  assert(io != 0);
1651  if (!io) {
1652  Msg::print(Msg::SevWarning, "Unable to find class type: " +
1653  className);
1654  return FieldPtr();
1655  }
1656 
1658  FieldBase::Ptr field = io->read(layerGroup, filename, layerPath, typeEnum);
1659 
1660  if (!field) {
1661  // We don't need to print a message, because it could just be that
1662  // a layer of the specified data type and name couldn't be found
1663  return FieldPtr();
1664  }
1665 
1666  FieldPtr result = field_dynamic_cast<Field<Data_T> >(field);
1667 
1668  if (result)
1669  return result;
1670 
1671  return FieldPtr();
1672 }
1673 
1674 //----------------------------------------------------------------------------//
1675 
1677 
1678 //----------------------------------------------------------------------------//
1679 
1680 #endif
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
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...
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
Namespace for file I/O specifics.
Definition: Field3DFile.h:111
EmptyField< Data_T >::Vec readProxyVectorLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each vector layer.
Definition: Field3DFile.h:1321
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
VectorLayerList m_vectorLayers
The vector-valued layers belonging to this partition.
Definition: Field3DFile.h:212
std::vector< Layer > ScalarLayerList
Definition: Field3DFile.h:149
Contains utility functions and classes for Hdf5 files.
Definition: Hdf5Util.h:86
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: Field3DFile.h:1049
FIELD3D_API bool writeAttribute(hid_t location, const std::string &attrName, const std::string &value)
Writes a string attribute.
Partition class_type
Definition: Field3DFile.h:157
FieldMetadata< FieldBase > & metadata()
accessor to the m_metadata class
Definition: Field.h:155
boost::intrusive_ptr< Partition > Ptr
Definition: Field3DFile.h:152
std::string m_filename
Filename, only to be set by open().
Definition: Field3DFile.h:730
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: Field3DFile.h:907
Namespace for Exception objects.
Definition: Exception.h:57
std::map< std::string, int > PartitionCountMap
Definition: Field3DFile.h:344
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: Field3DFile.h:1641
DEFINE_FIELD_RTTI_CONCRETE_CLASS
Definition: Field3DFile.h:158
FieldMetadata< Field3DFileBase > m_metadata
metadata
Definition: Field3DFile.h:403
std::map< std::string, std::string > GroupMembershipMap
Definition: Field3DFile.h:254
Field< Data_T >::Ptr readScalarLayer(const std::string &intPartitionName, const std::string &layerName) const
Retrieves a single layer given its and its parent partition&#39;s name. Maintains the on-disk data types...
Definition: Field3DFile.h:1356
Provides writing of .f3d (internally, hdf5) files.
Definition: Field3DFile.h:764
std::string name
Name of the partition.
Definition: Field3DFile.h:201
Definition: Field.h:394
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
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&#39;s name. Maintains the on-disk data types...
Definition: Field3DFile.h:1366
Contains the FieldCache class.
static ClassFactory & singleton()
}
boost::recursive_mutex::scoped_lock GlobalLock
Definition: Hdf5Util.h:78
RefBase base
Convenience typedef for referring to base class.
Definition: Field3DFile.h:217
Contains the EmptyField class.
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:66
boost::intrusive_ptr< FieldRes > Ptr
Definition: Field.h:218
FieldPtr getCachedField(const std::string &filename, const std::string &layerPath)
Checks the cache for a previously loaded field.
Definition: FieldCache.h:155
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 writeScalarLayer(const std::string &layerName, typename Field< Data_T >::Ptr layer)
Writes a scalar layer to the "Default" partition.
Definition: Field3DFile.h:792
std::vector< Layer > VectorLayerList
Definition: Field3DFile.h:150
static DataTypeEnum typeEnum()
Contains various utility functions for Hdf5.
Scoped object - creates a group on creation and closes it on destruction.
Definition: Hdf5Util.h:165
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&#39;s name. Converts it to the given template typ...
Definition: Field3DFile.h:589
PartitionCountMap m_partitionCount
Contains a counter for each partition name. This is used to keep multiple fields with the same name u...
Definition: Field3DFile.h:395
ScalarLayerList m_scalarLayers
The scalar-valued layers belonging to this partition.
Definition: Field3DFile.h:210
bool fileExists(const std::string &filename)
checks to see if a file/directory exists or not
EmptyField< Data_T >::Vec readProxyScalarLayers(const std::string &name=std::string("")) const
Retrieves a proxy version (EmptyField) of each scalar layer.
Definition: Field3DFile.h:1286
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: Field3DFile.h:554
std::vector< Ptr > Vec
Definition: EmptyField.h:94
std::vector< std::string > m_partitionNames
This stores partition names.
Definition: Field3DFile.h:391
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
void setSize(const V3i &size)
Resizes the object.
Definition: Field.h:918
void cacheField(FieldPtr field, const std::string &filename, const std::string &layerPath)
Adds the given field to the cache.
Definition: FieldCache.h:176
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: Field3DFile.h:1154
std::string name
The name of the layer (always available)
Definition: Field3DFile.h:124
void setMapping(FieldMapping::Ptr mapping)
Sets the field&#39;s mapping.
Definition: Field.h:352
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: Field3DFile.h:1444
PartitionList m_partitions
Vector of partitions.
Definition: Field3DFile.h:389
This subclass of Field does not store any data.
Definition: EmptyField.h:86
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: Field3DFile.h:485
Partition()
Ctor.
Definition: Field3DFile.h:168
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: Field3DFile.h:978
std::vector< Ptr > Vec
This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInput...
Definition: Field.h:408
Provides reading of .f3d (internally, hdf5) files.Refer to using_files for examples of how to use thi...
Definition: Field3DFile.h:434
#define FIELD3D_API
Definition: ns.h:77
static const char * staticClassType()
Definition: Field3DFile.h:160
Namespace for file input specifics.
Definition: Field3DFile.h:876
boost::intrusive_ptr< EmptyField > Ptr
Definition: EmptyField.h:93
FIELD3D_API FieldMapping::Ptr readFieldMapping(hid_t mappingGroup)
This function creates a FieldMappingIO instance based on className read from mappingGroup location wh...
boost::intrusive_ptr< const Partition > CPtr
Definition: Field3DFile.h:153
File::Partition::Ptr createNewPartition(const std::string &partitionName, const std::string &layerName, typename Field< Data_T >::Ptr field)
create newPartition given the input config
Definition: Field3DFile.h:1378
const FieldMetadata< Field3DFileBase > & metadata() const
Read only access to the m_metadata class.
Definition: Field3DFile.h:322
static FieldCache & singleton()
Returns a reference to the FieldCache singleton.
Definition: FieldCache.h:142
LayerInfo(std::string par, std::string nm, int cpt)
Definition: Field3DFile.h:247
FIELD3D_NAMESPACE_OPEN FIELD3D_API boost::recursive_mutex g_hdf5Mutex
Definition: Hdf5Util.cpp:67
std::vector< LayerInfo > m_layerInfo
This stores layer info.
Definition: Field3DFile.h:384
FieldMetadata< Field3DFileBase > & metadata()
accessor to the m_metadata class
Definition: Field3DFile.h:318
std::string attribute
Optional name of the attribute the field represents.
Definition: Field.h:178
Contains Field, WritableField and ResizableField classes.
Contains the ClassFactory class for registering Field3D classes.
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
struct used to pass the class and partition info back to the parseLayers() callback ...
Definition: Field3DFile.h:881
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...
Basic container for metedata.
void setIntMetadata(const std::string &name, const int val)
Set the a int value for the given metadata name.
Field_T< Data_T >::Vec readScalarLayersAs(const std::string &partitionName, const std::string &layerName) const
Retrieves a layers given their and its parent partition&#39;s name. Converts it to the given template typ...
Definition: Field3DFile.h:519
File::Partition::Ptr getPartition(const std::string &partitionName) const
Returns a pointer to the given partition.
Definition: Field3DFile.h:291
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:90
DataTypeEnum
Definition: Traits.h:66
FieldMapping::Ptr mapping
Pointer to the mapping object.
Definition: Field3DFile.h:203
hid_t m_file
The hdf5 id of the current file. Will be -1 if no file is open.
Definition: Field3DFile.h:387
GroupMembershipMap m_groupMembership
Keeps track of group membership for each layer of partition name. The key is the "group" and the valu...
Definition: Field3DFile.h:400
std::vector< File::Partition::Ptr > PartitionList
Definition: Field3DFile.h:343
Field3DInputFile * file
Definition: Field3DFile.h:883
Scoped object - opens a group on creation and closes it on destruction.
Definition: Hdf5Util.h:194
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...
virtual void metadataHasChanged(const std::string &)
This function should implemented by concrete classes to get the callback when metadata changes...
Definition: Field3DFile.h:327
std::string parent
The name of the parent partition. We need this in order to open its group.
Definition: Field3DFile.h:127
boost::intrusive_ptr< Field > Ptr
Definition: Field.h:400
FieldMapping::Ptr mapping()
Returns a pointer to the mapping.
Definition: Field.h:268
bool writeVectorLayer(const std::string &layerName, typename Field< FIELD3D_VEC3_T< Data_T > >::Ptr layer)
Writes a vector layer to the "Default" partition.
Definition: Field3DFile.h:798
std::string name
Optional name of the field.
Definition: Field.h:176
hid_t id() const
Query the hid_t value.
Definition: Hdf5Util.h:100