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 
100  void SetController(vtkMultiProcessController*);
101  vtkGetObjectMacro(Controller, vtkMultiProcessController);
103 
105 
109 
110 protected:
111 
113  bool OpenAndReadMetadata(void);
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);
134  void ReadObject(const vtkADIOSDirTree *dir, vtkDataSetAttributes* 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);
138  void ReadObject(const vtkADIOSDirTree *dir, vtkUnstructuredGrid* 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 
172  vtkADIOSReader();
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,
227  vtkInformationVector **input,
228  vtkInformationVector *output);
229  virtual int RequestUpdateExtent(vtkInformation *request,
230  vtkInformationVector **input,
231  vtkInformationVector *output);
232  virtual int RequestData(vtkInformation *request,
233  vtkInformationVector **input,
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
std::queue< BaseFunctor * > PostReadOperations
Store vtkAlgorithm input/output information.
#define DECLARE_EXPLICIT(T)
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
static vtkDataObjectAlgorithm * New()
std::map< std::pair< int, size_t >, std::pair< int, vtkSmartPointer< vtkObject > > > ObjectCache
void SetReadMethodBPAggregate()
void PrintSelf(ostream &os, vtkIndent indent)
Read ADIOS files.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
char * ReadMethodArguments
vtkADIOSDirTree * Tree
std::vector< std::vector< std::vector< int > > > BlockStepIndex
a simple class to control print indentation
Definition: vtkIndent.h:38
topologically and geometrically regular array of data
Definition: vtkImageData.h:44
dataset represents arbitrary combinations of all possible cell types
void SetReadMethodDataSpaces()
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
represent and manipulate attribute data in a dataset
void SetReadMethodFlexPath()
std::map< double, size_t > TimeStepsIndex
void SetReadMethodDIMES()
vtkMultiProcessController * Controller
A directory tree structure holding ADIOS data.
Superclass for algorithms that produce only data object as output.
object to represent cell connectivity
Definition: vtkCellArray.h:49
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
void SetReadMethodBP()
Store zero or more vtkInformation instances.
ADIOS::Reader * Reader
std::vector< double > TimeSteps
general representation of visualization data
Definition: vtkDataObject.h:64
virtual int FillOutputPortInformation(int port, vtkInformation *info)
represent and manipulate fields of data
Definition: vtkFieldData.h:55
Multiprocessing communication superclass.
std::vector< std::map< std::string, size_t > > BlockStepIndexIdMap