TBTK
DataManager.h
Go to the documentation of this file.
1 /* Copyright 2017 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_DATA_MANAGER
24 #define COM_DAFER45_TBTK_DATA_MANAGER
25 
26 #include "TBTK/Serializable.h"
27 
28 #include <string>
29 #include <vector>
30 
31 namespace TBTK{
32 
33 class DataManager : public Serializable{
34 public:
37  const std::vector<double> &lowerBounds,
38  const std::vector<double> &upperBounds,
39  const std::vector<unsigned int> &numTicks,
40  const std::vector<std::string> &parameterNames,
41  const std::string &dataManagerName = ""
42  );
43 
45  DataManager(const DataManager &dataManager) = delete;
46 
49  DataManager(const std::string &serialization, Mode mode);
50 
52  virtual ~DataManager();
53 
55  DataManager& operator=(const DataManager &dataManager) = delete;
56 
58  double getLowerBound(unsigned int parameterIndex) const;
59 
61  double getUpperBound(unsigned int parameterIndex) const;
62 
64  unsigned int getNumTicks(unsigned int parameterIndex) const;
65 
67  unsigned int getNumParameters() const;
68 
70  const std::string& getParameterName(unsigned int parameterIndex) const;
71 
73  void setPath(const std::string &path = "");
74 
76  const std::string& getPath() const;
77 
78  enum class FileType {
79  Custom,
80  SerializableJSON,
81  PNG
82  };
83 
85  void addDataType(
86  const std::string &dataType,
87  FileType fileType
88  );
89 
91  unsigned int getNumDataTypes() const;
92 
94  const std::string& getDataType(unsigned int dataTypeIndex) const;
95 
97  FileType getFileType(const std::string &dataType) const;
98 
100  int reserveDataPoint(const std::string &dataTypes = "");
101 
103  std::vector<double> getParameters(int id) const;
104 
106  unsigned int getID(const std::vector<unsigned int> &dataPoint) const;
107 
109  std::vector<unsigned int> getDataPoint(unsigned int id) const;
110 
113  std::string getFilename(const std::string &dataType, int id) const;
114 
116  void markCompleted(
117  const std::string &dataType,
118  int id
119  );
120 
122  void complete(
123  const Serializable &serializable,
124  const std::string &dataType,
125  int id
126  );
127 
129  virtual std::string serialize(Mode mode) const;
130 private:
132  std::vector<double> lowerBounds;
133 
135  std::vector<double> upperBounds;
136 
138  std::vector<unsigned int> numTicks;
139 
141  std::vector<std::string> parameterNames;
142 
144  std::string dataManagerName;
145 
147  std::string path;
148 
150  unsigned int numDataPoints;
151 
153  std::vector<std::string> dataTypes;
154 
156  std::vector<FileType> fileTypes;
157 
159  std::vector<bool*> reservedDataPoints;
160 
162  std::vector<bool*> completedDataPoints;
163 
165  void addDataTables();
166 
168  unsigned int getDataTypeIndex(const std::string &dataType) const;
169 
171  bool reserveDataPoint(
172  const std::string &dataType,
173  unsigned int id
174  );
175 };
176 
177 inline double DataManager::getLowerBound(unsigned int parameterIndex) const{
178  return lowerBounds.at(parameterIndex);
179 }
180 
181 inline double DataManager::getUpperBound(unsigned int parameterIndex) const{
182  return upperBounds.at(parameterIndex);
183 }
184 
185 inline unsigned int DataManager::getNumTicks(unsigned int parameterIndex) const{
186  return numTicks.at(parameterIndex);
187 }
188 
189 inline unsigned int DataManager::getNumParameters() const{
190  return parameterNames.size();
191 }
192 
193 inline const std::string& DataManager::getParameterName(
194  unsigned int parameterIndex
195 ) const{
196  return parameterNames.at(parameterIndex);
197 }
198 
199 inline unsigned int DataManager::getNumDataTypes() const{
200  return dataTypes.size();
201 }
202 
203 inline const std::string& DataManager::getDataType(
204  unsigned int dataTypeIndex
205 ) const{
206  return dataTypes.at(dataTypeIndex);
207 }
208 
209 inline DataManager::FileType DataManager::getFileType(
210  const std::string &dataType
211 ) const{
212  return fileTypes.at(getDataTypeIndex(dataType));
213 }
214 
215 inline const std::string& DataManager::getPath() const{
216  return path;
217 }
218 
219 }; //End namespace TBTK
220 
221 #endif
unsigned int getNumParameters() const
Definition: DataManager.h:189
int reserveDataPoint(const std::string &dataTypes="")
std::vector< double > getParameters(int id) const
Definition: Serializable.h:40
void complete(const Serializable &serializable, const std::string &dataType, int id)
unsigned int getNumTicks(unsigned int parameterIndex) const
Definition: DataManager.h:185
void addDataType(const std::string &dataType, FileType fileType)
std::vector< unsigned int > getDataPoint(unsigned int id) const
virtual std::string serialize(Mode mode) const
DataManager(const std::vector< double > &lowerBounds, const std::vector< double > &upperBounds, const std::vector< unsigned int > &numTicks, const std::vector< std::string > &parameterNames, const std::string &dataManagerName="")
FileType getFileType(const std::string &dataType) const
Definition: DataManager.h:209
Definition: DataManager.h:33
const std::string & getParameterName(unsigned int parameterIndex) const
Definition: DataManager.h:193
const std::string & getPath() const
Definition: DataManager.h:215
unsigned int getNumDataTypes() const
Definition: DataManager.h:199
DataManager & operator=(const DataManager &dataManager)=delete
double getLowerBound(unsigned int parameterIndex) const
Definition: DataManager.h:177
double getUpperBound(unsigned int parameterIndex) const
Definition: DataManager.h:181
virtual ~DataManager()
unsigned int getID(const std::vector< unsigned int > &dataPoint) const
Definition: ModelFactory.h:35
void markCompleted(const std::string &dataType, int id)
const std::string & getDataType(unsigned int dataTypeIndex) const
Definition: DataManager.h:203
Mode
Definition: Serializable.h:44
void setPath(const std::string &path="")
Abstract base class for serializable objects.
std::string getFilename(const std::string &dataType, int id) const