TkN 2.4
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 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#ifndef tkisotope_builder_H
15#define tkisotope_builder_H
16
17#include <algorithm>
18#include <iterator>
19#include <vector>
20
21#include "tkn_config.h"
22#include "tkstring.h"
23#include "tkdatabase.h"
24#include "json.hpp"
25#include "tkdb_builder.h"
26
27#ifdef HAS_ROOT
28#include "TClass.h"
29#endif
30
31using json = nlohmann::json;
32using namespace std;
33
34namespace tkn {
35
37
38protected:
39
40 struct json_nucleus {
41 tkstring name="";
42 int Z,A,N;
45 tkdb_table::measure_data_struct quadrupoleDeformation;
46
48 tkdb_table::measure_data_struct electric_quadrupole;
49 tkdb_table::measure_data_struct magnetic_dipole;
50
56
62
63 vector<pair<tkstring, double>> decay_modes;
64
65 int year=0.;
66
67 void print_data(const tkstring &_name, const tkdb_table::measure_data_struct &data) {
68 if(data.value!=-1) cout<<left<<setw(33)<<_name<<": "<< setw(10) << data.value << " (" << setw(8) << data.err << ")" << setw(5) << data.unit << data.info << endl;
69 }
70
71 vector<pair<tkdb_table::measure_data_struct,tkstring>> sort_map(map<tkstring, tkdb_table::measure_data_struct> &map_in, bool inverse = false) {
72
73 vector<pair<tkdb_table::measure_data_struct,tkstring>> sorted_map;
74 sorted_map.reserve(map_in.size());
75 std::transform(map_in.begin(), map_in.end(), std::back_inserter(sorted_map),
76 [](const auto &it) { return std::make_pair(it.second, it.first); });
77 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) {
78 if(inverse) return a.first.value > b.first.value;
79 else return a.first.value <= b.first.value;
80 });
81
82 return sorted_map;
83 }
84
85 void print() {
86 if(name.is_empty() || Z==-1 || N==-1 || A==-1) {
87 glog << error << "empty nucleus" << do_endl;
88 return;
89 }
90 cout<<left<<"Nucleus: "<<setw(5)<<name<<endl;
91 cout<<"Z="<<setw(3)<<Z<<", N="<<setw(3)<<N<<", A="<<setw(3)<<A<<endl;
92 print_data("Mass Excess",mass_excess);
93 print_data("Quadrupole deformation",quadrupoleDeformation);
94 print_data("Abundance",abundance);
95 if(decay_modes.size()) {
96 cout<<left<<setw(33)<<"Decay modes"<<": ";
97 for(auto &mode: decay_modes) cout<< mode.first << " : " << tkstring::form("%g",mode.second) << " ; ";
98 cout<<endl;
99 }
100 print_data("Radius",radius);
101 print_data("Electirc quadrupole",electric_quadrupole);
102 print_data("Magnetic dipole",magnetic_dipole);
103
104 }
105 };
106
107 int fIsotopeIdx = 0;
108
109 std::map<int,tkn::tkstring> columns;
110
111public:
112 tkisotope_builder(tkdatabase *_database, const char* _table_name="ISOTOPE");
113 virtual ~tkisotope_builder() override;
114
115protected:
116 void read_measure(const tkstring &key, const json &entry, tkdb_table::measure_data_struct &_data, bool _fromstd=false);
117 json_nucleus read_nucleus(json &entry);
118 void fill_isotope(const json_nucleus &_json_nuc);
119
120public:
121 int fill_database(const char* _json_filename, const char *_gs_filename, int _only_charge=0, int _only_mass=0);
122
123#ifdef HAS_ROOT
125 ClassDefOverride(tkisotope_builder,0);
126#endif
127};
128
129}
130#endif
Interface to the sqlite database.
Definition tkdatabase.h:34
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:31
static const char * form(const char *_format,...)
Definition tkstring.cpp:408
bool is_empty() const
Definition tkstring.h:140
Definition tklog.cpp:16
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212
data structure used to fill a tkmeasure object from the sqlite database
Definition tkdb_table.h:49