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

src/DataSource/DataConnectCreator.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/DataConnectCreator.h"
00028 #include "DataSource/DataConnect.h"
00029 #include "DataSource/FileDataConnect.h"
00030 #include "Utility/IpplInfo.h"
00031 #include "Profile/Profiler.h"
00032 
00033 // include ACLVIS code if available
00034 #ifdef IPPL_ACLVIS
00035 #include "DataSource/ACLVISDataConnect.h"
00036 #endif
00037 
00038 // include PAWS code if available
00039 #ifdef IPPL_PAWS
00040 #include "IpplPaws/PawsDataConnect.h"
00041 #endif
00042 
00043 #include <string.h>
00044 
00045 
00046 // static data for this file
00047 static const int CONNECTMETHODS = 4;   // includes "no connection" method
00048 static char *ConnectMethodList  = "aclvis, paws, file, or none";
00049 static char *ConnectMethodNames[CONNECTMETHODS] =
00050   { "aclvis", "paws", "file", "none" };
00051 static bool  ConnectMethodSupported[CONNECTMETHODS] = {
00052 #ifdef IPPL_ACLVIS
00053   true,
00054 #else
00055   false,
00056 #endif
00057 #ifdef IPPL_PAWS
00058   true,
00059 #else
00060   false,
00061 #endif
00062   true,
00063   true
00064 };
00065 
00066 
00067 // a global instance of DataConnectCreator ... when this is destroyed
00068 // at the end of the program, it will clean up the default connection
00069 // object, if necessary
00070 static DataConnectCreator GlobalDataConnectCreatorInstance;
00071 
00072 
00073 
00075 // static member data for DataConnectCreator
00076 int          DataConnectCreator::ConnectNodes      = 1;
00077 int          DataConnectCreator::InstanceCount     = 0;
00078 int          DataConnectCreator::DefaultMethod     = CONNECTMETHODS - 1;
00079 DataConnect *DataConnectCreator::DefaultConnection = 0;
00080 
00081 
00082 
00084 // constructor: increment the instance count
00085 DataConnectCreator::DataConnectCreator() {
00086   TAU_PROFILE("DataConnectCreator::DataConnectCreator()", "void ()", TAU_VIZ);
00087   InstanceCount++;
00088 }
00089 
00090 
00092 // destructor: deccrement the instance count, and if it goes to zero,
00093 // delete any static object if necessary
00094 DataConnectCreator::~DataConnectCreator() {
00095   TAU_PROFILE("DataConnectCreator::~DataConnectCreator()", "void ()", TAU_VIZ);
00096   if (--InstanceCount == 0)
00097     if (DefaultConnection != 0)
00098       delete DefaultConnection;
00099 }
00100 
00101 
00103 // return the name of the Nth method
00104 int DataConnectCreator::getNumMethods() {
00105   TAU_PROFILE("DataConnectCreator::getNumMethods()", "int ()", TAU_VIZ);
00106   return CONNECTMETHODS;
00107 }
00108 
00109 
00111 // return the name of the Nth method
00112 const char *DataConnectCreator::getMethodName(int n) {
00113   TAU_PROFILE("DataConnectCreator::getMethodName()", "char * (int )", TAU_VIZ);
00114   if (n >= 0 && n < CONNECTMETHODS)
00115     return ConnectMethodNames[n];
00116   else
00117     return 0;
00118 }
00119 
00120 
00122 // return a list of all the methods, as a single string
00123 const char *DataConnectCreator::getAllMethodNames() {
00124   TAU_PROFILE("DataConnectCreator::getAllMethodNames()", "char * ()", TAU_VIZ);
00125   return ConnectMethodList;
00126 }
00127 
00128 
00130 // check if the given connection method is supported
00131 bool DataConnectCreator::supported(int cm) {
00132   TAU_PROFILE("DataConnectCreator::supported()", "bool (int )", TAU_VIZ);
00133   return (known(cm) ? ConnectMethodSupported[cm] : false);
00134 }
00135 
00136 
00138 // check if the given connection method is supported
00139 bool DataConnectCreator::supported(const char *nm) {
00140   TAU_PROFILE("DataConnectCreator::supported()", "bool (char *)", TAU_VIZ);
00141   return supported(libindex(nm));
00142 }
00143 
00144 
00146 // check if the given connection method is known at all
00147 bool DataConnectCreator::known(int cm) {
00148   TAU_PROFILE("DataConnectCreator::known()", "bool (int )", TAU_VIZ);
00149   return (cm >= 0 && cm < CONNECTMETHODS);
00150 }
00151 
00152 
00154 // check if the given connection method is known at all
00155 bool DataConnectCreator::known(const char *nm) {
00156   TAU_PROFILE("DataConnectCreator::known()", "bool (char *)", TAU_VIZ);
00157   return known(libindex(nm));
00158 }
00159 
00160 
00162 // create a new connection.  Arguments = type, name, direction, nodes
00163 // If n <= 0, use the "default" number of nodes set earlier
00164 DataConnect *DataConnectCreator::create(int cm, const char *nm, int n) {
00165   TAU_PROFILE("DataConnectCreator::create()", "DataConnect * (int, char * )",
00166               TAU_VIZ);
00167   
00168   // initially, we have a null pointer for the connection.  If everything
00169   // checks out, we'll have a non-null pointer at the end.  If we still
00170   // have a null pointer at the end of this routine, something went wrong
00171   // and we return NULL to indicate an error.
00172   DataConnect *dataconn = 0;
00173 
00174   // figure out how many nodes the connection should use, if it cares
00175   // at all about that.  For example, ACLVIS may use multipple nodes
00176   // in the visualization, or maybe just one.
00177   int nodes = n;
00178   if (n <= 0)
00179     nodes = getDefaultNodes();
00180 
00181   // based on the connection method, create a new DataConnect
00182   if (cm == 0) {
00183     // use the ACLVIS library for the connection, which will result in the
00184     // data objects being displayed in a visualization window
00185 #ifdef IPPL_ACLVIS
00186     dataconn = new ACLVISDataConnect(nm, nodes);
00187 #endif
00188   } else if (cm == 1) {
00189     // use the PAWS library for the connection, which is a general-purpose
00190     // method for transferring data to/from another application
00191 #ifdef IPPL_PAWS
00192     dataconn = new PawsDataConnect(nm, nodes);
00193 #endif
00194   } else if (cm == 2) {
00195     // transfer the data to/from a file using some form of parallel I/O
00196     dataconn = new FileDataConnect(nm, nodes);
00197   } else if (cm == 3) {
00198     // just make a dummy connect object, which does nothing
00199     dataconn = new DataConnect(nm, getMethodName(cm), DataSource::OUTPUT,
00200                                nodes);
00201   }
00202 
00203   // make sure we have something
00204   if (dataconn == 0) {
00205     ERRORMSG("DataConnectCreator: unknown connection method." << endl);
00206   }
00207 
00208   return dataconn;
00209 }
00210 
00211 
00213 // a final method for creating objects; this one provides a default name,
00214 // and if the default connection object has already been created, this just
00215 // returns that one.
00216 DataConnect *DataConnectCreator::create() {
00217   TAU_PROFILE("DataConnectCreator::create()", "DataConnect * ()", TAU_VIZ);
00218 
00219   if (DefaultConnection == 0)
00220     DefaultConnection = create(getMethodName(DefaultMethod));
00221   return DefaultConnection;
00222 }
00223 
00224 
00226 // change the default connection method.  Return success.
00227 bool DataConnectCreator::setDefaultMethod(int cm) {
00228   TAU_PROFILE("DataConnectCreator::setDefaultMethod()", "bool (int)", TAU_VIZ);
00229   if (supported(cm)) {
00230     DefaultMethod = cm;
00231     return true;
00232   }
00233   return false;
00234 }
00235 
00236 
00238 // return the index of the given named method, or (-1) if not found
00239 int DataConnectCreator::libindex(const char *nm) {
00240   TAU_PROFILE("DataConnectCreator::libindex()", "int (char * )", TAU_VIZ);
00241   for (int i=0; i < CONNECTMETHODS; ++i) {
00242     if (strcmp(nm, getMethodName(i)) == 0)
00243       return i;
00244   }
00245 
00246   // if here, it was not found
00247   return (-1);
00248 }
00249 
00250 
00252 // change the default number of nodes to use for the connection
00253 void DataConnectCreator::setDefaultNodes(int n) {
00254   ConnectNodes = n;
00255 }
00256 
00257 
00259 // return the default number of nodes to use in a connection
00260 int DataConnectCreator::getDefaultNodes() {
00261   return (ConnectNodes >= 0 && ConnectNodes <= Ippl::getNodes() ?
00262           ConnectNodes :
00263           Ippl::getNodes());
00264 }
00265 
00266 
00267 /***************************************************************************
00268  * $RCSfile: DataConnectCreator.cpp,v $   $Author: adelmann $
00269  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00270  * IPPL_VERSION_ID: $Id: DataConnectCreator.cpp,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00271  ***************************************************************************/

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