TkN 2.7
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkensdf_record.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 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tkensdf_record.h"
15#include "tklog.h"
16
17namespace tkn {
24}
25
26using namespace tkn;
27using namespace std;
28
29std::string tkensdf_record::BLANK = " ";
30
32{
33 clear();
34
35 if(_record.size() != (RSIZE-1)) { // -1 to remove the \n
36 glog << error_v << "oups, record size: "<<_record.length()<<" not equal to RSIZE: "<<RSIZE-1<< do_endl;
37 return false;
38 }
39
40 frecord = _record;
41 fid = frecord.substr(5,4);
42
44
45 return true;
46}
47
48void tkensdf_record::add_continuation_record(const tkstring &_continuation_record)
49{
50 tkstring rec = _continuation_record;
51 rec.erase(0, 9);
52 if(!fcontinuation_record.is_empty()) fcontinuation_record += "$";
53 fcontinuation_record += rec.remove_all_extra_white_space();
54}
55
56void tkensdf_record::add_comment_record(const tkstring &_record, bool _is_continuation)
57{
58 tkstring rec = _record;
59 rec.erase(0, 9);
60 if(!_is_continuation && !fcomment_record.empty()) fcomment_record += "\n";
61 fcomment_record += rec.remove_all_extra_white_space() + " ";
62}
63
66{
67 tkstring field6 = fid.substr(0,1);
68 tkstring field7 = fid.substr(1,1);
69 tkstring field9 = fid.substr(3,1);
70
71 f_is_continuation_record = false;
72
73 // gamma record
74 if(fid.match("* G ")) {
75 ftype = kgamma;
76 if(!field6.is_empty()) f_is_continuation_record = true;
77 return;
78 }
79 // Comment record
80 if( !field7.is_empty() && ( field7.equal_to("C",tkstring::ECaseCompare::kIgnoreCase) ||
83 ftype = kcomment;
84 if(!field6.is_empty()) f_is_continuation_record = true;
85 return;
86 }
87 // Level record
88 if(fid.match("* L ")) {
89 ftype = klevel;
90 if(!field6.is_empty()) f_is_continuation_record = true;
91 return;
92 }
93 // history record
94 if(fid.match("* H ")) {
95 ftype = khistory;
96 if(!field6.is_empty()) f_is_continuation_record = true;
97 return;
98 }
99 // EC record
100 if(fid.match("* E ")) {
101 ftype = kec;
102 if(!field6.is_empty()) f_is_continuation_record = true;
103 return;
104 }
105 // Beta record
106 if(fid.match("* B ")) {
107 ftype = kbeta;
108 if(!field6.is_empty()) f_is_continuation_record = true;
109 return;
110 }
111 // Termination record
112 if(frecord.is_empty()) {
113 ftype = kend;
114 return;
115 }
116 // identification record
117 if(fid.match("* ")) {
118 ftype = kident;
119 if(!field6.is_empty()) f_is_continuation_record = true;
120 return;
121 }
122 // X-ref record
123 if(fid.match(" X*") && !field9.is_empty()) {
124 ftype = kxref;
125 return;
126 }
127 // Production normalization record
128 if(fid.match("*PN*")) {
129 ftype = kprodnorm;
130 if(!field6.is_empty()) f_is_continuation_record = true;
131 return;
132 }
133 // Normalization record
134 if(fid.match(" N*")) {
135 ftype = knorm;
136 return;
137 }
138 // Q-value record
139 if(fid.match("* Q ")) {
140 ftype = kq_value;
141 if(!field6.is_empty()) f_is_continuation_record = true;
142 return;
143 }
144 // Parent record
145 if(fid.match(" P*")) {
146 ftype = kparent;
147 return;
148 }
149 // Alpha record
150 if(fid.match("* A ")) {
151 ftype = kalpha;
152 if(!field6.is_empty()) f_is_continuation_record = true;
153 return;
154 }
155 // particle record
156 if( (fid.match("* *") || fid.match("* D*")) && (field9.equal_to("N") || field9.equal_to("P") || field9.equal_to("A")) ) {
157 ftype = kparticle;
158 if(!field6.is_empty()) f_is_continuation_record = true;
159 return;
160 }
161 // reference record
162 if(fid.match(" R ")) {
163 ftype = kreference;
164 return;
165 }
166 ftype = kunknown;
167}
168
170{
171 // Check if the level includes an offset
172 size_t index=0;
173
174 tkstring tmp_e = _st.substr(0,10);
175 tkstring tmp_de = _st.substr(10,2);
176
177 tmp_e.remove_all(" ");
178 tmp_de.remove_all(" ");
179
180 // check if this is a resonance level => ignored
181 if(tmp_e.begins_with("SN+")) {
182 tmp_e.erase(0,3);
183 return false;
184 }
185 // check if this is a resonance level => ignored
186 if(tmp_e.begins_with("SP+")) {
187 tmp_e.erase(0,3);
188 return false;
189 }
190
191 // check if the level is at an undefined energy
192 if(tmp_e.substr(0,1).is_alpha()) {
193 fenergy.info += ";OFF=" + tmp_e;
194 set_offset(tmp_e.substr(0,1));
195 tmp_e.erase(0,1);
196 if(tmp_e.is_empty()) {
197 tmp_e="0";
198 }
199 else if(tmp_e.substr(0,1)=="+"){
200 tmp_e.erase(0,1);
201 }
202 }
203
204 // check if the energy is only known relatively to a level of unknwon energy
205 index = tmp_e.index("+");
206 if(index != std::string::npos && tmp_e.substr(index-1,1).to_lower() != "e") {
207 tkstring offset = tmp_e.substr(index+1);
208 fenergy.info += ";OFF=" + offset;
209 set_offset(offset);
210 tmp_e.erase(index);
211 }
212
213 // check if the energy is only temptative
214 index = tmp_e.index("(");
215 if(index != std::string::npos) {
216 tmp_e.remove_all("("); tmp_e.remove_all(")");
217 fenergy.info += ";VAL=()";
218 }
219 // check if something is remaining
220 if(tmp_e.empty()) {
221 return false;
222 }
223
224 fenergy.unit = "KEV";
225 fenergy.value = tmp_e.atof();
226
227 fenergy.filled = true;
228
229 // cases LT,GT,LE,GE,AP,CA,SY
230 if(tmp_de.is_alpha()) {
231 fenergy.info += ";ERR=" + tmp_de;
232 tmp_de="";
233 }
234
235 if(fenergy.value>0.) {
236 if(tmp_de.is_empty()) fenergy.info += ";ERR=?";
237 double precision = tkstring::get_precision(tmp_e);
238 fenergy.err = tmp_de.atof()*precision;
239 }
240
241 return true;
242}
243
244bool tkensdf_record::decode_lifetime(const tkstring &_st, const tkstring &_st_ms)
245{
246 tkstring tmp_lt = _st.substr(0,10);
247
248 if(tmp_lt.is_empty()) return false;
249
250 if(fglobal_time_unit=="skip") return false;
251
252 if(tmp_lt.contains("?")) {
253 flifetime.info = "? ";
254 tmp_lt.remove_all("?");
255 }
256
257 if(tmp_lt.contains("STABLE")) {
258 flifetime.value = 3.2E23;
259 flifetime.unit = "S";
260 flifetime.info += ";STABLE";
261 }
262 else {
263 auto tokens_lt = tmp_lt.tokenize(" ");
264 if(tokens_lt.size() !=2 && fglobal_time_unit.is_empty()) {
265 // in this specific case, the most probable scenario is that this field has been used for something else than lifetime
266 // glog << error << "problem in decoding life time in record: " << frecord << " (no unit given)" << do_endl;
267 return false;
268 }
269 flifetime.value = tokens_lt.front().atof();
270 if(tokens_lt.size() !=2 && !fglobal_time_unit.is_empty()) flifetime.unit = fglobal_time_unit;
271 else flifetime.unit = tokens_lt.back();
272 if(flifetime.unit.equal_to("m",tkstring::ECaseCompare::kIgnoreCase)) flifetime.unit = "MIN";
273
274 tkstring lt_err = _st.substr(10,6).strip_all_extra_white_space();
275 if(!lt_err.is_empty()) {
276
277 if(lt_err.is_alpha()) {
278 flifetime.info += ";ERR=" + lt_err;
279 }
280 else {
281 // define precision according to the value string
282 double precision = tkstring::get_precision(tokens_lt.front());
283
284 // check if asym errors
285 if(lt_err.contains("+") && lt_err.contains("-")) {
286 bool inv = lt_err.index("-") < lt_err.index("+");
287 lt_err.replace_all("+"," ");
288 lt_err.replace_all("-"," ");
289 auto tokens_lt_err = lt_err.tokenize(" ");
290 if(tokens_lt_err.size()!=2) {
291 glog << error << " bad asymetric error decoding in record " << frecord << do_endl;
292 return false;
293 }
294 tkstring err_low_str = tokens_lt_err.back();
295 tkstring err_high_str = tokens_lt_err.front();
296 if(inv) {
297 err_low_str = tokens_lt_err.front();
298 err_high_str = tokens_lt_err.back();
299 }
300
301 flifetime.err_low = err_low_str.atof()*precision;
302 flifetime.err_high = err_high_str.atof()*precision;
303 }
304 else {
305 flifetime.err = lt_err.atof()*precision;
306 }
307 }
308 }
309 else
310 flifetime.info += ";ERR=?";
311 }
312
313 if(!_st_ms.is_empty()) {
314 flifetime.info += ";ISO=" + _st_ms;
315 }
316
317 flifetime.filled = true;
318
319 return true;
320}
321
323{
324 fenergy.clear();
325 flifetime.clear();
326
327 frecord = "";
328 ftype = kunknown;
329 f_is_continuation_record = false;
330 fcontinuation_record = "";
331 fcomment_record = "";
332
333 fUncertain_record = "";
334
335 fisknown_woth_offset = false;
336 fOffset="";
337}
338
339void tkensdf_record::print(std::ostream &out) const
340{
341 out << "Record: " << frecord << std::endl;
342}
bool decode_lifetime(const tkstring &_st, const tkstring &_st_ms)
decode a lifetime record
bool decode_energy(const tkstring &_st)
decode an anergy record
static std::string BLANK
void check_record_type()
check record type from its string
virtual void print(std::ostream &) const
virtual void add_comment_record(const tkstring &_comment_record, bool _is_continuation=false)
add a continuation record from a string
virtual bool set_record(const tkstring &_record)
define the record from a string. Option false only checks if the record is an identification record
virtual void add_continuation_record(const tkstring &_continuation_record)
add a continuation record from a string
static const int RSIZE
void set_offset(tkstring _offset)
set_energy_offset
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:33
tkstring strip_all_extra_white_space() const
Definition tkstring.cpp:550
tkstring & to_lower()
Change all letters to lower case.
Definition tkstring.cpp:118
std::vector< tkstring > tokenize(const tkstring &_delim=" ") const
Create a vector of string separated by at least one delimiter.
Definition tkstring.cpp:292
bool is_empty() const
Definition tkstring.h:145
tkstring & remove_all(const tkstring &_s1)
Definition tkstring.h:208
tkstring substr(size_type __pos=0, size_type __n=npos) const
Inlines.
Definition tkstring.h:160
bool is_alpha() const
Checks whether tkstring is only composed of alphabetic letters.
Definition tkstring.cpp:427
bool equal_to(const char *_s, ECaseCompare _cmp=kExact) const
Returns true if the string and _s are identical.
Definition tkstring.cpp:259
size_t index(const char *_s, size_t _pos=0, ECaseCompare _cmp=kExact) const
Returns the index of the substring _s.
Definition tkstring.cpp:237
tkstring & remove_all_extra_white_space()
Definition tkstring.cpp:525
bool contains(const char *_pat, ECaseCompare _cmp=kExact) const
Definition tkstring.h:184
bool begins_with(const char *_s, ECaseCompare _cmp=kExact) const
Definition tkstring.h:166
static double get_precision(tkstring _st)
Extract the precision for a given ENSDF data.
Definition tkstring.cpp:642
tkstring & replace_all(const tkstring &_s1, const tkstring &_s2)
Definition tkstring.h:196
double atof() const
Converts a string to double value.
Definition tkstring.cpp:226
Definition tklog.cpp:16
tklog & error_v(tklog &log)
Definition tklog.h:407
tklog & error(tklog &log)
Definition tklog.h:344
tklog & do_endl(tklog &log)
Definition tklog.h:212