DataCenterMongoDB.h
Go to the documentation of this file.
1/*!
2 * \file DataCenterMongoDB.h
3 * \brief Data center for running SEIMS based on MongoDB.
4 * including configuration, input data, output data, etc.
5 *
6 * Changelog:
7 * - 1. 2017-05-30 - lj - Initial implementation.
8 * - 2. 2021-04-06 - lj - Compatible with different flow direction algorithms.
9 *
10 *
11 * \author Liangjun Zhu
12 */
13#ifndef SEIMS_DATA_CENTER_MONGODB_H
14#define SEIMS_DATA_CENTER_MONGODB_H
15
16#include "DataCenter.h"
17
18/*!
19 * \ingroup data
20 * \class DataCenterMongoDB
21 * \brief Class of Data center inherited from DataCenter based on MongoDB
22 * \version 1.3
23 */
25public:
26 /*!
27 * \brief Constructor based on MongoDB
28 * \param[in] input_args Input arguments of SEIMS
29 * \param[in] client MongoDB connection client
30 * \param[in] spatial_gfs_in MongoDB GridFS that stores input data
31 * \param[in] spatial_gfs_out MongoDB GridFS that stores output data
32 * \param[in] factory SEIMS modules factory
33 * \param[in] subbasin_id Subbasin ID, 0 is the default for entire watershed
34 */
36 MongoGridFs* spatial_gfs_in, MongoGridFs* spatial_gfs_out,
37 ModuleFactory* factory, int subbasin_id = 0);
38 //! Destructor
40 /*!
41 * \brief Make sure all the required data are presented
42 */
44 /*!
45 * \brief Get file.in configuration from FILE_IN collection
46 */
48 /*!
49 * \brief Get file.out configuration
50 */
52 /*!
53 * \brief Read climate site data from HydroClimate database
54 */
56 /*!
57 * \brief Read initial and calibrated parameters
58 *
59 * Changlog:
60 * - 1. 2017-12-23 - lj - Read parameters (Impact value) according to calibration ID.
61 */
63 /*!
64 * \brief Get subbasin number and outlet ID
65 */
66 int ReadIntParameterInDB(const char* param_name) OVERRIDE;
67 /*!
68 * \brief Read raster data, both 1D and 2D, and insert to m_rsMap
69 * \param[in] remote_filename Raster file name.
70 * \param[in] flt_rst Float raster data
71 */
72 bool ReadRasterData(const string& remote_filename, FloatRaster*& flt_rst) OVERRIDE;
73 /*!
74 * \brief Read raster data, both 1D and 2D, and insert to m_rsMap
75 * \param[in] remote_filename Raster file name.
76 * \param[in] int_rst Float raster data
77 */
78 bool ReadRasterData(const string& remote_filename, IntRaster*& int_rst) OVERRIDE;
79 /*!
80 * \brief Read interpolated weight data from MongoDB and insert to m_weightDataMap
81 * \param[in] remote_filename \a string data file name
82 * \param[out] num \a int&, data length
83 * \param[out] stations \a int& number of stations
84 * \param[out] data \a float*&, returned data
85 */
86 void ReadItpWeightData(const string& remote_filename, int& num, int& stations, FLTPT**& data) OVERRIDE;
87 /*!
88 * \brief Read 1D array data from MongoDB and insert to m_1DArrayMap
89 * CAUTION: Value data type stored in MongoDB MUST be float
90 * \param[in] remote_filename \a string data file name
91 * \param[out] num \a int&, data length
92 * \param[out] data \a float*&, returned data
93 */
94 void Read1DArrayData(const string& remote_filename, int& num, FLTPT*& data) OVERRIDE;
95 /*!
96 * \brief Read 1D integer array data from MongoDB and insert to m_1DArrayMap
97 * CAUTION: Value data type stored in MongoDB MUST be float
98 * TODO: data stored in MongoDB should have an attribute to indicate data type!
99 * \param[in] remote_filename \a string data file name
100 * \param[out] num \a int&, data length
101 * \param[out] data \a int*&, returned data
102 */
103 void Read1DArrayData(const string& remote_filename, int& num, int*& data) OVERRIDE;
104 /*!
105 * \brief Read 2D array data from MongoDB database
106 * \param[in] remote_filename \a string data file name
107 * \param[out] rows \a int&, first dimension of the 2D Array, i.e., Rows
108 * \param[out] cols \a int&, second dimension of the 2D Array, i.e., Cols. If each col are different, set cols to 1.
109 * \param[out] data \a float**&, returned data
110 */
111 void Read2DArrayData(const string& remote_filename, int& rows, int& cols, FLTPT**& data) OVERRIDE;
112 // Read 2D integer array data
113 void Read2DArrayData(const string& remote_filename, int& rows, int& cols, int**& data) OVERRIDE;
114 /*!
115 * \brief Read IUH data from MongoDB and insert to m_2DArrayMap
116 * \param[in] remote_filename \a string data file name
117 * \param[out] n \a int&, valid cell number
118 * \param[out] data \a float*&, returned data
119 */
120 void ReadIuhData(const string& remote_filename, int& n, FLTPT**& data) OVERRIDE;
121 /*!
122 * \brief Set Raster data for Scenario data
123 * \return True if set successfully, otherwise false.
124 */
126
127 /******* MongoDB specified functions *********/
128
129 /*!
130 * \brief Query database name
131 */
132 string QueryDatabaseName(bson_t* query, const char* tabname);
133public:
134 /**** Accessors: Set and Get *****/
135
136 const char* GetHostIp() const { return mongodb_ip_; }
137 uint16_t GetPort() const { return mongodb_port_; }
138 string GetClimateDBName() const { return clim_dbname_; }
139 string GetScenarioDBName() const { return scenario_dbname_; }
140 MongoClient* GetMongoClient() const { return mongo_client_; }
141 MongoDatabase* GetMainDatabase() const { return main_database_; }
142 MongoGridFs* GetMongoGridFs() const { return spatial_gridfs_; }
143 MongoGridFs* GetMongoGridFsOutput() const { return spatial_gfs_out_; }
144private:
145 const char* mongodb_ip_; ///< Host IP address of MongoDB
146 const uint16_t mongodb_port_; ///< Port
147 string clim_dbname_; ///< Climate database name
148 string scenario_dbname_; ///< Scenario database name
149 MongoClient* mongo_client_; ///< MongoDB Client
150 MongoDatabase* main_database_; ///< Main model database
151 MongoGridFs* spatial_gridfs_; ///< Spatial data handler
152 MongoGridFs* spatial_gfs_out_; ///< Spatial data handler
153};
154#endif /* SEIMS_DATA_CENTER_MONGODB_H */
Data center for running SEIMS including configuration, input data, output data, etc.
#define OVERRIDE
A compatible reference to override or blank if not supported by the compiler.
Definition: basic.h:160
A simple wrapper of the class of MongoDB Client mongoc_client_t.
Definition: db_mongoc.h:46
A simple wrapper of the class of MongoDB database mongoc_database_t.
Definition: db_mongoc.h:97
A simple wrapper of the class of MongoDB database mongoc_gridfs_t.
Definition: db_mongoc.h:141
bool ReadParametersInDB() OVERRIDE
Read initial and calibrated parameters.
bool GetFileInStringVector() OVERRIDE
Get file.in configuration from FILE_IN collection.
bool ReadRasterData(const string &remote_filename, FloatRaster *&flt_rst) OVERRIDE
Read raster data, both 1D and 2D, and insert to m_rsMap.
void Read2DArrayData(const string &remote_filename, int &rows, int &cols, FLTPT **&data) OVERRIDE
Read 2D array data from MongoDB database.
void Read1DArrayData(const string &remote_filename, int &num, FLTPT *&data) OVERRIDE
Read 1D array data from MongoDB and insert to m_1DArrayMap CAUTION: Value data type stored in MongoDB...
void ReadIuhData(const string &remote_filename, int &n, FLTPT **&data) OVERRIDE
Read IUH data from MongoDB and insert to m_2DArrayMap.
~DataCenterMongoDB()
Destructor.
bool CheckModelPreparedData() OVERRIDE
Make sure all the required data are presented.
string QueryDatabaseName(bson_t *query, const char *tabname)
Query database name.
void ReadItpWeightData(const string &remote_filename, int &num, int &stations, FLTPT **&data) OVERRIDE
Read interpolated weight data from MongoDB and insert to m_weightDataMap.
bool SetRasterForScenario() OVERRIDE
Set Raster data for Scenario data.
int ReadIntParameterInDB(const char *param_name) OVERRIDE
Get subbasin number and outlet ID.
bool GetFileOutVector() OVERRIDE
Get file.out configuration.
DataCenterMongoDB(InputArgs *input_args, MongoClient *client, MongoGridFs *spatial_gfs_in, MongoGridFs *spatial_gfs_out, ModuleFactory *factory, int subbasin_id=0)
Constructor based on MongoDB.
void ReadClimateSiteList() OVERRIDE
Read climate site data from HydroClimate database.
Base class of Data center for SEIMS.
Definition: DataCenter.h:37
Class of Data center inherited from DataCenter based on MongoDB.
Definition: DataCenterMongoDB.h:24
Parse the input arguments of SEIMS.
Definition: invoke.h:29
Linking user-defined modules to create the modeling workflow.
Definition: ModuleFactory.h:40
#define FloatRaster
Float-typed raster with int-typed mask, specific for legacy SEIMS code.
Definition: seims.h:133
#define IntRaster
Integer-typed raster.
Definition: seims.h:126