Replace automatic rdtscp checks with boolean option
[gromacs.git] / python_packaging / sample_restraint / src / cpp / sessionresources.cpp
blobe9bb5825e58d1df5e5ec75a0f750e6e053077082
1 /*! \file
2 * \brief Definitions for some useful types and templates for GROMACS restraints.
4 * \todo This should be part of a template library installed with GROMACS.
6 * \author M. Eric Irrgang <ericirrgang@gmail.com>
7 */
9 #include "sessionresources.h"
11 #include <cassert>
13 #include <memory>
15 #include "gmxapi/exceptions.h"
16 #include "gmxapi/md/mdsignals.h"
18 namespace plugin
21 // Explicit instantiation.
22 template
23 class ::plugin::Matrix<double>;
25 void ResourcesHandle::reduce(const Matrix<double>& send,
26 Matrix<double>* receive) const
28 assert(reduce_);
29 if (*reduce_)
31 (*reduce_)(send,
32 receive);
34 else
36 throw gmxapi::ProtocolError("'reduce' functor was not initialized before use.");
40 void ResourcesHandle::stop()
42 assert(session_);
43 auto signaller = gmxapi::getMdrunnerSignal(session_,
44 gmxapi::md::signals::STOP);
46 // Should probably check that the function object has been initialized...
47 signaller();
50 ResourcesHandle Resources::getHandle() const
52 auto handle = ResourcesHandle();
54 if (!bool(reduce_))
56 throw gmxapi::ProtocolError("reduce operation functor is not set, which should not happen...");
58 handle.reduce_ = &reduce_;
60 if (!session_)
62 throw gmxapi::ProtocolError("Resources::getHandle() must not be called before setSession() has been called.");
64 handle.session_ = session_;
66 return handle;
69 void Resources::setSession(gmxapi::SessionResources* session)
71 if (!session)
73 throw gmxapi::ProtocolError("Resources::setSession received a null SessionResources pointer.");
75 session_ = session;
78 } // end namespace myplugin