Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / analysismodule.cpp
index da1b84ded54603c61593565992595be9a0d4c601..a64a95fec7ec0f53d213d9beefd50f054e69c060 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,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.
@@ -39,7 +39,9 @@
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \ingroup module_trajectoryanalysis
  */
-#include "gromacs/trajectoryanalysis/analysismodule.h"
+#include "gmxpre.h"
+
+#include "analysismodule.h"
 
 #include <utility>
 
@@ -111,6 +113,9 @@ class TrajectoryAnalysisModuleData::Impl
              const AnalysisDataParallelOptions &opt,
              const SelectionCollection         &selections);
 
+        //! Checks whether the given AnalysisData has been initialized.
+        bool isInitialized(const AnalysisData &data) const;
+
         //! Keeps a data handle for each AnalysisData object.
         HandleContainer            handles_;
         //! Stores thread-local selections.
@@ -127,10 +132,30 @@ TrajectoryAnalysisModuleData::Impl::Impl(
     for (i = module->impl_->analysisDatasets_.begin();
          i != module->impl_->analysisDatasets_.end(); ++i)
     {
-        handles_.insert(std::make_pair(i->second, i->second->startData(opt)));
+        AnalysisDataHandle handle;
+        if (isInitialized(*i->second))
+        {
+            handle = i->second->startData(opt);
+        }
+        handles_.insert(std::make_pair(i->second, handle));
     }
 }
 
+bool TrajectoryAnalysisModuleData::Impl::isInitialized(
+        const AnalysisData &data) const
+{
+    for (int i = 0; i < data.dataSetCount(); ++i)
+    {
+        if (data.columnCount(i) > 0)
+        {
+            // If not all of the column counts are set, startData() in the
+            // constructor asserts, so that does not need to be checked here.
+            return true;
+        }
+    }
+    return false;
+}
+
 
 /********************************************************************
  * TrajectoryAnalysisModuleData
@@ -156,7 +181,10 @@ void TrajectoryAnalysisModuleData::finishDataHandles()
     Impl::HandleContainer::iterator i;
     for (i = impl_->handles_.begin(); i != impl_->handles_.end(); ++i)
     {
-        i->second.finishData();
+        if (i->second.isValid())
+        {
+            i->second.finishData();
+        }
     }
     impl_->handles_.clear();
 }
@@ -267,7 +295,9 @@ void TrajectoryAnalysisModule::optionsFinished(
 }
 
 
-void TrajectoryAnalysisModule::initAfterFirstFrame(const t_trxframe & /*fr*/)
+void TrajectoryAnalysisModule::initAfterFirstFrame(
+        const TrajectoryAnalysisSettings & /*settings*/,
+        const t_trxframe                 & /*fr*/)
 {
 }