TkN 2.1
Toolkit for Nuclei
tkspin_parity.cpp
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#include "tkspin_parity.h"
38
39#include <iomanip>
40#include <cmath>
41
42#include "tklog.h"
43
44namespace tkn {
65}
66
67using namespace tkn;
68using namespace std;
69
70tkspin::tkspin(int N, int D)
71{
72 set(N,D);
73}
74
82{
83 tkstring spin;
84
85 if (fD != 1)
86 spin = tkstring::Form("%d/%d", fN, fD);
87 else
88 spin = tkstring::Form("%d", fN);
89
90 if(is_info(kTentative)) {
91 spin.prepend("(");spin.append(")");
92 }
93 else if(is_info(kTheo)) {
94 spin.prepend("[");spin.append("]");
95 }
96 else if(is_info(kAbout)) {
97 spin.prepend("~");
98 }
99
100 return spin;
101}
102
103void tkspin::set(const tkstring &_st)
104{
105 tkstring st = _st;
106
107 if(st.ends_with("(-)") || st.ends_with("(+)")) st.erase(st.length()-3,3);
108
109 std::istringstream input; input.clear();
110 switch( what_is(st.data()) ){
111 case kKnown:
112 if ( st.contains("/") ) { // not an integer
113 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
114 }
115 else { input.str(st); input >> fN; fD = 1; }
116 if ( input.fail() )
118 else
120 break;
121 case kUnknown:
123 break;
124 case kAbout:
125 st.replace_all("~"," ");
126 if ( st.contains("/") ) { // not an integer
127 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
128 }
129 else { input.str(st); input >> fN; fD = 1; }
130 if ( input.fail() )
132 else
134 break;
135 case kTentative:
136 st.replace_all("("," ");
137 st.replace_all(")"," ");
138 if ( st.contains("/") ) { // not an integer
139 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
140 }
141 else { input.str(st); input >> fN; fD = 1; }
142 if ( input.fail() )
144 else
146 break;
147 case kTheo:
148 st.replace_all("["," ");
149 st.replace_all("]"," ");
150 if ( st.contains("/") ) { // not an integer
151 st.replace_all("/"," "); input.str(st); input >> fN >> fD;
152 }
153 else { input.str(st); input >> fN; fD = 1; }
154 if ( input.fail() )
156 else
158 break;
159 default:
161 break;
162 }
163}
164
169void tkspin::set(int _n, int _d)
170{
171 fN = _n; fD = _d;
173 if ( fD < 1 || fD > 2 ) {
174 glog << warning << "A spin should be an integer or half an integer !\n";
175 glog << tkstring::form("\t [%d/%d] --> [%d/1]",fN,fD,fN) << do_endl;
176 fD = 1;
178 }
179}
180
184void tkspin::set(double _spin)
185{
186 int _2spin = lround(2*_spin);
187 if(_2spin%2==0) {
188 fN = _2spin/2;
189 fD = 1;
190 }
191 else {
192 fN = _2spin;
193 fD = 2;
194 }
196 if ( fD < 1 || fD > 2 ) {
197 glog << warning << "A spin should be an integer or half an integer !\n";
198 glog << tkstring::form("\t [%d/%d] --> [%d/1]",fN,fD,fN) << do_endl;
199 fD = 1;
201 }
202}
203
205{
206 if(!is_info(kUnknown)) {
207 glog << info_o << "spin: " << get_string() << " type: " << get_info_str() << do_endl;
208 }
209 else {
210 glog << warning_o << "spin is unknown" << do_endl;
211 }
212}
213
214#ifdef HAS_ROOT
216ClassImp(tkspin);
217#endif
218
219void tkparity::set(const tkstring &_st)
220{
222 fParity = kParityUnknown;
223
224 if(_st.contains("+")) {
225 fParity = kParityPlus;
226 if(_st.ends_with("+")) set_info(kKnown);
227 if(_st.ends_with(")")) set_info(kTentative);
228 else if(_st.ends_with("]")) set_info(kTheo);
229 }
230 if(_st.contains("-")) {
231 fParity = kParityMinus;
232 if(_st.ends_with("-")) set_info(kKnown);
233 if(_st.ends_with(")")) set_info(kTentative);
234 else if(_st.ends_with("]")) set_info(kTheo);
235 }
236}
237
241void tkparity::set(int _parity)
242{
243 if(_parity==0) {
244 fParity = kParityPlus;
246 }
247 else if(_parity==1) {
248 fParity = kParityMinus;
250 }
251 else {
253 fParity = kParityUnknown;
254 }
255}
256
258{
259 tkstring parity;
260
261 if(is_info(kUnknown)) return ("");
262
263 if (fParity == kParityPlus) parity = "+";
264 else parity = "-";
265
266 if(is_info(kTentative)) {
267 parity.prepend("(");parity.append(")");
268 }
269 else if(is_info(kTheo)) {
270 parity.prepend("[");parity.append("]");
271 }
272 else if(is_info(kAbout)) {
273 parity.prepend("~");
274 }
275
276 return parity;
277}
278
280{
281 if(!is_info(kUnknown)) {
282 glog << info_o << "parity: " << get_string() << " type: " << get_info_str() << do_endl;
283 }
284 else {
285 glog << warning_o << "parity is unknown: " << do_endl;
286 }
287}
288
289#ifdef HAS_ROOT
291ClassImp(tkparity);
292#endif
293
295
297{
298 fJpi_str = tkstring::form("%s",_st.data());
300 fJpi_str.replace_all("GE",">=");
301 fJpi_str.replace_all("LE","<=");
302 fJpi_str.replace_all("GT",">");
303 fJpi_str.replace_all("LT","<");
304}
305
306void tkspin_parity::set_spin(double _spin)
307{
308 fSpin.set(_spin);
309}
310
312{
313 fParity.set(_parity);
314}
315
317{
318 return fJpi_str;
319}
320
322{
323 if(!is_known()) glog << warning_o << "Unknown Jpi: " << fJpi_str << do_endl;
324 else glog << info_o << "Jpi: " << setw(10) << fJpi_str << do_endl;
325}
326
327#ifdef HAS_ROOT
329ClassImp(tkspin_parity)
330#endif
Nuclear excited state parity.
Definition: tkspin_parity.h:85
void print()
print the spin properties
tkstring get_string()
returns the parity as a string
virtual void set(const tkstring &_st)
define the parity from a string
void set_info(tkproperty::data_info _info)
to set some information about this data
Definition: tkproperty.h:78
tkstring get_info_str(bool _showknown=true) const
to print in string the data_info
Definition: tkproperty.cpp:93
static data_info what_is(const tkstring &_st)
It deduces from a string the kind of data.
Definition: tkproperty.cpp:67
bool is_info(data_info _info) const
to get some information about this data
Definition: tkproperty.h:88
Nuclear excited state spin-parity.
void set_from_str(const tkstring &_st)
define the spin parity from a string
void print()
print the spin and parity properties
void set_parity(int _parity)
define the parity from an integer
void set_spin(double _spin)
define the spin from a float
virtual bool is_known()
test if the spin and parity are known
const tkstring & get_jpi_str() const
returns the spin and parity string
Nuclear excited state spin.
Definition: tkspin_parity.h:49
virtual void print()
print the spin properties
tkstring get_string()
returns the spin as a string
void set(int n, int d=1)
define the spin value
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
static tkstring Form(const char *_format,...)
Definition: tkstring.cpp:345
bool ends_with(const char *_s, ECaseCompare _cmp=kExact) const
Definition: tkstring.cpp:241
tkstring & remove_all_extra_white_space()
Definition: tkstring.cpp:526
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition: tkstring.h:197
tkstring & prepend(const tkstring &_st)
Definition: tkstring.h:224
tkstring & append(const tkstring &_st)
Definition: tkstring.h:227
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition: tkstring.h:203
Definition: tklog.cpp:39
tklog & warning_o(tklog &log)
Definition: tklog.h:348
tklog & info_o(tklog &log)
Definition: tklog.h:331
tklog & do_endl(tklog &log)
Definition: tklog.h:235
tklog & warning(tklog &log)
Definition: tklog.h:354