TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
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 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tklevel_builder.h"
15
16#include <unistd.h>
17
18#include "tklog.h"
19#include "tkensdf_level_rec.h"
20
21using namespace tkn;
22using namespace std;
23
24namespace tkn {
31}
32
34
35tklevel_builder::tklevel_builder(tkdatabase *_database, const char *_table_name) : tkdb_builder(_database, _table_name)
36{
37 fTable = &fDataBase->new_table(fTableName);
38
39 fTable->add_column("level_id", "INT NOT NULL PRIMARY KEY");
40 fTable->add_column("isotope_id", "INT NOT NULL");
41 fTable->add_column("dataset_id", "INT NOT NULL");
42
43 add_measure("energy");
44
45 fTable->add_column("level_spin", "REAL");
46 fTable->add_column("level_parity", "INT");
47 fTable->add_column("level_spin_parity", "TEXT");
48
49 add_measure("lifetime");
50
51 fTable->add_column("level_comment", "TEXT");
52
53 fTable->add_column("level_uncertain", "TEXT");
54
55 fTable->add_constraint("FOREIGN KEY (isotope_id) REFERENCES ISOTOPE (isotope_id),"); // hold this link with a constraints
56 fTable->add_constraint("FOREIGN KEY (dataset_id) REFERENCES DATASET (dataset_id)"); // hold this link with a constraints
57
58 fTable->write_to_database();
59
60 glog << info << "Creating '" << _table_name << "' table" << do_endl;
61}
62
63void tklevel_builder::fill_level(int _dset_idx, int _isotope_idx, const tkensdf_level_rec &_lev_record, bool _adopted)
64{
65 fLevelIdx++;
66 (*fTable)["level_id"].set_value(fLevelIdx); // level id
67 (*fTable)["isotope_id"].set_value(_isotope_idx); // link to isotope -> to be set for each level
68 (*fTable)["dataset_id"].set_value(_dset_idx); // link to dataset -> to be set for each level
69
70 fill_measure("energy", _lev_record.get_energy());
71
72 if (!_lev_record.get_Jpi_str().is_empty()) {
73 if (_lev_record.get_J()->is_known()) (*fTable)["level_spin"].set_value(_lev_record.get_j());
74 if (_lev_record.get_Pi()->is_known()) (*fTable)["level_parity"].set_value(_lev_record.get_pi());
75 (*fTable)["level_spin_parity"].set_value(_lev_record.get_Jpi_str());
76 }
77
78 fill_measure("lifetime", _lev_record.get_lifetime());
79
80 if (!_lev_record.get_comment_record().is_empty()) (*fTable)["level_comment"].set_value(_lev_record.get_comment_record());
81
82 if (_lev_record.is_uncertain()) (*fTable)["level_uncertain"].set_value(_lev_record.get_uncertain_record().data());
83
84 // // fill the isotope ground state lifetime and spin
85 if (_lev_record.get_energy().value == 0. && _adopted && !_lev_record.get_energy().info.contains("OFF")) {
86 tkdb_table &isotope = (*fDataBase)["ISOTOPE"];
87
88 if (!_lev_record.get_Jpi_str().is_empty()) {
89 isotope["spin"].set_value(_lev_record.get_j());
90 isotope["parity"].set_value(_lev_record.get_pi());
91 isotope["spin_parity"].set_value(_lev_record.get_Jpi_str());
92 }
93
94 if (_lev_record.get_lifetime().filled) {
95 isotope["lifetime"].set_value(_lev_record.get_lifetime().value);
96 isotope["lifetime_unit"].set_value(_lev_record.get_lifetime().unit);
97 if (_lev_record.get_lifetime().value == 0.) isotope["lifetime_unc"].set_value(0.);
98 if (_lev_record.get_lifetime().err > 0.) isotope["lifetime_unc"].set_value(_lev_record.get_lifetime().err);
99 if (_lev_record.get_lifetime().err_low > 0.) isotope["lifetime_unc_low"].set_value(_lev_record.get_lifetime().err_low);
100 if (_lev_record.get_lifetime().err_high > 0.) isotope["lifetime_unc_high"].set_value(_lev_record.get_lifetime().err_high);
101 if (!_lev_record.get_lifetime().info.is_empty()) isotope["lifetime_info"].set_value(_lev_record.get_lifetime().info);
102 }
103
104 isotope.update_row(tkstring::form("isotope_id=%d", _isotope_idx));
105 }
106
107 fTable->push_row();
108}
109
110#ifdef HAS_ROOT
111ClassImp(tklevel_builder);
112#endif
Interface to the sqlite database.
Definition tkdatabase.h:34
tkdb_builder(tkdatabase *_database, const char *_table_name)
Representaiton of a sqlite data table.
Definition tkdb_table.h:29
void update_row(const tkstring &_where)
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)
tklevel_builder(tkdatabase *_database, const char *_table_name="LEVEL")
virtual ~tklevel_builder() override
bool is_known() const
to get some information about this data
Definition tkproperty.h:68
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
bool is_empty() const
Definition tkstring.h:140
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:174
Definition tklog.cpp:16
tklog & info(tklog &log)
Definition tklog.h:313
tklog & do_endl(tklog &log)
Definition tklog.h:212