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
BaseFunctor
Definition: FunctionPointers.h:19
vtkADIOSReader::Controller
vtkMultiProcessController * Controller
Definition: vtkADIOSReader.h:160
vtkADIOSReader::RequestStep
double RequestStep
Definition: vtkADIOSReader.h:254
ADIOSDefs.h
vtkADIOSReader::BlockStepIndexIdMap
std::vector< std::map< std::string, size_t > > BlockStepIndexIdMap
Definition: vtkADIOSReader.h:166
vtkDataObjectAlgorithm::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkADIOSReader::Tree
vtkADIOSDirTree * Tree
Definition: vtkADIOSReader.h:158
ADIOS::ReadMethod_FlexPath
Definition: ADIOSDefs.h:55
vtkADIOSReader::SetReadMethodDIMES
void SetReadMethodDIMES()
Definition: vtkADIOSReader.h:91
vtkDataSetAttributes
represent and manipulate attribute data in a dataset
Definition: vtkDataSetAttributes.h:53
vtkX3D::data
Definition: vtkX3D.h:315
vtkInformationVector
Store zero or more vtkInformation instances.
Definition: vtkInformationVector.h:35
vtkADIOSReader::SetReadMethodBPAggregate
void SetReadMethodBPAggregate()
Definition: vtkADIOSReader.h:89
vtkDataObjectAlgorithm
Superclass for algorithms that produce only data object as output.
Definition: vtkDataObjectAlgorithm.h:43
vtkMultiProcessController.h
vtkADIOSReader::ReadMethodArguments
char * ReadMethodArguments
Definition: vtkADIOSReader.h:157
vtkX3D::dir
Definition: vtkX3D.h:324
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkDataObjectAlgorithm::FillOutputPortInformation
int FillOutputPortInformation(int port, vtkInformation *info) override
Fill the output port information objects for this algorithm.
vtkADIOSReader::RequestPiece
int RequestPiece
Definition: vtkADIOSReader.h:257
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:53
vtkADIOSReader::SetReadMethodFlexPath
void SetReadMethodFlexPath()
Definition: vtkADIOSReader.h:92
vtkDataObjectAlgorithm::RequestUpdateExtent
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
This is called by the superclass.
Definition: vtkDataObjectAlgorithm.h:115
vtkADIOSReader::TimeSteps
std::vector< double > TimeSteps
Definition: vtkADIOSReader.h:251
vtkMultiProcessController
Multiprocessing communication superclass.
Definition: vtkMultiProcessController.h:76
ADIOS::Reader
Definition: ADIOSReader.h:36
vtkADIOSDirTree
A directory tree structure holding ADIOS data.
Definition: vtkADIOSDirTree.h:35
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkADIOSReader::TimeStepsIndex
std::map< double, size_t > TimeStepsIndex
Definition: vtkADIOSReader.h:252
vtkSmartPointer.h
DECLARE_EXPLICIT
#define DECLARE_EXPLICIT(T)
Definition: vtkADIOSReader.h:264
vtkADIOSReader::ObjectCache
std::map< std::pair< int, size_t >, std::pair< int, vtkSmartPointer< vtkObject > > > ObjectCache
Definition: vtkADIOSReader.h:184
ADIOS::ReadMethod_BP
Definition: ADIOSDefs.h:51
vtkX3D::name
Definition: vtkX3D.h:219
vtkADIOSReader::RequestStepIndex
int RequestStepIndex
Definition: vtkADIOSReader.h:255
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:56
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:80
vtkX3D::info
Definition: vtkX3D.h:376
vtkX3D::string
Definition: vtkX3D.h:490
ADIOS::ReadMethod
ReadMethod
Definition: ADIOSDefs.h:49
vtkADIOSReader
Read ADIOS files.
Definition: vtkADIOSReader.h:59
ADIOS
Definition: ADIOSAttribute.h:27
ADIOS::VarInfo
Definition: ADIOSVarInfo.h:31
vtkDataObjectAlgorithm::ProcessRequest
int ProcessRequest(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
see vtkAlgorithm for details
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
vtkDataObjectAlgorithm::New
static vtkDataObjectAlgorithm * New()
vtkDataObjectAlgorithm::RequestData
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
Definition: vtkDataObjectAlgorithm.h:122
vtkUnstructuredGrid
dataset represents arbitrary combinations of all possible cell types
Definition: vtkUnstructuredGrid.h:81
vtkDataObjectAlgorithm.h
vtkADIOSReader::SetReadMethodDataSpaces
void SetReadMethodDataSpaces()
Definition: vtkADIOSReader.h:90
vtkADIOSReader::RequestNumberOfPieces
int RequestNumberOfPieces
Definition: vtkADIOSReader.h:256
ADIOS::ReadMethod_BP_AGGREGATE
Definition: ADIOSDefs.h:52
vtkADIOSReader::FileName
char * FileName
Definition: vtkADIOSReader.h:155
vtkDataObjectAlgorithm::RequestInformation
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
vtkDataObject
general representation of visualization data
Definition: vtkDataObject.h:58
vtkADIOSReader::ReadMethod
int ReadMethod
Definition: vtkADIOSReader.h:156
vtkADIOSReader::Reader
ADIOS::Reader * Reader
Definition: vtkADIOSReader.h:159
vtkADIOSReader::BlockStepIndex
std::vector< std::vector< std::vector< int > > > BlockStepIndex
Definition: vtkADIOSReader.h:178
ADIOS::ReadMethod_DataSpaces
Definition: ADIOSDefs.h:53
vtkADIOSReader::NumberOfPieces
int NumberOfPieces
Definition: vtkADIOSReader.h:250
vtkADIOSReader::PostReadOperations
std::queue< BaseFunctor * > PostReadOperations
Definition: vtkADIOSReader.h:209
vtkADIOSReader::SetReadMethodBP
void SetReadMethodBP()
Definition: vtkADIOSReader.h:88
ADIOS::ReadMethod_DIMES
Definition: ADIOSDefs.h:54