2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
5 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 * others, as listed in the AUTHORS file in the top-level source
7 * 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
42 #include "gromacs/analysisdata/analysisdata.h"
44 #include "gromacs/analysisdata/dataframe.h"
45 #include "gromacs/analysisdata/datastorage.h"
46 #include "gromacs/analysisdata/paralleloptions.h"
47 #include "gromacs/utility/exceptions.h"
48 #include "gromacs/utility/gmxassert.h"
49 #include "gromacs/utility/uniqueptr.h"
54 /********************************************************************
55 * AnalysisDataHandleImpl
62 * Private implementation class for AnalysisDataHandle.
64 * \ingroup module_analysisdata
66 class AnalysisDataHandleImpl
69 //! Creates a handle associated with the given data object.
70 explicit AnalysisDataHandleImpl(AnalysisData *data)
71 : data_(*data), currentFrame_(NULL)
75 //! The data object that this handle belongs to.
77 //! Current storage frame object, or NULL if no current frame.
78 AnalysisDataStorageFrame *currentFrame_;
81 } // namespace internal
83 /********************************************************************
88 * Private implementation class for AnalysisData.
90 * \ingroup module_analysisdata
92 class AnalysisData::Impl
95 //! Smart pointer type to manage a data handle implementation.
96 typedef gmx_unique_ptr<internal::AnalysisDataHandleImpl>::type
98 //! Shorthand for a list of data handles.
99 typedef std::vector<HandlePointer> HandleList;
101 //! Storage implementation.
102 AnalysisDataStorage storage_;
104 * List of handles for this data object.
106 * Note that AnalysisDataHandle objects also contain (raw) pointers
112 /********************************************************************
116 AnalysisData::AnalysisData()
122 AnalysisData::~AnalysisData()
128 AnalysisData::setDataSetCount(int dataSetCount)
130 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
131 "Cannot change data dimensionality after creating handles");
132 AbstractAnalysisData::setDataSetCount(dataSetCount);
137 AnalysisData::setColumnCount(int dataSet, int columnCount)
139 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
140 "Cannot change data dimensionality after creating handles");
141 AbstractAnalysisData::setColumnCount(dataSet, columnCount);
146 AnalysisData::setMultipoint(bool bMultipoint)
148 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
149 "Cannot change data type after creating handles");
150 AbstractAnalysisData::setMultipoint(bMultipoint);
155 AnalysisData::frameCount() const
157 return impl_->storage_.frameCount();
162 AnalysisData::startData(const AnalysisDataParallelOptions &opt)
164 GMX_RELEASE_ASSERT(impl_->handles_.size() < static_cast<unsigned>(opt.parallelizationFactor()),
165 "Too many calls to startData() compared to provided options");
166 if (impl_->handles_.empty())
168 impl_->storage_.setParallelOptions(opt);
169 impl_->storage_.startDataStorage(this, &moduleManager());
172 Impl::HandlePointer handle(new internal::AnalysisDataHandleImpl(this));
173 impl_->handles_.push_back(move(handle));
174 return AnalysisDataHandle(impl_->handles_.back().get());
179 AnalysisData::finishData(AnalysisDataHandle handle)
181 Impl::HandleList::iterator i;
183 for (i = impl_->handles_.begin(); i != impl_->handles_.end(); ++i)
185 if (i->get() == handle.impl_)
190 GMX_RELEASE_ASSERT(i != impl_->handles_.end(),
191 "finishData() called for an unknown handle");
193 impl_->handles_.erase(i);
195 if (impl_->handles_.empty())
197 impl_->storage_.finishDataStorage();
203 AnalysisData::tryGetDataFrameInternal(int index) const
205 return impl_->storage_.tryGetDataFrame(index);
210 AnalysisData::requestStorageInternal(int nframes)
212 return impl_->storage_.requestStorage(nframes);
216 /********************************************************************
220 AnalysisDataHandle::AnalysisDataHandle()
226 AnalysisDataHandle::AnalysisDataHandle(internal::AnalysisDataHandleImpl *impl)
233 AnalysisDataHandle::startFrame(int index, real x, real dx)
235 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
236 GMX_RELEASE_ASSERT(impl_->currentFrame_ == NULL,
237 "startFrame() called twice without calling finishFrame()");
238 impl_->currentFrame_ =
239 &impl_->data_.impl_->storage_.startFrame(index, x, dx);
244 AnalysisDataHandle::selectDataSet(int index)
246 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
247 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
248 "selectDataSet() called without calling startFrame()");
249 impl_->currentFrame_->selectDataSet(index);
254 AnalysisDataHandle::setPoint(int column, real value, bool bPresent)
256 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
257 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
258 "setPoint() called without calling startFrame()");
259 impl_->currentFrame_->setValue(column, value, bPresent);
264 AnalysisDataHandle::setPoint(int column, real value, real error, bool bPresent)
266 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
267 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
268 "setPoint() called without calling startFrame()");
269 impl_->currentFrame_->setValue(column, value, error, bPresent);
274 AnalysisDataHandle::setPoints(int firstColumn, int count, const real *values)
276 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
277 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
278 "setPoints() called without calling startFrame()");
279 for (int i = 0; i < count; ++i)
281 impl_->currentFrame_->setValue(firstColumn + i, values[i]);
287 AnalysisDataHandle::finishPointSet()
289 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
290 GMX_RELEASE_ASSERT(impl_->data_.isMultipoint(),
291 "finishPointSet() called for non-multipoint data");
292 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
293 "finishPointSet() called without calling startFrame()");
294 impl_->currentFrame_->finishPointSet();
299 AnalysisDataHandle::finishFrame()
301 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
302 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
303 "finishFrame() called without calling startFrame()");
304 AnalysisDataStorageFrame *frame = impl_->currentFrame_;
305 impl_->currentFrame_ = NULL;
306 frame->finishFrame();
311 AnalysisDataHandle::finishData()
313 GMX_RELEASE_ASSERT(impl_ != NULL, "Invalid data handle used");
314 // Deletes the implementation pointer.
315 impl_->data_.finishData(*this);