2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Implements classes in analysisdata.h.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_analysisdata
44 #include "analysisdata.h"
46 #include "gromacs/analysisdata/dataframe.h"
47 #include "gromacs/analysisdata/datastorage.h"
48 #include "gromacs/analysisdata/paralleloptions.h"
49 #include "gromacs/utility/exceptions.h"
50 #include "gromacs/utility/gmxassert.h"
51 #include "gromacs/utility/uniqueptr.h"
56 /********************************************************************
57 * AnalysisDataHandleImpl
64 * Private implementation class for AnalysisDataHandle.
66 * \ingroup module_analysisdata
68 class AnalysisDataHandleImpl
71 //! Creates a handle associated with the given data object.
72 explicit AnalysisDataHandleImpl(AnalysisData *data)
73 : data_(*data), currentFrame_(NULL)
77 //! The data object that this handle belongs to.
79 //! Current storage frame object, or NULL if no current frame.
80 AnalysisDataStorageFrame *currentFrame_;
83 } // namespace internal
85 /********************************************************************
90 * Private implementation class for AnalysisData.
92 * \ingroup module_analysisdata
94 class AnalysisData::Impl
97 //! Smart pointer type to manage a data handle implementation.
98 typedef gmx_unique_ptr<internal::AnalysisDataHandleImpl>::type
100 //! Shorthand for a list of data handles.
101 typedef std::vector<HandlePointer> HandleList;
103 //! Storage implementation.
104 AnalysisDataStorage storage_;
106 * List of handles for this data object.
108 * Note that AnalysisDataHandle objects also contain (raw) pointers
114 /********************************************************************
118 AnalysisData::AnalysisData()
124 AnalysisData::~AnalysisData()
130 AnalysisData::setDataSetCount(int dataSetCount)
132 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
133 "Cannot change data dimensionality after creating handles");
134 AbstractAnalysisData::setDataSetCount(dataSetCount);
139 AnalysisData::setColumnCount(int dataSet, int columnCount)
141 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
142 "Cannot change data dimensionality after creating handles");
143 AbstractAnalysisData::setColumnCount(dataSet, columnCount);
148 AnalysisData::setMultipoint(bool bMultipoint)
150 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
151 "Cannot change data type after creating handles");
152 AbstractAnalysisData::setMultipoint(bMultipoint);
157 AnalysisData::frameCount() const
159 return impl_->storage_.frameCount();
164 AnalysisData::startData(const AnalysisDataParallelOptions &opt)
166 GMX_RELEASE_ASSERT(impl_->handles_.size() < static_cast<unsigned>(opt.parallelizationFactor()),
167 "Too many calls to startData() compared to provided options");
168 if (impl_->handles_.empty())
170 impl_->storage_.startParallelDataStorage(this, &moduleManager(), opt);
173 Impl::HandlePointer handle(new internal::AnalysisDataHandleImpl(this));
174 impl_->handles_.push_back(move(handle));
175 return AnalysisDataHandle(impl_->handles_.back().get());
180 AnalysisData::finishData(AnalysisDataHandle handle)
182 Impl::HandleList::iterator i;
184 for (i = impl_->handles_.begin(); i != impl_->handles_.end(); ++i)
186 if (i->get() == handle.impl_)
191 GMX_RELEASE_ASSERT(i != impl_->handles_.end(),
192 "finishData() called for an unknown handle");
194 impl_->handles_.erase(i);
196 if (impl_->handles_.empty())
198 impl_->storage_.finishDataStorage();
204 AnalysisData::tryGetDataFrameInternal(int index) const
206 return impl_->storage_.tryGetDataFrame(index);
211 AnalysisData::requestStorageInternal(int nframes)
213 return impl_->storage_.requestStorage(nframes);
217 /********************************************************************
221 AnalysisDataHandle::AnalysisDataHandle()
227 AnalysisDataHandle::AnalysisDataHandle(internal::AnalysisDataHandleImpl *impl)
234 AnalysisDataHandle::startFrame(int index, real x, real dx)
236 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
237 GMX_RELEASE_ASSERT(impl_->currentFrame_ == NULL,
238 "startFrame() called twice without calling finishFrame()");
239 impl_->currentFrame_ =
240 &impl_->data_.impl_->storage_.startFrame(index, x, dx);
245 AnalysisDataHandle::selectDataSet(int index)
247 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
248 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
249 "selectDataSet() called without calling startFrame()");
250 impl_->currentFrame_->selectDataSet(index);
255 AnalysisDataHandle::setPoint(int column, real value, bool bPresent)
257 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
258 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
259 "setPoint() called without calling startFrame()");
260 impl_->currentFrame_->setValue(column, value, bPresent);
265 AnalysisDataHandle::setPoint(int column, real value, real error, bool bPresent)
267 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
268 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
269 "setPoint() called without calling startFrame()");
270 impl_->currentFrame_->setValue(column, value, error, bPresent);
275 AnalysisDataHandle::setPoints(int firstColumn, int count, const real *values)
277 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
278 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
279 "setPoints() called without calling startFrame()");
280 for (int i = 0; i < count; ++i)
282 impl_->currentFrame_->setValue(firstColumn + i, values[i]);
288 AnalysisDataHandle::finishPointSet()
290 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
291 GMX_RELEASE_ASSERT(impl_->data_.isMultipoint(),
292 "finishPointSet() called for non-multipoint data");
293 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
294 "finishPointSet() called without calling startFrame()");
295 impl_->currentFrame_->finishPointSet();
300 AnalysisDataHandle::finishFrame()
302 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
303 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
304 "finishFrame() called without calling startFrame()");
305 AnalysisDataStorageFrame *frame = impl_->currentFrame_;
306 impl_->currentFrame_ = NULL;
307 frame->finishFrame();
312 AnalysisDataHandle::finishData()
314 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
315 // Deletes the implementation pointer.
316 impl_->data_.finishData(*this);