TCPSPSuite
db_objects.hpp
1 //
2 // Created by lukas on 24.10.17.
3 //
4 
5 #ifndef TCPSPSUITE_DB_OBJECTS_HPP
6 #define TCPSPSUITE_DB_OBJECTS_HPP
7 
8 #include <iostream>
9 #include <memory>
10 #include <odb/core.hxx>
11 #include <odb/lazy-ptr.hxx>
12 #include <odb/nullable.hxx>
13 #include <string>
14 #include <vector>
15 
16 #include <boost/date_time/posix_time/posix_time_types.hpp>
17 
18 #include "../../datastructures/maybe.hpp"
19 
20 #pragma GCC diagnostic push
21 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
22 
23 // Forwards for back-and-forth relationships
24 class DBIntermediate;
25 class DBSolutionJob;
26 class DBConfig;
27 class DBResourcesInfo;
28 class DBPapiMeasurement;
29 class DBSolution;
30 class DBExtendedMeasure;
31 class DBResult;
32 
33 #pragma db namespace() session
34 #pragma db namespace() pointer(std::shared_ptr)
35 
36 #pragma db object
37 class DBConfigKV {
38 public:
39 #pragma db not_null
40  std::weak_ptr<DBConfig> cfg;
41  std::string key;
42  std::string value;
43 
44  DBConfigKV(std::shared_ptr<DBConfig> cfg, const std::string & key,
45  const std::string & value);
46  DBConfigKV(std::shared_ptr<const DBConfigKV> src);
47 
48 #pragma db index member(cfg)
49 
50 private:
51  DBConfigKV() {}
52 
53 #pragma db id auto
54  unsigned long id_;
55 
56  friend class odb::access;
57 };
58 
59 #pragma db object
60 class DBConfig {
61 public:
62  std::string name;
63 
64 #pragma db null
65  std::shared_ptr<unsigned int> time_limit;
66 
67 #pragma db value_not_null inverse(cfg)
68  std::vector<std::shared_ptr<DBConfigKV>> entries;
69 
70  DBConfig(const std::string & name, Maybe<unsigned int> time_limit);
71  DBConfig(std::shared_ptr<const DBConfig> src);
72 
73 #pragma db index member(name)
74 private:
75  DBConfig() {}
76 
77 #pragma db id auto
78  unsigned long id_;
79 
80  friend class odb::access;
81 };
82 
83 #pragma db object
84 class DBInvocation {
85 public:
86  DBInvocation(std::string cmdline, std::string git_revision,
87  std::string hostname, unsigned long time);
88  DBInvocation(std::shared_ptr<const DBInvocation> src);
89 
90  std::string cmdline;
91  std::string git_revision;
92  std::string hostname;
93  unsigned long time;
94 
95 #pragma db value_not_null inverse(invocation)
96  std::vector<std::shared_ptr<DBResult>> results;
97 
98  unsigned long get_id() const noexcept;
99 
100 private:
101  DBInvocation(){};
102 
103 #pragma db id auto
104  unsigned long id_;
105 
106  friend class odb::access;
107 };
108 
109 #pragma db object
110 class DBResult {
111 public:
112  DBResult(std::string run, std::string instance, double score,
113  std::string algorithm, std::string config_name, int seed,
114  bool optimal, bool feasible, Maybe<double> lower_bound,
115  double elapsed, std::shared_ptr<DBConfig> cfg,
116  std::shared_ptr<DBInvocation> invocation);
117  DBResult(std::shared_ptr<const DBResult> src);
118 
119  std::string run;
120 
121  std::string instance;
122  double score;
123  std::string algorithm;
124  std::string config; // TODO remove this
125  int seed;
126  bool optimal;
127  bool feasible;
128 #pragma db null
129  std::shared_ptr<double> lower_bound;
130  double elapsed;
131  unsigned long time;
132  std::shared_ptr<DBInvocation> invocation;
133 
134 #pragma db not_null
135  std::shared_ptr<DBConfig> cfg;
136 
137  // Reverse sides of stuff that points here
138 #pragma db inverse(res)
139  std::vector<std::shared_ptr<DBResourcesInfo>> resource_infos;
140 #pragma db inverse(res)
141  std::vector<std::shared_ptr<DBPapiMeasurement>> papi_measurements;
142 #pragma db inverse(res)
143  std::vector<std::shared_ptr<DBSolution>> solutions;
144 #pragma db inverse(res)
145  std::vector<std::shared_ptr<DBIntermediate>> intermediates;
146 #pragma db inverse(res)
147  std::vector<std::shared_ptr<DBExtendedMeasure>> extended_measures;
148 
149 #pragma db index member(instance)
150 #pragma db index member(algorithm)
151 #pragma db index member(cfg)
152 
153  unsigned long
154  get_id() const noexcept
155  {
156  return this->id_;
157  }
158 
159 private:
160  DBResult() {}
161 
162 #pragma db id auto
163  unsigned long id_;
164 
165  friend class odb::access;
166 };
167 
168 #pragma db object
169 class DBResourcesInfo {
170 public:
171  DBResourcesInfo(std::shared_ptr<DBResult> res,
172  odb::nullable<size_t> max_rss_size,
173  odb::nullable<size_t> max_data_size,
174  odb::nullable<size_t> malloc_max_size,
175  odb::nullable<size_t> malloc_count, size_t major_pagefaults,
176  size_t minor_pagefaults, unsigned long user_usecs,
177  unsigned long system_usecs);
178  DBResourcesInfo(std::shared_ptr<const DBResourcesInfo> src);
179 
180 #pragma db not_null
181  std::shared_ptr<DBResult> res;
182 
183  size_t major_pagefaults;
184  size_t minor_pagefaults;
185  unsigned long user_usecs;
186  unsigned long system_usecs;
187 
188  odb::nullable<size_t> max_rss_size;
189  odb::nullable<size_t> max_data_size;
190  odb::nullable<size_t> malloc_max_size;
191  odb::nullable<size_t> malloc_count;
192 
193 #pragma db index member(res)
194 
195 private:
196  DBResourcesInfo() {}
197 
198 #pragma db id auto
199  unsigned long id_;
200 
201  friend class odb::access;
202 };
203 
204 #pragma db object
205 class DBPapiMeasurement {
206 public:
207  DBPapiMeasurement(std::shared_ptr<DBResult> res, std::string event_type,
208  long long event_count);
209  DBPapiMeasurement(std::shared_ptr<const DBPapiMeasurement> src);
210 
211 #pragma db not_null
212  std::shared_ptr<DBResult> res;
213 
214  std::string event_type;
215  long long event_count;
216 
217 #pragma db index member(res)
218 
219 private:
220  DBPapiMeasurement() {}
221 
222 #pragma db id auto
223  unsigned long id_;
224 
225  friend class odb::access;
226 };
227 
228 #pragma db object
229 class DBSolution {
230 public:
231  DBSolution(std::shared_ptr<DBResult> res);
232  DBSolution(std::shared_ptr<const DBSolution> src);
233 
234 #pragma db not_null
235  std::shared_ptr<DBResult> res;
236 
237 #pragma db value_not_null inverse(sol)
238  std::vector<std::shared_ptr<DBSolutionJob>> jobs;
239 #pragma db inverse(solution)
240  std::vector<std::shared_ptr<DBIntermediate>> intermediates;
241 
242 #pragma db index member(res)
243 
244  unsigned long
245  get_id() const
246  {
247  return this->id_;
248  }
249 
250 private:
251  DBSolution() {}
252 
253 #pragma db id auto
254  unsigned long id_;
255 
256  friend class odb::access;
257 };
258 
259 #pragma db object
260 class DBSolutionJob {
261 public:
262  DBSolutionJob(std::shared_ptr<DBSolution> sol, unsigned int job_id,
263  unsigned int start_time);
264  DBSolutionJob(std::shared_ptr<const DBSolutionJob> src);
265 
266 #pragma db not_null
267  std::shared_ptr<DBSolution> sol;
268 
269  unsigned int job_id;
270  unsigned int start_time;
271 
272 private:
273  DBSolutionJob() {}
274 
275 #pragma db id auto
276  unsigned long id_;
277 
278  friend class odb::access;
279 };
280 
281 #pragma db object
282 class DBIntermediate {
283 public:
284  DBIntermediate(std::shared_ptr<DBResult> res, Maybe<double> time,
285  Maybe<unsigned int> iteration, Maybe<double> costs,
286  Maybe<double> bound, std::shared_ptr<DBSolution> solution);
287  DBIntermediate(std::shared_ptr<const DBIntermediate> src);
288 
289 #pragma db not_null
290  std::shared_ptr<DBResult> res;
291 
292  std::shared_ptr<double> time;
293  std::shared_ptr<unsigned int> iteration;
294  std::shared_ptr<double> costs;
295  std::shared_ptr<double> bound;
296 
297  std::shared_ptr<DBSolution> solution;
298 
299  unsigned long
300  get_id() const
301  {
302  return this->id_;
303  }
304 
305 #pragma db index member(res)
306 
307 private:
308  DBIntermediate() {}
309 
310 #pragma db id auto
311  unsigned long id_;
312 
313  friend class odb::access;
314 };
315 
316 #pragma db object
317 class DBError {
318 public:
319  // TODO add config
320  DBError(unsigned long timestamp, std::string run, std::string instance,
321  std::string algorithm, std::string config_name, int seed,
322  int fault_code, int error_id);
323  DBError(std::shared_ptr<const DBError> src);
324 
325  unsigned long timestamp;
326  std::string run;
327  std::string instance;
328  std::string algorithm;
329  std::string config;
330  int seed;
331  int fault_code;
332  int error_id;
333  unsigned long time;
334  std::string git_revision;
335 
336 private:
337  DBError() {}
338 
339 #pragma db id auto
340  unsigned long id_;
341 
342  friend class odb::access;
343 };
344 
345 #pragma db object
346 class DBExtendedMeasure {
347 public:
348  DBExtendedMeasure(std::shared_ptr<DBResult> res, std::string key,
349  Maybe<unsigned int> iteration, Maybe<double> time,
350  Maybe<int> v_int, Maybe<double> v_double);
351  DBExtendedMeasure(std::shared_ptr<const DBExtendedMeasure> src);
352 
353 #pragma db not_null
354  std::shared_ptr<DBResult> res;
355 
356  std::string key;
357 #pragma db null
358  std::shared_ptr<unsigned int> iteration;
359 #pragma db null
360  std::shared_ptr<double> time;
361 #pragma db null
362  std::shared_ptr<int> v_int;
363 #pragma db null
364  std::shared_ptr<double> v_double;
365 
366 #pragma db index member(res)
367 
368 private:
369  DBExtendedMeasure() {}
370 
371 #pragma db id auto
372  unsigned long id_;
373 
374  friend class odb::access;
375 };
376 
377 /*
378  * Magic view to retrieve a specific config
379  */
380 #pragma db view query("SELECT DBConfig.id from DBConfig INNER JOIN (")
381 struct ConfigGetterView
382 {
383 #pragma db type("INTEGER")
384  unsigned long config_id;
385 };
386 
387 #pragma GCC diagnostic pop
388 
389 #endif // TCPSPSUITE_DB_OBJECTS_HPP