Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/DataSource/FileFieldDataSource.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files 
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 // constructor: the name, the connection, the transfer method,
00038 // the field to connect, and the parent node.
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     // find which DiscField to use ... first look for one in the DataConnect
00058     FieldID = dc->size();
00059     FileDataConnect *fdc = (FileDataConnect *)dc;
00060     if (dc->size() == 0) {
00061       // this is the first field in the FileDataConnect, so make a new
00062       // DiscField
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       // use the DiscField in the first DataSource
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 // destructor
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 // Update the object, that is, make sure the receiver of the data has a
00097 // current and consistent snapshot of the current stat dc->name()e.  Return success.
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 // Indicate to the receiver that we're allowing the FieldDisc time to
00113 // manipulate the data (e.g., for a viz program, to rotate it, change
00114 // representation, etc.).
00115 // This should only return when the manipulation is done.
00116 template<class T, unsigned Dim, class M, class C>
00117 void FileFieldDataSource<T,Dim,M,C>::interact(const char *) {}
00118 
00119 
00120 /***************************************************************************
00121  * $RCSfile: FileFieldDataSource.cpp,v $   $Author: adelmann $
00122  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:25 $
00123  * IPPL_VERSION_ID: $Id: FileFieldDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $ 
00124  ***************************************************************************/

Generated on Fri Nov 2 01:25:55 2007 for IPPL by doxygen 1.3.5