TkN 2.1
Toolkit for Nuclei
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 * 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 tkmanager_H
38#define tkmanager_H
39
40#include <map>
41#include <mutex>
42#include <functional>
43
44#include "tklevel_scheme.h"
45#include "tknucleus.h"
46#include "tkstring.h"
47
48#ifdef HAS_ROOT
49#include "TClass.h"
50#endif
51
52namespace tkn {
53
55{
56 friend class tknucleus;
57
58 static std::recursive_mutex& get_mutex() {
59 static std::recursive_mutex mutex;
60 return mutex;
61 }
62
63protected:
64 std::map<tkstring, shared_ptr<tklevel_scheme>> fmap_of_level_scheme;
65
66 std::vector<shared_ptr<tknucleus>> fvector_of_nuclei;
67
68 std::map<tkstring, shared_ptr<tknucleus>> fmap_of_nuclei;
69 std::map<int, std::map<int, shared_ptr<tknucleus>>> fmap_of_nuclei_per_z_and_a;
70 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_z;
71 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_a;
72 std::map<int, std::vector<shared_ptr<tknucleus>>> fmap_of_nuclei_per_n;
73
74 std::map<int, tkstring> fmap_of_symbols;
75
76 int fmax_level_id=0;
77 int fmax_decay_id=0;
78
79 static tkmanager* g_data_manager;
80
81public:
83 tkmanager();
84 virtual ~tkmanager();
85
87 bool is_level_scheme_loaded(const tkstring &_nuc) {return fmap_of_level_scheme.count(_nuc)!=0;}
88
90 void preload_level_schemes(bool _verbose=false);
91
93 bool known_nucleus(tkstring _nuc){return fmap_of_nuclei.count(_nuc);}
95 bool known_nucleus(int _z, int _a){return (fmap_of_nuclei_per_z_and_a.count(_z) && fmap_of_nuclei_per_z_and_a.at(_z).count(_a));}
97 bool known_element(tkstring _nuc, int &_z);
99 bool known_element(int _z) { return fmap_of_nuclei_per_z.count(_z); }
101 const tkstring &get_element_symbol(int _charge){return fmap_of_symbols[_charge];}
102
104 vector<shared_ptr<tknucleus> > get_nuclei(std::function<bool(shared_ptr<tknucleus>)>const& _selection);
105
107 const vector<shared_ptr<tknucleus>> &get_nuclei(){return fvector_of_nuclei;}
108
110 const std::map<tkstring, shared_ptr<tknucleus>> &get_map_of_nuclei(){return fmap_of_nuclei;}
112 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_z(){return fmap_of_nuclei_per_z;}
114 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_a(){return fmap_of_nuclei_per_a;}
116 const std::map<int, std::vector<shared_ptr<tknucleus>>> &get_map_of_nuclei_per_n(){return fmap_of_nuclei_per_n;}
117
119 const vector<shared_ptr<tknucleus>> &get_nuclei_for_z(int z){return fmap_of_nuclei_per_z[z];}
121 const vector<shared_ptr<tknucleus>> &get_nuclei_for_a(int a){return fmap_of_nuclei_per_a[a];}
123 const vector<shared_ptr<tknucleus>> &get_nuclei_for_n(int n){return fmap_of_nuclei_per_n[n];}
124
126 shared_ptr<tknucleus> get_nucleus(const tkstring &_nuc){ return (fmap_of_nuclei.count(_nuc)) ? fmap_of_nuclei[_nuc] : nullptr;}
128 shared_ptr<tknucleus> get_nucleus(int _z, int _a) { return (known_nucleus(_z, _a)) ? fmap_of_nuclei_per_z_and_a[_z][_a] : nullptr;}
129
131 int get_new_level_id();
133 int get_new_decay_id();
134
136 void set_max_level_id(int _id) {if(_id>fmax_level_id) fmax_level_id = _id;}
138 void set_max_decay_id(int _id) {if(_id>fmax_decay_id) fmax_decay_id = _id;}
139
140protected:
141 void preload_nuclei();
142 shared_ptr<tklevel_scheme> get_level_scheme(const tkstring &_nuc, int _zz, int _aa);
143
144#ifdef HAS_ROOT
146 ClassDef(tkmanager,0)
147#endif
148
149};
150}
151
152#define gmanager (tkn::tkmanager::the_data_manager())
153
154#endif
Manages the database loading and provides access to the physics properties.
Definition: tkmanager.h:55
void set_max_level_id(int _id)
define the max value of the attributed level ids
Definition: tkmanager.h:136
static tkmanager * the_data_manager()
Definition: tkmanager.cpp:56
int get_new_level_id()
define a new unique level id
Definition: tkmanager.cpp:386
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:114
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:121
const std::map< tkstring, shared_ptr< tknucleus > > & get_map_of_nuclei()
return a map of nuclei sorted by name
Definition: tkmanager.h:110
shared_ptr< tknucleus > get_nucleus(const tkstring &_nuc)
return a shared pointer to a nucleus from its name
Definition: tkmanager.h:126
bool known_nucleus(int _z, int _a)
is the nucleus Z and A known
Definition: tkmanager.h:95
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:123
const vector< shared_ptr< tknucleus > > & get_nuclei()
return a vector containing all the known nuclei
Definition: tkmanager.h:107
int get_new_decay_id()
define a new unique decay id
Definition: tkmanager.cpp:393
shared_ptr< tknucleus > get_nucleus(int _z, int _a)
return a shared pointer to a nucleus from its z an a
Definition: tkmanager.h:128
virtual ~tkmanager()
Definition: tkmanager.cpp:77
bool known_nucleus(tkstring _nuc)
is the nucleus symbol known (ex: "12C")
Definition: tkmanager.h:93
const tkstring & get_element_symbol(int _charge)
returns the element symbol for a given proton number
Definition: tkmanager.h:101
void set_max_decay_id(int _id)
define the max value of the attributed level ids
Definition: tkmanager.h:138
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:112
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:116
bool known_element(int _z)
is the element Z is known
Definition: tkmanager.h:99
bool known_element(tkstring _nuc, int &_z)
is the element symbol is known (ex: "C")
Definition: tkmanager.cpp:375
void preload_level_schemes(bool _verbose=false)
preload all the level schemes from the database
Definition: tkmanager.cpp:342
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:119
bool is_level_scheme_loaded(const tkstring &_nuc)
returns true if the level scheme has already been loaded
Definition: tkmanager.h:87
A nucleus made of Z protons and N neutrons.
Definition: tknucleus.h:54
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition: tkstring.h:54
Definition: tklog.cpp:39