TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
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 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tkdb_builder.h"
15
16#include <unistd.h>
17
18namespace tkn {
25}
26
27using namespace tkn;
28using namespace std;
29
30tkdb_builder::tkdb_builder(tkdatabase *_database, const char *_table_name):
31 fDataBase(_database),
32 fTableName(_table_name)
33{
34}
35
37
38void tkdb_builder::add_measure(const tkstring &_measure_name, bool _with_dbname)
39{
40 tkstring db_name = fTableName.copy().to_lower() + "_";
41 if(!_with_dbname) db_name = "";
42
43 fTable->add_column(tkstring::form("%s%s",db_name.data(),_measure_name.data()),"REAL");
44 fTable->add_column(tkstring::form("%s%s_unit",db_name.data(), _measure_name.data()),"TEXT");
45 fTable->add_column(tkstring::form("%s%s_unc",db_name.data(),_measure_name.data()),"REAL");
46 fTable->add_column(tkstring::form("%s%s_unc_low",db_name.data(),_measure_name.data()),"REAL");
47 fTable->add_column(tkstring::form("%s%s_unc_high",db_name.data(),_measure_name.data()),"REAL");
48 fTable->add_column(tkstring::form("%s%s_info",db_name.data(),_measure_name.data()),"TEXT");
49}
50
51void tkdb_builder::fill_measure(tkstring _measure_name, const tkdb_table::measure_data_struct &_mes, bool _with_dbname)
52{
53 if(!_mes.filled) return;
54
55 tkstring db_name = fTableName.copy().to_lower() + "_";
56 if(!_with_dbname) db_name = "";
57 (*fTable)[tkstring::form("%s%s",db_name.data(),_measure_name.data())].set_value(_mes.value);
58 (*fTable)[tkstring::form("%s%s_unit",db_name.data(),_measure_name.data())].set_value(_mes.unit);
59 if(_mes.value==0.) (*fTable)[tkstring::form("%s%s_unc",db_name.data(),_measure_name.data())].set_value(0.);
60 if(_mes.err>0.) (*fTable)[tkstring::form("%s%s_unc",db_name.data(),_measure_name.data())].set_value(_mes.err);
61 if(_mes.err_low>0.) (*fTable)[tkstring::form("%s%s_unc_low",db_name.data(),_measure_name.data())].set_value(_mes.err_low);
62 if(_mes.err_high>0.) (*fTable)[tkstring::form("%s%s_unc_high",db_name.data(),_measure_name.data())].set_value(_mes.err_high);
63 if(!_mes.info.is_empty()) (*fTable)[tkstring::form("%s%s_info",db_name.data(),_measure_name.data())].set_value(_mes.info);
64}
65
66#ifdef HAS_ROOT
67ClassImp(tkdb_builder);
68#endif
Interface to the sqlite database.
Definition tkdatabase.h:34
Mother class used to fill the sqlite database.
virtual ~tkdb_builder()
tkdb_builder(tkdatabase *_database, const char *_table_name)
void add_column(const char *_colname, const char *_coltype)
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
tkstring copy() const
Returns a copy of this string.
Definition tkstring.cpp:347
tkstring & to_lower()
Change all letters to lower case.
Definition tkstring.cpp:36
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
bool is_empty() const
Definition tkstring.h:140
Definition tklog.cpp:16
data structure used to fill a tkmeasure object from the sqlite database
Definition tkdb_table.h:49