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 =========================================================================*/
22 #ifndef vtkADIOSReader_h
23 #define vtkADIOSReader_h
24 
25 #include <map> // For independently time stepped array indexing
26 #include <queue> // For post read operations
27 #include <string> // For variable name index mapping
28 #include <vector> // For independently time stepped array indexing
29 
30 #include "vtkDataObjectAlgorithm.h"
31 #include "vtkMultiProcessController.h" // For the MPI controller member
32 #include "vtkSetGet.h" // For property get/set macros
33 #include "vtkSmartPointer.h" // For the object cache
34 
35 #include "ADIOSDefs.h" // For enum definitions
36 
37 #include "vtkIOADIOSModule.h" // For export macro
38 
39 namespace ADIOS
40 {
41 class VarInfo;
42 class Reader;
43 }
44 class vtkADIOSDirTree;
45 class BaseFunctor;
46 
47 class vtkCellArray;
48 class vtkDataArray;
49 class vtkDataObject;
50 class vtkDataSet;
52 class vtkFieldData;
53 class vtkImageData;
54 class vtkPolyData;
56 
57 //----------------------------------------------------------------------------
58 
59 class VTKIOADIOS_EXPORT vtkADIOSReader : public vtkDataObjectAlgorithm
60 {
61 public:
62  static vtkADIOSReader* New(void);
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65 
70  int CanReadFile(const char* name);
71 
73 
76  vtkSetStringMacro(FileName);
77  vtkGetStringMacro(FileName);
79 
81 
84  vtkGetMacro(ReadMethod, int);
85  vtkSetClampMacro(ReadMethod, int,
86  static_cast<int>(ADIOS::ReadMethod_BP),
87  static_cast<int>(ADIOS::ReadMethod_FlexPath));
88  void SetReadMethodBP() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_BP)); }
89  void SetReadMethodBPAggregate() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_BP_AGGREGATE)); }
90  void SetReadMethodDataSpaces() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_DataSpaces)); }
91  void SetReadMethodDIMES() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_DIMES)); }
92  void SetReadMethodFlexPath() { this->SetReadMethod(static_cast<int>(ADIOS::ReadMethod_FlexPath)); }
94 
95 
97 
100  vtkSetStringMacro(ReadMethodArguments);
101  vtkGetStringMacro(ReadMethodArguments);
103 
105 
108  void SetController(vtkMultiProcessController*);
109  vtkGetObjectMacro(Controller, vtkMultiProcessController);
111 
117 
118 protected:
119 
123  bool OpenAndReadMetadata(void);
124 
128  void WaitForReads(void);
129 
134  template<typename T>
135  T* ReadObject(const std::string& path, int blockId);
136 
138 
144  void ReadObject(const ADIOS::VarInfo* info, const vtkADIOSDirTree *subDir,
145  vtkDataArray* data, int blockId);
146  void ReadObject(const vtkADIOSDirTree *dir, vtkCellArray* data, int blockId);
147  void ReadObject(const vtkADIOSDirTree *dir, vtkFieldData* data, int blockId);
148  void ReadObject(const vtkADIOSDirTree *dir, vtkDataSetAttributes* data, int blockId);
149  void ReadObject(const vtkADIOSDirTree *dir, vtkDataSet* data, int blockId);
150  void ReadObject(const vtkADIOSDirTree *dir, vtkImageData* data, int blockId);
151  void ReadObject(const vtkADIOSDirTree *dir, vtkPolyData* data, int blockId);
152  void ReadObject(const vtkADIOSDirTree *dir, vtkUnstructuredGrid* data, int blockId);
154 
155  char *FileName;
161 
162  // Index information for independently stepped variables
163 
164  // Map variable names to their position in the block step index
165  // [BlockId][VarName] = IndexId
166  std::vector<std::map<std::string, size_t> > BlockStepIndexIdMap;
167 
168  // [BlockId][GlobalStep][IndexId] = LocalStep
169  // Ex: The file has 30 steps, but the Variable "/Foo/Bar" in block 3 only
170  // has 2 steps, written out at global step 10 and global step 17. To
171  // lookup the local step for the variable at global time step 25:
172  //
173  // size_t idx = this->BlockStepIndexIdMap[3]["/Foo/Bar"];
174  // int localStep = this->BlockStepIndex[3][25][idx];
175  //
176  // At this point, localStep = 2, since at global step 25, local step 2 is the
177  // most recent version of "/Foo/Bar" available
178  std::vector<std::vector<std::vector<int> > > BlockStepIndex;
179 
180  // Cache the VTK objects as they are read
181  // Key = <BlockId, IndexId>, Value = <LocalStep, Object>
182  std::map<std::pair<int, size_t>,
183  std::pair<int, vtkSmartPointer<vtkObject> > >
185 
186  vtkADIOSReader();
187  virtual ~vtkADIOSReader();
188 
189  /* The design of ADIOS is such that array IO is not directly performed
190  * upon request, but instead is scheduled to be performed later, at which
191  * time all IO operations are processed at once in bulk. This creates
192  * an odd situation for data management since arrays will be allocated with
193  * junk data and scheduled to be filled, but they cannot be safely assigned
194  * to a VTK object until the data contained in them is valid, e.g. through
195  * a call to vtkUnstructuredGrid::SetPoints or similar. Similarly,
196  * they cannot have their reference could safely decremented until after
197  * they have been assigned to a vtk object. To work around this, a generic
198  * action queue is created to hold a list of arbitrary functions that need
199  * to be called in a particular order after the reads have been
200  * processed. The AddPostReadOperation prototypes use a large number of
201  * template parameters in order to permit the compiler to automatically
202  * perform the correct type deduction necessary to translate between
203  * member function signatures and the objects and arguments they get called
204  * with. This allows for arbitrary functions with arbitrary return types
205  * and arbitrary argument types to be collected into a single event queue
206  */
207 
208  // A set of operations to perform after reading is complete
209  std::queue<BaseFunctor*> PostReadOperations;
210 
211  // A set of shortcuts to allow automatic parameter deduction
212 
213  template<typename TObjectFun, typename TObjectData, typename TReturn>
214  void AddPostReadOperation(TObjectData*, TReturn (TObjectFun::*)());
215 
216  template<typename TObjectFun, typename TObjectData, typename TReturn,
217  typename TArg1Fun, typename TArg1Data>
218  void AddPostReadOperation(TObjectData*,
219  TReturn (TObjectFun::*)(TArg1Fun), TArg1Data);
220 
221  template<typename TObjectFun, typename TObjectData, typename TReturn,
222  typename TArg1Fun, typename TArg1Data,
223  typename TArg2Fun, typename TArg2Data>
224  void AddPostReadOperation(TObjectData*,
225  TReturn (TObjectFun::*)(TArg1Fun, TArg2Fun),
226  TArg1Data, TArg2Data);
227 
228  template<typename TObjectFun, typename TObjectData, typename TReturn,
229  typename TArg1Fun, typename TArg1Data,
230  typename TArg2Fun, typename TArg2Data,
231  typename TArg3Fun, typename TArg3Data>
232  void AddPostReadOperation(TObjectData*,
233  TReturn (TObjectFun::*)(TArg1Fun, TArg2Fun, TArg3Fun),
234  TArg1Data, TArg2Data, TArg3Data);
235 
236  // Used to implement vtkAlgorithm
237 
239 
240  virtual int RequestInformation(vtkInformation *request,
241  vtkInformationVector **input,
242  vtkInformationVector *output);
243  virtual int RequestUpdateExtent(vtkInformation *request,
244  vtkInformationVector **input,
245  vtkInformationVector *output);
246  virtual int RequestData(vtkInformation *request,
247  vtkInformationVector **input,
248  vtkInformationVector *output);
249 
251  std::vector<double> TimeSteps;
252  std::map<double, size_t> TimeStepsIndex;
253 
254  double RequestStep;
258 
259 private:
260  vtkADIOSReader(const vtkADIOSReader&) = delete;
261  void operator=(const vtkADIOSReader&) = delete;
262 };
263 
264 #define DECLARE_EXPLICIT(T) \
265 template<> T* vtkADIOSReader::ReadObject<T>(const std::string& path, \
266  int blockId);
270 #undef DECLARE_EXPLICIT
271 
272 #endif
std::queue< BaseFunctor * > PostReadOperations
Store vtkAlgorithm input/output information.
#define DECLARE_EXPLICIT(T)
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
static vtkDataObjectAlgorithm * New()
std::map< std::pair< int, size_t >, std::pair< int, vtkSmartPointer< vtkObject > > > ObjectCache
void SetReadMethodBPAggregate()
Get/Set the ADIOS read method.
Read ADIOS files.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
char * ReadMethodArguments
ReadMethod
Definition: ADIOSDefs.h:49
int FillOutputPortInformation(int port, vtkInformation *info) override
Fill the output port information objects for this algorithm.
vtkADIOSDirTree * Tree
std::vector< std::vector< std::vector< int > > > BlockStepIndex
a simple class to control print indentation
Definition: vtkIndent.h:33
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
see vtkAlgorithm for details
dataset represents arbitrary combinations of all possible cell types
void SetReadMethodDataSpaces()
Get/Set the ADIOS read method.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
represent and manipulate attribute data in a dataset
void SetReadMethodFlexPath()
Get/Set the ADIOS read method.
std::map< double, size_t > TimeStepsIndex
void SetReadMethodDIMES()
Get/Set the ADIOS read method.
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:44
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
void SetReadMethodBP()
Get/Set the ADIOS read method.
Store zero or more vtkInformation instances.
ADIOS::Reader * Reader
std::vector< double > TimeSteps
general representation of visualization data
Definition: vtkDataObject.h:58
represent and manipulate fields of data
Definition: vtkFieldData.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Multiprocessing communication superclass.
std::vector< std::map< std::string, size_t > > BlockStepIndexIdMap