OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FileFieldDataSource.hpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 // include files
29 #include "Utility/DiscField.h"
30 #include "Message/Communicate.h"
31 #include "Utility/IpplInfo.h"
32 
33 
35 // constructor: the name, the connection, the transfer method,
36 // the field to connect, and the parent node.
37 template<class T, unsigned Dim, class M, class C>
39  DataConnect *dc,
40  int tm,
42  : DataSourceObject(nm,&F,dc,tm), DF(0), myField(F), FieldID(0), counter(0) {
43 
44 
45 
46 
47  std::string filestring = "file";
48  if (std::string(dc->DSID()) != filestring) {
49  ERRORMSG("Illegal DataConnect object for FILE Data Object." << endl);
50  Connection = 0;
51  } else if (tm != DataSource::OUTPUT && tm != DataSource::INPUT) {
52  ERRORMSG("FILE connections may only be of type INPUT or OUTPUT." << endl);
53  Connection = 0;
54  } else {
55  // find which DiscField to use ... first look for one in the DataConnect
56  FieldID = dc->size();
57  FileDataConnect *fdc = (FileDataConnect *)dc;
58  if (dc->size() == 0) {
59  // this is the first field in the FileDataConnect, so make a new
60  // DiscField
62  DF = new DiscField<Dim>(nm, dc->name(), fdc->getNumObjects(),
63  fdc->getTypeString());
64  else
65  DF = new DiscField<Dim>(nm, dc->name());
66  }
67  else {
68  // use the DiscField in the first DataSource
69  DataSourceObject *dso = (*(dc->begin()))->findDataSourceObject(dc);
70  if (dso == 0) {
71  ERRORMSG("Could not find proper DiscField while connecting " << nm << endl);
72  }
73  else {
74  DF = ((FileFieldDataSource<T,Dim,M,C> *)dso)->DF;
75  }
76  }
77  }
78 }
79 
80 
82 // destructor
83 template<class T, unsigned Dim, class M, class C>
85 
86 
87 
88  if (DF != 0 && getConnection()->size() == 0)
89  delete DF;
90 }
91 
92 
94 // Update the object, that is, make sure the receiver of the data has a
95 // current and consistent snapshot of the current stat dc->name()e. Return success.
96 template<class T, unsigned Dim, class M, class C>
98 
99 
100 
101  if (TransferMethod == DataSource::OUTPUT)
102  DF->write(myField, FieldID);
103  else if (TransferMethod == DataSource::INPUT)
104  DF->read(myField, FieldID, counter++);
105  return true;
106 }
107 
108 
110 // Indicate to the receiver that we're allowing the FieldDisc time to
111 // manipulate the data (e.g., for a viz program, to rotate it, change
112 // representation, etc.).
113 // This should only return when the manipulation is done.
114 template<class T, unsigned Dim, class M, class C>
116 
117 
118 /***************************************************************************
119  * $RCSfile: FileFieldDataSource.cpp,v $ $Author: adelmann $
120  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
121  * IPPL_VERSION_ID: $Id: FileFieldDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
122  ***************************************************************************/
iterator begin()
Definition: DataConnect.h:71
#define ERRORMSG(msg)
Definition: IpplInfo.h:399
const char * name() const
Definition: NamedObj.h:35
DataConnect * Connection
const char * DSID() const
Definition: DataConnect.h:55
const char * getTypeString() const
DiscField< Dim > * DF
unsigned int size() const
Definition: DataConnect.h:82
FileFieldDataSource(const char *, DataConnect *, int, Field< T, Dim, M, C > &)
virtual void interact(const char *=0)
unsigned int getNumObjects() const
Inform & endl(Inform &inf)
Definition: Inform.cpp:42