/*
+ * This file is part of the GROMACS molecular simulation package.
*
- * This source code is part of
+ * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
*
- * G R O M A C S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
*
- * GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \internal \file
* \brief
* Implements gmx::AbstractAnalysisData.
*
- * \author Teemu Murtola <teemu.murtola@cbr.su.se>
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_analysisdata
*/
-#include "gromacs/analysisdata/abstractdata.h"
+#include "gmxpre.h"
+
+#include "abstractdata.h"
#include <vector>
+#include "gromacs/analysisdata/dataframe.h"
#include "gromacs/analysisdata/datamodule.h"
+#include "gromacs/analysisdata/datamodulemanager.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/uniqueptr.h"
-#include "dataframe.h"
#include "dataproxy.h"
namespace gmx
class AbstractAnalysisData::Impl
{
public:
- //! Shorthand for list of modules added to the data.
- typedef std::vector<AnalysisDataModulePointer> ModuleList;
-
Impl();
- /*! \brief
- * Present data already added to the data object to a module.
- *
- * \param[in] data Data object to read data from.
- * \param[in] module Module to present the data to.
- * \throws APIError if \p module is not compatible with the data
- * object.
- * \throws APIError if all data is not available through
- * getDataFrame().
- * \throws unspecified Any exception thrown by \p module in its data
- * notification methods.
- *
- * Uses getDataFrame() in \p data to access all data in the object, and
- * calls the notification functions in \p module as if the module had
- * been registered to the data object when the data was added.
- */
- void presentData(AbstractAnalysisData *data,
- AnalysisDataModuleInterface *module);
-
- //! List of modules added to the data.
- ModuleList _modules;
- //! true if all modules support missing data.
- bool _bAllowMissing;
- //! Whether notifyDataStart() has been called.
- mutable bool _bDataStart;
- //! Whether new data is being added.
- mutable bool _bInData;
- //! Whether data for a frame is being added.
- mutable bool _bInFrame;
- //! Index of the currently active frame.
- mutable int _currIndex;
- /*! \brief
- * Total number of frames in the data.
- *
- * The counter is incremented in notifyFrameFinish().
- */
- int _nframes;
+ //! Column counts for each data set in the data.
+ std::vector<int> columnCounts_;
+ //! Whether the data is multipoint.
+ bool bMultipoint_;
+ //! Manager for the added modules.
+ AnalysisDataModuleManager modules_;
};
AbstractAnalysisData::Impl::Impl()
- : _bAllowMissing(true), _bDataStart(false), _bInData(false), _bInFrame(false),
- _currIndex(-1), _nframes(0)
+ : bMultipoint_(false)
{
-}
-
-void
-AbstractAnalysisData::Impl::presentData(AbstractAnalysisData *data,
- AnalysisDataModuleInterface *module)
-{
- module->dataStarted(data);
- bool bCheckMissing = _bAllowMissing
- && !(module->flags() & AnalysisDataModuleInterface::efAllowMissing);
- for (int i = 0; i < data->frameCount(); ++i)
- {
- AnalysisDataFrameRef frame = data->getDataFrame(i);
- GMX_RELEASE_ASSERT(frame.isValid(), "Invalid data frame returned");
- // TODO: Check all frames before doing anything for slightly better
- // exception behavior.
- if (bCheckMissing && !frame.allPresent())
- {
- GMX_THROW(APIError("Missing data not supported by a module"));
- }
- module->frameStarted(frame.header());
- module->pointsAdded(frame.points());
- module->frameFinished(frame.header());
- }
- if (!_bInData)
- {
- module->dataFinished();
- }
+ columnCounts_.push_back(0);
}
*/
/*! \cond libapi */
AbstractAnalysisData::AbstractAnalysisData()
- : _impl(new Impl()), _ncol(0), _bMultiPoint(false)
+ : impl_(new Impl())
{
}
//! \endcond
{
}
+bool
+AbstractAnalysisData::isMultipoint() const
+{
+ return impl_->bMultipoint_;
+}
+
+int
+AbstractAnalysisData::dataSetCount() const
+{
+ return impl_->columnCounts_.size();
+}
+
+int
+AbstractAnalysisData::columnCount(int dataSet) const
+{
+ GMX_ASSERT(dataSet >= 0 && dataSet < dataSetCount(),
+ "Out of range data set index");
+ return impl_->columnCounts_[dataSet];
+}
int
-AbstractAnalysisData::frameCount() const
+AbstractAnalysisData::columnCount() const
{
- return _impl->_nframes;
+ GMX_ASSERT(dataSetCount() == 1,
+ "Convenience method not available for multiple data sets");
+ return columnCount(0);
}
void
AbstractAnalysisData::addModule(AnalysisDataModulePointer module)
{
- if ((columnCount() > 1 && !(module->flags() & AnalysisDataModuleInterface::efAllowMulticolumn))
- || (isMultipoint() && !(module->flags() & AnalysisDataModuleInterface::efAllowMultipoint))
- || (!isMultipoint() && (module->flags() & AnalysisDataModuleInterface::efOnlyMultipoint)))
- {
- GMX_THROW(APIError("Data module not compatible with data object properties"));
- }
-
- if (_impl->_bDataStart)
- {
- GMX_RELEASE_ASSERT(!_impl->_bInFrame,
- "Cannot add data modules in mid-frame");
- _impl->presentData(this, module.get());
- }
- if (!(module->flags() & AnalysisDataModuleInterface::efAllowMissing))
- {
- _impl->_bAllowMissing = false;
- }
- _impl->_modules.push_back(module);
+ impl_->modules_.addModule(this, module);
}
AbstractAnalysisData::addColumnModule(int col, int span,
AnalysisDataModulePointer module)
{
- GMX_RELEASE_ASSERT(col >= 0 && span >= 1 && col + span <= _ncol,
+ GMX_RELEASE_ASSERT(col >= 0 && span >= 1,
"Invalid columns specified for a column module");
- if (_impl->_bDataStart)
- {
- GMX_THROW(NotImplementedError("Cannot add column modules after data"));
- }
-
boost::shared_ptr<AnalysisDataProxy> proxy(
new AnalysisDataProxy(col, span, this));
proxy->addModule(module);
void
AbstractAnalysisData::applyModule(AnalysisDataModuleInterface *module)
{
- if ((columnCount() > 1 && !(module->flags() & AnalysisDataModuleInterface::efAllowMulticolumn))
- || (isMultipoint() && !(module->flags() & AnalysisDataModuleInterface::efAllowMultipoint))
- || (!isMultipoint() && (module->flags() & AnalysisDataModuleInterface::efOnlyMultipoint)))
- {
- GMX_THROW(APIError("Data module not compatible with data object properties"));
- }
- GMX_RELEASE_ASSERT(_impl->_bDataStart && !_impl->_bInData,
- "Data module can only be applied to ready data");
-
- _impl->presentData(this, module);
+ impl_->modules_.applyModule(this, module);
}
/*! \cond libapi */
void
-AbstractAnalysisData::setColumnCount(int ncol)
+AbstractAnalysisData::setDataSetCount(int dataSetCount)
{
- GMX_RELEASE_ASSERT(ncol > 0, "Invalid data column count");
- GMX_RELEASE_ASSERT(_ncol == 0 || _impl->_modules.empty(),
- "Data column count cannot be changed after modules are added");
- GMX_RELEASE_ASSERT(!_impl->_bDataStart,
- "Data column count cannot be changed after data has been added");
- _ncol = ncol;
+ GMX_RELEASE_ASSERT(dataSetCount > 0, "Invalid data column count");
+ impl_->modules_.dataPropertyAboutToChange(
+ AnalysisDataModuleManager::eMultipleDataSets, dataSetCount > 1);
+ impl_->columnCounts_.resize(dataSetCount);
}
-
void
-AbstractAnalysisData::setMultipoint(bool multipoint)
+AbstractAnalysisData::setColumnCount(int dataSet, int columnCount)
{
- GMX_RELEASE_ASSERT(_impl->_modules.empty(),
- "Data type cannot be changed after modules are added");
- GMX_RELEASE_ASSERT(!_impl->_bDataStart,
- "Data type cannot be changed after data has been added");
- _bMultiPoint = multipoint;
-}
+ GMX_RELEASE_ASSERT(dataSet >= 0 && dataSet < dataSetCount(),
+ "Out of range data set index");
+ GMX_RELEASE_ASSERT(columnCount > 0, "Invalid data column count");
-
-/*! \internal
- * This method is not const because the dataStarted() methods of the attached
- * modules can request storage of the data.
- */
-void
-AbstractAnalysisData::notifyDataStart()
-{
- GMX_RELEASE_ASSERT(!_impl->_bDataStart,
- "notifyDataStart() called more than once");
- GMX_RELEASE_ASSERT(_ncol > 0, "Data column count is not set");
- _impl->_bDataStart = _impl->_bInData = true;
-
- Impl::ModuleList::const_iterator i;
- for (i = _impl->_modules.begin(); i != _impl->_modules.end(); ++i)
+ bool bMultipleColumns = columnCount > 1;
+ for (int i = 0; i < dataSetCount() && !bMultipleColumns; ++i)
{
- if (_ncol > 1 && !((*i)->flags() & AnalysisDataModuleInterface::efAllowMulticolumn))
+ if (i != dataSet && this->columnCount(i) > 1)
{
- GMX_THROW(APIError("Data module not compatible with data object properties"));
+ bMultipleColumns = true;
}
- (*i)->dataStarted(this);
- }
-}
-
-
-void
-AbstractAnalysisData::notifyFrameStart(const AnalysisDataFrameHeader &header) const
-{
- GMX_ASSERT(_impl->_bInData, "notifyDataStart() not called");
- GMX_ASSERT(!_impl->_bInFrame,
- "notifyFrameStart() called while inside a frame");
- GMX_ASSERT(header.index() == _impl->_nframes,
- "Out of order frames");
- _impl->_bInFrame = true;
- _impl->_currIndex = header.index();
-
- Impl::ModuleList::const_iterator i;
- for (i = _impl->_modules.begin(); i != _impl->_modules.end(); ++i)
- {
- (*i)->frameStarted(header);
}
+ impl_->modules_.dataPropertyAboutToChange(
+ AnalysisDataModuleManager::eMultipleColumns, bMultipleColumns);
+ impl_->columnCounts_[dataSet] = columnCount;
}
-
void
-AbstractAnalysisData::notifyPointsAdd(const AnalysisDataPointSetRef &points) const
+AbstractAnalysisData::setMultipoint(bool bMultipoint)
{
- GMX_ASSERT(_impl->_bInData, "notifyDataStart() not called");
- GMX_ASSERT(_impl->_bInFrame, "notifyFrameStart() not called");
- GMX_ASSERT(points.lastColumn() < columnCount(), "Invalid columns");
- GMX_ASSERT(points.frameIndex() == _impl->_currIndex,
- "Points do not correspond to current frame");
- if (!_impl->_bAllowMissing && !points.allPresent())
- {
- GMX_THROW(APIError("Missing data not supported by a module"));
- }
-
- Impl::ModuleList::const_iterator i;
- for (i = _impl->_modules.begin(); i != _impl->_modules.end(); ++i)
- {
- (*i)->pointsAdded(points);
- }
+ impl_->modules_.dataPropertyAboutToChange(
+ AnalysisDataModuleManager::eMultipoint, bMultipoint);
+ impl_->bMultipoint_ = bMultipoint;
}
-
-void
-AbstractAnalysisData::notifyFrameFinish(const AnalysisDataFrameHeader &header)
+AnalysisDataModuleManager &AbstractAnalysisData::moduleManager()
{
- GMX_ASSERT(_impl->_bInData, "notifyDataStart() not called");
- GMX_ASSERT(_impl->_bInFrame, "notifyFrameStart() not called");
- GMX_ASSERT(header.index() == _impl->_currIndex,
- "Header does not correspond to current frame");
- _impl->_bInFrame = false;
- _impl->_currIndex = -1;
-
- // Increment the counter before notifications to allow frame access from
- // modules.
- ++_impl->_nframes;
-
- Impl::ModuleList::const_iterator i;
- for (i = _impl->_modules.begin(); i != _impl->_modules.end(); ++i)
- {
- (*i)->frameFinished(header);
- }
+ return impl_->modules_;
}
-
-void
-AbstractAnalysisData::notifyDataFinish() const
+const AnalysisDataModuleManager &AbstractAnalysisData::moduleManager() const
{
- GMX_RELEASE_ASSERT(_impl->_bInData, "notifyDataStart() not called");
- GMX_RELEASE_ASSERT(!_impl->_bInFrame,
- "notifyDataFinish() called while inside a frame");
- _impl->_bInData = false;
-
- Impl::ModuleList::const_iterator i;
- for (i = _impl->_modules.begin(); i != _impl->_modules.end(); ++i)
- {
- (*i)->dataFinished();
- }
+ return impl_->modules_;
}
//! \endcond