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

src/DataSource/ACLVISPtclAttribDataSource.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/ACLVISPtclAttribDataSource.h"
00028 #include "DataSource/ACLVISOperations.h"
00029 #include "Particle/ParticleAttrib.h"
00030 #include "Particle/ParticleLayout.h"
00031 #include "Message/Message.h"
00032 #include "Utility/IpplInfo.h"
00033 #include "Utility/Pstring.h"
00034 #include "Profile/Profiler.h"
00035 
00036 
00038 // constructor: the name, the connection, the transfer method, the attrib
00039 template<class T>
00040 ACLVISParticleAttribDataSource<T>::ACLVISParticleAttribDataSource(const
00041                                                                   char *nm,
00042       DataConnect *dc, int tm, ParticleAttrib<T>& pa)
00043   : ParticleAttribDataSource(nm, dc, tm, &pa, &pa), MyParticles(pa) {
00044 
00045   TAU_TYPE_STRING(taustr, "void (char *, DataConnect *, int, " +
00046                   CT(pa));
00047   TAU_PROFILE(
00048     "ACLVISParticleAttribDataSource::ACLVISParticleAttribDataSource()",
00049     taustr, TAU_VIZ);
00050 
00051   // do general initialization
00052   LocalData = 0;
00053   string filestring = "aclvis";
00054   if (string(dc->ID()) != filestring) {
00055     ERRORMSG("Illegal DataConnect object for ACLVIS Data Object." << endl);
00056     Connection = 0;
00057   } else if (tm != DataSource::OUTPUT) {
00058     ERRORMSG("ACLVIS data connections may only be of type OUTPUT." << endl);
00059     Connection = 0;
00060   } else {    
00061     // check if our ParticleBase container has been connected already ...
00062     if (PBase != 0) {
00063       // yes it has ... set up our ACLVIS info.
00064       // make a Tool object to store the data on the parent node
00065       // We do not need to register this with the ACLVIS API, as this is
00066       // done by the ACLVISParticleBaseDataSource
00067       if (getConnection()->onConnectNode())
00068         LocalData = new ReadParticleTool;
00069 
00070       // tell the PBase we're connected ... we had to wait until now to do
00071       // this, because we had to have the ReadParticleTool object available
00072       PBase->connect_attrib(this);
00073 
00074     } else {
00075       // no luck; indicate we did not get connected
00076       Connection = 0;
00077     }
00078   }
00079 }
00080 
00081 
00083 // destructor
00084 template<class T>
00085 ACLVISParticleAttribDataSource<T>::~ACLVISParticleAttribDataSource() {
00086 
00087   TAU_TYPE_STRING(taustr, CT(*this) + " void ()");
00088   TAU_PROFILE("ACLVISParticleAttribDataSource::~ACLVISParticleAttribDataSource()", 
00089     taustr, TAU_VIZ);
00090 
00091   // disassociate ourselves from the ParticleBase container
00092   if (PBase != 0)
00093     PBase->disconnect_attrib(this);
00094 
00095   // delete local storage
00096   if (LocalData != 0)
00097     delete LocalData;
00098 }
00099 
00100 
00102 // Update the object, that is, make sure the receiver of the data has a
00103 // current and consistent snapshot of the current state.  Return success.
00104 // In fact, this version of update does nothing.  Only the update for
00105 // particlebase actually does any work.  This version will just silently
00106 // return (since it may be called if updateConnections is called for the
00107 // DataConnect object).
00108 template<class T>
00109 bool ACLVISParticleAttribDataSource<T>::update() {
00110   TAU_TYPE_STRING(taustr, CT(*this) + " bool ()");
00111   TAU_PROFILE("ACLVISParticleAttribDataSource::update()", taustr, TAU_VIZ);
00112 
00113   // just return, the user should do an update for the ParticleBase
00114   return true;
00115 }
00116 
00117 
00119 // Indicate to the receiver that we're allowing them time to manipulate the
00120 // data (e.g., for a viz program, to rotate it, change representation, etc.)
00121 // This should only return when the manipulation is done.
00122 template<class T>
00123 void ACLVISParticleAttribDataSource<T>::interact(const char *str) {
00124   TAU_TYPE_STRING(taustr, CT(*this) + " void ()");
00125   TAU_PROFILE("ACLVISParticleAttribDataSource::interact()", taustr, TAU_VIZ);
00126 
00127   // hand off control to ACLVIS API
00128   if (PBase != 0)
00129     PBase->interact(str);
00130 }
00131 
00132 
00134 // put the local particle data into a message
00135 template<class T>
00136 void ACLVISParticleAttribDataSource<T>::putMessage(Message *msg) {
00137 
00138   TAU_TYPE_STRING(taustr, CT(*this) + " void (Message *)");
00139   TAU_PROFILE("ACLVISParticleAttribDataSource::putMessage()", taustr, TAU_VIZ);
00140 
00141   unsigned N = MyParticles.size();
00142 
00143   //  Inform dbgmsg("attrib_putmessage", INFORM_ALL_NODES);
00144   //  dbgmsg << "Putting ParticleAttrib's in message: num = " << N << endl;
00145 
00146   // put in the data
00147   if (N > 0) {
00148     // WARNMSG("ACLVIS putMessage: on node " << Ippl::myNode() << ", N = ");
00149     // WARNMSG(N << endl);
00150     MyParticles.putMessage(*msg, N, 0);
00151     // WARNMSG("Message now: " << *msg << endl);
00152   }
00153 }
00154 
00155 
00157 // prepare the agency-specific data structures for update; this may
00158 // require reallocation of storage memory, etc.
00159 // Argument = are we at the start (true) or end (false) of the data update;
00160 //            # of particles to prepare for.
00161 template<class T>
00162 void ACLVISParticleAttribDataSource<T>::prepare_data(bool start, unsigned N) {
00163   TAU_TYPE_STRING(taustr, CT(*this) + " void (bool, unsigned)");
00164   TAU_PROFILE("ACLVISParticleAttribDataSource::prepare_data()", taustr, TAU_VIZ);
00165 
00166   if (start) {
00167     // reallocate new storage for the attribute and coordinate data
00168     LocalData->GetVizData()->InitData(N,
00169               ACLVISTraits<ReadParticleTool,T>::getType(), 1);
00170   } else {
00171     // tell data storage objects that we're done adding data for this step
00172     LocalData->PrepareFinishedData();
00173   }
00174 }
00175 
00176 
00178 // copy the data out of the given Message and into the proper vtk structure.
00179 // If Message is 0, just put in the data from our local particles.
00180 // Arguments: num particles, starting index for inserted particles,
00181 // Message with data, total number of particles in entire system,
00182 // iterators for position and ID data.
00183 template<class T>
00184 void ACLVISParticleAttribDataSource<T>::insert_data(unsigned N,unsigned sIndx,
00185                                                     Message* msg) {
00186   TAU_TYPE_STRING(taustr, CT(*this) + " void (unsigned, unsigned, Message *)");
00187   TAU_PROFILE("ACLVISParticleAttribDataSource::insert_data()", taustr, TAU_VIZ);
00188 
00189   // maximum index for the data
00190   unsigned maxIndx = sIndx + N;
00191 
00192   if (msg != 0) {
00193     // insert particles from a message into the vtk structure
00194     T* msgdata = (T *)(msg->remove());
00195     if (msgdata != 0) {
00196       T *data = msgdata;
00197       for ( ; sIndx < maxIndx; ++sIndx, ++data)
00198         ACLVISTraits<ReadParticleTool,T>::setPoint(LocalData, sIndx, *data);
00199 
00200       // delete unneeded storage
00201       free(static_cast<void *>(msgdata));
00202     }
00203 
00204   } else {
00205     // grab particles from our local storage and put them into the vtk struct
00206     typename ParticleAttrib<T>::iterator msgdata = MyParticles.begin();
00207     for ( ; sIndx < maxIndx; ++sIndx, ++msgdata)
00208       ACLVISTraits<ReadParticleTool,T>::setPoint(LocalData, sIndx, *msgdata);
00209   }
00210 }
00211 
00212 
00213 /***************************************************************************
00214  * $RCSfile: ACLVISPtclAttribDataSource.cpp,v $   $Author: adelmann $
00215  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00216  * IPPL_VERSION_ID: $Id: ACLVISPtclAttribDataSource.cpp,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00217  ***************************************************************************/

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