FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTParallelWriter.h
Go to the documentation of this file.
1#ifndef FMTparallelwriter_Hm_included
2#define FMTparallelwriter_Hm_included
3#include "FMTModelParser.h"
4#include <vector>
5#include <string>
6#include <memory>
7#include <boost/thread/recursive_mutex.hpp>
8#include "FMTutility.h"
9
10#ifdef FMTWITHGDAL
11class GDALDataset;
12class OGRLayer;
13#endif
14
15namespace Models {
16 class FMTModel;
17}
18
19
20namespace Parallel
21{
22 // DocString: FMTParallelWriter
27 {
28 public:
29 // DocString: FMTParallelWriter::FMTParallelWriter()
33 FMTParallelWriter() = default;
34 // DocString: ~FMTparallelwrite()
39 // DocString: FMTParallelWriter::FMTParallelWriter(const FMTParallelWriter&)
44 FMTParallelWriter(const FMTParallelWriter& rhs) = default;
45 // DocString: FMTParallelWriter::operator=()
51 FMTParallelWriter& operator = (const FMTParallelWriter& rhs) = default;
52 // DocString: FMTParallelWriter::FMTParallelWriter(const std::string&,const std::string&,const std::vector<Core::FMTOutput>&,const Models::FMTModel&)
63 FMTParallelWriter(const std::string& location,
64 const std::string& driver,
65 const std::vector<Core::FMTOutput>& outputs,
66 const std::vector<Models::FMTModel*>& allmodels,
67 std::vector<std::string>layersoptions = std::vector<std::string>(),
68 double minimaldrift = 0.5,
70 // DocString: FMTParallelWriter::FMTParallelWriter(const std::string&,const std::string&,std::vector<std::string>,Core::FMToutputlevel)
81 FMTParallelWriter(const std::string& location,
82 const std::string& driver,
84 std::vector<std::string>layersoptions = std::vector<std::string>(),
85 int firstPeriod=1,
86 int lastPeriod=1,
87 std::string primaryfilelocation = std::string());
88 // DocString: FMTParallelWriter::setLayer
93 void setLayer(const std::string& p_name);
94 // DocString: FMTParallelWriter::write()
103 void write(const std::string& modelname,
104 const std::map<std::string, std::vector<std::vector<double>>>& results,
105 const int& firstPeriod, const int& lastPeriod, const int& iteration) const;
106 // DocString: FMTParallelWriter::writeSchedules
113 void writeSchedules(const std::string seqName, const std::vector<Core::FMTSchedule> scheduleList, bool append) const;
114 // DocString: FMTParallelWriter::getResults()
122 std::map<std::string, std::vector<std::vector<double>>> getResults(const std::unique_ptr<Models::FMTModel>& modelptr, const int& firstPeriod, const int& lastPeriod) const;
123 // DocString: FMTParallelWriter::setDriftProbability()
129 void setDriftProbability(const std::string& globalmodel, const std::string& localmodel) const;
130 // DocString: FMTParallelWriter::getAndWrite()
136 void getAndWrite(const std::unique_ptr<Models::FMTModel>& modelptr, const std::vector<Core::FMTOutput>& loutputs);
137 // DocString: FMTParallelWriter::close()
141 void close() noexcept;
142 protected:
143 // DocString: FMTParallelWriter::_getDriftProbability()
151 const std::map<std::string, std::map<double, std::vector<double>>>_getDriftProbability(
152 const std::map<std::string, std::vector<std::vector<double>>>& globalvalues,
153 const std::map<std::string, std::vector<std::vector<double>>>& localvalues,
154 const bool lower = true) const;
155 private:
156 // DocString: FMTParallelWriter::m_outputstowrite
158 std::vector<Core::FMTOutput>m_outputstowrite;
159 #ifdef FMTWITHGDAL
160 // DocString: FMTParallelWriter::m_resultsdataset
162 GDALDataset* m_resultsdataset;
163 // DocString: FMTParallelWriter::m_resultslayer
165 std::map<std::string, OGRLayer*> m_resultslayer;
166 // DocString: FMTParallelWriter::m_driftlayer
168 OGRLayer* m_driftlayer;
169 #endif
170 // DocString: FMTParallelWriter::m_mtx
172 mutable boost::recursive_mutex m_mtx;
173 // DocString: FMTParallelWriter::m_resultsminimaldrift;
175 double m_resultsminimaldrift;
176 // DocString: FMTParallelWriter::m_outputslevel
178 Core::FMToutputlevel m_outputslevel;
179 // DocString: FMTParallelWriter::m_alllayeroptions
181 std::vector<std::string> m_alllayeroptions;
182 // DocString: FMTParallelWriter::m_outputfirstperiod
184 int m_outputfirstperiod;
185 // DocString: FMTParallelWriter::m_outputlastperiod;
187 int m_outputlastperiod;
188 // DocString: FMTParallelWriter::m_projectdirectory;
190 std::string m_projectdirectory;
191 // DocString: FMTParallelWriter::m_projectname;
193 std::string m_projectname;
194 // DocString: FMTParallelWriter::m_projectname;
196 std::string m_outputLocationPath;
197 };
198}
199#endif
#define FMTEXPORT
Definition: FMTutility.h:125
Writer used in concurrency to write multiple results in the same layer.
Definition: FMTParallelWriter.h:27
FMTParallelWriter(const std::string &location, const std::string &driver, const std::vector< Core::FMTOutput > &outputs, const std::vector< Models::FMTModel * > &allmodels, std::vector< std::string >layersoptions=std::vector< std::string >(), double minimaldrift=0.5, Core::FMToutputlevel outputlevel=Core::FMToutputlevel::totalonly)
Construct a FMTParallelWriter from the location, driver and outputs and the base models to write.
void setLayer(const std::string &p_name)
Add a new layer for a given model.
FMTParallelWriter(const std::string &location, const std::string &driver, Core::FMToutputlevel outputlevel=Core::FMToutputlevel::totalonly, std::vector< std::string >layersoptions=std::vector< std::string >(), int firstPeriod=1, int lastPeriod=1, std::string primaryfilelocation=std::string())
Construct a FMTParallelWriter without layers and outputs.
void getAndWrite(const std::unique_ptr< Models::FMTModel > &modelptr, const std::vector< Core::FMTOutput > &loutputs)
Get the results of a model and write them down.
std::map< std::string, std::vector< std::vector< double > > > getResults(const std::unique_ptr< Models::FMTModel > &modelptr, const int &firstPeriod, const int &lastPeriod) const
Get the results of a model.
void setDriftProbability(const std::string &globalmodel, const std::string &localmodel) const
Compute the drift probability from the global and local models starting from a minimal drift proporti...
FMTParallelWriter(const FMTParallelWriter &rhs)=default
Default copy constructor for FMTParallelWriter.
void close() noexcept
Close the dataset and destroy the layers, after which the writer is no longer usable.
FMTParallelWriter()=default
Default constructor for FMTParallelWriter.
void writeSchedules(const std::string seqName, const std::vector< Core::FMTSchedule > scheduleList, bool append) const
Write schedules to a file.
void write(const std::string &modelname, const std::map< std::string, std::vector< std::vector< double > > > &results, const int &firstPeriod, const int &lastPeriod, const int &iteration) const
Write the model results from the first to the last period for a given iteration (replicate).
virtual ~FMTParallelWriter()
Default destructor for FMTParallelWriter.
Main parser reading and writing model files, for single or multiple scenarios, using all the other FM...
Definition: FMTModelParser.h:48
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMToutputlevel
Enumerator describing the level of detail of an output (standard, total only, development).
Definition: FMTutility.h:22
@ totalonly
Definition: FMTutility.h:24
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Namespace for parallel tasking may include multithreading / multiprocessing.
Definition: FMTOpAreaSchedulerTask.h:40
STL namespace.