TkN 2.1
Toolkit for Nuclei
tklevel_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 "tklevel_builder.h"
38
39#include <unistd.h>
40
41#include "tklog.h"
42#include "tkensdf_level_rec.h"
43
44using namespace tkn;
45using namespace std;
46
47namespace tkn {
54}
55
56tklevel_builder::~tklevel_builder() = default;
57
58tklevel_builder::tklevel_builder(tkdatabase *_database, const char *_table_name) : tkdb_builder(_database, _table_name)
59{
60 fTable = &fDataBase->new_table(fTableName);
61
62 fTable->add_column("level_id","INT NOT NULL PRIMARY KEY");
63 fTable->add_column("isotope_id","INT NOT NULL");
64 fTable->add_column("dataset_id","INT NOT NULL");
65
66 add_measure("energy");
67
68 fTable->add_column("level_spin","REAL");
69 fTable->add_column("level_parity","INT");
70 fTable->add_column("level_spin_parity","TEXT");
71
72 add_measure("lifetime");
73
74 fTable->add_column("level_comment","TEXT");
75
76 fTable->add_column("level_uncertain","TEXT");
77
78 fTable->add_constraint("FOREIGN KEY (isotope_id) REFERENCES ISOTOPE (isotope_id),"); // hold this link with a constraints
79 fTable->add_constraint("FOREIGN KEY (dataset_id) REFERENCES DATASET (dataset_id)"); // hold this link with a constraints
80
81 fTable->write_to_database();
82
83 glog << info << "Creating '" << _table_name << "' table" << do_endl;
84}
85
86void tklevel_builder::fill_level(int _dset_idx, int _isotope_idx, const tkensdf_level_rec &_lev_record, bool _adopted)
87{
88 fLevelIdx++;
89 (*fTable)["level_id"].set_value(fLevelIdx); // level id
90 (*fTable)["isotope_id"].set_value(_isotope_idx); // link to isotope -> to be set for each level
91 (*fTable)["dataset_id"].set_value(_dset_idx); // link to dataset -> to be set for each level
92
93 fill_measure("energy",_lev_record.get_energy());
94
95 if(!_lev_record.get_Jpi_str().is_empty()) {
96 if(_lev_record.get_J()->is_known()) (*fTable)["level_spin"].set_value(_lev_record.get_j());
97 if(_lev_record.get_Pi()->is_known()) (*fTable)["level_parity"].set_value(_lev_record.get_pi());
98 (*fTable)["level_spin_parity"].set_value(_lev_record.get_Jpi_str());
99 }
100
101 fill_measure("lifetime",_lev_record.get_lifetime());
102
103 if(!_lev_record.get_comment_record().is_empty()) (*fTable)["level_comment"].set_value(_lev_record.get_comment_record());
104
105 if(_lev_record.is_uncertain()) (*fTable)["level_uncertain"].set_value(_lev_record.get_uncertain_record().data());
106
107 // // fill the isotope ground state lifetime and spin
108 if(_lev_record.get_energy().value==0. && _adopted && !_lev_record.get_energy().info.contains("OFF")) {
109 tkdb_table& isotope = (*gdatabase)["ISOTOPE"];
110
111 if(!_lev_record.get_Jpi_str().is_empty()) {
112 isotope["spin"].set_value(_lev_record.get_j());
113 isotope["parity"].set_value(_lev_record.get_pi());
114 isotope["spin_parity"].set_value(_lev_record.get_Jpi_str());
115 }
116
117 if(_lev_record.get_lifetime().filled) {
118 isotope["lifetime"].set_value(_lev_record.get_lifetime().value);
119 isotope["lifetime_unit"].set_value(_lev_record.get_lifetime().unit);
120 if(_lev_record.get_lifetime().value==0.) isotope["lifetime_unc"].set_value(0.);
121 if(_lev_record.get_lifetime().err>0.) isotope["lifetime_unc"].set_value(_lev_record.get_lifetime().err);
122 if(_lev_record.get_lifetime().err_low>0.) isotope["lifetime_unc_low"].set_value(_lev_record.get_lifetime().err_low);
123 if(_lev_record.get_lifetime().err_high>0.) isotope["lifetime_unc_high"].set_value(_lev_record.get_lifetime().err_high);
124 if(!_lev_record.get_lifetime().info.is_empty()) isotope["lifetime_info"].set_value(_lev_record.get_lifetime().info);
125 }
126
127 isotope.update_row(tkstring::form("isotope_id=%d",_isotope_idx));
128 }
129
130 fTable->push_row();
131}
132
133#ifdef HAS_ROOT
134ClassImp(tklevel_builder);
135#endif
Interface to the sqlite database.
Definition: tkdatabase.h:57
Mother class used to fill the sqlite database.
Definition: tkdb_builder.h:50
Representaiton of a sqlite data table.
Definition: tkdb_table.h:52
void update_row(const tkstring &_where)
Definition: tkdb_table.cpp:242
Decodding of the ENSDF level properties.
const bool & get_pi() const
const tkstring & get_Jpi_str() const
const tkparity * get_Pi() const
const double & get_j() const
const tkspin * get_J() const
bool is_uncertain() const
check if the record is uncertain
const tkstring & get_uncertain_record() const
get the record uncertain type
virtual const tkstring & get_comment_record() const
get the continuation record
const tkdb_table::measure_data_struct & get_energy() const
const tkdb_table::measure_data_struct & get_lifetime() const
Filling of the ENSDF level properties.
void fill_level(int _dset_idx, int _isotope_idx, const tkensdf_level_rec &_lev_record, bool _adopted)
bool is_known() const
to get some information about this data
Definition: tkproperty.h:91
static const char * form(const char *_format,...)
Definition: tkstring.cpp:431
bool is_empty() const
Definition: tkstring.h:163
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition: tkstring.h:197
Definition: tklog.cpp:39
tklog & info(tklog &log)
Definition: tklog.h:336
tklog & do_endl(tklog &log)
Definition: tklog.h:235