TkN 2.1
Toolkit for Nuclei
tkisotope_builder.h
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#ifndef tkisotope_builder_H
38#define tkisotope_builder_H
39
40#include <vector>
41
42#include "tkn_config.h"
43#include "tkstring.h"
44#include "tkdatabase.h"
45#include "json.hpp"
46#include "tkdb_builder.h"
47
48#ifdef HAS_ROOT
49#include "TClass.h"
50#endif
51
52using json = nlohmann::json;
53using namespace std;
54
55namespace tkn {
56
58
59protected:
60
61 struct json_nucleus {
62 tkstring name="";
63 int Z,A,N;
66 tkdb_table::measure_data_struct quadrupoleDeformation;
67
69 tkdb_table::measure_data_struct electric_quadrupole;
70 tkdb_table::measure_data_struct magnetic_dipole;
71
77
83
84 vector<pair<tkstring, double>> decay_modes;
85
86 int year=0.;
87
88 void print_data(const tkstring &_name, const tkdb_table::measure_data_struct &data) {
89 if(data.value!=-1) cout<<left<<setw(33)<<_name<<": "<< setw(10) << data.value << " (" << setw(8) << data.err << ")" << setw(5) << data.unit << data.info << endl;
90 }
91
92 vector<pair<tkdb_table::measure_data_struct,tkstring>> sort_map(map<tkstring, tkdb_table::measure_data_struct> &map_in, bool inverse = false) {
93
94 vector<pair<tkdb_table::measure_data_struct,tkstring>> sorted_map;
95 for (auto &it: map_in) {
96 sorted_map.push_back({ it.second, it.first });
97 }
98 std::sort(std::begin(sorted_map), std::end(sorted_map), [inverse](pair<tkdb_table::measure_data_struct,tkstring> a, pair<tkdb_table::measure_data_struct,tkstring> b) {
99 if(inverse) return a.first.value > b.first.value;
100 else return a.first.value <= b.first.value;
101 });
102
103 return sorted_map;
104 }
105
106 void print() {
107 if(name.is_empty() || Z==-1 || N==-1 || A==-1) {
108 glog << error << "empty nucleus" << do_endl;
109 return;
110 }
111 cout<<left<<"Nucleus: "<<setw(5)<<name<<endl;
112 cout<<"Z="<<setw(3)<<Z<<", N="<<setw(3)<<N<<", A="<<setw(3)<<A<<endl;
113 print_data("Mass Excess",mass_excess);
114 print_data("Quadrupole deformation",quadrupoleDeformation);
115 print_data("Abundance",abundance);
116 if(decay_modes.size()) {
117 cout<<left<<setw(33)<<"Decay modes"<<": ";
118 for(auto &mode: decay_modes) cout<< mode.first << " : " << tkstring::form("%g",mode.second) << " ; ";
119 cout<<endl;
120 }
121 print_data("Radius",radius);
122 print_data("Electirc quadrupole",electric_quadrupole);
123 print_data("Magnetic dipole",magnetic_dipole);
124
125 }
126 };
127
128 int fIsotopeIdx = 0;
129
130 std::map<int,tkn::tkstring> columns;
131
132public:
133 tkisotope_builder(tkdatabase *_database, const char* _table_name="ISOTOPE");
135
136protected:
137 void read_measure(const tkstring &key, const json &entry, tkdb_table::measure_data_struct &_data, bool _fromstd=false);
138 json_nucleus read_nucleus(json &entry);
139 void fill_isotope(const json_nucleus &_json_nuc);
140
141public:
142 int fill_database(const char* _json_filename, const char *_gs_filename, int _only_charge=0, int _only_mass=0);
143
144#ifdef HAS_ROOT
146 ClassDef(tkisotope_builder,0);
147#endif
148};
149
150}
151#endif
152
153
Interface to the sqlite database.
Definition: tkdatabase.h:57
Mother class used to fill the sqlite database.
Definition: tkdb_builder.h:50
Decoding of the NUDAT isotope properties.
int fill_database(const char *_json_filename, const char *_gs_filename, int _only_charge=0, int _only_mass=0)
virtual ~tkisotope_builder()
tkisotope_builder(tkdatabase *_database, const char *_table_name="ISOTOPE")
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition: tkstring.h:54
static const char * form(const char *_format,...)
Definition: tkstring.cpp:431
bool is_empty() const
Definition: tkstring.h:163
Definition: tklog.cpp:39
tklog & error(tklog &log)
Definition: tklog.h:367
tklog & do_endl(tklog &log)
Definition: tklog.h:235
data structure used to fill a tkmeasure object from the sqlite database
Definition: tkdb_table.h:72