*
* For more info, check our website at http://www.gromacs.org
*/
+#include <memory>
#include <string>
#include <vector>
AnalysisTemplate::startFrames(AnalysisDataParallelOptions opt,
const SelectionCollection &selections)
{
- ModuleData *pdata = new ModuleData(this, opt, selections);
- int rc = NeighborhoodSearch::create(&pdata->_nb, _cutoff, _refsel->posCount());
- if (rc != 0)
- {
- delete pdata;
- // FIXME: Use exceptions in the neighborhood search API
- GMX_THROW(InternalError("Neighborhood search initialization failed"));
- }
- return pdata;
+ std::auto_ptr<ModuleData> pdata(new ModuleData(this, opt, selections));
+ pdata->_nb = new NeighborhoodSearch(_cutoff, _refsel->posCount());
+ return pdata.release();
}
AnalysisDataHandle *dh = pdata->dataHandle("avedist");
NeighborhoodSearch *nb = static_cast<ModuleData *>(pdata)->_nb;
- int rc = nb->init(pbc, _refsel->positions());
- if (rc != 0)
- {
- // FIXME: Use exceptions in the neighborhood search API
- GMX_THROW(InternalError("Neighborhood search frame initialization failed"));
- }
+ nb->init(pbc, _refsel->positions());
dh->startFrame(frnr, fr.time);
for (size_t g = 0; g < _sel.size(); ++g)
{
#include <string2.h>
#include <vec.h>
+// FIXME: Should really be in the beginning, but causes compilation errors
+#include <algorithm>
+
#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/poscalc.h"
#include "selectioncollection-impl.h"
#include "selelem.h"
-static int min(int a, int b)
-{
- return (a < b) ? a : b;
-}
+using std::min;
/*! \internal \brief
* Compiler flags.
SEL_CDATA_EVALMAX = 8,
/** Whether memory has been allocated for \p gmin and \p gmax. */
SEL_CDATA_MINMAXALLOC = 16,
+ /** Whether to update \p gmin and \p gmax in static analysis. */
+ SEL_CDATA_DOMINMAX = 128,
/** Whether subexpressions use simple pass evaluation functions. */
SEL_CDATA_SIMPLESUBEXPR = 32,
/** Whether this expressions is a part of a common subexpression. */
break;
case SEL_GROUPREF:
- GMX_THROW(gmx::InconsistentInputError("Unresolved group reference in compilation"));
+ GMX_THROW(gmx::APIError("Unresolved group reference in compilation"));
}
}
}
else
{
- sel->cdata->flags |= SEL_CDATA_MINMAXALLOC;
+ sel->cdata->flags |= SEL_CDATA_MINMAXALLOC | SEL_CDATA_DOMINMAX;
snew(sel->cdata->gmin, 1);
snew(sel->cdata->gmax, 1);
}
* \param[in] g The evaluation group.
* \returns 0 on success, a non-zero error code on error.
*/
-static int
+static void
process_const(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
- rc = 0;
if (sel->v.type == GROUP_VALUE)
{
if (sel->cdata->evaluate)
{
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
}
}
/* Other constant expressions do not need evaluation */
- return rc;
}
/*! \brief
* If no \ref SPAR_ATOMVAL parameters are present, multiple initialization
* is prevented by using \ref SEL_METHODINIT and \ref SEL_OUTINIT flags.
*/
-static int
+static void
init_method(t_selelem *sel, t_topology *top, int isize)
{
t_selelem *child;
gmx_bool bAtomVal;
- int rc;
/* Find out whether there are any atom-valued parameters */
bAtomVal = FALSE;
&& (bAtomVal || !(sel->flags & SEL_METHODINIT)))
{
sel->flags |= SEL_METHODINIT;
- rc = sel->u.expr.method->init(top, sel->u.expr.method->nparams,
+ sel->u.expr.method->init(top, sel->u.expr.method->nparams,
sel->u.expr.method->param, sel->u.expr.mdata);
- if (rc != 0)
- {
- return rc;
- }
}
if (bAtomVal || !(sel->flags & SEL_OUTINIT))
{
sel->flags |= SEL_OUTINIT;
if (sel->u.expr.method->outinit)
{
- rc = sel->u.expr.method->outinit(top, &sel->v, sel->u.expr.mdata);
- if (rc != 0)
- {
- return rc;
- }
+ sel->u.expr.method->outinit(top, &sel->v, sel->u.expr.mdata);
if (sel->v.type != POS_VALUE && sel->v.type != GROUP_VALUE)
{
alloc_selection_data(sel, isize, TRUE);
/* A sanity check */
if (sel->v.type != STR_VALUE)
{
- gmx_bug("internal error");
- return -1;
+ GMX_THROW(gmx::InternalError("Char-valued selection method in non-string element"));
}
sel->flags |= SEL_ALLOCDATA;
for (i = 0; i < isize; ++i)
}
}
}
-
- return 0;
}
/*! \brief
*
* reorder_item_static_children() should have been called.
*/
-static int
+static void
evaluate_gmx_boolean_static_part(gmx_sel_evaluate_t *data, t_selelem *sel,
gmx_ana_index_t *g)
{
t_selelem *child, *next;
- int rc;
/* Find the last static subexpression */
child = sel->child;
}
if (!(child->cdata->flags & SEL_CDATA_STATIC))
{
- return 0;
+ return;
}
/* Evalute the static part if there is more than one expression */
{
next = child->next;
child->next = NULL;
- rc = sel->cdata->evaluate(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->cdata->evaluate(data, sel, g);
/* Replace the subexpressions with the result */
_gmx_selelem_free_chain(sel->child);
snew(child, 1);
}
else if (child->evaluate)
{
- rc = child->evaluate(data, child, g);
- if (rc != 0)
- {
- return rc;
- }
+ child->evaluate(data, child, g);
}
/* Set the evaluation function for the constant element.
* We never need to evaluate the element again during compilation,
gmx_ana_index_copy(&child->u.cgrp, child->v.u.g, TRUE);
}
}
- return 0;
}
/*! \brief
break;
case BOOL_XOR: /* Should not be reached */
- gmx_impl("xor expressions not implemented");
+ GMX_THROW(gmx::NotImplementedError("xor expressions not implemented"));
break;
}
}
* another pass is required for subexpressions that are referred to more than
* once and whose evaluation group is not known in advance.
*/
-static int
+static void
analyze_static(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
t_selelem *child, *next;
gmx_bool bDoMinMax;
- int rc;
if (sel->type != SEL_ROOT && g)
{
alloc_selection_data(sel, g->isize, FALSE);
}
- bDoMinMax = (sel->cdata->flags & SEL_CDATA_MINMAXALLOC);
+ bDoMinMax = (sel->cdata->flags & SEL_CDATA_DOMINMAX);
if (sel->type != SEL_SUBEXPR && bDoMinMax)
{
gmx_ana_index_deinit(sel->cdata->gmin);
}
/* TODO: This switch is awfully long... */
- rc = 0;
switch (sel->type)
{
case SEL_CONST:
- rc = process_const(data, sel, g);
+ process_const(data, sel, g);
break;
case SEL_EXPRESSION:
case SEL_MODIFIER:
- rc = _gmx_sel_evaluate_method_params(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
- rc = init_method(sel, data->top, g->isize);
- if (rc != 0)
- {
- return rc;
- }
+ _gmx_sel_evaluate_method_params(data, sel, g);
+ init_method(sel, data->top, g->isize);
if (!(sel->flags & SEL_DYNAMIC))
{
- rc = sel->cdata->evaluate(data, sel, g);
- if (rc == 0 && (sel->cdata->flags & SEL_CDATA_STATIC))
+ sel->cdata->evaluate(data, sel, g);
+ if (sel->cdata->flags & SEL_CDATA_STATIC)
{
make_static(sel);
}
* maximum possible selections. */
if (sel->type == SEL_MODIFIER)
{
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
}
if (bDoMinMax)
{
case SEL_BOOLEAN:
if (!(sel->flags & SEL_DYNAMIC))
{
- rc = sel->cdata->evaluate(data, sel, g);
- if (rc == 0 && (sel->cdata->flags & SEL_CDATA_STATIC))
+ sel->cdata->evaluate(data, sel, g);
+ if (sel->cdata->flags & SEL_CDATA_STATIC)
{
make_static(sel);
}
else
{
/* Evalute the static part if there is more than one expression */
- rc = evaluate_gmx_boolean_static_part(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ evaluate_gmx_boolean_static_part(data, sel, g);
/* Evaluate the selection.
* If the type is gmx_boolean, we must explicitly handle the
* here because g may be larger. */
if (sel->u.boolt == BOOL_AND && sel->child->type == SEL_CONST)
{
- rc = sel->cdata->evaluate(data, sel, sel->child->v.u.g);
+ sel->cdata->evaluate(data, sel, sel->child->v.u.g);
}
else
{
- rc = sel->cdata->evaluate(data, sel, g);
- }
- if (rc != 0)
- {
- return rc;
+ sel->cdata->evaluate(data, sel, g);
}
/* Evaluate minimal and maximal selections */
break;
case SEL_ARITHMETIC:
- rc = sel->cdata->evaluate(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->cdata->evaluate(data, sel, g);
if (!(sel->flags & SEL_DYNAMIC))
{
if (sel->cdata->flags & SEL_CDATA_STATIC)
break;
case SEL_ROOT:
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
break;
case SEL_SUBEXPR:
if (sel->cdata->flags & (SEL_CDATA_SIMPLESUBEXPR | SEL_CDATA_FULLEVAL))
{
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
_gmx_selvalue_setstore(&sel->v, sel->child->v.u.ptr);
}
else if (sel->u.cgrp.isize == 0)
{
gmx_ana_index_reserve(&sel->u.cgrp, g->isize);
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
if (bDoMinMax)
{
gmx_ana_index_copy(sel->cdata->gmin, sel->child->cdata->gmin, TRUE);
gmx_ana_index_reserve(&sel->u.cgrp, isize);
alloc_selection_data(sel, isize, FALSE);
}
- rc = sel->cdata->evaluate(data, sel, g);
+ sel->cdata->evaluate(data, sel, g);
if (isize > 0 && bDoMinMax)
{
gmx_ana_index_reserve(sel->cdata->gmin,
* selection). */
alloc_selection_data(sel, sel->child->cdata->gmax->isize, TRUE);
}
- rc = sel->cdata->evaluate(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->cdata->evaluate(data, sel, g);
if ((sel->cdata->flags & SEL_CDATA_SIMPLESUBEXPR)
&& (sel->child->child->flags & SEL_ALLOCVAL))
{
break;
case SEL_GROUPREF:
- gmx_incons("unresolved group reference in compilation");
- return -1;
- }
- /* Exit if there was some problem */
- if (rc != 0)
- {
- return rc;
+ GMX_THROW(gmx::APIError("Unresolved group reference in compilation"));
}
/* Update the minimal and maximal evaluation groups */
gmx_ana_index_copy(sel->v.u.g, sel->cdata->gmin, FALSE);
}
}
-
- return 0;
}
* The covered fraction information in \p sc is initialized to
* \ref CFRAC_NONE.
*/
-int
+void
gmx_ana_selcollection_compile(gmx::SelectionCollection *coll)
{
gmx_ana_selcollection_t *sc = &coll->_impl->_sc;
e_poscalc_t post;
size_t i;
int flags;
- int rc;
bool bDebug = (coll->_impl->_debugLevel >= 2
&& coll->_impl->_debugLevel != 3);
/* FIXME: Clean up the collection on exceptions */
- rc = _gmx_sel_mempool_create(&sc->mempool);
- if (rc != 0)
- {
- return rc;
- }
+ sc->mempool = _gmx_sel_mempool_create();
_gmx_sel_evaluate_init(&evaldata, sc->mempool, &sc->gall,
sc->top, NULL, NULL);
mark_subexpr_dynamic(item->child, TRUE);
}
set_evaluation_function(item, &analyze_static);
- rc = item->evaluate(&evaldata, item, NULL);
- if (rc != 0)
- {
- /* FIXME: Clean up the collection */
- return rc;
- }
+ item->evaluate(&evaldata, item, NULL);
item = item->next;
}
{
if (item->child->cdata->flags & SEL_CDATA_COMMONSUBEXPR)
{
- gmx_bool bMinMax = item->child->cdata->flags & SEL_CDATA_MINMAXALLOC;
+ bool bMinMax = item->child->cdata->flags & SEL_CDATA_DOMINMAX;
mark_subexpr_dynamic(item->child, FALSE);
item->child->u.cgrp.isize = 0;
* For the same reason, we clear the min/max flag so that the
* evaluation group doesn't get messed up. */
set_evaluation_function(item, &analyze_static);
- item->child->cdata->flags &= ~SEL_CDATA_MINMAXALLOC;
- rc = item->evaluate(&evaldata, item->child, item->child->cdata->gmax);
+ item->child->cdata->flags &= ~SEL_CDATA_DOMINMAX;
+ item->evaluate(&evaldata, item->child, item->child->cdata->gmax);
if (bMinMax)
{
- item->child->cdata->flags |= SEL_CDATA_MINMAXALLOC;
- }
- if (rc != 0)
- {
- /* FIXME: Clean up the collection */
- return rc;
+ item->child->cdata->flags |= SEL_CDATA_DOMINMAX;
}
}
item = item->next;
}
/* Allocate memory for the evaluation memory pool. */
- rc = _gmx_sel_mempool_reserve(sc->mempool, 0);
- if (rc != 0)
- {
- return rc;
- }
+ _gmx_sel_mempool_reserve(sc->mempool, 0);
/* Finish up by calculating total masses and charges. */
calculate_mass_charge(&sc->sel, sc->top);
-
- return 0;
}
#include <smalloc.h>
#include <vec.h>
+#include "gromacs/fatalerror/exceptions.h"
+#include "gromacs/fatalerror/gmxassert.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/poscalc.h"
#include "gromacs/selection/selection.h"
#include "selectioncollection-impl.h"
#include "selelem.h"
+/*! \internal \brief
+ * Reserves memory for a selection element from the evaluation memory pool.
+ */
+class MempoolSelelemReserver
+{
+ public:
+ MempoolSelelemReserver() : sel_(NULL) {}
+ MempoolSelelemReserver(t_selelem *sel, int count)
+ : sel_(NULL)
+ {
+ reserve(sel, count);
+ }
+ ~MempoolSelelemReserver()
+ {
+ if (sel_ != NULL)
+ {
+ _gmx_selelem_mempool_release(sel_);
+ }
+ }
+
+ void reserve(t_selelem *sel, int count)
+ {
+ GMX_RELEASE_ASSERT(sel_ == NULL, "Can only reserve one element with one instance");
+ _gmx_selelem_mempool_reserve(sel, count);
+ sel_ = sel;
+ }
+
+ private:
+ t_selelem *sel_;
+};
+
+/*! \internal \brief
+ * Reserves memory for an index group from the evaluation memory pool.
+ */
+class MempoolGroupReserver
+{
+ public:
+ explicit MempoolGroupReserver(gmx_sel_mempool_t *mp)
+ : mp_(mp), g_(NULL)
+ {
+ }
+ ~MempoolGroupReserver()
+ {
+ if (g_ != NULL)
+ {
+ _gmx_sel_mempool_free_group(mp_, g_);
+ }
+ }
+
+ void reserve(gmx_ana_index_t *g, int count)
+ {
+ GMX_RELEASE_ASSERT(g_ == NULL, "Can only reserve one element with one instance");
+ _gmx_sel_mempool_alloc_group(mp_, g, count);
+ g_ = g;
+ }
+
+ private:
+ gmx_sel_mempool_t *mp_;
+ gmx_ana_index_t *g_;
+};
+
+/*! \internal \brief
+ * Assigns a temporary value for a selection element.
+ */
+class SelelemTemporaryValueAssigner
+{
+ public:
+ SelelemTemporaryValueAssigner()
+ : sel_(NULL), old_ptr_(NULL), old_nalloc_(0)
+ {
+ }
+ SelelemTemporaryValueAssigner(t_selelem *sel, t_selelem *vsource)
+ : sel_(NULL)
+ {
+ assign(sel, vsource);
+ }
+ ~SelelemTemporaryValueAssigner()
+ {
+ if (sel_ != NULL)
+ {
+ _gmx_selvalue_setstore_alloc(&sel_->v, old_ptr_, old_nalloc_);
+ }
+ }
+
+ void assign(t_selelem *sel, t_selelem *vsource)
+ {
+ GMX_RELEASE_ASSERT(sel_ == NULL, "Can only assign one element with one instance");
+ old_ptr_ = sel->v.u.ptr;
+ old_nalloc_ = sel->v.nalloc;
+ _gmx_selvalue_setstore(&sel->v, vsource->v.u.ptr);
+ sel_ = sel;
+ }
+
+ private:
+ t_selelem *sel_;
+ void *old_ptr_;
+ int old_nalloc_;
+};
+
/*!
* \param[in] fp File handle to receive the output.
* \param[in] evalfunc Function pointer to print.
* This is the only function that user code should call if they want to
* evaluate a selection for a new frame.
*/
-int
+void
gmx_ana_selcollection_evaluate(gmx_ana_selcollection_t *sc,
t_trxframe *fr, t_pbc *pbc)
{
gmx_sel_evaluate_t data;
t_selelem *sel;
- int rc;
_gmx_sel_evaluate_init(&data, sc->mempool, &sc->gall, sc->top, fr, pbc);
init_frame_eval(sc->root);
}
if (sel->evaluate)
{
- rc = sel->evaluate(&data, sel, NULL);
- if (rc != 0)
- {
- return rc;
- }
+ sel->evaluate(&data, sel, NULL);
}
sel = sel->next;
}
sel->avecfrac += sel->cfrac;
}
}
- return 0;
}
/*!
*
* Evaluates each child of \p sel in \p g.
*/
-int
+void
_gmx_sel_evaluate_children(gmx_sel_evaluate_t *data, t_selelem *sel,
gmx_ana_index_t *g)
{
t_selelem *child;
- int rc;
child = sel->child;
while (child)
{
if (child->evaluate)
{
- rc = child->evaluate(data, child, g);
- if (rc != 0)
- {
- return rc;
- }
+ child->evaluate(data, child, g);
}
child = child->next;
}
- return 0;
}
/*!
* This function can be used as \c t_selelem::evaluate for \ref SEL_ROOT
* elements.
*/
-int
+void
_gmx_sel_evaluate_root(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
if (sel->u.cgrp.isize == 0 || !sel->child->evaluate)
{
- return 0;
+ return;
}
- rc = sel->child->evaluate(data, sel->child,
- sel->u.cgrp.isize < 0 ? NULL : &sel->u.cgrp);
-
- return rc;
+ sel->child->evaluate(data, sel->child,
+ sel->u.cgrp.isize < 0 ? NULL : &sel->u.cgrp);
}
/*!
* This function can be used as \c t_selelem::evaluate for \ref SEL_CONST
* elements with value type \ref GROUP_VALUE.
*/
-int
+void
_gmx_sel_evaluate_static(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
gmx_ana_index_intersection(sel->v.u.g, &sel->u.cgrp, g);
- return 0;
}
* elements that are used only once, and hence do not need full subexpression
* handling.
*/
-int
+void
_gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
if (sel->child->evaluate)
{
- rc = sel->child->evaluate(data, sel->child, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->child->evaluate(data, sel->child, g);
}
sel->v.nr = sel->child->v.nr;
- return 0;
}
/*!
* elements that have a static evaluation group, and hence do not need full
* subexpression handling.
*/
-int
+void
_gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
if (sel->u.cgrp.isize == 0)
{
- int rc;
-
- rc = sel->child->evaluate(data, sel->child, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->child->evaluate(data, sel->child, g);
sel->v.nr = sel->child->v.nr;
gmx_ana_index_set(&sel->u.cgrp, g->isize, g->index, sel->u.cgrp.name, 0);
}
- return 0;
}
/*!
* _gmx_sel_evaluate_subexpr_staticeval() can be used, so this should not be a
* major problem.
*/
-int
+void
_gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
gmx_ana_index_t gmiss;
- int rc;
+ MempoolGroupReserver gmissreserver(data->mp);
if (sel->u.cgrp.isize == 0)
{
- char *name;
- void *old_ptr = sel->child->v.u.ptr;
- int old_nalloc = sel->child->v.nalloc;
- _gmx_selvalue_setstore(&sel->child->v, sel->v.u.ptr);
- rc = sel->child->evaluate(data, sel->child, g);
- _gmx_selvalue_setstore_alloc(&sel->child->v, old_ptr, old_nalloc);
- if (rc != 0)
{
- return rc;
+ SelelemTemporaryValueAssigner assigner(sel->child, sel);
+ sel->child->evaluate(data, sel->child, g);
}
/* We need to keep the name for the cgrp across the copy to avoid
* problems if g has a name set. */
- name = sel->u.cgrp.name;
+ char *name = sel->u.cgrp.name;
gmx_ana_index_copy(&sel->u.cgrp, g, FALSE);
sel->u.cgrp.name = name;
gmiss.isize = 0;
}
else
{
- /* We allocate some extra memory here to avoid some computation. */
- rc = _gmx_sel_mempool_alloc_group(data->mp, &gmiss, g->isize);
- if (rc != 0)
- {
- return rc;
- }
+ gmissreserver.reserve(&gmiss, g->isize);
gmx_ana_index_difference(&gmiss, g, &sel->u.cgrp);
- if (gmiss.isize == 0)
- {
- _gmx_sel_mempool_free_group(data->mp, &gmiss);
- }
}
if (gmiss.isize > 0)
{
- rc = _gmx_selelem_mempool_reserve(sel->child, gmiss.isize);
- if (rc != 0)
- {
- return rc;
- }
+ MempoolSelelemReserver reserver(sel->child, gmiss.isize);
/* Evaluate the missing values for the child */
- rc = sel->child->evaluate(data, sel->child, &gmiss);
- if (rc != 0)
- {
- return rc;
- }
+ sel->child->evaluate(data, sel->child, &gmiss);
/* Merge the missing values to the existing ones. */
if (sel->v.type == GROUP_VALUE)
{
case POS_VALUE:
/* TODO: Implement this */
- gmx_impl("position subexpressions not implemented properly");
- return -1;
+ GMX_THROW(gmx::NotImplementedError("position subexpressions not implemented properly"));
case NO_VALUE:
case GROUP_VALUE:
- gmx_bug("internal error");
- return -1;
+ GMX_THROW(gmx::InternalError("Invalid subexpression type"));
}
}
gmx_ana_index_merge(&sel->u.cgrp, &sel->u.cgrp, &gmiss);
- _gmx_selelem_mempool_release(sel->child);
- _gmx_sel_mempool_free_group(data->mp, &gmiss);
}
- return 0;
}
/*!
* This function is used as \c t_selelem:evaluate for \ref SEL_SUBEXPRREF
* elements for which the \ref SEL_SUBEXPR does not have other references.
*/
-int
+void
_gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
if (g)
{
- int rc;
-
_gmx_selvalue_setstore(&sel->child->v, sel->v.u.ptr);
_gmx_selvalue_setstore_alloc(&sel->child->child->v, sel->v.u.ptr,
sel->child->child->v.nalloc);
- rc = sel->child->evaluate(data, sel->child, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->child->evaluate(data, sel->child, g);
}
sel->v.nr = sel->child->v.nr;
if (sel->u.param)
*sel->u.param->nvalptr = sel->u.param->val.nr;
}
}
- return 0;
}
/*!
* This function is used as \c t_selelem::evaluate for \ref SEL_SUBEXPRREF
* elements.
*/
-int
+void
_gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
t_selelem *expr;
if (g)
{
- int rc;
-
- rc = sel->child->evaluate(data, sel->child, g);
- if (rc != 0)
- {
- return rc;
- }
+ sel->child->evaluate(data, sel->child, g);
}
expr = sel->child;
switch (sel->v.type)
break;
default: /* should not be reached */
- gmx_bug("invalid subexpression reference type");
- return -1;
+ GMX_THROW(gmx::InternalError("Invalid subexpression reference type"));
}
/* Store the number of values if needed */
if (sel->u.param)
*sel->u.param->nvalptr = sel->u.param->val.nr;
}
}
- return 0;
}
/********************************************************************
* This function is not used as \c t_selelem::evaluate,
* but is used internally.
*/
-int
+void
_gmx_sel_evaluate_method_params(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
t_selelem *child;
- int rc;
child = sel->child;
while (child)
{
if (child->flags & SEL_ATOMVAL)
{
- rc = child->evaluate(data, child, g);
+ child->evaluate(data, child, g);
}
else
{
- rc = child->evaluate(data, child, NULL);
child->flags |= SEL_EVALFRAME;
- }
- if (rc != 0)
- {
- return rc;
+ child->evaluate(data, child, NULL);
}
}
child = child->next;
}
- return 0;
}
/*!
* This function is used as \c t_selelem::evaluate for \ref SEL_EXPRESSION
* elements.
*/
-int
+void
_gmx_sel_evaluate_method(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
- rc = _gmx_sel_evaluate_method_params(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ _gmx_sel_evaluate_method_params(data, sel, g);
if (sel->flags & SEL_INITFRAME)
{
- rc = sel->u.expr.method->init_frame(data->top, data->fr, data->pbc,
- sel->u.expr.mdata);
sel->flags &= ~SEL_INITFRAME;
- if (rc != 0)
- {
- return rc;
- }
+ sel->u.expr.method->init_frame(data->top, data->fr, data->pbc,
+ sel->u.expr.mdata);
}
if (sel->u.expr.pc)
{
gmx_ana_poscalc_update(sel->u.expr.pc, sel->u.expr.pos, g,
data->fr, data->pbc);
- rc = sel->u.expr.method->pupdate(data->top, data->fr, data->pbc,
- sel->u.expr.pos, &sel->v,
- sel->u.expr.mdata);
+ sel->u.expr.method->pupdate(data->top, data->fr, data->pbc,
+ sel->u.expr.pos, &sel->v,
+ sel->u.expr.mdata);
}
else
{
- rc = sel->u.expr.method->update(data->top, data->fr, data->pbc, g,
- &sel->v, sel->u.expr.mdata);
+ sel->u.expr.method->update(data->top, data->fr, data->pbc, g,
+ &sel->v, sel->u.expr.mdata);
}
- return rc;
}
/*!
* This function is used as \c t_selelem::evaluate for \ref SEL_MODIFIER
* elements.
*/
-int
+void
_gmx_sel_evaluate_modifier(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
- rc = _gmx_sel_evaluate_method_params(data, sel, g);
- if (rc != 0)
- {
- return rc;
- }
+ _gmx_sel_evaluate_method_params(data, sel, g);
if (sel->flags & SEL_INITFRAME)
{
- rc = sel->u.expr.method->init_frame(data->top, data->fr, data->pbc,
- sel->u.expr.mdata);
sel->flags &= ~SEL_INITFRAME;
- if (rc != 0)
- {
- return rc;
- }
+ sel->u.expr.method->init_frame(data->top, data->fr, data->pbc,
+ sel->u.expr.mdata);
}
if (sel->child->v.type != POS_VALUE)
{
- gmx_bug("non-position valued modifiers not implemented");
- return -1;
+ GMX_THROW(gmx::NotImplementedError("Non-position valued modifiers not implemented"));
}
- rc = sel->u.expr.method->pupdate(data->top, data->fr, data->pbc,
- sel->child->v.u.p,
- &sel->v, sel->u.expr.mdata);
- return rc;
+ sel->u.expr.method->pupdate(data->top, data->fr, data->pbc,
+ sel->child->v.u.p,
+ &sel->v, sel->u.expr.mdata);
}
* This function is used as \c t_selelem::evaluate for \ref SEL_BOOLEAN
* elements with \ref BOOL_NOT.
*/
-int
+void
_gmx_sel_evaluate_not(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
- int rc;
-
- rc = _gmx_selelem_mempool_reserve(sel->child, g->isize);
- if (rc == 0)
- {
- rc = sel->child->evaluate(data, sel->child, g);
- }
- if (rc != 0)
- {
- return rc;
- }
+ MempoolSelelemReserver reserver(sel->child, g->isize);
+ sel->child->evaluate(data, sel->child, g);
gmx_ana_index_difference(sel->v.u.g, g, sel->child->v.u.g);
- _gmx_selelem_mempool_release(sel->child);
- return 0;
}
/*!
* This function is used as \c t_selelem::evaluate for \ref SEL_BOOLEAN
* elements with \ref BOOL_AND.
*/
-int
+void
_gmx_sel_evaluate_and(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
t_selelem *child;
- int rc;
child = sel->child;
/* Skip the first child if it does not have an evaluation function. */
{
child = child->next;
}
- rc = _gmx_selelem_mempool_reserve(child, g->isize);
- if (rc == 0)
- {
- rc = child->evaluate(data, child, g);
- }
- if (rc != 0)
+ /* Evaluate the first child */
{
- return rc;
+ MempoolSelelemReserver reserver(child, g->isize);
+ child->evaluate(data, child, g);
+ gmx_ana_index_copy(sel->v.u.g, child->v.u.g, FALSE);
}
- gmx_ana_index_copy(sel->v.u.g, child->v.u.g, FALSE);
- _gmx_selelem_mempool_release(child);
child = child->next;
while (child && sel->v.u.g->isize > 0)
{
- rc = _gmx_selelem_mempool_reserve(child, sel->v.u.g->isize);
- if (rc == 0)
- {
- rc = child->evaluate(data, child, sel->v.u.g);
- }
- if (rc != 0)
- {
- return rc;
- }
+ MempoolSelelemReserver reserver(child, sel->v.u.g->isize);
+ child->evaluate(data, child, sel->v.u.g);
gmx_ana_index_intersection(sel->v.u.g, sel->v.u.g, child->v.u.g);
- _gmx_selelem_mempool_release(child);
child = child->next;
}
- return 0;
}
/*!
* This function is used as \c t_selelem::evaluate for \ref SEL_BOOLEAN
* elements with \ref BOOL_OR.
*/
-int
+void
_gmx_sel_evaluate_or(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g)
{
t_selelem *child;
gmx_ana_index_t tmp, tmp2;
- int rc;
child = sel->child;
if (child->evaluate)
{
- rc = _gmx_selelem_mempool_reserve(child, g->isize);
- if (rc == 0)
- {
- rc = child->evaluate(data, child, g);
- }
- if (rc != 0)
- {
- return rc;
- }
+ MempoolSelelemReserver reserver(child, g->isize);
+ child->evaluate(data, child, g);
gmx_ana_index_partition(sel->v.u.g, &tmp, g, child->v.u.g);
- _gmx_selelem_mempool_release(child);
}
else
{
while (child && tmp.isize > 0)
{
tmp.name = NULL;
- rc = _gmx_selelem_mempool_reserve(child, tmp.isize);
- if (rc == 0)
- {
- rc = child->evaluate(data, child, &tmp);
- }
- if (rc != 0)
{
- return rc;
+ MempoolSelelemReserver reserver(child, tmp.isize);
+ child->evaluate(data, child, &tmp);
+ gmx_ana_index_partition(&tmp, &tmp2, &tmp, child->v.u.g);
}
- gmx_ana_index_partition(&tmp, &tmp2, &tmp, child->v.u.g);
- _gmx_selelem_mempool_release(child);
sel->v.u.g->isize += tmp.isize;
tmp.isize = tmp2.isize;
tmp.index = tmp2.index;
child = child->next;
}
gmx_ana_index_sort(sel->v.u.g);
- return 0;
}
* \param[in] g Group for which \p sel should be evaluated.
* \returns 0 on success, a non-zero error code on error.
*/
-int
+void
_gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t *data, t_selelem *sel,
gmx_ana_index_t *g)
{
t_selelem *left, *right;
int n, i, i1, i2;
real lval, rval=0., val=0.;
- int rc;
left = sel->child;
right = left->next;
+ SelelemTemporaryValueAssigner assigner;
+ MempoolSelelemReserver reserver;
if (left->mempool)
{
- _gmx_selvalue_setstore(&left->v, sel->v.u.ptr);
+ assigner.assign(left, sel);
if (right)
{
- rc = _gmx_selelem_mempool_reserve(right, g->isize);
- if (rc != 0)
- {
- return rc;
- }
+ reserver.reserve(right, g->isize);
}
}
else if (right && right->mempool)
{
- _gmx_selvalue_setstore(&right->v, sel->v.u.ptr);
+ assigner.assign(right, sel);
}
- rc = _gmx_sel_evaluate_children(data, sel, g);
+ _gmx_sel_evaluate_children(data, sel, g);
n = (sel->flags & SEL_SINGLEVAL) ? 1 : g->isize;
sel->v.nr = n;
++i2;
}
}
-
- if (left->mempool)
- {
- _gmx_selvalue_setstore(&left->v, NULL);
- if (right)
- {
- _gmx_selelem_mempool_release(right);
- }
- }
- else if (right && right->mempool)
- {
- _gmx_selvalue_setstore(&right->v, NULL);
- }
- return 0;
}
struct gmx_sel_mempool_t *mp, gmx_ana_index_t *gall,
t_topology *top, t_trxframe *fr, t_pbc *pbc);
/** Evaluates the children of a general selection element. */
-int
+void
_gmx_sel_evaluate_children(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates the children of a \ref SEL_EXPRESSION element. */
-int
+void
_gmx_sel_evaluate_method_params(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/*@}*/
*/
/*@{*/
/** Evaluates a root selection element. */
-int
+void
_gmx_sel_evaluate_root(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a static group selection element. */
-int
+void
_gmx_sel_evaluate_static(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates an arithmetic expression element. */
-int
+void
_gmx_sel_evaluate_arithmetic(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/*@}*/
*/
/*@{*/
/** Evaluates a subexpression when there is only one reference. */
-int
+void
_gmx_sel_evaluate_subexpr_simple(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a subexpression when the evaluation group is static. */
-int
+void
_gmx_sel_evaluate_subexpr_staticeval(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a subexpression. */
-int
+void
_gmx_sel_evaluate_subexpr(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a subexpression reference when there are no other references. */
-int
+void
_gmx_sel_evaluate_subexprref_simple(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a subexpression reference. */
-int
+void
_gmx_sel_evaluate_subexprref(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/*@}*/
/*@{*/
/** Evaluates a method expression. */
-int
+void
_gmx_sel_evaluate_method(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a modifier expression. */
-int
+void
_gmx_sel_evaluate_modifier(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/*@}*/
*/
/*@{*/
/** Evaluates a boolean NOT element. */
-int
+void
_gmx_sel_evaluate_not(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a boolean AND element with short-circuiting. */
-int
+void
_gmx_sel_evaluate_and(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/** Evaluates a boolean OR element with short-circuiting. */
-int
+void
_gmx_sel_evaluate_or(gmx_sel_evaluate_t *data, t_selelem *sel, gmx_ana_index_t *g);
/*@}*/
#include <config.h>
#endif
-#include <assert.h>
#include <stdlib.h>
-#include <gmx_fatal.h>
+#include <new>
+
#include <smalloc.h>
+#include "gromacs/fatalerror/exceptions.h"
+#include "gromacs/fatalerror/gmxassert.h"
#include "gromacs/selection/indexutil.h"
#include "mempool.h"
size_t maxsize;
};
-int
-_gmx_sel_mempool_create(gmx_sel_mempool_t **mpp)
+gmx_sel_mempool_t *
+_gmx_sel_mempool_create()
{
gmx_sel_mempool_t *mp;
mp->blockstack = NULL;
mp->blockstack_nalloc = 0;
mp->maxsize = 0;
- *mpp = mp;
- return 0;
+ return mp;
}
void
sfree(mp);
}
-int
-_gmx_sel_mempool_alloc(gmx_sel_mempool_t *mp, void **ptrp, size_t size)
+void *
+_gmx_sel_mempool_alloc(gmx_sel_mempool_t *mp, size_t size)
{
void *ptr = NULL;
size_t size_walign;
- *ptrp = NULL;
size_walign = ((size + ALIGN_STEP - 1) / ALIGN_STEP) * ALIGN_STEP;
if (mp->buffer)
{
if (mp->freesize < size)
{
- gmx_bug("out of memory pool memory");
- return ENOMEM;
+ GMX_THROW(gmx::InternalError("Out of memory pool memory"));
}
ptr = mp->freeptr;
mp->freeptr += size_walign;
ptr = malloc(size);
if (!ptr)
{
- gmx_mem("out of memory");
- return ENOMEM;
+ throw std::bad_alloc();
}
mp->currsize += size_walign;
if (mp->currsize > mp->maxsize)
mp->blockstack[mp->nblocks].size = size_walign;
mp->nblocks++;
- *ptrp = ptr;
- return 0;
+ return ptr;
}
void
{
return;
}
- assert(mp->nblocks > 0 && mp->blockstack[mp->nblocks - 1].ptr == ptr);
+ GMX_RELEASE_ASSERT(mp->nblocks > 0 && mp->blockstack[mp->nblocks - 1].ptr == ptr,
+ "Invalid order of memory pool free calls");
mp->nblocks--;
size = mp->blockstack[mp->nblocks].size;
mp->currsize -= size;
}
}
-int
+void
_gmx_sel_mempool_reserve(gmx_sel_mempool_t *mp, size_t size)
{
- assert(mp->nblocks == 0 && !mp->buffer);
+ GMX_RELEASE_ASSERT(mp->nblocks == 0,
+ "Cannot reserve memory pool when there is something allocated");
+ GMX_RELEASE_ASSERT(!mp->buffer, "Cannot reserve memory pool twice");
if (size == 0)
{
size = mp->maxsize;
mp->buffer = (char *)malloc(size);
if (!mp->buffer)
{
- gmx_mem("out of memory");
- return ENOMEM;
+ throw std::bad_alloc();
}
mp->freesize = size;
mp->freeptr = mp->buffer;
- return 0;
}
-int
+void
_gmx_sel_mempool_alloc_group(gmx_sel_mempool_t *mp, gmx_ana_index_t *g,
int isize)
{
- return _gmx_sel_mempool_alloc(mp, (void **)&g->index,
- sizeof(*g->index)*isize);
+ void *ptr = _gmx_sel_mempool_alloc(mp, sizeof(*g->index)*isize);
+ g->index = static_cast<int *>(ptr);
}
void
typedef struct gmx_sel_mempool_t gmx_sel_mempool_t;
/** Create an empty memory pool. */
-int
-_gmx_sel_mempool_create(gmx_sel_mempool_t **mpp);
+gmx_sel_mempool_t *
+_gmx_sel_mempool_create();
/** Destroy a memory pool. */
void
_gmx_sel_mempool_destroy(gmx_sel_mempool_t *mp);
/** Allocate memory from a memory pool. */
-int
-_gmx_sel_mempool_alloc(gmx_sel_mempool_t *mp, void **ptrp, size_t size);
+void *
+_gmx_sel_mempool_alloc(gmx_sel_mempool_t *mp, size_t size);
/** Release memory allocated from a memory pool. */
void
_gmx_sel_mempool_free(gmx_sel_mempool_t *mp, void *ptr);
/** Set the size of a memory pool. */
-int
+void
_gmx_sel_mempool_reserve(gmx_sel_mempool_t *mp, size_t size);
/** Convenience function for allocating an index group from a memory pool. */
-int
+void
_gmx_sel_mempool_alloc_group(gmx_sel_mempool_t *mp, struct gmx_ana_index_t *g,
int isize);
/** Convenience function for freeing an index group from a memory pool. */
};
/*!
- * \param[out] data Neighborhood search data structure pointer to initialize.
* \param[in] cutoff Cutoff distance for the search
* (<=0 stands for no cutoff).
* \param[in] maxn Maximum number of reference particles.
- * \returns 0 on success.
+ * \returns Created neighborhood search data structure.
*/
-int
-gmx_ana_nbsearch_create(gmx_ana_nbsearch_t **data, real cutoff, int maxn)
+gmx_ana_nbsearch_t *
+gmx_ana_nbsearch_create(real cutoff, int maxn)
{
gmx_ana_nbsearch_t *d;
-
+
snew(d, 1);
d->bTryGrid = TRUE;
if (cutoff <= 0)
d->gnboffs = NULL;
d->gnboffs_nalloc = 0;
- *data = d;
- return 0;
+ return d;
}
/*!
* \param[in] pbc PBC information for the frame.
* \param[in] n Number of reference positions for the frame.
* \param[in] x \p n reference positions for the frame.
- * \returns 0 on success.
*
* Initializes the data structure \p d such that it can be used to search
* for the neighbors of \p x.
*/
-int
+void
gmx_ana_nbsearch_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, int n, const rvec x[])
{
d->pbc = pbc;
d->xref = const_cast<rvec *>(x);
}
d->refid = NULL;
- return 0;
}
/*!
* \param[in,out] d Neighborhood search data structure.
* \param[in] pbc PBC information for the frame.
* \param[in] p Reference positions for the frame.
- * \returns 0 on success.
*
* A convenience wrapper for gmx_ana_nbsearch_init().
*/
-int
+void
gmx_ana_nbsearch_pos_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, const gmx_ana_pos_t *p)
{
- int rc;
-
- rc = gmx_ana_nbsearch_init(d, pbc, p->nr, p->x);
+ gmx_ana_nbsearch_init(d, pbc, p->nr, p->x);
d->refid = (p->nr < d->maxnref ? p->m.refid : NULL);
- return rc;
}
/*!
* \param[in] nexcl Number of reference positions to exclude from next
* search.
* \param[in] excl Indices of reference positions to exclude.
- * \returns 0 on success.
*
* The set exclusions remain in effect until the next call of this function.
*/
-int
+void
gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[])
{
d->nexcl = nexcl;
d->excl = excl;
- return 0;
}
/*! \brief
#include "indexutil.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
struct gmx_ana_pos_t;
/** Data structure for neighborhood searches. */
typedef struct gmx_ana_nbsearch_t gmx_ana_nbsearch_t;
/** Create a new neighborhood search data structure. */
-int
-gmx_ana_nbsearch_create(gmx_ana_nbsearch_t **d, real cutoff, int maxn);
+gmx_ana_nbsearch_t *
+gmx_ana_nbsearch_create(real cutoff, int maxn);
/** Free memory allocated for neighborhood search. */
void
gmx_ana_nbsearch_free(gmx_ana_nbsearch_t *d);
/** Initializes neighborhood search for a new frame. */
-int
+void
gmx_ana_nbsearch_init(gmx_ana_nbsearch_t *d, t_pbc *pbc, int n, const rvec x[]);
/** Initializes neighborhood search for a frame using \c gmx_ana_pos_t. */
-int
+void
gmx_ana_nbsearch_pos_init(gmx_ana_nbsearch_t *d, t_pbc *pbc,
const struct gmx_ana_pos_t *p);
/** Sets the exclusions for the next neighborhood search. */
-int
+void
gmx_ana_nbsearch_set_excl(gmx_ana_nbsearch_t *d, int nexcl, int excl[]);
/** Check whether a point is within a neighborhood. */
gmx_bool
gmx_bool
gmx_ana_nbsearch_next_within(gmx_ana_nbsearch_t *d, int *jp);
-#ifdef __cplusplus
-}
-#endif
-
#endif
/*! \internal \brief
* Prepares the selections for evaluation and performs some optimizations.
*/
-int
+void
gmx_ana_selcollection_compile(gmx::SelectionCollection *coll);
/* In evaluate.cpp */
/*! \internal \brief
* Evaluates the selection.
*/
-int
+void
gmx_ana_selcollection_evaluate(gmx_ana_selcollection_t *sc,
t_trxframe *fr, t_pbc *pbc);
/*! \internal \brief
}
-int
+void
SelectionCollection::compile()
{
if (!_impl->hasFlag(Impl::efExternalGroupsSet))
{
printTree(stderr, false);
}
- int rc = gmx_ana_selcollection_compile(this);
- if (rc == 0 && _impl->hasFlag(Impl::efOwnPositionCollection))
+ gmx_ana_selcollection_compile(this);
+ if (_impl->hasFlag(Impl::efOwnPositionCollection))
{
if (_impl->_debugLevel >= 1)
{
std::fprintf(stderr, "\n");
}
}
- return rc;
}
-int
+void
SelectionCollection::evaluate(t_trxframe *fr, t_pbc *pbc)
{
if (_impl->hasFlag(Impl::efOwnPositionCollection))
{
gmx_ana_poscalc_init_frame(_impl->_sc.pcc);
}
- int rc = gmx_ana_selcollection_evaluate(&_impl->_sc, fr, pbc);
- if (rc == 0 && _impl->_debugLevel >= 3)
+ gmx_ana_selcollection_evaluate(&_impl->_sc, fr, pbc);
+ if (_impl->_debugLevel >= 3)
{
std::fprintf(stderr, "\n");
printTree(stderr, true);
}
- return rc;
}
* The covered fraction information is initialized to ::CFRAC_NONE for
* all selections.
*/
- int compile();
+ void compile();
/*! \brief
* Evaluates selections in the collection.
*
* \param[in] pbc PBC data, or NULL if no PBC should be used.
* \returns 0 on successful evaluation, a non-zero error code on error.
*/
- int evaluate(t_trxframe *fr, t_pbc *pbc);
+ void evaluate(t_trxframe *fr, t_pbc *pbc);
/*! \brief
* Evaluates the largest possible index groups from dynamic selections.
*
#include <smalloc.h>
#include <gmx_fatal.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/poscalc.h"
#include "gromacs/selection/position.h"
* Reserves memory for the values of \p sel from the \p sel->mempool
* memory pool. If no memory pool is set, nothing is done.
*/
-int
+void
_gmx_selelem_mempool_reserve(t_selelem *sel, int count)
{
- int rc = 0;
-
if (!sel->mempool)
{
- return 0;
+ return;
}
switch (sel->v.type)
{
case INT_VALUE:
- rc = _gmx_sel_mempool_alloc(sel->mempool, (void **)&sel->v.u.i,
- sizeof(*sel->v.u.i)*count);
+ sel->v.u.i = static_cast<int *>(
+ _gmx_sel_mempool_alloc(sel->mempool, sizeof(*sel->v.u.i)*count));
break;
case REAL_VALUE:
- rc = _gmx_sel_mempool_alloc(sel->mempool, (void **)&sel->v.u.r,
- sizeof(*sel->v.u.r)*count);
+ sel->v.u.r = static_cast<real *>(
+ _gmx_sel_mempool_alloc(sel->mempool, sizeof(*sel->v.u.r)*count));
break;
case GROUP_VALUE:
- rc = _gmx_sel_mempool_alloc_group(sel->mempool, sel->v.u.g, count);
+ _gmx_sel_mempool_alloc_group(sel->mempool, sel->v.u.g, count);
break;
default:
- gmx_incons("mem pooling not implemented for requested type");
- return -1;
+ GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
}
- return rc;
}
/*!
break;
default:
- gmx_incons("mem pooling not implemented for requested type");
- break;
+ GMX_THROW(gmx::InternalError("Memory pooling not implemented for requested type"));
}
}
/*! \brief
* Function pointer for evaluating a \c t_selelem.
*/
-typedef int (*sel_evalfunc)(struct gmx_sel_evaluate_t *data,
- struct t_selelem *sel, gmx_ana_index_t *g);
+typedef void (*sel_evalfunc)(struct gmx_sel_evaluate_t *data,
+ struct t_selelem *sel, gmx_ana_index_t *g);
/*! \internal \brief
* Represents an element of a selection expression.
extern int
_gmx_selelem_set_vtype(t_selelem *sel, e_selvalue_t vtype);
/** Reserves memory for value of a \c t_selelem from a memory pool. */
-extern int
+extern void
_gmx_selelem_mempool_reserve(t_selelem *sel, int count);
/** Releases memory pool used for value of a \c t_selelem. */
extern void
#include "selparam.h"
#include "selvalue.h"
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
struct gmx_ana_pos_t;
struct gmx_ana_poscalc_coll_t;
struct gmx_ana_selcollection_t;
* This function may be called multiple times for the same method if the
* method takes parameters with \ref SPAR_ATOMVAL set.
*/
-typedef int (*sel_initfunc)(t_topology *top, int npar,
+typedef void (*sel_initfunc)(t_topology *top, int npar,
gmx_ana_selparam_t *param, void *data);
/*! \brief
* Initializes output data structure.
* This function may be called multiple times for the same method if the
* method takes parameters with \ref SPAR_ATOMVAL set.
*/
-typedef int (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
+typedef void (*sel_outinitfunc)(t_topology *top, gmx_ana_selvalue_t *out,
void *data);
/*! \brief
* Frees the internal data.
* For static methods, it is called once, with \p fr and \p pbc set to
* NULL.
*/
-typedef int (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+typedef void (*sel_framefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
void *data);
/*! \brief
* Evaluates a selection method.
* without freeing; it is the responsibility of this function to provide
* pointers that can be discarded without memory leaks.
*/
-typedef int (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+typedef void (*sel_updatefunc)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out,
void *data);
/*! \brief
* without freeing; it is the responsibility of this function to provide
* pointers that can be discarded without memory leaks.
*/
-typedef int (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
+typedef void (*sel_updatefunc_pos)(t_topology *top, t_trxframe *fr, t_pbc *pbc,
struct gmx_ana_pos_t *pos,
gmx_ana_selvalue_t *out,
void *data);
gmx_ana_selparam_t *
gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method);
-#ifdef __cplusplus
-}
-#endif
-
#endif
#include <maths.h>
#include <macros.h>
#include <smalloc.h>
-#include <gmx_fatal.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/selmethod.h"
/** Defines the comparison operator for comparison expressions. */
static void *
init_data_compare(int npar, gmx_ana_selparam_t *param);
/** Initializes data for comparison expression evaluation. */
-static int
+static void
init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the memory allocated for comparison expression evaluation. */
static void
free_data_compare(void *data);
/** Evaluates comparison expressions. */
-static int
+static void
evaluate_compare(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
*
* The values are rounded such that the same comparison operator can be used.
*/
-static int
+static void
convert_real_int(int n, t_compare_value *val, e_comparison_t cmpt, gmx_bool bRight)
{
int i;
break;
case CMP_EQUAL:
case CMP_NEQ:
- fprintf(stderr, "comparing equality an integer expression and a real value\n");
sfree(iv);
- return EINVAL;
+ /* TODO: Implement, although it isn't typically very useful.
+ * Implementation is only a matter or proper initialization,
+ * the evaluation function can already handle this case with
+ * proper preparations. */
+ GMX_THROW(gmx::NotImplementedError("Equality comparison between dynamic integer and static real expressions not implemented"));
case CMP_INVALID: /* Should not be reached */
- gmx_bug("internal error");
sfree(iv);
- return EINVAL;
+ GMX_THROW(gmx::InternalError("Invalid comparison type"));
}
}
/* Free the previous value if one is present. */
val->i = iv;
val->flags &= ~CMP_REALVAL;
val->flags |= CMP_ALLOCINT;
- return 0;
}
/*!
* \param[in] data Should point to a \c t_methoddata_compare.
* \returns 0 if the input data is valid, -1 on error.
*/
-static int
+static void
init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_compare *d = (t_methoddata_compare *)data;
n2 = init_comparison_value(&d->right, ¶m[3]);
if (n1 == 0 || n2 == 0)
{
- gmx_bug("one of the values for comparison missing");
- return -1;
+ GMX_THROW(gmx::InternalError("One of the values for comparison missing"));
}
/* Store the comparison type */
d->cmpt = comparison_type(d->cmpop);
if (d->cmpt == CMP_INVALID)
{
- gmx_bug("invalid comparison type");
- return -1;
+ GMX_THROW(gmx::InternalError("Invalid comparison type"));
}
/* Convert the values to the same type */
if ((d->left.flags & CMP_REALVAL) && !(d->right.flags & CMP_REALVAL))
}
else /* d->left is static */
{
- if (convert_real_int(n1, &d->left, d->cmpt, FALSE))
- {
- return -1;
- }
+ convert_real_int(n1, &d->left, d->cmpt, FALSE);
}
}
else if (!(d->left.flags & CMP_REALVAL) && (d->right.flags & CMP_REALVAL))
}
else /* d->right is static */
{
- if (convert_real_int(n2, &d->right, d->cmpt, TRUE))
- {
- return -1;
- }
+ convert_real_int(n2, &d->right, d->cmpt, TRUE);
}
}
- return 0;
}
/*!
* \param[in] g Evaluation index group.
* \param[out] out Output data structure (\p out->u.g is used).
* \param[in] data Should point to a \c t_methoddata_compare.
- * \returns 0 for success.
*/
-static int
+static void
evaluate_compare_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
}
}
out->u.g->isize = ig;
- return 0;
}
/*!
* \param[in] g Evaluation index group.
* \param[out] out Output data structure (\p out->u.g is used).
* \param[in] data Should point to a \c t_methoddata_compare.
- * \returns 0 for success.
*/
-static int
+static void
evaluate_compare_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
}
}
out->u.g->isize = ig;
- return 0;
}
/*!
* \param[in] g Evaluation index group.
* \param[out] out Output data structure (\p out->u.g is used).
* \param[in] data Should point to a \c t_methoddata_compare.
- * \returns 0 for success.
*/
-static int
+static void
evaluate_compare(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
if (!((d->left.flags | d->right.flags) & CMP_REALVAL))
{
- return evaluate_compare_int(top, fr, pbc, g, out, data);
+ evaluate_compare_int(top, fr, pbc, g, out, data);
}
else
{
- return evaluate_compare_real(top, fr, pbc, g, out, data);
+ evaluate_compare_real(top, fr, pbc, g, out, data);
}
- return 0;
}
#include <smalloc.h>
#include <vec.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/nbsearch.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selmethod.h"
static void *
init_data_common(int npar, gmx_ana_selparam_t *param);
/** Initializes a distance-based selection method. */
-static int
+static void
init_common(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the data allocated for a distance-based selection method. */
static void
free_data_common(void *data);
/** Initializes the evaluation of a distance-based within selection method for a frame. */
-static int
+static void
init_frame_common(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Evaluates the \p distance selection method. */
-static int
+static void
evaluate_distance(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p within selection method. */
-static int
+static void
evaluate_within(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
* (\c t_methoddata_distance::nb).
* Also checks that the cutoff is valid.
*/
-static int
+static void
init_common(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_distance *d = (t_methoddata_distance *)data;
if ((param[0].flags & SPAR_SET) && d->cutoff <= 0)
{
- fprintf(stderr, "error: distance cutoff should be > 0");
- return -1;
+ GMX_THROW(gmx::InvalidInputError("Distance cutoff should be > 0"));
}
- return gmx_ana_nbsearch_create(&d->nb, d->cutoff, d->p.nr);
+ d->nb = gmx_ana_nbsearch_create(d->cutoff, d->p.nr);
}
/*!
*
* Initializes the neighborhood search for the current frame.
*/
-static int
+static void
init_frame_common(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data)
{
t_methoddata_distance *d = (t_methoddata_distance *)data;
- return gmx_ana_nbsearch_pos_init(d->nb, pbc, &d->p);
+ gmx_ana_nbsearch_pos_init(d->nb, pbc, &d->p);
}
/*!
* Calculates the distance of each position from \c t_methoddata_distance::p
* and puts them in \p out->u.r.
*/
-static int
+static void
evaluate_distance(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
out->u.r[i] = n;
}
}
- return 0;
}
/*!
* Finds the atoms that are closer than the defined cutoff to
* \c t_methoddata_distance::xref and puts them in \p out.g.
*/
-static int
+static void
evaluate_within(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
gmx_ana_pos_append(NULL, out->u.g, pos, b, 0);
}
}
- return 0;
}
#include <smalloc.h>
#include <vec.h>
+// FIXME: Should really be in the beginning, but causes compilation errors
+#include <algorithm>
+
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/indexutil.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selection.h"
#include "selelem.h"
+using std::min;
+using std::max;
+
/*! \internal \brief
* Internal data structure for the \p insolidangle selection method.
*
static void *
init_data_insolidangle(int npar, gmx_ana_selparam_t *param);
/** Initializes the \p insolidangle selection method. */
-static int
+static void
init_insolidangle(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Sets the COM/COG data for the \p insolidangle selection method. */
static void
static void
free_data_insolidangle(void *data);
/** Initializes the evaluation of the \p insolidangle selection method for a frame. */
-static int
+static void
init_frame_insolidangle(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Internal helper function for evaluate_insolidangle(). */
static gmx_bool
accept_insolidangle(rvec x, t_pbc *pbc, void *data);
/** Evaluates the \p insolidangle selection method. */
-static int
+static void
evaluate_insolidangle(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
* Converts t_methoddata_insolidangle::angcut to radians and allocates
* and allocates memory for the bins used during the evaluation.
*/
-static int
+static void
init_insolidangle(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_insolidangle *surf = (t_methoddata_insolidangle *)data;
if (surf->angcut <= 0)
{
- fprintf(stderr, "error: angle cutoff should be > 0");
- return -1;
+ GMX_THROW(gmx::InvalidInputError("Angle cutoff should be > 0"));
}
surf->angcut *= DEG2RAD;
}
surf->nbins = 0;
snew(surf->bin, surf->maxbins);
-
- return 0;
}
/*!
* \param[in] fr Current frame.
* \param[in] pbc PBC structure.
* \param data Should point to a \ref t_methoddata_insolidangle.
- * \returns 0 on success, a non-zero error code on error.
*
* Creates a lookup structure that enables fast queries of whether a point
* is within the solid angle or not.
*/
-static int
+static void
init_frame_insolidangle(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data)
{
t_methoddata_insolidangle *d = (t_methoddata_insolidangle *)data;
}
optimize_surface_points(d);
d->cfrac = -1;
- return 0;
}
/*!
* \c t_methoddata_insolidangle::span and centered at
* \c t_methoddata_insolidangle::center, and stores the result in \p out->u.g.
*/
-static int
+static void
evaluate_insolidangle(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
gmx_ana_pos_append(NULL, out->u.g, pos, b, 0);
}
}
- return 0;
}
/*!
tmax = acos(cos(theta) / cos(surf->angcut));
}
/* Find the first affected bin */
- tbin = max(floor((theta - surf->angcut) / surf->tbinsize), 0);
+ tbin = max(floor((theta - surf->angcut) / surf->tbinsize), 0.0);
theta1 = tbin * surf->tbinsize;
if (theta1 < theta - surf->angcut)
{
static void *
init_data_kwstr(int npar, gmx_ana_selparam_t *param);
/** Initializes data for integer keyword evaluation. */
-static int
+static void
init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes data for real keyword evaluation. */
-static int
+static void
init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes data for string keyword evaluation. */
-static int
+static void
init_kwstr(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the memory allocated for string keyword evaluation. */
static void
free_data_kwstr(void *data);
/** Evaluates integer selection keywords. */
-static int
+static void
evaluate_keyword_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates real selection keywords. */
-static int
+static void
evaluate_keyword_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates string selection keywords. */
-static int
+static void
evaluate_keyword_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
};
/** Initializes keyword evaluation for an arbitrary group. */
-static int
+static void
init_kweval(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes output for keyword evaluation in an arbitrary group. */
-static int
+static void
init_output_kweval(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Frees the data allocated for keyword evaluation in an arbitrary group. */
static void
free_data_kweval(void *data);
/** Initializes frame evaluation for keyword evaluation in an arbitrary group. */
-static int
+static void
init_frame_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Evaluates keywords in an arbitrary group. */
-static int
+static void
evaluate_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
* \param[in] npar Not used (should be 2).
* \param[in] param Method parameters (should point to \ref smparams_keyword_int).
* \param[in] data Should point to \ref t_methoddata_kwint.
- * \returns 0 (the initialization always succeeds).
*/
-static int
+static void
init_kwint(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kwint *d = (t_methoddata_kwint *)data;
d->v = param[0].val.u.i;
d->n = param[1].val.nr;
d->r = param[1].val.u.i;
- return 0;
}
/*!
* \c t_methoddata_kwint structure for this selection.
* Matching atoms are stored in \p out->u.g.
*/
-static int
+static void
evaluate_keyword_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
out->u.g->index[out->u.g->isize++] = g->index[i];
}
}
- return 0;
}
* \param[in] data Should point to \ref t_methoddata_kwreal.
* \returns 0 (the initialization always succeeds).
*/
-static int
+static void
init_kwreal(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kwreal *d = (t_methoddata_kwreal *)data;
d->v = param[0].val.u.r;
d->n = param[1].val.nr;
d->r = param[1].val.u.r;
- return 0;
}
/*!
* \c t_methoddata_kwreal structure for this selection.
* Matching atoms are stored in \p out->u.g.
*/
-static int
+static void
evaluate_keyword_real(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
out->u.g->index[out->u.g->isize++] = g->index[i];
}
}
- return 0;
}
* \param[in] npar Not used (should be 2).
* \param[in] param Method parameters (should point to \ref smparams_keyword_str).
* \param[in] data Should point to \ref t_methoddata_kwstr.
- * \returns 0 (the initialization always succeeds).
*/
-static int
+static void
init_kwstr(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kwstr *d = (t_methoddata_kwstr *)data;
/* Return if this is not the first time */
if (d->m)
{
- return 0;
+ return;
}
snew(d->m, d->n);
for (i = 0; i < d->n; ++i)
}
if (bRegExp)
{
+ // TODO: Get rid of these prints to stderr
#ifdef USE_REGEX
snew(buf, strlen(s) + 3);
sprintf(buf, "^%s$", s);
}
d->m[i].bRegExp = bRegExp;
}
- return 0;
}
/*!
* Wildcards are allowed in the strings.
* Matching atoms are stored in \p out->u.g.
*/
-static int
+static void
evaluate_keyword_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
out->u.g->index[out->u.g->isize++] = g->index[i];
}
}
- return 0;
}
*
* Calls the initialization method of the wrapped keyword.
*/
-static int
+static void
init_kweval(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
- return d->kwmethod->init(top, 0, NULL, d->kwmdata);
+ d->kwmethod->init(top, 0, NULL, d->kwmdata);
}
/*!
* \param[in,out] data Should point to \c t_methoddata_kweval.
* \returns 0 for success.
*/
-static int
+static void
init_output_kweval(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
out->nr = d->g.isize;
- return 0;
}
/*!
* Creates a lookup structure that enables fast queries of whether a point
* is within the solid angle or not.
*/
-static int
+static void
init_frame_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
- return d->kwmethod->init_frame(top, fr, pbc, d->kwmdata);
+ d->kwmethod->init_frame(top, fr, pbc, d->kwmdata);
}
/*!
* parameters, with the exception of using \c t_methoddata_kweval::g for the
* evaluation group.
*/
-static int
+static void
evaluate_kweval(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_kweval *d = (t_methoddata_kweval *)data;
- return d->kwmethod->update(top, fr, pbc, &d->g, out, d->kwmdata);
+ d->kwmethod->update(top, fr, pbc, &d->g, out, d->kwmdata);
}
/*!
#include <smalloc.h>
#include <vec.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selmethod.h"
static void *
init_data_merge(int npar, gmx_ana_selparam_t *param);
/** Initializes data for the merging selection modifiers. */
-static int
+static void
init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes output for the \p merge selection modifier. */
-static int
+static void
init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Initializes output for the \p plus selection modifier. */
-static int
+static void
init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Frees the memory allocated for the merging selection modifiers. */
static void
free_data_merge(void *data);
/** Evaluates the \p merge selection modifier. */
-static int
+static void
evaluate_merge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p plus selection modifier. */
-static int
+static void
evaluate_plus(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data);
* \param[in] data Should point to a \p t_methoddata_merge.
* \returns 0 if everything is successful, -1 on error.
*/
-static int
+static void
init_merge(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_merge *d = (t_methoddata_merge *)data;
if (d->stride < 0)
{
- fprintf(stderr, "error: stride for merging should be positive\n");
- return -1;
+ GMX_THROW(gmx::InvalidInputError("Stride for merging should be positive"));
}
/* If no stride given, deduce it from the input sizes */
if (d->stride == 0)
}
if (d->p1.nr != d->stride*d->p2.nr)
{
- fprintf(stderr, "error: the number of positions to be merged are not compatible\n");
- return -1;
+ GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
}
/* We access the m.b.nra field instead of g->isize in the position
* data structures to handle cases where g is NULL
* (this occurs with constant positions. */
gmx_ana_index_reserve(&d->g, d->p1.m.b.nra + d->p2.m.b.nra);
d->g.isize = d->p1.m.b.nra + d->p2.m.b.nra;
- return 0;
}
/*! \brief
* \param[in] top Topology data structure.
* \param[in,out] out Pointer to output data structure.
* \param[in,out] data Should point to \c t_methoddata_merge.
- * \returns 0 for success.
*/
-static int
+static void
init_output_common(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_merge *d = (t_methoddata_merge *)data;
gmx_ana_pos_set_evalgrp(out->u.p, &d->g);
gmx_ana_pos_empty_init(out->u.p);
d->g.isize = 0;
- return 0;
}
/*!
* \param[in] top Topology data structure.
* \param[in,out] out Pointer to output data structure.
* \param[in,out] data Should point to \c t_methoddata_merge.
- * \returns 0 for success.
*/
-static int
+static void
init_output_merge(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_merge *d = (t_methoddata_merge *)data;
}
gmx_ana_pos_append_init(out->u.p, &d->g, &d->p2, i);
}
- return 0;
}
/*!
* \param[in] top Topology data structure.
* \param[in,out] out Pointer to output data structure.
* \param[in,out] data Should point to \c t_methoddata_merge.
- * \returns 0 for success.
*/
-static int
+static void
init_output_plus(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_merge *d = (t_methoddata_merge *)data;
{
gmx_ana_pos_append_init(out->u.p, &d->g, &d->p2, i);
}
- return 0;
}
/*!
* \param[in] p Positions to merge (should point to \p data->p1).
* \param[out] out Output data structure (\p out->u.p is used).
* \param[in] data Should point to a \p t_methoddata_merge.
- * \returns 0 on success.
*/
-static int
+static void
evaluate_merge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data)
{
if (d->p1.nr != d->stride*d->p2.nr)
{
- fprintf(stderr, "error: the number of positions to be merged are not compatible\n");
- return -1;
+ GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
}
d->g.isize = 0;
gmx_ana_pos_empty(out->u.p);
gmx_ana_pos_append(out->u.p, &d->g, &d->p2, i, refid);
}
gmx_ana_pos_append_finish(out->u.p);
- return 0;
}
/*!
* \param[in] p Positions to merge (should point to \p data->p1).
* \param[out] out Output data structure (\p out->u.p is used).
* \param[in] data Should point to a \p t_methoddata_merge.
- * \returns 0 on success.
*/
-static int
+static void
evaluate_plus(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data)
{
gmx_ana_pos_append(out->u.p, &d->g, &d->p2, i, refid);
}
gmx_ana_pos_append_finish(out->u.p);
- return 0;
}
#include <smalloc.h>
#include <vec.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selmethod.h"
+#include "gromacs/utility/format.h"
/*! \internal \brief
* Data structure for the \p permute selection modifier.
static void *
init_data_permute(int npar, gmx_ana_selparam_t *param);
/** Initializes data for the \p permute selection modifier. */
-static int
+static void
init_permute(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes output for the \p permute selection modifier. */
-static int
+static void
init_output_permute(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Frees the memory allocated for the \p permute selection modifier. */
static void
free_data_permute(void *data);
/** Evaluates the \p permute selection modifier. */
-static int
+static void
evaluate_permute(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data);
* \param[in] data Should point to a \p t_methoddata_permute.
* \returns 0 if the input permutation is valid, -1 on error.
*/
-static int
+static void
init_permute(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_permute *d = (t_methoddata_permute *)data;
d->perm = param[1].val.u.i;
if (d->p.nr % d->n != 0)
{
- fprintf(stderr, "error: the number of positions to be permuted is not divisible by %d\n",
- d->n);
- return -1;
+ GMX_THROW(gmx::InconsistentInputError(
+ gmx::formatString("The number of positions to be permuted is not divisible by %d", d->n)));
}
snew(d->rperm, d->n);
for (i = 0; i < d->n; ++i)
d->perm[i]--;
if (d->perm[i] < 0 || d->perm[i] >= d->n)
{
- fprintf(stderr, "invalid permutation");
- return -1;
+ GMX_THROW(gmx::InvalidInputError("Invalid permutation"));
}
if (d->rperm[d->perm[i]] >= 0)
{
- fprintf(stderr, "invalid permutation");
- return -1;
+ GMX_THROW(gmx::InvalidInputError("Invalid permutation"));
}
d->rperm[d->perm[i]] = i;
}
- return 0;
}
/*!
* \param[in] top Topology data structure.
* \param[in,out] out Pointer to output data structure.
* \param[in,out] data Should point to \c t_methoddata_permute.
- * \returns 0 for success.
*/
-static int
+static void
init_output_permute(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_permute *d = (t_methoddata_permute *)data;
gmx_ana_pos_append_init(out->u.p, &d->g, &d->p, b);
}
}
- return 0;
}
/*!
* Returns -1 if the size of \p p is not divisible by the number of
* elements in the permutation.
*/
-static int
+static void
evaluate_permute(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *p, gmx_ana_selvalue_t *out, void *data)
{
if (d->p.nr % d->n != 0)
{
- fprintf(stderr, "error: the number of positions to be permuted is not divisible by %d\n",
- d->n);
- return -1;
+ GMX_THROW(gmx::InconsistentInputError(
+ gmx::formatString("The number of positions to be permuted is not divisible by %d", d->n)));
}
d->g.isize = 0;
gmx_ana_pos_empty(out->u.p);
}
}
gmx_ana_pos_append_finish(out->u.p);
- return 0;
}
static void
set_poscoll_pos(gmx_ana_poscalc_coll_t *pcc, void *data);
/** Initializes position evaluation keywords. */
-static int
+static void
init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes the \p cog selection method. */
-static int
+static void
init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes the \p cog selection method. */
-static int
+static void
init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Initializes output for position evaluation selection methods. */
-static int
+static void
init_output_pos(t_topology *top, gmx_ana_selvalue_t *out, void *data);
/** Frees the data allocated for position evaluation selection methods. */
static void
free_data_pos(void *data);
/** Evaluates position evaluation selection methods. */
-static int
+static void
evaluate_pos(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
* The \c t_methoddata_pos::type field should have been initialized
* externally using _gmx_selelem_set_kwpos_type().
*/
-static int
+static void
init_kwpos(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_pos *d = (t_methoddata_pos *)data;
- int rc;
if (!(param[0].flags & SPAR_DYNAMIC))
{
{
d->flags |= POS_DYNAMIC;
}
- // FIXME: This may throw, but only on internal errors.
- // Will be taken automatically care of when selection compilation fully
- // uses exceptions.
gmx_ana_poscalc_create_enum(&d->pc, d->pcc, d->type, d->flags);
gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
- return 0;
}
/*!
* \param[in,out] data Should point to \c t_methoddata_pos.
* \returns 0 on success, a non-zero error code on error.
*/
-static int
+static void
init_cog(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_pos *d = (t_methoddata_pos *)data;
- int rc;
d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0;
gmx_ana_poscalc_create(&d->pc, d->pcc, d->bPBC ? POS_ALL_PBC : POS_ALL,
d->flags);
gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
- return 0;
}
/*!
* \param[in,out] data Should point to \c t_methoddata_pos.
* \returns 0 on success, a non-zero error code on error.
*/
-static int
+static void
init_com(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_pos *d = (t_methoddata_pos *)data;
- int rc;
d->flags = (param[0].flags & SPAR_DYNAMIC) ? POS_DYNAMIC : 0;
d->flags |= POS_MASS;
gmx_ana_poscalc_create(&d->pc, d->pcc, d->bPBC ? POS_ALL_PBC : POS_ALL,
d->flags);
gmx_ana_poscalc_set_maxindex(d->pc, &d->g);
- return 0;
}
/*!
* \param[in,out] data Should point to \c t_methoddata_pos.
* \returns 0 for success.
*/
-static int
+static void
init_output_pos(t_topology *top, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_pos *d = (t_methoddata_pos *)data;
gmx_ana_poscalc_init_pos(d->pc, out->u.p);
gmx_ana_pos_set_evalgrp(out->u.p, &d->g);
- return 0;
}
/*!
* Calculates the positions using \c t_methoddata_pos::pc for the index group
* in \c t_methoddata_pos::g and stores the results in \p out->u.p.
*/
-static int
+static void
evaluate_pos(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
t_methoddata_pos *d = (t_methoddata_pos *)data;
gmx_ana_poscalc_update(d->pc, out->u.p, &d->g, fr, pbc);
- return 0;
}
#include <smalloc.h>
#include <string2.h>
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/selmethod.h"
#include "keywords.h"
static void *
init_data_same(int npar, gmx_ana_selparam_t *param);
/** Initializes the \p same selection method. */
-static int
+static void
init_same(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Frees the data allocated for the \p same selection method. */
static void
free_data_same(void *data);
/** Initializes the evaluation of the \p same selection method for a frame. */
-static int
+static void
init_frame_same_int(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Evaluates the \p same selection method. */
-static int
+static void
evaluate_same_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Initializes the evaluation of the \p same selection method for a frame. */
-static int
+static void
init_frame_same_str(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data);
/** Evaluates the \p same selection method. */
-static int
+static void
evaluate_same_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
* \param data Pointer to \ref t_methoddata_same to initialize.
* \returns 0 on success, -1 on failure.
*/
-static int
+static void
init_same(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
t_methoddata_same *d = (t_methoddata_same *)data;
}
if (!(param[0].flags & SPAR_ATOMVAL))
{
- fprintf(stderr, "ERROR: the same selection keyword combined with a "
- "non-keyword does not make sense\n");
- return -1;
+ GMX_THROW(gmx::InvalidInputError(
+ "The 'same' selection keyword combined with a "
+ "non-keyword does not make sense"));
}
- return 0;
}
/*!
* \param[in] fr Current frame.
* \param[in] pbc PBC structure.
* \param data Should point to a \ref t_methoddata_same.
- * \returns 0 on success, a non-zero error code on error.
*
* Sorts the \c data->as.i array and removes identical values for faster and
* simpler lookup.
*/
-static int
+static void
init_frame_same_int(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data)
{
t_methoddata_same *d = (t_methoddata_same *)data;
}
d->nas = j + 1;
}
- return 0;
}
/*!
* binary search of \c data->as is performed for each block of values in
* \c data->val.
*/
-static int
+static void
evaluate_same_int(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
d->bSorted = FALSE;
}
}
- return 0;
}
/*! \brief
* \param[in] fr Current frame.
* \param[in] pbc PBC structure.
* \param data Should point to a \ref t_methoddata_same.
- * \returns 0 on success, a non-zero error code on error.
*
* Sorts the \c data->as.s array and removes identical values for faster and
* simpler lookup.
*/
-static int
+static void
init_frame_same_str(t_topology *top, t_trxframe *fr, t_pbc *pbc, void *data)
{
t_methoddata_same *d = (t_methoddata_same *)data;
}
}
d->nas = j + 1;
- return 0;
}
/*!
* A binary search of \c data->as is performed for each block of values in
* \c data->val.
*/
-static int
+static void
evaluate_same_str(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
}
}
}
- return 0;
}
#include <config.h>
#endif
+#include "gromacs/fatalerror/exceptions.h"
#include "gromacs/selection/position.h"
#include "gromacs/selection/selmethod.h"
/** Evaluates the \p all selection keyword. */
-static int
+static void
evaluate_all(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p none selection keyword. */
-static int
+static void
evaluate_none(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p atomnr selection keyword. */
-static int
+static void
evaluate_atomnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p resnr selection keyword. */
-static int
+static void
evaluate_resnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p resindex selection keyword. */
-static int
+static void
evaluate_resindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Checks whether molecule information is present in the topology. */
-static int
+static void
check_molecules(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Evaluates the \p molindex selection keyword. */
-static int
+static void
evaluate_molindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p name selection keyword. */
-static int
+static void
evaluate_atomname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Checks whether atom types are present in the topology. */
-static int
+static void
check_atomtype(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Evaluates the \p type selection keyword. */
-static int
+static void
evaluate_atomtype(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p insertcode selection keyword. */
-static int
+static void
evaluate_insertcode(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p chain selection keyword. */
-static int
+static void
evaluate_chain(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p mass selection keyword. */
-static int
+static void
evaluate_mass(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p charge selection keyword. */
-static int
+static void
evaluate_charge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Checks whether PDB info is present in the topology. */
-static int
+static void
check_pdbinfo(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data);
/** Evaluates the \p altloc selection keyword. */
-static int
+static void
evaluate_altloc(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p occupancy selection keyword. */
-static int
+static void
evaluate_occupancy(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p betafactor selection keyword. */
-static int
+static void
evaluate_betafactor(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p resname selection keyword. */
-static int
+static void
evaluate_resname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p x selection keyword. */
-static int
+static void
evaluate_x(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p y selection keyword. */
-static int
+static void
evaluate_y(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
/** Evaluates the \p z selection keyword. */
-static int
+static void
evaluate_z(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data);
*
* Copies \p g to \p out->u.g.
*/
-static int
+static void
evaluate_all(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
gmx_ana_index_copy(out->u.g, g, FALSE);
- return 0;
}
/*!
*
* Returns an empty \p out->u.g.
*/
-static int
+static void
evaluate_none(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
out->u.g->isize = 0;
- return 0;
}
/*!
*
* Returns the indices for each atom in \p out->u.i.
*/
-static int
+static void
evaluate_atomnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.i[i] = g->index[i] + 1;
}
- return 0;
}
/*!
*
* Returns the residue numbers for each atom in \p out->u.i.
*/
-static int
+static void
evaluate_resnr(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
resind = top->atoms.atom[g->index[i]].resind;
out->u.i[i] = top->atoms.resinfo[resind].nr;
}
- return 0;
}
/*!
*
* Returns the residue indices for each atom in \p out->u.i.
*/
-static int
+static void
evaluate_resindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.i[i] = top->atoms.atom[g->index[i]].resind + 1;
}
- return 0;
}
/*!
*
* If molecule information is not found, also prints an error message.
*/
-static int
+static void
check_molecules(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
gmx_bool bOk;
bOk = (top != NULL && top->mols.nr > 0);
if (!bOk)
{
- fprintf(stderr, "Molecule information not available in topology!\n");
- return -1;
+ GMX_THROW(gmx::InconsistentInputError("Molecule information not available in topology"));
}
- return 0;
}
/*!
*
* Returns the molecule indices for each atom in \p out->u.i.
*/
-static int
+static void
evaluate_molindex(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
while (top->mols.index[j + 1] <= g->index[i]) ++j;
out->u.i[i] = j + 1;
}
- return 0;
}
/*!
*
* Returns the atom name for each atom in \p out->u.s.
*/
-static int
+static void
evaluate_atomname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.s[i] = *top->atoms.atomname[g->index[i]];
}
- return 0;
}
/*!
*
* If the atom types are not found, also prints an error message.
*/
-static int
+static void
check_atomtype(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
gmx_bool bOk;
bOk = (top != NULL && top->atoms.atomtype != NULL);
if (!bOk)
{
- fprintf(stderr, "Atom types not available in topology!\n");
- return -1;
+ GMX_THROW(gmx::InconsistentInputError("Atom types not available in topology"));
}
- return 0;
}
/*!
* Returns the atom type for each atom in \p out->u.s.
* Segfaults if atom types are not found in the topology.
*/
-static int
+static void
evaluate_atomtype(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.s[i] = *top->atoms.atomtype[g->index[i]];
}
- return 0;
}
/*!
*
* Returns the residue name for each atom in \p out->u.s.
*/
-static int
+static void
evaluate_resname(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
resind = top->atoms.atom[g->index[i]].resind;
out->u.s[i] = *top->atoms.resinfo[resind].name;
}
- return 0;
}
/*!
*
* Returns the insertion code for each atom in \p out->u.s.
*/
-static int
+static void
evaluate_insertcode(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
resind = top->atoms.atom[g->index[i]].resind;
out->u.s[i][0] = top->atoms.resinfo[resind].ic;
}
- return 0;
}
/*!
*
* Returns the chain for each atom in \p out->u.s.
*/
-static int
+static void
evaluate_chain(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
resind = top->atoms.atom[g->index[i]].resind;
out->u.s[i][0] = top->atoms.resinfo[resind].chainid;
}
- return 0;
}
/*!
*
* Returns the mass for each atom in \p out->u.r.
*/
-static int
+static void
evaluate_mass(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.r[i] = top->atoms.atom[g->index[i]].m;
}
- return 0;
}
/*!
*
* Returns the charge for each atom in \p out->u.r.
*/
-static int
+static void
evaluate_charge(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.r[i] = top->atoms.atom[g->index[i]].q;
}
- return 0;
}
/*!
*
* If PDB info is not found, also prints an error message.
*/
-static int
+static void
check_pdbinfo(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
gmx_bool bOk;
bOk = (top != NULL && top->atoms.pdbinfo != NULL);
if (!bOk)
{
- fprintf(stderr, "PDB info not available in topology!\n");
- return -1;
+ GMX_THROW(gmx::InconsistentInputError("PDB info not available in topology"));
}
- return 0;
}
/*!
*
* Returns the alternate location identifier for each atom in \p out->u.s.
*/
-static int
+static void
evaluate_altloc(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.s[i][0] = top->atoms.pdbinfo[g->index[i]].altloc;
}
- return 0;
}
/*!
* Returns the occupancy numbers for each atom in \p out->u.r.
* Segfaults if PDB info is not found in the topology.
*/
-static int
+static void
evaluate_occupancy(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.r[i] = top->atoms.pdbinfo[g->index[i]].occup;
}
- return 0;
}
/*!
* Returns the B-factors for each atom in \p out->u.r.
* Segfaults if PDB info is not found in the topology.
*/
-static int
+static void
evaluate_betafactor(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
{
{
out->u.r[i] = top->atoms.pdbinfo[g->index[i]].bfac;
}
- return 0;
}
/*! \brief
*
* Returns the \p x coordinate for each atom in \p out->u.r.
*/
-static int
+static void
evaluate_x(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
out->nr = pos->g->isize;
evaluate_coord(fr, pos->g, out->u.r, pos, XX);
- return 0;
}
/*!
*
* Returns the \p y coordinate for each atom in \p out->u.r.
*/
-static int
+static void
evaluate_y(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
out->nr = pos->g->isize;
evaluate_coord(fr, pos->g, out->u.r, pos, YY);
- return 0;
}
/*!
*
* Returns the \p z coordinate for each atom in \p out->u.r.
*/
-static int
+static void
evaluate_z(t_topology *top, t_trxframe *fr, t_pbc *pbc,
gmx_ana_pos_t *pos, gmx_ana_selvalue_t *out, void *data)
{
out->nr = pos->g->isize;
evaluate_coord(fr, pos->g, out->u.r, pos, ZZ);
- return 0;
}
void
SelectionCollectionDataTest::runCompiler()
{
- ASSERT_EQ(0, _sc.compile());
+ ASSERT_NO_THROW(_sc.compile());
ASSERT_EQ(_count, _sel.size());
checkCompiled();
}
SelectionCollectionDataTest::runEvaluate()
{
++_framenr;
- ASSERT_EQ(0, _sc.evaluate(_frame, NULL));
+ ASSERT_NO_THROW(_sc.evaluate(_frame, NULL));
for (size_t i = 0; i < _count; ++i)
{
SCOPED_TRACE(std::string("Checking selection \"") +
TEST_F(SelectionCollectionTest, HandlesNoSelections)
{
EXPECT_FALSE(_sc.requiresTopology());
- EXPECT_EQ(0, _sc.compile());
+ EXPECT_NO_THROW(_sc.compile());
}
+// TODO: Tests for error conditions
+
/********************************************************************
* Tests for selection keywords
}
common.initTopology(&selections);
- rc = selections.compile();
- if (rc != 0)
- {
- // Error message has already been printed.
- return 1;
- }
+ selections.compile();
const TopologyInformation &topology = common.topologyInformation();
module->initAnalysis(topology);
set_pbc(ppbc, topology.ePBC(), frame.box);
}
- rc = selections.evaluate(&frame, ppbc);
- if (rc != 0)
- {
- // Error message has already been printed.
- return 1;
- }
+ selections.evaluate(&frame, ppbc);
module->analyzeFrame(nframes, frame, ppbc, pdata.get());
nframes++;
class NeighborhoodSearch
{
public:
- ~NeighborhoodSearch() { gmx_ana_nbsearch_free(_d); }
-
- static int create(NeighborhoodSearch **nbp, real cutoff, int maxn)
+ NeighborhoodSearch(real cutoff, int maxn)
+ : _d(gmx_ana_nbsearch_create(cutoff, maxn))
{
- gmx_ana_nbsearch_t *d;
- int rc = gmx_ana_nbsearch_create(&d, cutoff, maxn);
- if (rc != 0)
- {
- *nbp = NULL;
- return rc;
- }
- *nbp = new NeighborhoodSearch(d);
- return 0;
}
+ ~NeighborhoodSearch() { gmx_ana_nbsearch_free(_d); }
- int init(t_pbc *pbc, int n, const rvec x[])
- { return gmx_ana_nbsearch_init(_d, pbc, n, x); }
+ void init(t_pbc *pbc, int n, const rvec x[])
+ { gmx_ana_nbsearch_init(_d, pbc, n, x); }
- int init(t_pbc *pbc, const gmx_ana_pos_t *p)
- { return gmx_ana_nbsearch_pos_init(_d, pbc, p); }
+ void init(t_pbc *pbc, const gmx_ana_pos_t *p)
+ { gmx_ana_nbsearch_pos_init(_d, pbc, p); }
- int setExclusions(int nexcl, atom_id *excl)
- { return gmx_ana_nbsearch_set_excl(_d, nexcl, excl); }
+ void setExclusions(int nexcl, atom_id *excl)
+ { gmx_ana_nbsearch_set_excl(_d, nexcl, excl); }
bool isWithin(const rvec x)
{ return gmx_ana_nbsearch_next_within(_d, jp); }
private:
- NeighborhoodSearch(gmx_ana_nbsearch_t *d) : _d(d) {}
-
gmx_ana_nbsearch_t *_d;
};