Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / analysisdata / datastorage.h
index 26ab9640b6230d4df629abc2598098a8a964ed9e..8fd2b00ff04ef2ee6de9d4dc2620fe64c0273b7c 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2012,2013, by the GROMACS development team, led by
- * David van der Spoel, Berk Hess, Erik Lindahl, and including many
- * others, as listed in the AUTHORS file in the top-level source
- * directory and at http://www.gromacs.org.
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
  * GROMACS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
 
 #include <vector>
 
-#include "../legacyheaders/types/simple.h"
-
-#include "../utility/common.h"
-#include "../utility/gmxassert.h"
-
-#include "dataframe.h"
+#include "gromacs/analysisdata/dataframe.h"
+#include "gromacs/utility/common.h"
+#include "gromacs/utility/gmxassert.h"
+#include "gromacs/utility/real.h"
 
 namespace gmx
 {
@@ -58,12 +56,14 @@ namespace gmx
 class AbstractAnalysisData;
 class AnalysisDataFrameHeader;
 class AnalysisDataFrameRef;
+class AnalysisDataModuleManager;
 class AnalysisDataParallelOptions;
 
 class AnalysisDataStorage;
 
 namespace internal
 {
+class AnalysisDataStorageImpl;
 class AnalysisDataStorageFrameData;
 }   // namespace internal
 
@@ -187,8 +187,9 @@ class AnalysisDataStorageFrame
          *
          * After this method has been called, all values appear as not set.
          *
-         * Calls AbstractAnalysisData::notifyPointsAdd(), and throws any
-         * exception this method throws.
+         * May call AnalysisDataModuleManager::notifyPointsAdd() and
+         * AnalysisDataModuleManager::notifyParallelPointsAdd(), and may throw
+         * any exception these methods throw.
          */
         void finishPointSet();
         /*! \brief
@@ -198,8 +199,8 @@ class AnalysisDataStorageFrame
          * after the corresponding call.
          * The frame object must not be accessed after the call.
          *
-         * Calls notification methods in AbstractAnalysisData, and throws any
-         * exceptions these methods throw.
+         * Calls notification methods in AnalysisDataModuleManager, and may
+         * throw any exceptions these methods throw.
          */
         void finishFrame();
 
@@ -232,7 +233,7 @@ class AnalysisDataStorageFrame
         bool                                    bPointSetInProgress_;
 
         //! Needed for access to the constructor.
-        friend class AnalysisDataStorage;
+        friend class internal::AnalysisDataStorageImpl;
         //! Needed for managing the frame the object points to.
         friend class internal::AnalysisDataStorageFrameData;
 
@@ -245,16 +246,15 @@ class AnalysisDataStorageFrame
  * This class implements a standard way of storing data to avoid implementing
  * storage in each class derived from AbstractAnalysisData separately.
  * To use this class in a class derived from AbstractAnalysisData, a member
- * variable of this type should be declared and the data storage methods
- * forwarded to tryGetDataFrame() and requestStorage() in that object.
- * Storage properties should be set up, and then startDataStorage() called
- * after calling AbstractAnalysisData::notifyDataStart().
+ * variable of this type should be declared and the pure virtual methods
+ * forwarded to frameCount(), tryGetDataFrame() and requestStorage().
+ * Storage properties should be set up, and then startDataStorage() or
+ * startParallelDataStorage() called.
  * New frames can then be added using startFrame(), currentFrame() and
- * finishFrame() methods.  These methods (and
- * AnalysisDataStorageFrame::finishPointSet()) take the responsibility of
- * calling AbstractAnalysisData::notifyFrameStart(),
- * AbstractAnalysisData::notifyPointsAdd() and
- * AbstractAnalysisData::notifyFrameFinish() appropriately.
+ * finishFrame() methods.  When all frames are ready, finishDataStorage() must
+ * be called.  These methods (and AnalysisDataStorageFrame::finishPointSet())
+ * take the responsibility of calling all the notification methods in
+ * AnalysisDataModuleManager,
  *
  * \todo
  * Proper multi-threaded implementation.
@@ -270,17 +270,18 @@ class AnalysisDataStorage
         ~AnalysisDataStorage();
 
         /*! \brief
-         * Set parallelization options for the storage.
+         * Returns the number of ready frames.
          *
-         * \param[in] opt  Parallization options to use.
+         * This method is designed such that calls to
+         * AbstractAnalysisData::frameCount() can be directly forwarded to this
+         * method.  See that method for more documentation.
          *
-         * If this method is not called, the storage is set up for serial
-         * storage only.
+         * If this method returns N, this means that the first N frames have
+         * all been finished.
          *
-         * Does not throw.
+         * \see AbstractAnalysisData::frameCount()
          */
-        void setParallelOptions(const AnalysisDataParallelOptions &opt);
-
+        int frameCount() const;
         /*! \brief
          * Implements access to data frames.
          *
@@ -308,21 +309,47 @@ class AnalysisDataStorage
         /*! \brief
          * Start storing data.
          *
-         * \param  data  AbstractAnalysisData object containing this storage.
+         * \param[in] data    AbstractAnalysisData object containing this
+         *      storage.
+         * \param     modules Module manager for \p data.
          * \exception std::bad_alloc if storage allocation fails.
          *
-         * Lifetime of \p data must exceed the lifetime of the storage object
+         * Typically called as \c startDataStorage(this, &moduleManager())
+         * from a member of \p data when the data is ready to be started.
+         * The storage object will take responsibility of calling all
+         * module notification methods in AnalysisDataModuleManager using
+         * \p modules.
+         *
+         * Lifetime of \p data and \p modules must exceed the lifetime of the
+         * storage object
          * (typically, the storage object will be a member in \p data).
-         * The storage object will take responsibility of calling
-         * AbstractAnalysisData::notifyFrameStart(),
-         * AbstractAnalysisData::notifyPointsAdd() and
-         * AbstractAnalysisData::notifyFrameFinish() for \p data appropriately.
-         *
-         * AbstractAnalysisData::notifyDataStart() must have been called for
-         * \p data, because that may trigger storage requests from attached
-         * modules.
+         *
+         * Calls AnalysisDataModuleManager::notifyDataStart(), and throws any
+         * exceptions this method throws.
+         */
+        void startDataStorage(AbstractAnalysisData      *data,
+                              AnalysisDataModuleManager *modules);
+        /*! \brief
+         * Start storing data in parallel.
+         *
+         * \param[in] data    AbstractAnalysisData object containing this
+         *      storage.
+         * \param[in] options Parallelization options to use.
+         * \param     modules Module manager for \p data.
+         * \exception std::bad_alloc if storage allocation fails.
+         *
+         * Should be called instead of startDataStorage() if the data will be
+         * produced in parallel.  Works as startDataStorage(), but additionally
+         * initializes the storage and the attached modules to prepare for
+         * out-of-order data frames.
+         *
+         * Calls AnalysisDataModuleManager::notifyParallelDataStart(), and
+         * throws any exceptions this method throws.
          */
-        void startDataStorage(AbstractAnalysisData *data);
+        void startParallelDataStorage(
+            AbstractAnalysisData              *data,
+            AnalysisDataModuleManager         *modules,
+            const AnalysisDataParallelOptions &options);
         /*! \brief
          * Starts storing a new frame.
          *
@@ -346,8 +373,9 @@ class AnalysisDataStorage
          * setParallelOptions().
          * Throws APIError if this constraint is violated.
          *
-         * Calls AbstractAnalysisData::notifyDataStarted() in certain cases,
-         * and throws any exceptions this method throws.
+         * Calls AnalysisDataModuleManager::notifyFrameStart() (in certain
+         * cases) and AnalysisDataModuleManager::notifyParallelFrameStart(),
+         * and throws any exceptions these methods throw.
          */
         AnalysisDataStorageFrame &startFrame(const AnalysisDataFrameHeader &header);
         /*! \brief
@@ -380,14 +408,18 @@ class AnalysisDataStorage
          * \see AnalysisDataStorageFrame::finishFrame()
          */
         void finishFrame(int index);
+        /*! \brief
+         * Finishes storing data.
+         *
+         * Calls AnalysisDataModuleManager::notifyDataFinish(), and throws any
+         * exceptions this method throws.
+         */
+        void finishDataStorage();
 
     private:
-        class Impl;
+        typedef internal::AnalysisDataStorageImpl Impl;
 
         PrivateImplPointer<Impl> impl_;
-
-        //! Needed because the frame needs to access the implementation class.
-        friend class internal::AnalysisDataStorageFrameData;
 };
 
 } // namespace gmx