3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Implements classes in analysisdata.h.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
36 * \ingroup module_analysisdata
38 #include "gromacs/analysisdata/analysisdata.h"
43 #include "gromacs/analysisdata/dataframe.h"
44 #include "gromacs/analysisdata/datastorage.h"
45 #include "gromacs/analysisdata/paralleloptions.h"
46 #include "gromacs/fatalerror/exceptions.h"
47 #include "gromacs/fatalerror/gmxassert.h"
49 #include "analysisdata-impl.h"
54 /********************************************************************
58 AnalysisData::Impl::Impl()
63 AnalysisData::Impl::~Impl()
65 HandleList::const_iterator i;
66 for (i = handles_.begin(); i != handles_.end(); ++i)
73 /********************************************************************
77 AnalysisData::AnalysisData()
83 AnalysisData::~AnalysisData()
89 AnalysisData::setColumns(int ncol, bool multipoint)
91 GMX_RELEASE_ASSERT(ncol > 0, "Number of columns must be positive");
92 GMX_RELEASE_ASSERT(impl_->handles_.empty(),
93 "Cannot change data dimensionality after creating handles");
95 setMultipoint(multipoint);
96 impl_->storage_.setMultipoint(multipoint);
101 AnalysisData::startData(const AnalysisDataParallelOptions &opt)
103 GMX_RELEASE_ASSERT(impl_->handles_.size() < static_cast<unsigned>(opt.parallelizationFactor()),
104 "Too many calls to startData() compared to provided options");
105 if (impl_->handles_.empty())
108 impl_->storage_.setParallelOptions(opt);
109 impl_->storage_.startDataStorage(this);
111 else if (isMultipoint())
113 GMX_THROW(NotImplementedError("Parallelism not supported for multipoint data"));
116 std::auto_ptr<AnalysisDataHandle> handle(new AnalysisDataHandle(this));
117 impl_->handles_.push_back(handle.get());
118 return handle.release();
123 AnalysisData::finishData(AnalysisDataHandle *handle)
125 Impl::HandleList::iterator i;
127 i = std::find(impl_->handles_.begin(), impl_->handles_.end(), handle);
128 GMX_RELEASE_ASSERT(i != impl_->handles_.end(),
129 "finishData() called for an unknown handle");
131 impl_->handles_.erase(i);
134 if (impl_->handles_.empty())
142 AnalysisData::tryGetDataFrameInternal(int index) const
144 return impl_->storage_.tryGetDataFrame(index);
149 AnalysisData::requestStorageInternal(int nframes)
151 return impl_->storage_.requestStorage(nframes);
155 /********************************************************************
156 * AnalysisDataHandle::Impl
159 AnalysisDataHandle::Impl::Impl(AnalysisData *data)
160 : data_(*data), currentFrame_(NULL)
165 /********************************************************************
169 AnalysisDataHandle::AnalysisDataHandle(AnalysisData *data)
170 : impl_(new Impl(data))
175 AnalysisDataHandle::~AnalysisDataHandle()
181 AnalysisDataHandle::startFrame(int index, real x, real dx)
183 GMX_RELEASE_ASSERT(impl_->currentFrame_ == NULL,
184 "startFrame() called twice without calling finishFrame()");
185 impl_->currentFrame_ =
186 &impl_->data_.impl_->storage_.startFrame(index, x, dx);
191 AnalysisDataHandle::setPoint(int col, real y, real dy, bool present)
193 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
194 "setPoint() called without calling startFrame()");
195 impl_->currentFrame_->setValue(col, y, dy, present);
200 AnalysisDataHandle::setPoints(int firstcol, int n, const real *y)
202 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
203 "setPoints() called without calling startFrame()");
204 for (int i = 0; i < n; ++i)
206 impl_->currentFrame_->setValue(firstcol + i, y[i]);
212 AnalysisDataHandle::finishPointSet()
214 GMX_RELEASE_ASSERT(impl_->data_.isMultipoint(),
215 "finishPointSet() called for non-multipoint data");
216 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
217 "finishPointSet() called without calling startFrame()");
218 impl_->currentFrame_->finishPointSet();
223 AnalysisDataHandle::finishFrame()
225 GMX_RELEASE_ASSERT(impl_->currentFrame_ != NULL,
226 "finishFrame() called without calling startFrame()");
227 int index = impl_->currentFrame_->frameIndex();
228 impl_->currentFrame_ = NULL;
229 impl_->data_.impl_->storage_.finishFrame(index);
234 AnalysisDataHandle::finishData()
237 impl_->data_.finishData(this);