TkN 2.1
Toolkit for Nuclei
tkdb_builder.cpp
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * This software is governed by the CeCILL-B license under French law and *
11 * abiding by the rules of distribution of free software. You can use, *
12 * modify and/ or redistribute the software under the terms of the *
13 * CeCILL-B license as circulated by CEA, CNRS and INRIA at the following *
14 * URL \"http://www.cecill.info\". *
15 * *
16 * As a counterpart to the access to the source code and rights to copy, *
17 * modify and redistribute granted by the license, users are provided *
18 * only with a limited warranty and the software's author, the holder of *
19 * the economic rights, and the successive licensors have only limited *
20 * liability. *
21 * *
22 * In this respect, the user's attention is drawn to the risks associated *
23 * with loading, using, modifying and/or developing or reproducing the *
24 * software by the user in light of its specific status of free software, *
25 * that may mean that it is complicated to manipulate, and that also *
26 * therefore means that it is reserved for developers and experienced *
27 * professionals having in-depth computer knowledge. Users are therefore *
28 * encouraged to load and test the software's suitability as regards *
29 * their requirements in conditions enabling the security of their *
30 * systems and/or data to be ensured and, more generally, to use and *
31 * operate it in the same conditions as regards security. *
32 * *
33 * The fact that you are presently reading this means that you have had *
34 * knowledge of the CeCILL-B license and that you accept its terms. *
35 ********************************************************************************/
36
37#include "tkdb_builder.h"
38
39#include <unistd.h>
40
41namespace tkn {
48}
49
50using namespace tkn;
51using namespace std;
52
53tkdb_builder::tkdb_builder(tkdatabase *_database, const char *_table_name):
54 fDataBase(_database),
55 fTableName(_table_name)
56{
57}
58
60
61void tkdb_builder::add_measure(const tkstring &_measure_name, bool _with_dbname)
62{
63 tkstring db_name = fTableName.copy().to_lower() + "_";
64 if(!_with_dbname) db_name = "";
65
66 fTable->add_column(tkstring::form("%s%s",db_name.data(),_measure_name.data()),"REAL");
67 fTable->add_column(tkstring::form("%s%s_unit",db_name.data(), _measure_name.data()),"TEXT");
68 fTable->add_column(tkstring::form("%s%s_unc",db_name.data(),_measure_name.data()),"REAL");
69 fTable->add_column(tkstring::form("%s%s_unc_low",db_name.data(),_measure_name.data()),"REAL");
70 fTable->add_column(tkstring::form("%s%s_unc_high",db_name.data(),_measure_name.data()),"REAL");
71 fTable->add_column(tkstring::form("%s%s_info",db_name.data(),_measure_name.data()),"TEXT");
72}
73
74void tkdb_builder::fill_measure(tkstring _measure_name, const tkdb_table::measure_data_struct &_mes, bool _with_dbname)
75{
76 if(!_mes.filled) return;
77
78 tkstring db_name = fTableName.copy().to_lower() + "_";
79 if(!_with_dbname) db_name = "";
80 (*fTable)[tkstring::form("%s%s",db_name.data(),_measure_name.data())].set_value(_mes.value);
81 (*fTable)[tkstring::form("%s%s_unit",db_name.data(),_measure_name.data())].set_value(_mes.unit);
82 if(_mes.value==0.) (*fTable)[tkstring::form("%s%s_unc",db_name.data(),_measure_name.data())].set_value(0.);
83 if(_mes.err>0.) (*fTable)[tkstring::form("%s%s_unc",db_name.data(),_measure_name.data())].set_value(_mes.err);
84 if(_mes.err_low>0.) (*fTable)[tkstring::form("%s%s_unc_low",db_name.data(),_measure_name.data())].set_value(_mes.err_low);
85 if(_mes.err_high>0.) (*fTable)[tkstring::form("%s%s_unc_high",db_name.data(),_measure_name.data())].set_value(_mes.err_high);
86 if(!_mes.info.is_empty()) (*fTable)[tkstring::form("%s%s_info",db_name.data(),_measure_name.data())].set_value(_mes.info);
87}
88
89#ifdef HAS_ROOT
90ClassImp(tkdb_builder);
91#endif
Interface to the sqlite database.
Definition: tkdatabase.h:57
Mother class used to fill the sqlite database.
Definition: tkdb_builder.h:50
virtual ~tkdb_builder()
void add_column(const char *_colname, const char *_coltype)
Definition: tkdb_table.cpp:195
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition: tkstring.h:54
tkstring copy() const
Returns a copy of this string.
Definition: tkstring.cpp:370
tkstring & to_lower()
Change all letters to lower case.
Definition: tkstring.cpp:59
static const char * form(const char *_format,...)
Definition: tkstring.cpp:431
bool is_empty() const
Definition: tkstring.h:163
Definition: tklog.cpp:39
data structure used to fill a tkmeasure object from the sqlite database
Definition: tkdb_table.h:72