Add replacements for pbc enumerations
[gromacs.git] / src / gromacs / analysisdata / abstractdata.cpp
blob341a979347a4673fc255f3f3028fe8d0b70baf88
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014,2015,2018, 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.
35 /*! \internal \file
36 * \brief
37 * Implements gmx::AbstractAnalysisData.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_analysisdata
42 #include "gmxpre.h"
44 #include "abstractdata.h"
46 #include <utility>
47 #include <vector>
49 #include "gromacs/analysisdata/dataframe.h"
50 #include "gromacs/analysisdata/datamodule.h"
51 #include "gromacs/analysisdata/datamodulemanager.h"
52 #include "gromacs/utility/exceptions.h"
53 #include "gromacs/utility/gmxassert.h"
55 #include "dataproxy.h"
57 namespace gmx
60 /********************************************************************
61 * AbstractAnalysisData::Impl
64 /*! \internal \brief
65 * Private implementation class for AbstractAnalysisData.
67 * \ingroup module_analysisdata
69 class AbstractAnalysisData::Impl
71 public:
72 Impl();
74 //! Column counts for each data set in the data.
75 std::vector<int> columnCounts_;
76 //! Whether the data is multipoint.
77 bool bMultipoint_;
78 //! Manager for the added modules.
79 AnalysisDataModuleManager modules_;
82 AbstractAnalysisData::Impl::Impl()
83 : bMultipoint_(false)
85 columnCounts_.push_back(0);
89 /********************************************************************
90 * AbstractAnalysisData
92 /*! \cond libapi */
93 AbstractAnalysisData::AbstractAnalysisData()
94 : impl_(new Impl())
97 //! \endcond
99 AbstractAnalysisData::~AbstractAnalysisData()
103 bool
104 AbstractAnalysisData::isMultipoint() const
106 return impl_->bMultipoint_;
110 AbstractAnalysisData::dataSetCount() const
112 return impl_->columnCounts_.size();
116 AbstractAnalysisData::columnCount(int dataSet) const
118 GMX_ASSERT(dataSet >= 0 && dataSet < dataSetCount(),
119 "Out of range data set index");
120 return impl_->columnCounts_[dataSet];
124 AbstractAnalysisData::columnCount() const
126 GMX_ASSERT(dataSetCount() == 1,
127 "Convenience method not available for multiple data sets");
128 return columnCount(0);
132 AnalysisDataFrameRef
133 AbstractAnalysisData::tryGetDataFrame(int index) const
135 if (index < 0 || index >= frameCount())
137 return AnalysisDataFrameRef();
139 return tryGetDataFrameInternal(index);
143 AnalysisDataFrameRef
144 AbstractAnalysisData::getDataFrame(int index) const
146 AnalysisDataFrameRef frame = tryGetDataFrame(index);
147 if (!frame.isValid())
149 GMX_THROW(APIError("Invalid frame accessed"));
151 return frame;
155 bool
156 AbstractAnalysisData::requestStorage(int nframes)
158 GMX_RELEASE_ASSERT(nframes >= -1, "Invalid number of frames requested");
159 if (nframes == 0)
161 return true;
163 return requestStorageInternal(nframes);
167 void
168 AbstractAnalysisData::addModule(AnalysisDataModulePointer module)
170 impl_->modules_.addModule(this, std::move(module));
174 void
175 AbstractAnalysisData::addColumnModule(int col, int span,
176 AnalysisDataModulePointer module)
178 GMX_RELEASE_ASSERT(col >= 0 && span >= 1,
179 "Invalid columns specified for a column module");
180 std::shared_ptr<AnalysisDataProxy> proxy(
181 new AnalysisDataProxy(col, span, this));
182 proxy->addModule(std::move(module));
183 addModule(proxy);
187 void
188 AbstractAnalysisData::applyModule(IAnalysisDataModule *module)
190 impl_->modules_.applyModule(this, module);
193 /*! \cond libapi */
194 void
195 AbstractAnalysisData::setDataSetCount(int dataSetCount)
197 GMX_RELEASE_ASSERT(dataSetCount > 0, "Invalid data column count");
198 impl_->modules_.dataPropertyAboutToChange(
199 AnalysisDataModuleManager::eMultipleDataSets, dataSetCount > 1);
200 impl_->columnCounts_.resize(dataSetCount);
203 void
204 AbstractAnalysisData::setColumnCount(int dataSet, int columnCount)
206 GMX_RELEASE_ASSERT(dataSet >= 0 && dataSet < dataSetCount(),
207 "Out of range data set index");
208 GMX_RELEASE_ASSERT(columnCount > 0, "Invalid data column count");
210 bool bMultipleColumns = columnCount > 1;
211 for (int i = 0; i < dataSetCount() && !bMultipleColumns; ++i)
213 if (i != dataSet && this->columnCount(i) > 1)
215 bMultipleColumns = true;
218 impl_->modules_.dataPropertyAboutToChange(
219 AnalysisDataModuleManager::eMultipleColumns, bMultipleColumns);
220 impl_->columnCounts_[dataSet] = columnCount;
223 void
224 AbstractAnalysisData::setMultipoint(bool bMultipoint)
226 impl_->modules_.dataPropertyAboutToChange(
227 AnalysisDataModuleManager::eMultipoint, bMultipoint);
228 impl_->bMultipoint_ = bMultipoint;
231 AnalysisDataModuleManager &AbstractAnalysisData::moduleManager()
233 return impl_->modules_;
236 const AnalysisDataModuleManager &AbstractAnalysisData::moduleManager() const
238 return impl_->modules_;
240 //! \endcond
242 } // namespace gmx