OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
FilePtclBaseDataSource.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/DiscParticle.h"
30 #include "Utility/IpplInfo.h"
31 
33 // constructor: the name, the connection, the transfer method,
34 // the particlebase to connect
35 template<class T>
37  DataConnect *dc,
38  int tm,
40  : DataSourceObject(nm,&P,dc,tm), DP(0), MyParticles(P), counter(0) {
41 
42  std::string filestring = "file";
43  if (std::string(dc->DSID()) != filestring) {
44  ERRORMSG("Illegal DataConnect object for FILE Data Object." << endl);
45  Connection = 0;
46  } else if (tm != DataSource::OUTPUT && tm != DataSource::INPUT) {
47  ERRORMSG("FILE connections may only be of type INPUT or OUTPUT." << endl);
48  Connection = 0;
49  } else {
50  FileDataConnect *fdc = (FileDataConnect *)dc;
51  int dptm = (TransferMethod == DataSource::OUTPUT ?
53  DP = new DiscParticle(nm, dc->name(), dptm, fdc->getTypeString());
54  }
55 }
56 
57 
59 // destructor
60 template<class T>
62 
63  if (DP != 0)
64  delete DP;
65 }
66 
67 
69 // Update the object, that is, make sure the receiver of the data has a
70 // current and consistent snapshot of the current state. Return success.
71 template<class T>
73 
74  if (TransferMethod == DataSource::OUTPUT)
75  return DP->write(MyParticles);
76  else if (TransferMethod == DataSource::INPUT)
77  return DP->read(MyParticles, counter++);
78  else
79  return false;
80 }
81 
82 
84 // Indicate to the receiver that we're allowing the connection time to
85 // manipulate the data (e.g., for a viz program, to rotate it, change
86 // representation, etc.).
87 // This should only return when the manipulation is done.
88 template<class T>
90 
91 
92 /***************************************************************************
93  * $RCSfile: FilePtclBaseDataSource.cpp,v $ $Author: adelmann $
94  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
95  * IPPL_VERSION_ID: $Id: FilePtclBaseDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
96  ***************************************************************************/
#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
FileIpplParticleBaseDataSource(const char *, DataConnect *, int, IpplParticleBase< T > &)
virtual void interact(const char *=0)
Inform & endl(Inform &inf)
Definition: Inform.cpp:42