2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2018,2019, 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 * Declares gmx::AbstractAnalysisArrayData and gmx::AnalysisArrayData.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_analysisdata
43 #ifndef GMX_ANALYSISDATA_ARRAYDATA_H
44 #define GMX_ANALYSISDATA_ARRAYDATA_H
48 #include "gromacs/analysisdata/abstractdata.h"
49 #include "gromacs/analysisdata/dataframe.h"
50 #include "gromacs/utility/gmxassert.h"
56 * Abstract base class for data objects that present in-memory data.
58 * This class implements a subclass of AbstractAnalysisData that presents an
59 * in-memory array through the AbstractAnalysisData interface. Subclasses
60 * should initialize the in-memory array through the provided protected member
61 * functions. This class provides public accessor methods for read access to
64 * Public accessor methods in this class do not throw, but assert if data is
65 * accessed before it is available.
68 * Add support for multiple data sets.
71 * \ingroup module_analysisdata
73 class AbstractAnalysisArrayData : public AbstractAnalysisData
76 ~AbstractAnalysisArrayData() override;
78 int frameCount() const override { return bReady_ ? rowCount_ : 0; }
81 * Returns the number of rows in the data array.
83 * This function is identical to frameCount(), except that frameCount()
84 * returns 0 before valuesReady() has been called.
86 int rowCount() const { return rowCount_; }
87 //! Returns true if values have been allocated.
88 bool isAllocated() const { return !value_.empty(); }
89 //! Returns the x value of the first frame.
90 real xstart() const { return xvalue_[0]; }
91 //! Returns the step between frame x values.
94 GMX_ASSERT(bUniformX_, "Accessing x step for non-uniform data");
97 //! Returns the x value of a row.
98 real xvalue(int row) const
100 GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
103 //! Returns a given array element.
104 const AnalysisDataValue& value(int row, int col) const
106 GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
107 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
108 GMX_ASSERT(isAllocated(), "Data array not allocated");
109 return value_[row * columnCount() + col];
114 * Initializes an empty array data object.
116 * \throws std::bad_alloc if out of memory.
118 AbstractAnalysisArrayData();
121 * Sets the number of columns in the data array.
123 * \param[in] ncols Number of columns in the data.
125 * Cannot be called after allocateValues().
127 * See AbstractAnalysisData::setColumnCount() for exception behavior.
129 void setColumnCount(int ncols);
131 * Sets the number of rows in the data array.
133 * \param[in] rowCount Number of rows in the data.
135 * Cannot be called after allocateValues().
139 void setRowCount(int rowCount);
141 * Allocates memory for the values.
143 * \throws std::bad_alloc if memory allocation fails.
145 * setColumnCount() and setRowCount() must have been called.
147 * Strong exception safety guarantee.
149 void allocateValues();
151 * Sets the values reported as x values for frames.
153 * \param[in] start x value for the first frame.
154 * \param[in] step Step between x values of successive frames.
156 * Must not be called after valuesReady().
157 * Any values set with setXAxisValue() are overwritten.
161 void setXAxis(real start, real step);
163 * Sets a single value reported as x value for frames.
165 * \param[in] row Row/frame for which to set the value.
166 * \param[in] value x value for the frame specified by \p row.
168 * Must not be called after valuesReady().
172 void setXAxisValue(int row, real value);
173 //! Returns a reference to a given array element.
174 AnalysisDataValue& value(int row, int col)
176 GMX_ASSERT(row >= 0 && row < rowCount(), "Row index out of range");
177 GMX_ASSERT(col >= 0 && col < columnCount(), "Column index out of range");
178 GMX_ASSERT(isAllocated(), "Data array not allocated");
179 return value_[row * columnCount() + col];
182 * Notifies modules of the data.
184 * \throws unspecified Any exception thrown by attached data modules
185 * in data notification methods.
187 * This function should be called once the values in the array
188 * have been initialized. The values should not be changed after this
189 * function has been called.
194 * Copies the contents into a new object.
196 * \param[in] src Object to copy data from.
197 * \param[in,out] dest Empty array data object to copy data to.
198 * \throws std::bad_alloc if memory allocation for \p dest fails.
200 * \p dest should not have previous contents.
202 static void copyContents(const AbstractAnalysisArrayData* src, AbstractAnalysisArrayData* dest);
205 AnalysisDataFrameRef tryGetDataFrameInternal(int index) const override;
206 bool requestStorageInternal(int nframes) override;
209 AnalysisDataPointSetInfo pointSetInfo_;
210 std::vector<AnalysisDataValue> value_;
211 std::vector<real> xvalue_;
216 // Copy and assign disallowed by base.
220 * Simple in-memory data array.
222 * This class is a simple alternative to AnalysisData for in-memory data arrays
223 * that are constructed in-place.
225 * Public accessor methods in this class do not throw, but assert if data is
226 * accessed before it is available.
229 * This class exposes the protected functions of AbstractAnalysisArrayData for
234 * \ingroup module_analysisdata
236 class AnalysisArrayData : public AbstractAnalysisArrayData
240 * Initializes an empty array data object.
242 * \throws std::bad_alloc if out of memory.
244 AnalysisArrayData() {}
246 // TODO: These statements cause Doxygen to generate confusing
248 using AbstractAnalysisArrayData::allocateValues;
249 using AbstractAnalysisArrayData::setColumnCount;
250 using AbstractAnalysisArrayData::setRowCount;
251 using AbstractAnalysisArrayData::setXAxis;
252 using AbstractAnalysisArrayData::setXAxisValue;
253 using AbstractAnalysisArrayData::value;
254 using AbstractAnalysisArrayData::valuesReady;
256 // Copy and assign disallowed by base.