OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DataConnect.cpp
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
27 #include "DataSource/DataConnect.h"
28 #include "DataSource/DataSource.h"
31 #include "Utility/IpplInfo.h"
32 
33 
34 
36 // constructor
37 DataConnect::DataConnect(const char *nm, const char *id, int dtm, int n)
38  : NamedObj(nm), MyID(id), nodes(n), DefTransMethod(dtm)
39 {
40  if (n <= 0)
42 }
43 
44 
46 // destructor
48 {
50 }
51 
52 
54 // return true if our nodes is one of the connection nodes
56  return (Ippl::myNode() < getNodes());
57 }
58 
59 
61 // are we currently connected to a receiver? The base-class default
62 // behavior for this is to indicate that we're not connected.
63 bool DataConnect::connected() const {
64  return false;
65 }
66 
67 
69 // Register an object as something that can be a source of data.
70 // Arguments = name of item, DataSource object, and transfer method
71 // (INPUT, OUTPUT, BOTH, or DEFAULT). If this connection object is
72 // not actually connected, it is an error and this will return NULL.
73 // Otherwise, if the connection works, return the connection.
74 DataConnect *DataConnect::connect(const char *nm, DataSource *s, int tm) {
75  DataConnect *conn = 0;
76  if (connected() && s != 0)
77  conn = s->connect(nm, this, tm);
78  return conn;
79 }
80 
81 DataConnect *DataConnect::connect(const char *nm, DataSource& s, int tm) {
82  return connect(nm, &s, tm);
83 }
84 
85 
87 // Add a new single DataSourceObject connection. It is added to the
88 // DataSource's list of single connections, and the DataSource will
89 // end up being added to our list of known sources. Return success.
91 
92 
93  // make sure the DataSourceObject has a source and the proper DataConnect
94  if (dso == 0 || dso->getSource() == 0 || dso->getConnection() != this)
95  return false;
96 
97  // tell the relevant DataSource it has a new DataSourceObject connection.
98  // the DataSource will check itself in to our list of DataSources.
99  return dso->getSource()->connect(dso);
100 }
101 
102 
104 // perform update for all registered DataSource's
106  for (iterator a = begin(); a != end(); ++a)
107  (*a)->updateConnection(dc);
108 }
109 
110 
112 // disconnect all the registered DataSource's
114 
115  while (! SourceList.empty() )
116  checkout(SourceList.front());
117 }
118 
119 
121 // allow all connections to perform an interactive action
122 void DataConnect::interact(const char *str, DataConnect *dc) {
123  for (iterator a = begin(); a != end(); ++a)
124  (*a)->interact(str, dc);
125 }
126 
127 
129 // Register a data object as connected here. Return success.
131 
132 
133  // make sure we do not have this DataSource already
134  for (iterator a = begin(); a != end(); ++a) {
135  if (*a == ds)
136  return true;
137  }
138 
139  // we don't have it, so add it to our list
140  SourceList.push_back(ds);
141  return true;
142 }
143 
144 
146 // remove a data object from our connected list. Return success.
147 bool DataConnect::checkout(DataSource *ds, bool NeedDisconnect) {
148 
149 
150  //Inform dbgmsg("DataConnect::checkout", INFORM_ALL_NODES);
151 
152  // make sure we have it ...
153  for (iterator a = begin(); a != end(); ++a) {
154  if (*a == ds) {
155  // we do have it; make sure it is disconnected,
156  // remove it and return success
157  //dbgmsg << "Found DataSource ... ";
158  SourceList.erase(a);
159  if (NeedDisconnect) {
160  //dbgmsg << "calling disconnect." << endl;
161  ds->disconnect(this);
162  } else {
163  //dbgmsg << "SKIPPING disconnect." << endl;
164  }
165  return true;
166  }
167  }
168 
169  // if we're here, we did not find it
170  //dbgmsg << "Could not find specified DataSource." << endl;
171  return false;
172 }
173 
175 // wait for synchronization from outside.
176 // default behavior is nothing.
178 {
179 }
180 
181 /***************************************************************************
182  * $RCSfile: DataConnect.cpp,v $ $Author: adelmann $
183  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:24 $
184  * IPPL_VERSION_ID: $Id: DataConnect.cpp,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $
185  ***************************************************************************/
std::complex< double > a
iterator end()
Definition: DataConnect.h:72
bool checkin(DataSource *)
virtual void ready()
bool checkout(DataSource *, bool=true)
virtual bool connected() const
Definition: DataConnect.cpp:63
virtual void updateConnections(DataConnect *=0)
int getNodes() const
Definition: DataConnect.h:62
container_t::iterator iterator
Definition: DataConnect.h:37
iterator begin()
Definition: DataConnect.h:71
container_t SourceList
Definition: DataConnect.h:132
bool onConnectNode() const
Definition: DataConnect.cpp:55
virtual DataConnect * connect(const char *, DataSource *, int=DataSource::DEFAULT)
Definition: DataConnect.cpp:74
virtual ~DataConnect()
Definition: DataConnect.cpp:47
virtual void interact(const char *=0, DataConnect *=0)
DataConnect(const char *nm, const char *id, int dtm=DataSource::OUTPUT, int n=0)
Definition: DataConnect.cpp:37
virtual void disconnectConnections()
DataConnect * connect(const char *, DataConnect *=0, int=DataSource::DEFAULT)
Definition: DataSource.cpp:83
bool disconnect(DataConnect *=0)
Definition: DataSource.cpp:143
DataConnect * getConnection()
DataSource * getSource()
static int myNode()
Definition: IpplInfo.cpp:691