Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
RISI_read.cc
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include <stdlib.h>
11#include <iostream>
12#include <iomanip>
13#include <fstream>
14#include <ctype.h>
15#include <algorithm>
16
17#include <RISI.hpp>
18
19namespace GIDI {
20
21namespace RISI {
22
23static void readRIS2( std::string const &a_basePath, std::string const &a_fileName, Projectiles &a_projectiles, std::string const &a_energyUnit );
24
25/*! \class Reaction
26 * Class to store a reaction for a reaction information summary **RIS**.
27 */
28
29/* *********************************************************************************************************//**
30 * @param a_effectiveThreshold [in] The effective threshold for the reaction.
31 * @param a_products [in] The list of final products for the reaction.
32 * @param a_multiplicities [in] The multiplicities for each product in *a_products*.
33 * @param a_intermediates [in] The list of intermediates products for the reaction.
34 * @param a_process [in] The process for the reaction.
35 ***********************************************************************************************************/
36
37Reaction::Reaction( double a_effectiveThreshold, std::vector<std::string> const &a_products, std::vector<int> const &a_multiplicities,
38 std::vector<std::string> const &a_intermediates, std::string const &a_process, std::string const &reactionLabel,
39 std::string const &convarianceFlag ) :
40 m_effectiveThreshold( a_effectiveThreshold ),
41 m_products( a_products ),
42 m_multiplicities( a_multiplicities ),
43 m_intermediates( a_intermediates ),
44 m_process( a_process ),
45 m_reactionLabel( reactionLabel ),
46 m_convarianceFlag( convarianceFlag ) {
47
48}
49
50/* *********************************************************************************************************//**
51 * Returns true if the reaction process contains 'fission' (case-insensitive).
52 *
53 * @return True if this is a fission reaction, false otherwise.
54 ***********************************************************************************************************/
55
56bool Reaction::isFission( ) const {
57
58 std::string processLower = m_process;
59 std::transform(processLower.begin(), processLower.end(), processLower.begin(), ::tolower);
60 return processLower.find("fission") != std::string::npos;
61}
62
63/* *********************************************************************************************************//**
64 * Returns the multiplicity for the specified product ID.
65 *
66 * @param a_productId [in] The product ID to look up.
67 * @return The multiplicity of the specified product, -1 if multiplicity is energy-dependent, or 0 if not found.
68 ***********************************************************************************************************/
69
70int Reaction::multiplicity( std::string const &a_productId ) const {
71
72 for( std::size_t index = 0; index < m_products.size( ); ++index ) {
73 if( m_products[index] == a_productId ) {
74 if( m_multiplicities[index] == 0 ) {
75 return -1;
76 }
77 return m_multiplicities[index];
78 }
79 }
80 return 0;
81}
82
83/* *********************************************************************************************************//**
84 *
85 *
86 * @param a_projectile [in] The **Projectile** instance for the requested projectile.
87 * @param a_level [in] The current recursive level.
88 * @param a_maxLevel [in] The maximum recursive level requested by the user.
89 * @param a_energyMax [in] Only reactions with effective thresholds less than this value are processed.
90 * @param a_products [in] The list to add additional products to.
91 ***********************************************************************************************************/
92
93void Reaction::products( double a_energyMax, std::set<std::string> &a_products ) const {
94
95 if( m_effectiveThreshold >= a_energyMax ) return;
96
97 for( auto productIter = m_products.begin( ); productIter != m_products.end( ); ++productIter ) a_products.insert( *productIter );
98}
99
100/* *********************************************************************************************************//**
101 * This method attempts to print *this* as it appears in a file.
102 ***********************************************************************************************************/
103
104void Reaction::printAsRIS_file( int a_labelWidth ) const {
105
106 std::string sep = "";
107 std::string productList;
108 for( std::size_t index = 0; index < m_products.size( ); ++index ) {
109 std::string product = m_products[index];
111 productList += sep + product;
112 sep = " + ";
113 }
114
115 sep = "";
116 std::string intermediates;
117 for( auto iterIntermediate = m_intermediates.begin( ); iterIntermediate != m_intermediates.end( ); ++iterIntermediate ) {
118 intermediates += sep + (*iterIntermediate);
119 sep = " ";
120 }
121
122 std::string effectiveThresholdStr = LUPI::Misc::doubleToShortestString( m_effectiveThreshold, 15, -3 );
123 if( effectiveThresholdStr.find( "e" ) == std::string::npos ) {
124 if( effectiveThresholdStr.find( "." ) == std::string::npos ) {
125 effectiveThresholdStr += ".0";
126 } }
127 else {
128 std::size_t eMinus = effectiveThresholdStr.find( "e-" );
129 if( ( eMinus != std::string::npos ) && ( effectiveThresholdStr.size( ) == eMinus + 3 ) ) {
130 effectiveThresholdStr = effectiveThresholdStr.replace( eMinus, 2, "e-0" );
131 }
132 }
133
134 std::cout << " " << std::left << std::setw( 31 ) << productList
135 << " : " << std::left << std::setw( 12 ) << effectiveThresholdStr
136 << " : " << std::left << std::setw( 10 ) << intermediates
137 << " : " << std::left << std::setw( 9 ) << m_process
138 << " : " << std::left << std::setw( a_labelWidth ) << m_reactionLabel
139 << " : " << m_convarianceFlag << std::endl;
140}
141
142/*! \class Protare
143 * Class to store a protare for a reaction information summary **RIS**.
144 */
145
146/* *********************************************************************************************************//**
147 * @param a_projectile [in] The PoPs id for the projectile.
148 * @param a_target [in] The PoPs id for the target.
149 * @param a_evaluation [in] The evaluation string for the protare.
150 * @param a_protareEnergyUnit [in] The unit of energy in the **RIS** file.
151 * @param a_requestedEnergyUnit [in] The unit of energy specified by the user.
152 ***********************************************************************************************************/
153
154Protare::Protare( std::string const &a_projectile, std::string const &a_target, std::string const &a_evaluation,
155 std::string const &a_protareEnergyUnit, std::string const &a_requestedEnergyUnit ) :
156 m_addMode( 0 ),
157 m_projectile( a_projectile ),
158 m_target( a_target ),
159 m_evaluation( a_evaluation ),
160 m_energyUnit( a_protareEnergyUnit ),
161 m_energyConversionFactor( 1.0 ) {
162
163 if( a_protareEnergyUnit != a_requestedEnergyUnit ) {
164 if( a_protareEnergyUnit == "eV" ) {
165 if( a_requestedEnergyUnit != "MeV" ) throw "RISI::Protare: supported a_requestedEnergyUnit '" + a_requestedEnergyUnit + "'.";
166 m_energyConversionFactor = 1e-6; }
167 else if( a_protareEnergyUnit == "MeV" ) {
168 if( a_requestedEnergyUnit != "eV" ) throw "RISI::Protare: supported a_requestedEnergyUnit '" + a_requestedEnergyUnit + "'.";
169 m_energyConversionFactor = 1e6; }
170 else {
171 throw "RISI::Protare: supported a_protareEnergyUnit '" + a_requestedEnergyUnit + "'.";
172 }
173 }
174}
175
176/* *********************************************************************************************************//**
177 ***********************************************************************************************************/
178
180
181 for( auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter ) delete *reactionIter;
182
183}
184
185/* *********************************************************************************************************//**
186 ***********************************************************************************************************/
187
188void Protare::Oops( LUPI_maybeUnused std::vector<std::string> const &a_elements ) {
189
190 throw "No mode has been set for adding to the Protare: " + m_projectile + " + " + m_target + ".";
191}
192
193/* *********************************************************************************************************//**
194 ***********************************************************************************************************/
195
196void Protare::addAlias( std::vector<std::string> const &a_elements ) {
197
198 std::pair<std::string, std::string> keyName = { a_elements[0], a_elements[1] };
199 m_aliases.push_back( keyName );
200}
201
202/* *********************************************************************************************************//**
203 * Returns true if any reaction in this protare is a fission reaction.
204 *
205 * @return True if fission reactions are present, false otherwise.
206 ***********************************************************************************************************/
207
209
210 for( auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter ) {
211 if( (*reactionIter)->isFission( ) ) return true;
212 }
213 return false;
214}
215
216/* *********************************************************************************************************//**
217 ***********************************************************************************************************/
218
219void Protare::addReaction( std::vector<std::string> const &a_elements ) {
220
221 std::vector<std::string> productsString = LUPI::Misc::splitString( a_elements[0], '+', true );
222 double effectiveThreshold = m_energyConversionFactor * std::stod( a_elements[1] );
223 std::vector<std::string> intermediates = LUPI::Misc::splitString( a_elements[2], ' ', true );
224
225 std::string reactionLabel;
226 std::string covarianceFlag;
227
228 if( a_elements.size( ) > 5 ) {
229 reactionLabel = a_elements[4];
230 covarianceFlag = a_elements[5];
231 }
232
233 std::vector<std::string> products;
234 std::vector<int> multiplicities;
235
236 for( auto iter = productsString.begin( ); iter != productsString.end( ); ++iter ) {
237 char *begin = const_cast<char *>( (*iter).c_str( ) ), *end = begin;
238 long multiplicity = 1;
239
240 if( isdigit( begin[0] ) ) {
241 multiplicity = strtol( begin, &end, 10 );
242 }
243 products.push_back( end );
244 multiplicities.push_back( static_cast<int>( multiplicity ) );
245 }
246
247 m_reactions.push_back( new Reaction( effectiveThreshold, products, multiplicities, intermediates, a_elements[3], reactionLabel, covarianceFlag ) );
248}
249
250/* *********************************************************************************************************//**
251 ***********************************************************************************************************/
252
253void Protare::add( std::vector<std::string> const &a_elements ) {
254
255 if( m_addMode == 0 ) {
256 Oops( a_elements ); }
257 else if( m_addMode == 1 ) {
258 addAlias( a_elements ); }
259 else if( m_addMode == 2 ) {
260 addReaction( a_elements );
261 }
262}
263
264/* *********************************************************************************************************//**
265 *
266 * @param a_projectile [in] The **Projectile** instance for the requested projectile.
267 * @param a_level [in] The current recursive level.
268 * @param a_maxLevel [in] The maximum recursive level requested by the user.
269 * @param a_energyMax [in] Only reactions with effective thresholds less than this value are processed.
270 * @param a_products [in] The list to add additional products to.
271 ***********************************************************************************************************/
272
273void Protare::products( Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map<std::string, int> &a_products ) const {
274
275 std::set<std::string> productSet;
276 for( auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter )
277 (*reactionIter)->products( a_energyMax, productSet );
278
279 for( auto productIter = productSet.begin( ); productIter != productSet.end( ); ++productIter ) {
280 a_projectile->products( *productIter, a_level, a_maxLevel, a_energyMax, a_products );
281 }
282}
283
284/* *********************************************************************************************************//**
285 * This method attempts to print *this* as it appears in a file.
286 ***********************************************************************************************************/
287
289
290 std::size_t labelWidth = 0;
291 for( auto iter = m_reactions.begin( ); iter != m_reactions.end( ); ++iter ) {
292 if( labelWidth < (*iter)->m_reactionLabel.size( ) ) labelWidth = (*iter)->m_reactionLabel.size( );
293 }
294
295 std::cout << "#protare : " << m_projectile << " : " << m_target << " : " << m_evaluation << " : " << m_energyUnit << std::endl;
296 if( m_aliases.size( ) > 0 ) {
297 std::cout << "#aliases : " << m_aliases.size( ) << std::endl;
298 for( auto iter = m_aliases.begin( ); iter != m_aliases.end( ); ++iter ) {
299 std::cout << " " << iter->first << " : " << iter->second << std::endl;
300 }
301 }
302 std::cout << "#reactions : " << m_reactions.size( ) << std::endl;
303 for( auto iter = m_reactions.begin( ); iter != m_reactions.end( ); ++iter ) (*iter)->printAsRIS_file( (int) labelWidth );
304}
305
306/*! \class Target
307 * Stores a list of **Protare** instances for a specified target.
308 */
309
310/* *********************************************************************************************************//**
311 ***********************************************************************************************************/
312
314
315 for( auto iter = m_protares.begin( ); iter != m_protares.end( ); ++iter ) delete *iter;
316
317}
318
319/* *********************************************************************************************************//**
320 * Adds *a_protare* to *this* list of **Protare** instances.
321 *
322 * @param a_protare [in] The **Protare** instance to add to *this*.
323 ***********************************************************************************************************/
324
325void Target::add( Protare *a_protare ) {
326
327 m_protares.push_back( a_protare );
328}
329
330/* *********************************************************************************************************//**
331 * Returns true if any protare in this target has fission reactions.
332 *
333 * @return True if fission reactions are present, false otherwise.
334 ***********************************************************************************************************/
335
337
338 for( auto protareIter = m_protares.begin( ); protareIter != m_protares.end( ); ++protareIter ) {
339 if( (*protareIter)->fissionPresent( ) ) return true;
340 }
341 return false;
342}
343
344/* *********************************************************************************************************//**
345 *
346 * @param a_projectile [in] The **Projectile** instance for the requested projectile.
347 * @param a_level [in] The current recursive level.
348 * @param a_maxLevel [in] The maximum recursive level requested by the user.
349 * @param a_energyMax [in] Only reactions with effective thresholds less than this value are processed.
350 * @param a_products [in] The list to add additional products to.
351 ***********************************************************************************************************/
352
353void Target::products( Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map<std::string, int> &a_products ) const {
354
355 m_protares[0]->products( a_projectile, a_level, a_maxLevel, a_energyMax, a_products );
356}
357
358/* *********************************************************************************************************//**
359 * Calls the *print* method on each **Projectile** in *this*.
360 *
361 * @param a_indent [in] The **Protare** instance to add to *this*.
362 ***********************************************************************************************************/
363
364void Target::print( std::string const &a_indent ) const {
365
366 std::cout << a_indent + m_id << ":";
367 for( auto iter = m_protares.begin( ); iter != m_protares.end( ); ++iter ) std::cout << " " << (*iter)->evaluation( );
368 std::cout << std::endl;
369}
370
371/* *********************************************************************************************************//**
372 * Calls the *printAsRIS_file* method on each **Protare** in *this*. This method attempts to print *this* as it appears in a file.
373 ***********************************************************************************************************/
374
376
377 for( auto iter = m_protares.begin( ); iter != m_protares.end( ); ++iter ) (*iter)->printAsRIS_file( );
378}
379
380/*! \class Projectile
381 * Stores a list of projectiles and their associated **Target** instance.
382 */
383
384
385/* *********************************************************************************************************//**
386 ***********************************************************************************************************/
387
389
390 for( auto iter = m_targets.begin( ); iter != m_targets.end( ); ++iter ) delete (*iter).second;
391
392}
393
394/* *********************************************************************************************************//**
395 * Adds *a_protare* to the associated target of *this*.
396 *
397 * @param a_protare [in] The **Protare** instance to add to *this*.
398 ***********************************************************************************************************/
399
400void Projectile::add( Protare *a_protare ) {
401
402 std::string const &target = a_protare->target( );
403
404 auto iter = m_targets.find( target );
405 if( iter == m_targets.end( ) ) {
406 m_targets[target] = new Target( target );
407 iter = m_targets.find( target );
408 }
409
410 (*iter).second->add( a_protare );
411}
412
413/* *********************************************************************************************************//**
414 * Returns true if any target in this projectile has fission reactions.
415 *
416 * @return True if fission reactions are present, false otherwise.
417 ***********************************************************************************************************/
418
419bool Projectile::fissionPresent( std::vector<std::string> targetIds ) const {
420
421 for( auto& targetId : targetIds ) {
422 auto iter = m_targets.find( targetId );
423 if ( iter == m_targets.end( ) ) {
424 throw LUPI::Exception( "Target " + targetId + " missing from .ris file for projectile " + m_id );
425 }
426 if( (*iter).second->fissionPresent( ) ) return true;
427 }
428 return false;
429}
430
431/* *********************************************************************************************************//**
432 * Returns a pointer to the target with the specified name, or nullptr if not found.
433 *
434 * @param a_targetName [in] The name of the target to find.
435 * @return A pointer to the Target object, or nullptr if not found.
436 ***********************************************************************************************************/
437
438Target const *Projectile::target( std::string const &a_targetName ) const {
439
440 auto targetIter = m_targets.find( a_targetName );
441 if( targetIter != m_targets.end( ) ) {
442 return (*targetIter).second;
443 }
444 return nullptr;
445}
446
447/* *********************************************************************************************************//**
448 * Returns a vector containing the names of all targets available for this projectile.
449 *
450 * @return A vector of target names.
451 ***********************************************************************************************************/
452
453std::vector<std::string> Projectile::targetIds( ) const {
454
455 std::vector<std::string> targetList;
456
457 for( auto targetIter = m_targets.begin( ); targetIter != m_targets.end( ); ++targetIter ) {
458 targetList.push_back( (*targetIter).first );
459 }
460
461 return( targetList );
462}
463
464/* *********************************************************************************************************//**
465 * Populate std::map with product id: max multiplicity for that product that can be created from the given target.
466 *
467 * @param a_target [in] Target particle id.
468 * @param a_level [in] The current recursive level.
469 * @param a_maxLevel [in] The maximum recursive level requested by the user.
470 * @param a_energyMax [in] Only reactions with effective thresholds less than this value are processed.
471 * @param a_products [in] The map to be populated with (product: max multiplicity) pairs.
472 ***********************************************************************************************************/
473
474void Projectile::products( std::string const &a_target, int a_level, int a_maxLevel, double a_energyMax, std::map<std::string, int> &a_products ) const {
475
476 auto productIter = a_products.find( a_target );
477 if( productIter != a_products.end( ) ) {
478 if( a_level < (*productIter).second ) {
479 // found a way to make the product in fewer reaction steps
480 a_products[a_target] = a_level;
481 } else {
482 return;
483 }
484 } else {
485 a_products[a_target] = a_level; // Adds a_target to a_products.
486 }
487
488 if( a_level >= a_maxLevel ) return;
489
490 auto targetIter = m_targets.find( a_target );
491 if( targetIter != m_targets.end( ) ) (*targetIter).second->products( this, a_level + 1, a_maxLevel, a_energyMax, a_products );
492}
493
494/* *********************************************************************************************************//**
495 * Filter an initial list of products, returning only those that are available as targets for this projectile
496 *
497 * @param a_products [in] The list of product IDs to filter.
498 * @return A vector of filtered product IDs.
499 ***********************************************************************************************************/
500
501std::vector<std::string> Projectile::filterProducts( std::vector<std::string> const &a_productIds ) const {
502
503 std::vector<std::string> filteredProducts;
504
505 for (const auto &productId : a_productIds) {
506 if (m_targets.find(productId) != m_targets.end()) {
507 filteredProducts.push_back(productId);
508 }
509 }
510
511 return filteredProducts;
512}
513
514/* *********************************************************************************************************//**
515 * Prints *this* id and then calls the *print* method on each **Target** in *this*.
516 *
517 * @param a_indent [in] The **Protare** instance to add to *this*.
518 ***********************************************************************************************************/
519
520void Projectile::print( std::string const &a_indent ) const {
521
522 std::cout << a_indent + m_id << std::endl;
523 for( auto iter = m_targets.begin( ); iter != m_targets.end( ); ++iter ) (*iter).second->print( a_indent + " " );
524}
525
526/* *********************************************************************************************************//**
527 * Calls the *printAsRIS_file* method on each **Target** in *this*. This method attempts to print *this* as it appears in a file.
528 *
529 ***********************************************************************************************************/
530
532
533 for( auto iter = m_targets.begin( ); iter != m_targets.end( ); ++iter ) (*iter).second->printAsRIS_file( );
534}
535
536/*! \class Projectiles
537 * Stores a list of projectiles.
538 */
539
540/* *********************************************************************************************************//**
541 ***********************************************************************************************************/
542
544
545 clear( );
546}
547
548/* *********************************************************************************************************//**
549 * Adds *a_protare* to the associated projectile of *this*.
550 *
551 * @param a_protare [in] The **Protare** instance to add to *this*.
552 ***********************************************************************************************************/
553
554void Projectiles::add( Protare *a_protare ) {
555
556 std::string const &projectile = a_protare->projectile( );
557
558 auto iter = m_projectiles.find( projectile );
559 if( iter == m_projectiles.end( ) ) {
560 m_projectiles[projectile] = new Projectile( projectile );
561 iter = m_projectiles.find( projectile );
562 }
563
564 (*iter).second->add( a_protare );
565}
566
567/* *********************************************************************************************************//**
568 * Clears the contents of the *m_projectiles* member.
569 ***********************************************************************************************************/
570
572
573 for( auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter ) delete (*iter).second;
574 m_projectiles.clear( );
575}
576
577/* *********************************************************************************************************//**
578 * Returns a vector containing the particle ids of all projectiles in this collection.
579 *
580 * @return A vector of projectile ids.
581 ***********************************************************************************************************/
582
583std::vector<std::string> Projectiles::projectileIds( ) const {
584
585 std::vector<std::string> projectileList;
586
587 for( auto projectileIter = m_projectiles.begin( ); projectileIter != m_projectiles.end( ); ++projectileIter ) {
588 projectileList.push_back( (*projectileIter).first );
589 }
590
591 return( projectileList );
592}
593
594/* *********************************************************************************************************//**
595 * Returns a pointer to the projectile with the specified name, or nullptr if not found.
596 *
597 * @param a_projectile [in] The name of the projectile to find.
598 * @return A pointer to the Projectile object, or nullptr if not found.
599 ***********************************************************************************************************/
600
601Projectile const *Projectiles::projectile( std::string const &a_projectile ) const {
602
603 auto projectileIter = m_projectiles.find( a_projectile );
604 if( projectileIter != m_projectiles.end( ) ) {
605 return( (*projectileIter).second );
606 }
607
608 return( nullptr );
609}
610
611/* *********************************************************************************************************//**
612 * Return a list of products that can be created for the given projectile and initial 'seed' targets.
613 *
614 * @param a_projectile [in] Projectile particle id (e.g. 'n' or 'photon')
615 * @param a_seedTargets [in] List of initial targets, used to determine what products can be created.
616 * @param a_maxLevel [in] The maximum recursive level requested by the user.
617 * @param a_energyMax [in] Only reactions with effective thresholds less than this value are processed.
618 * @param a_onlyIncludeTargets [in] Only return products that correspond to protares.
619 ***********************************************************************************************************/
620
621std::vector<std::string> Projectiles::products( std::string const &a_projectile, std::vector<std::string> const &a_seedTargets, int a_maxLevel,
622 double a_energyMax, bool a_onlyIncludeTargets ) const {
623
624 std::map<std::string, int> productMap;
625
626 auto projectile = m_projectiles.find( a_projectile );
627 if( projectile != m_projectiles.end( ) ) {
628 for( auto targetIter = a_seedTargets.begin( ); targetIter != a_seedTargets.end( ); ++targetIter )
629 (*projectile).second->products( (*targetIter), 0, a_maxLevel, a_energyMax, productMap );
630 }
631
632 std::vector<std::string> productList;
633 for( auto productIter = productMap.begin( ); productIter != productMap.end( ); ++productIter ) productList.push_back( (*productIter).first );
634
635 if( a_onlyIncludeTargets ) {
636 productList = (*projectile).second->filterProducts( productList );
637 }
638
639 return( productList );
640}
641
642/* *********************************************************************************************************//**
643 * Calls the *print* method on each **Projectile** in *this*.
644 *
645 * @param a_indent [in] The **Protare** instance to add to *this*.
646 ***********************************************************************************************************/
647
648void Projectiles::print( std::string const &a_indent ) const {
649
650 for( auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter ) (*iter).second->print( a_indent );
651}
652
653/* *********************************************************************************************************//**
654 * Calls the *printAsRIS_file* method on each **Projectile** in *this*. This method attempts to print *this* as it appears in a file.
655 *
656 ***********************************************************************************************************/
657
659
660 std::cout << "#ris : 1.0" << std::endl;
661 for( auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter ) (*iter).second->printAsRIS_file( );
662}
663
664/* *********************************************************************************************************//**
665 ***********************************************************************************************************/
666
667void readRIS( std::string const &a_fileName, std::string const &a_energyUnit, Projectiles &a_projectiles ) {
668
669 a_projectiles.clear( );
670 readRIS2( ".", a_fileName, a_projectiles, a_energyUnit );
671}
672
673/* *********************************************************************************************************//**
674 ***********************************************************************************************************/
675
676static void readRIS2( std::string const &a_basePath, std::string const &a_fileName, Projectiles &a_projectiles, std::string const &a_energyUnit ) {
677
678 std::string errorString;
679
680 std::string fileName( a_fileName );
681 if( fileName[0] != '/' ) { // Only works on Unix like systems.
682 fileName = a_basePath + "/" + fileName;
683 }
684 fileName = LUPI::FileInfo::realPath( fileName );
685
686 std::ifstream inputFile;
687 inputFile.open( fileName );
688 if( !inputFile.good( ) ) throw LUPI::Exception( "Opening RIS file " + a_fileName + " failed." );
689
690 std::string line;
691 try {
692 if( getline( inputFile, line ) ) {
693 std::vector<std::string> elements = LUPI::Misc::splitString( line, ':', true );
694 if( elements.size( ) != 2 ) throw LUPI::Exception( "Invalid header line in RIS file '" + fileName + "'" );
695
696 if( elements[0] != "#ris" ) throw LUPI::Exception( "Invalid header tag in RIS file '" + fileName + "'" );
697
698 std::string formatMajor = elements[1].substr(0, elements[1].find('.'));
699 if( formatMajor != "1" ) throw LUPI::Exception( "Invalid header version in RIS file '" + fileName + "'" );
700
701 std::string sep = " : ";
702 if( line.find( sep ) == std::string::npos ) sep = ": ";
703
704 Protare *protare = nullptr;
705 while( getline( inputFile, line ) ) {
706 elements = LUPI::Misc::splitString( line, sep, true );
707 if( elements.size( ) == 0 ) continue;
708 std::string command = elements[0];
709
710 if( command == "#import" ) {
711 readRIS2( LUPI::FileInfo::_dirname( fileName ), elements[1], a_projectiles, a_energyUnit );
712 protare = nullptr; }
713 else if( command == "#protare" ) {
714 protare = new Protare( elements[1], elements[2], elements[3], elements[4], a_energyUnit );
715 a_projectiles.add( protare ); }
716 else if( command == "#aliases" ) {
717 if( protare == nullptr ) throw LUPI::Exception( "Aliases without protare defined in RIS file '" + fileName + "'." );
718 protare->setAddingAliases( ); }
719 else if( command == "#reactions" ) {
720 if( protare == nullptr ) throw LUPI::Exception( "Reactions without protare defined in RIS file '" + fileName + "'." );
721 protare->setAddingReactions( ); }
722 else {
723 if( protare == nullptr ) throw LUPI::Exception( "Data without protare defined in RIS file '" + fileName + "'." );
724 protare->add( elements );
725 }
726 }
727 } }
728 catch (...) {
729 inputFile.close( );
730 throw;
731 }
732}
733
734} // End of namespace RISI.
735
736} // End of namespace GIDI.
#define LUPI_maybeUnused
Target const * target(std::string const &a_targetName) const
Definition RISI_read.cc:438
bool fissionPresent(std::vector< std::string > targetIds) const
Definition RISI_read.cc:419
void products(std::string const &a_target, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
Definition RISI_read.cc:474
std::vector< std::string > filterProducts(std::vector< std::string > const &a_productIds) const
Definition RISI_read.cc:501
void printAsRIS_file() const
Definition RISI_read.cc:531
std::vector< std::string > targetIds() const
Definition RISI_read.cc:453
void print(std::string const &a_indent="") const
Definition RISI_read.cc:520
void add(Protare *a_protare)
Definition RISI_read.cc:400
std::vector< std::string > projectileIds() const
Definition RISI_read.cc:583
void print(std::string const &a_indent="") const
Definition RISI_read.cc:648
std::vector< std::string > products(std::string const &a_projectile, std::vector< std::string > const &a_seedTargets, int a_maxLevel, double a_energyMax, bool a_onlyIncludeTargets=true) const
Definition RISI_read.cc:621
void printAsRIS_file() const
Definition RISI_read.cc:658
void add(Protare *a_protare)
Definition RISI_read.cc:554
Projectile const * projectile(std::string const &a_projectile) const
Definition RISI_read.cc:601
std::string const & target()
Definition RISI.hpp:65
void addAlias(std::vector< std::string > const &a_elements)
Definition RISI_read.cc:196
std::string const & projectile()
Definition RISI.hpp:64
void printAsRIS_file() const
Definition RISI_read.cc:288
void products(Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
Definition RISI_read.cc:273
void Oops(std::vector< std::string > const &a_elements)
Definition RISI_read.cc:188
bool fissionPresent() const
Definition RISI_read.cc:208
void add(std::vector< std::string > const &a_elements)
Definition RISI_read.cc:253
void addReaction(std::vector< std::string > const &a_elements)
Definition RISI_read.cc:219
std::vector< int > m_multiplicities
Definition RISI.hpp:29
void products(double a_energyMax, std::set< std::string > &a_products) const
Definition RISI_read.cc:93
std::vector< std::string > m_products
Definition RISI.hpp:28
bool isFission() const
Definition RISI_read.cc:56
std::vector< std::string > m_intermediates
Definition RISI.hpp:30
std::string m_reactionLabel
Definition RISI.hpp:32
std::string m_convarianceFlag
Definition RISI.hpp:33
int multiplicity(std::string const &a_productId) const
Definition RISI_read.cc:70
double m_effectiveThreshold
Definition RISI.hpp:27
void printAsRIS_file(int a_labelWidth) const
Definition RISI_read.cc:104
Reaction(double a_effectiveThreshold, std::vector< std::string > const &a_products, std::vector< int > const &a_multiplicities, std::vector< std::string > const &a_intermediates, std::string const &a_process, std::string const &reactionLabel, std::string const &convarianceFlag)
Definition RISI_read.cc:37
std::string m_process
Definition RISI.hpp:31
void add(Protare *a_protare)
Definition RISI_read.cc:325
void products(Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
Definition RISI_read.cc:353
void print(std::string const &a_indent="") const
Definition RISI_read.cc:364
bool fissionPresent() const
Definition RISI_read.cc:336
void printAsRIS_file() const
Definition RISI_read.cc:375
void readRIS(std::string const &a_fileName, std::string const &a_energyUnit, Projectiles &a_projectiles)
Definition RISI_read.cc:667
Definition GIDI.hpp:32
std::string realPath(std::string const &a_path)
Definition LUPI_file.cc:63
std::string _dirname(std::string const &a_path)
Definition LUPI_file.cc:112
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
Definition LUPI_misc.cc:349
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
Definition LUPI_misc.cc:103
std::string argumentsToString(char const *a_format,...)
Definition LUPI_misc.cc:305