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 * 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::AnalysisDataModuleInterface and related convenience classes.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
41 * \ingroup module_analysisdata
43 #ifndef GMX_ANALYSISDATA_DATAMODULE_H
44 #define GMX_ANALYSISDATA_DATAMODULE_H
46 #include "../legacyheaders/types/simple.h"
51 class AbstractAnalysisData;
52 class AnalysisDataFrameHeader;
53 class AnalysisDataParallelOptions;
54 class AnalysisDataPointSetRef;
57 * Interface for a module that gets notified whenever data is added.
59 * The interface provides one method (flags()) that describes features of
60 * data objects the module supports. Only most common features are included
61 * in the flags; custom checks can be implemented in the dataStarted() and/or
62 * parallelDataStarted() methods (see below).
63 * All other methods in the interface are callbacks that are called by the
64 * data object to which the module is attached to describe the data.
66 * The modules can operate in two modes: serial or parallel.
67 * In serial mode, the frames are presented to the module always in the order
68 * of increasing indices, even if they become ready in a different order in the
70 * In parallel mode, the frames are presented in the order that they become
71 * available in the input data, which may not be sequential. This mode allows
72 * the input data to optimize its behavior if it does not need to store and
74 * If the input data supports parallel mode, it calls parallelDataStarted().
75 * If the module returns true from this method, then it will process the frames
76 * in the parallel mode. If the module returns false, it will get the frames
78 * If the input data does not support parallel mode, it calls dataStarted().
80 * Concrete modules typically do not directly derive from this interface, but
81 * from either AnalysisDataModuleSerial or AnalysisDataModuleParallel.
82 * Both these classes implement one of dataStarted()/parallelDataStarted() by
83 * forwarding the calls to the other method of this pair. This allows the
84 * module to only implement the initialization once, without needing to worry
85 * how to correctly handle both cases.
87 * Currently, if the module throws an exception, it requires the analysis tool
88 * to terminate, since AbstractAnalysisData will be left in a state where it
89 * is not possible to continue processing. See a related todo item in
90 * AbstractAnalysisData.
93 * \ingroup module_analysisdata
95 class AnalysisDataModuleInterface
99 * Possible flags for flags().
103 //! The module can process multipoint data.
104 efAllowMultipoint = 1<<0,
105 //! The module does not make sense for non-multipoint data.
106 efOnlyMultipoint = 1<<1,
107 //! The module can process data with more than one column.
108 efAllowMulticolumn = 1<<2,
109 //! The module can process data with missing points.
110 efAllowMissing = 1<<3,
111 //! The module can process data with multiple data sets.
112 efAllowMultipleDataSets = 1<<4
115 virtual ~AnalysisDataModuleInterface() {};
118 * Returns properties supported by the module.
120 * The return value of this method should not change after the module
121 * has been added to a data (this responsibility can, and in most cases
122 * must, be delegated to the user of the module).
124 * The purpose of this method is to remove the need for common checks
125 * for data compatibility in the classes that implement the interface.
126 * Instead, AbstractAnalysisData performs these checks based on the
131 virtual int flags() const = 0;
134 * Called (once) when the data has been set up properly.
136 * \param[in] data Data object to which the module is added.
137 * \throws APIError if the provided data is not compatible.
138 * \throws unspecified Can throw any exception required by the
139 * implementing class to report errors.
141 * When the data is ready, either this method or parallelDataStarted()
142 * is called, depending on the nature of the input data. If this
143 * method is called, the input data will always present the frames in
146 * The data to which the module is attached is passed as an argument
147 * to provide access to properties of the data for initialization
148 * and/or validation. The module can also call
149 * AbstractAnalysisData::requestStorage() if needed.
151 * This is the only place where the module gets access to the data;
152 * if properties of the data are required later, the module should
153 * store them internally. It is guaranteed that the data properties
154 * (column count, whether it's multipoint) do not change once this
155 * method has been called.
157 * Notice that \p data will be a proxy object if the module is added as
158 * a column module, not the data object for which
159 * AbstractAnalysisData::addColumnModule() was called.
161 virtual void dataStarted(AbstractAnalysisData *data) = 0;
163 * Called (once) for parallel data when the data has been set up.
165 * \param[in] data Data object to which the module is added.
166 * \param[in] options Parallelization properties of the input data.
167 * \returns true if the module can process the input in
168 * non-sequential order.
169 * \throws APIError if the provided data is not compatible.
170 * \throws unspecified Can throw any exception required by the
171 * implementing class to report errors.
173 * This method is called instead of dataStarted() if the input data has
174 * the capability to present data in non-sequential order.
175 * If the method returns true, then the module accepts this and frame
176 * notification methods may be called in that non-sequential order.
177 * If the method returns false, then the frame notification methods are
178 * called in sequential order, as if dataStarted() had been called.
180 * See dataStarted() for general information on initializing the data.
181 * That applies to this method as well, with the exception that calling
182 * AbstractAnalysisData::requestStorage() is currently not very well
183 * supported (or rather, accessing the requested storage doesn't work).
185 virtual bool parallelDataStarted(
186 AbstractAnalysisData *data,
187 const AnalysisDataParallelOptions &options) = 0;
189 * Called at the start of each data frame.
191 * \param[in] frame Header information for the frame that is starting.
192 * \throws unspecified Can throw any exception required by the
193 * implementing class to report errors.
195 virtual void frameStarted(const AnalysisDataFrameHeader &frame) = 0;
197 * Called one or more times during each data frame.
199 * \param[in] points Set of points added (also provides access to
201 * \throws APIError if the provided data is not compatible.
202 * \throws unspecified Can throw any exception required by the
203 * implementing class to report errors.
205 * Can be called once or multiple times for a frame. For all data
206 * objects currently implemented in the library (and all objects that
207 * will use AnalysisDataStorage for internal implementation), it is
208 * called exactly once for each frame if the data is not multipoint,
209 * but currently this restriction is not enforced.
211 virtual void pointsAdded(const AnalysisDataPointSetRef &points) = 0;
213 * Called when a data frame is finished.
215 * \param[in] header Header information for the frame that is ending.
216 * \throws unspecified Can throw any exception required by the
217 * implementing class to report errors.
219 virtual void frameFinished(const AnalysisDataFrameHeader &header) = 0;
221 * Called (once) when no more data is available.
223 * \throws unspecified Can throw any exception required by the
224 * implementing class to report errors.
226 virtual void dataFinished() = 0;
230 * Convenience base class for serial analysis data modules.
232 * Implements the parallelDataStarted() method such that initialization is
233 * always forwarded to dataStarted(), and the module always behaves as serial
234 * (parallelDataStarted() returns false).
237 * \ingroup module_analysisdata
239 class AnalysisDataModuleSerial : public AnalysisDataModuleInterface
242 virtual ~AnalysisDataModuleSerial() {}
244 virtual int flags() const = 0;
246 virtual void dataStarted(AbstractAnalysisData *data) = 0;
247 virtual void frameStarted(const AnalysisDataFrameHeader &frame) = 0;
248 virtual void pointsAdded(const AnalysisDataPointSetRef &points) = 0;
249 virtual void frameFinished(const AnalysisDataFrameHeader &header) = 0;
250 virtual void dataFinished() = 0;
253 virtual bool parallelDataStarted(
254 AbstractAnalysisData *data,
255 const AnalysisDataParallelOptions &options);
259 * Convenience base class for parallel analysis data modules.
261 * Implements the dataStarted() method such that initialization is always done
262 * in parallelDataStarted(). dataStarted() calls are forwarded to
263 * parallelDataStarted() using a dummy serial AnalysisDataParallelOptions.
266 * \ingroup module_analysisdata
268 class AnalysisDataModuleParallel : public AnalysisDataModuleInterface
271 virtual ~AnalysisDataModuleParallel() {}
273 virtual int flags() const = 0;
275 virtual bool parallelDataStarted(
276 AbstractAnalysisData *data,
277 const AnalysisDataParallelOptions &options) = 0;
278 virtual void frameStarted(const AnalysisDataFrameHeader &frame) = 0;
279 virtual void pointsAdded(const AnalysisDataPointSetRef &points) = 0;
280 virtual void frameFinished(const AnalysisDataFrameHeader &header) = 0;
281 virtual void dataFinished() = 0;
284 virtual void dataStarted(AbstractAnalysisData *data);