TkN 2.7
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkmanager.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 tkmanager_H
15#define tkmanager_H
16
17#include <map>
18#include <mutex>
19#include <functional>
20#include <unordered_map>
21#include <utility>
22
23#include "tklevel_scheme.h"
24#include "tknucleus.h"
25#include "tkstring.h"
26
27#ifdef HAS_ROOT
28#include "TClass.h"
29#endif
30
31namespace tkn {
32
33
41 int Z {0};
42 int N {0};
43 double value_mev {std::numeric_limits<double>::quiet_NaN()};
44 double sigma_mev {std::numeric_limits<double>::quiet_NaN()};
45 std::string type;
46
47 void print() {cout << "(Z,N) = " << Z << ", " << N << " : " << type << " = " << value_mev << " MeV, sigma = " << sigma_mev << endl;}
48};
49
51{
52 friend class tknucleus;
53
54 static std::recursive_mutex& get_mutex() {
55 static std::recursive_mutex mutex;
56 return mutex;
57 }
58
59protected:
60 std::map<tkstring, shared_ptr<tklevel_scheme>> fmap_of_level_scheme;
61 std::map<tkstring, shared_ptr<std::once_flag>> fmap_of_level_scheme_once;
62 std::mutex flevel_scheme_load_mutex;
63
64 std::vector<shared_ptr<tknucleus>> fvector_of_nuclei;
65
66 std::map<tkstring, shared_ptr<tknucleus>> fmap_of_nuclei;
67 std::map<int, std::map<int, shared_ptr<tknucleus>>> fmap_of_nuclei_per_z_and_a;
68 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_z;
69 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_a;
70 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_n;
71
72 std::map<int, tkstring> fmap_of_symbols;
73
74 int fmax_level_id=0;
75 int fmax_decay_id=0;
76
78 std::unordered_map<std::string, std::vector<tkn_drip_point>> fdrip_lines;
79
80public:
82 tkmanager();
83 virtual ~tkmanager();
84
86 bool is_level_scheme_loaded(const tkstring &_nuc);
87
89 void preload_level_schemes(bool _verbose=false);
90
92 bool known_nucleus(tkstring _nuc){return fmap_of_nuclei.find(_nuc) != fmap_of_nuclei.end();}
94 bool known_nucleus(int _z, int _a) {
95 const auto isotopes = fmap_of_nuclei_per_z_and_a.find(_z);
96 return isotopes != fmap_of_nuclei_per_z_and_a.end() &&
97 isotopes->second.find(_a) != isotopes->second.end();
98 }
99
100 bool known_element(tkstring _nuc, int &_z);
102 bool known_element(int _z) { return fmap_of_nuclei_per_z.count(_z); }
104 const tkstring &get_element_symbol(int _charge){return fmap_of_symbols[_charge];}
105
107 vector<shared_ptr<tknucleus> > get_nuclei(std::function<bool(shared_ptr<tknucleus>)>const& _selection);
108
110 const vector<shared_ptr<tknucleus>> &get_nuclei(){return fvector_of_nuclei;}
111
113 const std::map<tkstring, shared_ptr<tknucleus>> &get_map_of_nuclei(){return fmap_of_nuclei;}
115 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_z(){return fmap_of_nuclei_per_z;}
117 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_a(){return fmap_of_nuclei_per_a;}
119 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_n(){return fmap_of_nuclei_per_n;}
120
122 const vector<shared_ptr<tknucleus>> &get_nuclei_for_z(int z){return fmap_of_nuclei_per_z[z];}
124 const vector<shared_ptr<tknucleus>> &get_nuclei_for_a(int a){return fmap_of_nuclei_per_a[a];}
126 const vector<shared_ptr<tknucleus>> &get_nuclei_for_n(int n){return fmap_of_nuclei_per_n[n];}
127
129 shared_ptr<tknucleus> get_nucleus(const tkstring &_nuc) {
130 const auto nucleus = fmap_of_nuclei.find(_nuc);
131 return nucleus == fmap_of_nuclei.end() ? nullptr : nucleus->second;
132 }
133
134 shared_ptr<tknucleus> get_nucleus(int _z, int _a) {
135 const auto isotopes = fmap_of_nuclei_per_z_and_a.find(_z);
136 if (isotopes == fmap_of_nuclei_per_z_and_a.end()) return nullptr;
137 const auto nucleus = isotopes->second.find(_a);
138 return nucleus == isotopes->second.end() ? nullptr : nucleus->second;
139 }
140
142 int get_new_level_id();
144 int get_new_decay_id();
145
147 void set_max_level_id(int _id);
149 void set_max_decay_id(int _id);
150
152 std::vector<tkn_drip_point> get_drip_line(const std::string& _type, bool reduce_per_Z=true);
153
154protected:
155 void preload_nuclei();
156 shared_ptr<tklevel_scheme> get_level_scheme(const tkstring &_nuc, int _zz, int _aa);
157
159 void load_drip_lines(const tkstring& json_path);
160
161#ifdef HAS_ROOT
163 ClassDef(tkmanager,0)
164#endif
165
166};
167}
168
169#define gmanager (tkn::tkmanager::the_data_manager())
170
171#endif
Manages the database loading and provides access to the physics properties.
Definition tkmanager.h:51
void set_max_level_id(int _id)
define the max value of the attributed level ids
friend class tknucleus
Definition tkmanager.h:52
static tkmanager * the_data_manager()
Definition tkmanager.cpp:39
int get_new_level_id()
define a new unique level id
const std::map< int, std::vector< shared_ptr< tknucleus > > > & get_map_of_nuclei_per_a()
return a map of nuclei vector sorted by a
Definition tkmanager.h:117
const vector< shared_ptr< tknucleus > > & get_nuclei_for_a(int a)
return a vector containing all the known nuclei for a given a
Definition tkmanager.h:124
std::vector< tkn_drip_point > get_drip_line(const std::string &_type, bool reduce_per_Z=true)
Get the drip line for a given type (optionally reduced per Z)
const std::map< tkstring, shared_ptr< tknucleus > > & get_map_of_nuclei()
return a map of nuclei sorted by name
Definition tkmanager.h:113
shared_ptr< tknucleus > get_nucleus(const tkstring &_nuc)
return a shared pointer to a nucleus from its name
Definition tkmanager.h:129
bool known_nucleus(int _z, int _a)
is the nucleus Z and A known
Definition tkmanager.h:94
const vector< shared_ptr< tknucleus > > & get_nuclei_for_n(int n)
return a vector containing all the known nuclei for a given n
Definition tkmanager.h:126
const vector< shared_ptr< tknucleus > > & get_nuclei()
return a vector containing all the known nuclei
Definition tkmanager.h:110
int get_new_decay_id()
define a new unique decay id
shared_ptr< tknucleus > get_nucleus(int _z, int _a)
return a shared pointer to a nucleus from its z an a
Definition tkmanager.h:134
virtual ~tkmanager()
bool known_nucleus(tkstring _nuc)
is the nucleus symbol known (ex: "12C")
Definition tkmanager.h:92
const tkstring & get_element_symbol(int _charge)
returns the element symbol for a given proton number
Definition tkmanager.h:104
void set_max_decay_id(int _id)
define the max value of the attributed level ids
const std::map< int, std::vector< shared_ptr< tknucleus > > > & get_map_of_nuclei_per_z()
return a map of nuclei vector sorted by z
Definition tkmanager.h:115
const std::map< int, std::vector< shared_ptr< tknucleus > > > & get_map_of_nuclei_per_n()
return a map of nuclei vector sorted by n
Definition tkmanager.h:119
bool known_element(int _z)
is the element Z is known
Definition tkmanager.h:102
bool known_element(tkstring _nuc, int &_z)
is the element symbol is known (ex: "C")
void preload_level_schemes(bool _verbose=false)
preload all the level schemes from the database
const vector< shared_ptr< tknucleus > > & get_nuclei_for_z(int z)
return a vector containing all the known nuclei for a given z
Definition tkmanager.h:122
bool is_level_scheme_loaded(const tkstring &_nuc)
returns true if the level scheme has already been loaded
Definition tkmanager.cpp:55
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
Definition tklog.cpp:16
A single drip-line data point.
Definition tkmanager.h:40
int Z
Proton number.
Definition tkmanager.h:41
double value_mev
Quantity value (MeV)
Definition tkmanager.h:43
std::string type
Quantity type: "S1n", "S2n", "S1p", or "S2p".
Definition tkmanager.h:45
int N
Neutron number.
Definition tkmanager.h:42
double sigma_mev
Quantity uncertainty (MeV)
Definition tkmanager.h:44