VTK
vtkADIOSReader.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkADIOSReader.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
24 #ifndef vtkADIOSReader_h
25 #define vtkADIOSReader_h
26 
27 #include <map> // For independently time stepped array indexing
28 #include <queue> // For post read operations
29 #include <string> // For variable name index mapping
30 #include <vector> // For independently time stepped array indexing
31 
32 #include "vtkDataObjectAlgorithm.h"
33 #include "vtkMultiProcessController.h" // For the MPI controller member
34 #include "vtkSetGet.h" // For property get/set macros
35 #include "vtkSmartPointer.h" // For the object cache
36 
37 #include "ADIOSDefs.h" // For enum definitions
38 
39 #include "vtkIOADIOSModule.h" // For export macro
40 
41 namespace ADIOS
42 {
43 class VarInfo;
44 class Reader;
45 }
46 class vtkADIOSDirTree;
47 class BaseFunctor;
48 
49 class vtkCellArray;
50 class vtkDataArray;
51 class vtkDataObject;
52 class vtkDataSet;
54 class vtkFieldData;
55 class vtkImageData;
56 class vtkPolyData;
58 
59 //----------------------------------------------------------------------------
60 
61 class VTKIOADIOS_EXPORT vtkADIOSReader : public vtkDataObjectAlgorithm
62 {
63 public:
64  static vtkADIOSReader* New(void);
66  virtual void PrintSelf(ostream& os, vtkIndent indent);
67 
70  int CanReadFile(const char* name);
71 
73 
74  vtkSetStringMacro(FileName);
75  vtkGetStringMacro(FileName);
77 
79 
80  vtkGetMacro(ReadMethod, int);
81  vtkSetClampMacro(ReadMethod, int,
82  static_cast<int>(ADIOS::ReadMethod_BP),
83  static_cast<int>(ADIOS::ReadMethod_FlexPath));
84  void SetReadMethodBP() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_BP)); }
85  void SetReadMethodBPAggregate() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_BP_AGGREGATE)); }
86  void SetReadMethodDataSpaces() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_DataSpaces)); }
87  void SetReadMethodDIMES() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_DIMES)); }
88  void SetReadMethodFlexPath() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_FlexPath)); }
90 
91 
93 
94  vtkSetStringMacro(ReadMethodArguments);
95  vtkGetStringMacro(ReadMethodArguments);
97 
99 
103 
105 
109 
110 protected:
111 
114 
116  void WaitForReads(void);
117 
119 
121  template<typename T>
122  T* ReadObject(const std::string& path, int blockId);
124 
126 
130  void ReadObject(const ADIOS::VarInfo* info, const vtkADIOSDirTree *subDir,
131  vtkDataArray* data, int blockId);
132  void ReadObject(const vtkADIOSDirTree *dir, vtkCellArray* data, int blockId);
133  void ReadObject(const vtkADIOSDirTree *dir, vtkFieldData* data, int blockId);
135  void ReadObject(const vtkADIOSDirTree *dir, vtkDataSet* data, int blockId);
136  void ReadObject(const vtkADIOSDirTree *dir, vtkImageData* data, int blockId);
137  void ReadObject(const vtkADIOSDirTree *dir, vtkPolyData* data, int blockId);
140 
141  char *FileName;
145  ADIOS::Reader *Reader;
147 
148  // Index information for independently stepped variables
149 
150  // Map variable names to thier position in the block step index
151  // [BlockId][VarName] = IndexId
152  std::vector<std::map<std::string, size_t> > BlockStepIndexIdMap;
153 
154  // [BlockId][GlobalStep][IndexId] = LocalStep
155  // Ex: The file has 30 steps, but the Variable "/Foo/Bar" in block 3 only
156  // has 2 steps, written out at global step 10 and global step 17. To
157  // lookup the local step for the variable at global time step 25:
158  //
159  // size_t idx = this->BlockStepIndexIdMap[3]["/Foo/Bar"];
160  // int localStep = this->BlockStepIndex[3][25][idx];
161  //
162  // At this point, localStep = 2, since at global step 25, local step 2 is the
163  // most recent version of "/Foo/Bar" available
164  std::vector<std::vector<std::vector<int> > > BlockStepIndex;
165 
166  // Cache the VTK objects as they are read
167  // Key = <BlockId, IndexId>, Value = <LocalStep, Object>
168  std::map<std::pair<int, size_t>,
169  std::pair<int, vtkSmartPointer<vtkObject> > >
171 
173  virtual ~vtkADIOSReader();
174 
175  /* The design of ADIOS is such that array IO is not directly performed
176  * upon request, but instead is scheduled to be performed later, at which
177  * time all IO operations are processed at once in bulk. This creates
178  * an odd situation for data management since arrays will be allocated with
179  * junk data and scheduled to be filled, but they cannot be safely assigned
180  * to a VTK object until the data contained in them is valid, e.g. through
181  * a call to vtkUnstructuredGrid::SetPoints or similar. Similary,
182  * they cannot have thier reference cound safely decremented until after
183  * they have been assigned to a vtk object. To work around this, a generic
184  * action queue is created to hold a list of arbitrary functions that need
185  * to be called in a particular order after the reads have been
186  * processed. The AddPostReadOperation prototypes use a large number of
187  * template parameters in order to permit the compiler to automatically
188  * perform the correct type deduction necessary to translate between
189  * member function signatures and the objects and arguments they get called
190  * with. This allows for arbitrary functions with arbitrary return types
191  * and arbitrary argument types to be collected into a single event queue
192  */
193 
194  // A set of operations to perform after reading is complete
195  std::queue<BaseFunctor*> PostReadOperations;
196 
197  // A set of shortcuts to allow automatic parameter deduction
198 
199  template<typename TObjectFun, typename TObjectData, typename TReturn>
200  void AddPostReadOperation(TObjectData*, TReturn (TObjectFun::*)());
201 
202  template<typename TObjectFun, typename TObjectData, typename TReturn,
203  typename TArg1Fun, typename TArg1Data>
204  void AddPostReadOperation(TObjectData*,
205  TReturn (TObjectFun::*)(TArg1Fun), TArg1Data);
206 
207  template<typename TObjectFun, typename TObjectData, typename TReturn,
208  typename TArg1Fun, typename TArg1Data,
209  typename TArg2Fun, typename TArg2Data>
210  void AddPostReadOperation(TObjectData*,
211  TReturn (TObjectFun::*)(TArg1Fun, TArg2Fun),
212  TArg1Data, TArg2Data);
213 
214  template<typename TObjectFun, typename TObjectData, typename TReturn,
215  typename TArg1Fun, typename TArg1Data,
216  typename TArg2Fun, typename TArg2Data,
217  typename TArg3Fun, typename TArg3Data>
218  void AddPostReadOperation(TObjectData*,
219  TReturn (TObjectFun::*)(TArg1Fun, TArg2Fun, TArg3Fun),
220  TArg1Data, TArg2Data, TArg3Data);
221 
222  // Used to implement vtkAlgorithm
223 
225 
226  virtual int RequestInformation(vtkInformation *request,
228  vtkInformationVector *output);
229  virtual int RequestUpdateExtent(vtkInformation *request,
231  vtkInformationVector *output);
232  virtual int RequestData(vtkInformation *request,
234  vtkInformationVector *output);
235 
237  std::vector<double> TimeSteps;
238  std::map<double, size_t> TimeStepsIndex;
239 
240  double RequestStep;
244 
245 private:
246  vtkADIOSReader(const vtkADIOSReader&); // Not implemented.
247  void operator=(const vtkADIOSReader&); // Not implemented.
248 };
249 
250 #define DECLARE_EXPLICIT(T) \
251 template<> T* vtkADIOSReader::ReadObject<T>(const std::string& path, \
252  int blockId);
256 #undef DECLARE_EXPLICIT
257 
258 #endif
vtkADIOSReader::RequestUpdateExtent
virtual int RequestUpdateExtent(vtkInformation *request, vtkInformationVector **input, vtkInformationVector *output)
vtkADIOSReader::Controller
vtkMultiProcessController * Controller
Definition: vtkADIOSReader.h:146
vtkgl::data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: vtkgl.h:11339
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkADIOSReader::RequestStep
double RequestStep
Definition: vtkADIOSReader.h:240
vtkADIOSReader::ProcessRequest
virtual int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
vtkADIOSReader::BlockStepIndexIdMap
std::vector< std::map< std::string, size_t > > BlockStepIndexIdMap
Definition: vtkADIOSReader.h:152
vtkADIOSReader::Tree
vtkADIOSDirTree * Tree
Definition: vtkADIOSReader.h:144
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkCellArray *data, int blockId)
vtkADIOSReader::SetReadMethodDIMES
void SetReadMethodDIMES()
Definition: vtkADIOSReader.h:87
vtkADIOSReader::RequestInformation
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **input, vtkInformationVector *output)
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:58
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:41
vtkADIOSReader::SetReadMethodBPAggregate
void SetReadMethodBPAggregate()
Definition: vtkADIOSReader.h:85
vtkDataObjectAlgorithm
Superclass for algorithms that produce only data object as output.
Definition: vtkDataObjectAlgorithm.h:43
vtkMultiProcessController.h
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkSetGet.h
vtkADIOSReader::ReadMethodArguments
char * ReadMethodArguments
Definition: vtkADIOSReader.h:143
vtkX3D::dir
@ dir
Definition: vtkX3D.h:324
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkADIOSReader::vtkADIOSReader
vtkADIOSReader()
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkPolyData *data, int blockId)
vtkgl::input
GLenum GLenum GLenum input
Definition: vtkgl.h:15941
vtkADIOSReader::RequestPiece
int RequestPiece
Definition: vtkADIOSReader.h:243
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkUnstructuredGrid *data, int blockId)
vtkADIOSReader::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkDataSetAttributes *data, int blockId)
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkFieldData *data, int blockId)
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkImageData *data, int blockId)
vtkADIOSReader::~vtkADIOSReader
virtual ~vtkADIOSReader()
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:56
vtkADIOSReader::ReadObject
void ReadObject(const ADIOS::VarInfo *info, const vtkADIOSDirTree *subDir, vtkDataArray *data, int blockId)
vtkSetClampMacro
#define vtkSetClampMacro(name, type, min, max)
Definition: vtkSetGet.h:143
vtkADIOSReader::SetReadMethodFlexPath
void SetReadMethodFlexPath()
Definition: vtkADIOSReader.h:88
vtkgl::name
GLuint const GLchar * name
Definition: vtkgl.h:11983
vtkADIOSReader::TimeSteps
std::vector< double > TimeSteps
Definition: vtkADIOSReader.h:237
vtkADIOSReader::RequestData
virtual int RequestData(vtkInformation *request, vtkInformationVector **input, vtkInformationVector *output)
vtkADIOSReader::WaitForReads
void WaitForReads(void)
vtkADIOSReader::ReadObject
T * ReadObject(const std::string &path, int blockId)
vtkMultiProcessController
Multiprocessing communication superclass.
Definition: vtkMultiProcessController.h:85
vtkADIOSDirTree
A directory tree structure holding ADIOS data.
Definition: vtkADIOSDirTree.h:33
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkADIOSReader::SetController
void SetController(vtkMultiProcessController *)
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:50
vtkSetStringMacro
#define vtkSetStringMacro(name)
Definition: vtkSetGet.h:104
vtkADIOSReader::TimeStepsIndex
std::map< double, size_t > TimeStepsIndex
Definition: vtkADIOSReader.h:238
vtkSmartPointer.h
vtkgl::path
GLsizei const GLchar ** path
Definition: vtkgl.h:13835
vtkADIOSReader::AddPostReadOperation
void AddPostReadOperation(TObjectData *, TReturn(TObjectFun::*)(TArg1Fun, TArg2Fun), TArg1Data, TArg2Data)
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
DECLARE_EXPLICIT
#define DECLARE_EXPLICIT(T)
Definition: vtkADIOSReader.h:250
vtkADIOSReader::AddPostReadOperation
void AddPostReadOperation(TObjectData *, TReturn(TObjectFun::*)(TArg1Fun), TArg1Data)
vtkGetStringMacro
vtkGetStringMacro(ExtensionsString)
vtkADIOSReader::ObjectCache
std::map< std::pair< int, size_t >, std::pair< int, vtkSmartPointer< vtkObject > > > ObjectCache
Definition: vtkADIOSReader.h:170
vtkADIOSReader::RequestStepIndex
int RequestStepIndex
Definition: vtkADIOSReader.h:241
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:86
vtkX3D::info
@ info
Definition: vtkX3D.h:376
vtkADIOSReader::ReadObject
void ReadObject(const vtkADIOSDirTree *dir, vtkDataSet *data, int blockId)
vtkADIOSReader::AddPostReadOperation
void AddPostReadOperation(TObjectData *, TReturn(TObjectFun::*)())
vtkADIOSReader
Read ADIOS files.
Definition: vtkADIOSReader.h:62
ADIOS
Definition: vtkADIOSReader.h:42
vtkADIOSReader::New
static vtkADIOSReader * New(void)
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
vtkADIOSReader::CanReadFile
int CanReadFile(const char *name)
vtkADIOSReader::FillOutputPortInformation
int FillOutputPortInformation(int, vtkInformation *)
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:82
vtkDataObjectAlgorithm.h
vtkADIOSReader::SetReadMethodDataSpaces
void SetReadMethodDataSpaces()
Definition: vtkADIOSReader.h:86
vtkADIOSReader::RequestNumberOfPieces
int RequestNumberOfPieces
Definition: vtkADIOSReader.h:242
vtkADIOSReader::OpenAndReadMetadata
bool OpenAndReadMetadata(void)
vtkADIOSReader::FileName
char * FileName
Definition: vtkADIOSReader.h:141
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:65
vtkADIOSReader::ReadMethod
int ReadMethod
Definition: vtkADIOSReader.h:142
vtkADIOSReader::Reader
ADIOS::Reader * Reader
Definition: vtkADIOSReader.h:145
vtkADIOSReader::BlockStepIndex
std::vector< std::vector< std::vector< int > > > BlockStepIndex
Definition: vtkADIOSReader.h:164
vtkgl::string
GLsizei const GLchar ** string
Definition: vtkgl.h:12011
vtkADIOSReader::NumberOfPieces
int NumberOfPieces
Definition: vtkADIOSReader.h:236
vtkADIOSReader::PostReadOperations
std::queue< BaseFunctor * > PostReadOperations
Definition: vtkADIOSReader.h:195
vtkADIOSReader::AddPostReadOperation
void AddPostReadOperation(TObjectData *, TReturn(TObjectFun::*)(TArg1Fun, TArg2Fun, TArg3Fun), TArg1Data, TArg2Data, TArg3Data)
vtkADIOSReader::SetReadMethodBP
void SetReadMethodBP()
Definition: vtkADIOSReader.h:84