TkN 2.3
Toolkit for Nuclei
Loading...
Searching...
No Matches
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 <algorithm>
41#include <iterator>
42#include <vector>
43
44#include "tkn_config.h"
45#include "tkstring.h"
46#include "tkdatabase.h"
47#include "json.hpp"
48#include "tkdb_builder.h"
49
50#ifdef HAS_ROOT
51#include "TClass.h"
52#endif
53
54using json = nlohmann::json;
55using namespace std;
56
57namespace tkn {
58
60
61protected:
62
63 struct json_nucleus {
64 tkstring name="";
65 int Z,A,N;
68 tkdb_table::measure_data_struct quadrupoleDeformation;
69
71 tkdb_table::measure_data_struct electric_quadrupole;
72 tkdb_table::measure_data_struct magnetic_dipole;
73
79
85
86 vector<pair<tkstring, double>> decay_modes;
87
88 int year=0.;
89
90 void print_data(const tkstring &_name, const tkdb_table::measure_data_struct &data) {
91 if(data.value!=-1) cout<<left<<setw(33)<<_name<<": "<< setw(10) << data.value << " (" << setw(8) << data.err << ")" << setw(5) << data.unit << data.info << endl;
92 }
93
94 vector<pair<tkdb_table::measure_data_struct,tkstring>> sort_map(map<tkstring, tkdb_table::measure_data_struct> &map_in, bool inverse = false) {
95
96 vector<pair<tkdb_table::measure_data_struct,tkstring>> sorted_map;
97 sorted_map.reserve(map_in.size());
98 std::transform(map_in.begin(), map_in.end(), std::back_inserter(sorted_map),
99 [](const auto &it) { return std::make_pair(it.second, it.first); });
100 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) {
101 if(inverse) return a.first.value > b.first.value;
102 else return a.first.value <= b.first.value;
103 });
104
105 return sorted_map;
106 }
107
108 void print() {
109 if(name.is_empty() || Z==-1 || N==-1 || A==-1) {
110 glog << error << "empty nucleus" << do_endl;
111 return;
112 }
113 cout<<left<<"Nucleus: "<<setw(5)<<name<<endl;
114 cout<<"Z="<<setw(3)<<Z<<", N="<<setw(3)<<N<<", A="<<setw(3)<<A<<endl;
115 print_data("Mass Excess",mass_excess);
116 print_data("Quadrupole deformation",quadrupoleDeformation);
117 print_data("Abundance",abundance);
118 if(decay_modes.size()) {
119 cout<<left<<setw(33)<<"Decay modes"<<": ";
120 for(auto &mode: decay_modes) cout<< mode.first << " : " << tkstring::form("%g",mode.second) << " ; ";
121 cout<<endl;
122 }
123 print_data("Radius",radius);
124 print_data("Electirc quadrupole",electric_quadrupole);
125 print_data("Magnetic dipole",magnetic_dipole);
126
127 }
128 };
129
130 int fIsotopeIdx = 0;
131
132 std::map<int,tkn::tkstring> columns;
133
134public:
135 tkisotope_builder(tkdatabase *_database, const char* _table_name="ISOTOPE");
136 virtual ~tkisotope_builder() override;
137
138protected:
139 void read_measure(const tkstring &key, const json &entry, tkdb_table::measure_data_struct &_data, bool _fromstd=false);
140 json_nucleus read_nucleus(json &entry);
141 void fill_isotope(const json_nucleus &_json_nuc);
142
143public:
144 int fill_database(const char* _json_filename, const char *_gs_filename, int _only_charge=0, int _only_mass=0);
145
146#ifdef HAS_ROOT
148 ClassDefOverride(tkisotope_builder,0);
149#endif
150};
151
152}
153#endif
Interface to the sqlite database.
Definition tkdatabase.h:57
tkdb_builder(tkdatabase *_database, const char *_table_name)
int fill_database(const char *_json_filename, const char *_gs_filename, int _only_charge=0, int _only_mass=0)
virtual ~tkisotope_builder() override
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