23static void readRIS2( std::string
const &a_basePath, std::string
const &a_fileName,
Projectiles &a_projectiles, std::string
const &a_energyUnit );
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 ) :
59 std::transform(processLower.begin(), processLower.end(), processLower.begin(), ::tolower);
60 return processLower.find(
"fission") != std::string::npos;
72 for( std::size_t index = 0; index <
m_products.size( ); ++index ) {
97 for(
auto productIter =
m_products.begin( ); productIter !=
m_products.end( ); ++productIter ) a_products.insert( *productIter );
106 std::string sep =
"";
107 std::string productList;
108 for( std::size_t index = 0; index <
m_products.size( ); ++index ) {
116 std::string intermediates;
118 intermediates += sep + (*iterIntermediate);
123 if( effectiveThresholdStr.find(
"e" ) == std::string::npos ) {
124 if( effectiveThresholdStr.find(
"." ) == std::string::npos ) {
125 effectiveThresholdStr +=
".0";
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" );
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
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 ) :
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 ) {
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; }
171 throw "RISI::Protare: supported a_protareEnergyUnit '" + a_requestedEnergyUnit +
"'.";
181 for(
auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter )
delete *reactionIter;
190 throw "No mode has been set for adding to the Protare: " + m_projectile +
" + " + m_target +
".";
198 std::pair<std::string, std::string> keyName = { a_elements[0], a_elements[1] };
199 m_aliases.push_back( keyName );
210 for(
auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter ) {
211 if( (*reactionIter)->isFission( ) )
return true;
222 double effectiveThreshold = m_energyConversionFactor * std::stod( a_elements[1] );
225 std::string reactionLabel;
226 std::string covarianceFlag;
228 if( a_elements.size( ) > 5 ) {
229 reactionLabel = a_elements[4];
230 covarianceFlag = a_elements[5];
234 std::vector<int> multiplicities;
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;
240 if( isdigit( begin[0] ) ) {
241 multiplicity = strtol( begin, &end, 10 );
244 multiplicities.push_back(
static_cast<int>( multiplicity ) );
247 m_reactions.push_back(
new Reaction( effectiveThreshold,
products, multiplicities, intermediates, a_elements[3], reactionLabel, covarianceFlag ) );
255 if( m_addMode == 0 ) {
256 Oops( a_elements ); }
257 else if( m_addMode == 1 ) {
259 else if( m_addMode == 2 ) {
273void Protare::products(
Projectile const *a_projectile,
int a_level,
int a_maxLevel,
double a_energyMax, std::map<std::string, int> &a_products )
const {
275 std::set<std::string> productSet;
276 for(
auto reactionIter = m_reactions.begin( ); reactionIter != m_reactions.end( ); ++reactionIter )
277 (*reactionIter)->products( a_energyMax, productSet );
279 for(
auto productIter = productSet.begin( ); productIter != productSet.end( ); ++productIter ) {
280 a_projectile->
products( *productIter, a_level, a_maxLevel, a_energyMax, a_products );
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( );
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;
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 );
315 for(
auto iter = m_protares.begin( ); iter != m_protares.end( ); ++iter )
delete *iter;
327 m_protares.push_back( a_protare );
338 for(
auto protareIter = m_protares.begin( ); protareIter != m_protares.end( ); ++protareIter ) {
339 if( (*protareIter)->fissionPresent( ) )
return true;
353void Target::products(
Projectile const *a_projectile,
int a_level,
int a_maxLevel,
double a_energyMax, std::map<std::string, int> &a_products )
const {
355 m_protares[0]->products( a_projectile, a_level, a_maxLevel, a_energyMax, a_products );
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;
377 for(
auto iter = m_protares.begin( ); iter != m_protares.end( ); ++iter ) (*iter)->printAsRIS_file( );
390 for(
auto iter = m_targets.begin( ); iter != m_targets.end( ); ++iter )
delete (*iter).second;
404 auto iter = m_targets.find(
target );
405 if( iter == m_targets.end( ) ) {
407 iter = m_targets.find(
target );
410 (*iter).second->add( a_protare );
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 );
426 if( (*iter).second->fissionPresent( ) )
return true;
440 auto targetIter = m_targets.find( a_targetName );
441 if( targetIter != m_targets.end( ) ) {
442 return (*targetIter).second;
455 std::vector<std::string> targetList;
457 for(
auto targetIter = m_targets.begin( ); targetIter != m_targets.end( ); ++targetIter ) {
458 targetList.push_back( (*targetIter).first );
461 return( targetList );
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 {
476 auto productIter = a_products.find( a_target );
477 if( productIter != a_products.end( ) ) {
478 if( a_level < (*productIter).second ) {
480 a_products[a_target] = a_level;
485 a_products[a_target] = a_level;
488 if( a_level >= a_maxLevel )
return;
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 );
503 std::vector<std::string> filteredProducts;
505 for (
const auto &productId : a_productIds) {
506 if (m_targets.find(productId) != m_targets.end()) {
507 filteredProducts.push_back(productId);
511 return filteredProducts;
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 +
" " );
533 for(
auto iter = m_targets.begin( ); iter != m_targets.end( ); ++iter ) (*iter).second->printAsRIS_file( );
559 if( iter == m_projectiles.end( ) ) {
564 (*iter).second->add( a_protare );
573 for(
auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter )
delete (*iter).second;
574 m_projectiles.clear( );
585 std::vector<std::string> projectileList;
587 for(
auto projectileIter = m_projectiles.begin( ); projectileIter != m_projectiles.end( ); ++projectileIter ) {
588 projectileList.push_back( (*projectileIter).first );
591 return( projectileList );
603 auto projectileIter = m_projectiles.find( a_projectile );
604 if( projectileIter != m_projectiles.end( ) ) {
605 return( (*projectileIter).second );
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 {
624 std::map<std::string, int> productMap;
626 auto projectile = m_projectiles.find( a_projectile );
628 for(
auto targetIter = a_seedTargets.begin( ); targetIter != a_seedTargets.end( ); ++targetIter )
629 (*projectile).second->products( (*targetIter), 0, a_maxLevel, a_energyMax, productMap );
632 std::vector<std::string> productList;
633 for(
auto productIter = productMap.begin( ); productIter != productMap.end( ); ++productIter ) productList.push_back( (*productIter).first );
635 if( a_onlyIncludeTargets ) {
636 productList = (*projectile).second->filterProducts( productList );
639 return( productList );
650 for(
auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter ) (*iter).second->print( a_indent );
660 std::cout <<
"#ris : 1.0" << std::endl;
661 for(
auto iter = m_projectiles.begin( ); iter != m_projectiles.end( ); ++iter ) (*iter).second->printAsRIS_file( );
667void readRIS( std::string
const &a_fileName, std::string
const &a_energyUnit,
Projectiles &a_projectiles ) {
669 a_projectiles.
clear( );
670 readRIS2(
".", a_fileName, a_projectiles, a_energyUnit );
676static void readRIS2( std::string
const &a_basePath, std::string
const &a_fileName, Projectiles &a_projectiles, std::string
const &a_energyUnit ) {
678 std::string errorString;
680 std::string fileName( a_fileName );
681 if( fileName[0] !=
'/' ) {
682 fileName = a_basePath +
"/" + fileName;
686 std::ifstream inputFile;
687 inputFile.open( fileName );
688 if( !inputFile.good( ) )
throw LUPI::Exception(
"Opening RIS file " + a_fileName +
" failed." );
692 if( getline( inputFile, line ) ) {
694 if( elements.size( ) != 2 )
throw LUPI::Exception(
"Invalid header line in RIS file '" + fileName +
"'" );
696 if( elements[0] !=
"#ris" )
throw LUPI::Exception(
"Invalid header tag in RIS file '" + fileName +
"'" );
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 +
"'" );
701 std::string sep =
" : ";
702 if( line.find( sep ) == std::string::npos ) sep =
": ";
705 while( getline( inputFile, line ) ) {
707 if( elements.size( ) == 0 )
continue;
708 std::string command = elements[0];
710 if( command ==
"#import" ) {
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( ); }
723 if(
protare ==
nullptr )
throw LUPI::Exception(
"Data without protare defined in RIS file '" + fileName +
"'." );
Target const * target(std::string const &a_targetName) const
bool fissionPresent(std::vector< std::string > targetIds) const
void products(std::string const &a_target, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
std::vector< std::string > filterProducts(std::vector< std::string > const &a_productIds) const
void printAsRIS_file() const
std::vector< std::string > targetIds() const
void print(std::string const &a_indent="") const
void add(Protare *a_protare)
std::vector< std::string > projectileIds() const
void print(std::string const &a_indent="") const
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
void printAsRIS_file() const
void add(Protare *a_protare)
Projectile const * projectile(std::string const &a_projectile) const
std::string const & target()
void addAlias(std::vector< std::string > const &a_elements)
std::string const & projectile()
void printAsRIS_file() const
void products(Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
void Oops(std::vector< std::string > const &a_elements)
bool fissionPresent() const
void add(std::vector< std::string > const &a_elements)
void addReaction(std::vector< std::string > const &a_elements)
std::vector< int > m_multiplicities
void products(double a_energyMax, std::set< std::string > &a_products) const
std::vector< std::string > m_products
std::vector< std::string > m_intermediates
std::string m_reactionLabel
std::string m_convarianceFlag
int multiplicity(std::string const &a_productId) const
double m_effectiveThreshold
void printAsRIS_file(int a_labelWidth) const
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)
void add(Protare *a_protare)
void products(Projectile const *a_projectile, int a_level, int a_maxLevel, double a_energyMax, std::map< std::string, int > &a_products) const
void print(std::string const &a_indent="") const
bool fissionPresent() const
void printAsRIS_file() const
void readRIS(std::string const &a_fileName, std::string const &a_energyUnit, Projectiles &a_projectiles)
std::string realPath(std::string const &a_path)
std::string _dirname(std::string const &a_path)
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
std::string argumentsToString(char const *a_format,...)