00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "DataSource/FileFieldDataSource.h"
00028 #include "DataSource/FileDataConnect.h"
00029 #include "Utility/DiscField.h"
00030 #include "Message/Communicate.h"
00031 #include "Utility/IpplInfo.h"
00032 #include "Utility/Pstring.h"
00033 #include "Profile/Profiler.h"
00034
00035
00037
00038
00039 template<class T, unsigned Dim, class M, class C>
00040 FileFieldDataSource<T,Dim,M,C>::FileFieldDataSource(const char *nm,
00041 DataConnect *dc,
00042 int tm,
00043 Field<T,Dim,M,C>& F)
00044 : DataSourceObject(nm,&F,dc,tm), myField(F), DF(0), counter(0), FieldID(0) {
00045
00046 TAU_TYPE_STRING(taustr, "void (char *, DataConnect *, int, " + CT(F) + " )");
00047 TAU_PROFILE("FileFieldDataSource::FileFieldDataSource()", taustr, TAU_VIZ);
00048
00049 string filestring = "file";
00050 if (string(dc->ID()) != filestring) {
00051 ERRORMSG("Illegal DataConnect object for FILE Data Object." << endl);
00052 Connection = 0;
00053 } else if (tm != DataSource::OUTPUT && tm != DataSource::INPUT) {
00054 ERRORMSG("FILE connections may only be of type INPUT or OUTPUT." << endl);
00055 Connection = 0;
00056 } else {
00057
00058 FieldID = dc->size();
00059 FileDataConnect *fdc = (FileDataConnect *)dc;
00060 if (dc->size() == 0) {
00061
00062
00063 if (TransferMethod == DataSource::OUTPUT)
00064 DF = new DiscField<Dim>(nm, dc->name(), fdc->getNumObjects(),
00065 fdc->getTypeString());
00066 else
00067 DF = new DiscField<Dim>(nm, dc->name());
00068 }
00069 else {
00070
00071 DataSourceObject *dso = (*(dc->begin()))->findDataSourceObject(dc);
00072 if (dso == 0) {
00073 ERRORMSG("Could not find proper DiscField while connecting " << nm << endl);
00074 }
00075 else {
00076 DF = ((FileFieldDataSource<T,Dim,M,C> *)dso)->DF;
00077 }
00078 }
00079 }
00080 }
00081
00082
00084
00085 template<class T, unsigned Dim, class M, class C>
00086 FileFieldDataSource<T,Dim,M,C>::~FileFieldDataSource() {
00087 TAU_TYPE_STRING(taustr, CT(*this) + " void ()" );
00088 TAU_PROFILE("FileFieldDataSource::~FileFieldDataSource()", taustr, TAU_VIZ);
00089
00090 if (DF != 0 && getConnection()->size() == 0)
00091 delete DF;
00092 }
00093
00094
00096
00097
00098 template<class T, unsigned Dim, class M, class C>
00099 bool FileFieldDataSource<T,Dim,M,C>::update() {
00100 TAU_TYPE_STRING(taustr, CT(*this) + " void ()" );
00101 TAU_PROFILE("FileFieldDataSource::update()", taustr, TAU_VIZ);
00102
00103 if (TransferMethod == DataSource::OUTPUT)
00104 DF->write(myField, FieldID);
00105 else if (TransferMethod == DataSource::INPUT)
00106 DF->read(myField, FieldID, counter++);
00107 return true;
00108 }
00109
00110
00112
00113
00114
00115
00116 template<class T, unsigned Dim, class M, class C>
00117 void FileFieldDataSource<T,Dim,M,C>::interact(const char *) {}
00118
00119
00120
00121
00122
00123
00124