2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
5 * Copyright (c) 2015,2018,2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
38 * Implements gmx::AbstractAnalysisData.
40 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_analysisdata
45 #include "abstractdata.h"
50 #include "gromacs/analysisdata/dataframe.h"
51 #include "gromacs/analysisdata/datamodule.h"
52 #include "gromacs/analysisdata/datamodulemanager.h"
53 #include "gromacs/utility/exceptions.h"
54 #include "gromacs/utility/gmxassert.h"
56 #include "dataproxy.h"
61 /********************************************************************
62 * AbstractAnalysisData::Impl
66 * Private implementation class for AbstractAnalysisData.
68 * \ingroup module_analysisdata
70 class AbstractAnalysisData::Impl
75 //! Column counts for each data set in the data.
76 std::vector
<int> columnCounts_
;
77 //! Whether the data is multipoint.
79 //! Manager for the added modules.
80 AnalysisDataModuleManager modules_
;
83 AbstractAnalysisData::Impl::Impl() : bMultipoint_(false)
85 columnCounts_
.push_back(0);
89 /********************************************************************
90 * AbstractAnalysisData
93 AbstractAnalysisData::AbstractAnalysisData() : impl_(new Impl()) {}
96 AbstractAnalysisData::~AbstractAnalysisData() {}
98 bool AbstractAnalysisData::isMultipoint() const
100 return impl_
->bMultipoint_
;
103 int AbstractAnalysisData::dataSetCount() const
105 return impl_
->columnCounts_
.size();
108 int AbstractAnalysisData::columnCount(int dataSet
) const
110 GMX_ASSERT(dataSet
>= 0 && dataSet
< dataSetCount(), "Out of range data set index");
111 return impl_
->columnCounts_
[dataSet
];
114 int AbstractAnalysisData::columnCount() const
116 GMX_ASSERT(dataSetCount() == 1, "Convenience method not available for multiple data sets");
117 return columnCount(0);
121 AnalysisDataFrameRef
AbstractAnalysisData::tryGetDataFrame(int index
) const
123 if (index
< 0 || index
>= frameCount())
125 return AnalysisDataFrameRef();
127 return tryGetDataFrameInternal(index
);
131 AnalysisDataFrameRef
AbstractAnalysisData::getDataFrame(int index
) const
133 AnalysisDataFrameRef frame
= tryGetDataFrame(index
);
134 if (!frame
.isValid())
136 GMX_THROW(APIError("Invalid frame accessed"));
142 bool AbstractAnalysisData::requestStorage(int nframes
)
144 GMX_RELEASE_ASSERT(nframes
>= -1, "Invalid number of frames requested");
149 return requestStorageInternal(nframes
);
153 void AbstractAnalysisData::addModule(const AnalysisDataModulePointer
& module
)
155 impl_
->modules_
.addModule(this, module
);
159 void AbstractAnalysisData::addColumnModule(int col
, int span
, const AnalysisDataModulePointer
& module
)
161 GMX_RELEASE_ASSERT(col
>= 0 && span
>= 1, "Invalid columns specified for a column module");
162 std::shared_ptr
<AnalysisDataProxy
> proxy(new AnalysisDataProxy(col
, span
, this));
163 proxy
->addModule(module
);
168 void AbstractAnalysisData::applyModule(IAnalysisDataModule
* module
)
170 impl_
->modules_
.applyModule(this, module
);
174 void AbstractAnalysisData::setDataSetCount(int dataSetCount
)
176 GMX_RELEASE_ASSERT(dataSetCount
> 0, "Invalid data column count");
177 impl_
->modules_
.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipleDataSets
,
179 impl_
->columnCounts_
.resize(dataSetCount
);
182 void AbstractAnalysisData::setColumnCount(int dataSet
, int columnCount
)
184 GMX_RELEASE_ASSERT(dataSet
>= 0 && dataSet
< dataSetCount(), "Out of range data set index");
185 GMX_RELEASE_ASSERT(columnCount
> 0, "Invalid data column count");
187 bool bMultipleColumns
= columnCount
> 1;
188 for (int i
= 0; i
< dataSetCount() && !bMultipleColumns
; ++i
)
190 if (i
!= dataSet
&& this->columnCount(i
) > 1)
192 bMultipleColumns
= true;
195 impl_
->modules_
.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipleColumns
, bMultipleColumns
);
196 impl_
->columnCounts_
[dataSet
] = columnCount
;
199 void AbstractAnalysisData::setMultipoint(bool bMultipoint
)
201 impl_
->modules_
.dataPropertyAboutToChange(AnalysisDataModuleManager::eMultipoint
, bMultipoint
);
202 impl_
->bMultipoint_
= bMultipoint
;
205 AnalysisDataModuleManager
& AbstractAnalysisData::moduleManager()
207 return impl_
->modules_
;
210 const AnalysisDataModuleManager
& AbstractAnalysisData::moduleManager() const
212 return impl_
->modules_
;