Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_targetInfo.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 <algorithm>
12#include <cmath>
13
14#include <GIDI.hpp>
15#include <HAPI.hpp>
16
17namespace GIDI {
18
19namespace TargetInfo {
20
21static GUPI::Entry *parseChemicalElement( LUPI_maybeUnused GUPI::Suite *a_parent, HAPI::Node const &a_node );
22static GUPI::Entry *parseNuclide( LUPI_maybeUnused GUPI::Suite *a_parent, HAPI::Node const &a_node );
23
24/*! \class Nuclide
25 * The class that stores a chemicalElement node.
26 */
27
28/* *********************************************************************************************************//**
29 ***********************************************************************************************************/
30
31Nuclide::Nuclide( HAPI::Node const &a_node ) :
32 GUPI::Entry( a_node, GIDI_pidChars ),
33 m_atomFraction( a_node.attribute( GIDI_atomFractionChars ).as_double( ) ) {
34
35}
36
37/* *********************************************************************************************************//**
38 ***********************************************************************************************************/
39
43
44/* *********************************************************************************************************//**
45 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
46 *
47 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
48 * @param a_indent [in] The amount to indent *this* node.
49 ***********************************************************************************************************/
50
51void Nuclide::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
52
53 std::string attributes;
54
55 attributes = a_writeInfo.addAttribute( GIDI_pidChars, pid( ) );
57 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
58}
59
60/*! \class ChemicalElement
61 * The class that stores a chemicalElement node.
62 */
63
64/* *********************************************************************************************************//**
65 ***********************************************************************************************************/
66
68 GUPI::Entry( a_node, PoPI_symbolChars ),
69 m_nuclides( a_node.child( PoPI_nuclidesChars ), GIDI_pidChars, parseNuclide ) {
70
71}
72
73/* *********************************************************************************************************//**
74 ***********************************************************************************************************/
75
79
80/* *********************************************************************************************************//**
81 * Returns the **Nuclide** with pid *a_pid* if it exists; otherwise, **nullptr** is returned.
82 *
83 * @param a_symbol [in] The symbol for the chemical element whose nuclide abundance data are being requested.
84 ***********************************************************************************************************/
85
86Nuclide const *ChemicalElement::operator[]( std::string const &a_pid ) const {
87
88 for( auto nuclideIter = m_nuclides.begin( ); nuclideIter != m_nuclides.end( ); ++nuclideIter ) {
89 Nuclide const *nuclide = static_cast<Nuclide *>( *nuclideIter );
90 if( nuclide->pid( ) == a_pid ) return( nuclide );
91 }
92
93 return( nullptr );
94}
95
96/* *********************************************************************************************************//**
97 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
98 *
99 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
100 * @param a_indent [in] The amount to indent *this* node.
101 ***********************************************************************************************************/
102
103void ChemicalElement::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
104
105 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
106 std::string attributes;
107
108 attributes = a_writeInfo.addAttribute( PoPI_symbolChars, symbol( ) );
109 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
110 m_nuclides.toXMLList( a_writeInfo, indent2 );
111 a_writeInfo.addNodeEnder( moniker( ) );
112}
113
114/*! \class IsotopicAbundances
115 * The class that stores an isotopicAbundances node.
116 */
117
118/* *********************************************************************************************************//**
119 ***********************************************************************************************************/
120
126
127/* *********************************************************************************************************//**
128 ***********************************************************************************************************/
129
133
135
136 m_chemicalElements.parse( a_node.child( PoPI_chemicalElementsChars ), parseChemicalElement );
137}
138
139/* *********************************************************************************************************//**
140 * Returns the **ChemicalElement** with symbol *a_symbol* if it exists; otherwise, **nullptr** is returned.
141 *
142 * @param a_symbol [in] The symbol for the chemical element whose isotopic abundance data are being requested.
143 ***********************************************************************************************************/
144
145ChemicalElement const *IsotopicAbundances::operator[]( std::string const &a_symbol ) const {
146
147 for( auto iter = m_chemicalElements.begin( ); iter != m_chemicalElements.end( ); ++iter ) {
148 ChemicalElement const *chemicalElement = static_cast<ChemicalElement const *>( *iter );
149 if( chemicalElement->symbol( ) == a_symbol ) return( chemicalElement );
150 }
151
152 return( nullptr );
153}
154
155/* *********************************************************************************************************//**
156 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
157 *
158 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
159 * @param a_indent [in] The amount to indent *this* node.
160 ***********************************************************************************************************/
161
162void IsotopicAbundances::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
163
164 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
165
166 a_writeInfo.addNodeStarter( a_indent, moniker( ) );
167 m_chemicalElements.toXMLList( a_writeInfo, indent2 );
168 a_writeInfo.addNodeEnder( moniker( ) );
169}
170
171/*! \class TargetInfo
172 * The class that stores the **targetInfo** node.
173 */
174
175/* *********************************************************************************************************//**
176 ***********************************************************************************************************/
177
182
183/* *********************************************************************************************************//**
184 ***********************************************************************************************************/
185
189
190/* *********************************************************************************************************//**
191 * For internal use only.
192 *
193 * @param a_node [in] The **HAPI::Node** node whose text is to be converted into a list of doubles.
194 ***********************************************************************************************************/
195
197
198 m_isotopicAbundances.initialize( a_node.child( GIDI_isotopicAbundancesChars ) );
199}
200
201/* *********************************************************************************************************//**
202 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
203 *
204 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
205 * @param a_indent [in] The amount to indent *this* node.
206 ***********************************************************************************************************/
207
208void TargetInfo::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
209
210 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
211
212 a_writeInfo.addNodeStarter( a_indent, moniker( ) );
213 m_isotopicAbundances.toXMLList( a_writeInfo, indent2 );
214 a_writeInfo.addNodeEnder( moniker( ) );
215}
216
217/* *********************************************************************************************************//**
218 ***********************************************************************************************************/
219
220static GUPI::Entry *parseChemicalElement( LUPI_maybeUnused GUPI::Suite *a_parent, HAPI::Node const &a_node ) {
221
222 return new ChemicalElement( a_node );
223}
224
225/* *********************************************************************************************************//**
226 ***********************************************************************************************************/
227
228static GUPI::Entry *parseNuclide( LUPI_maybeUnused GUPI::Suite *a_parent, HAPI::Node const &a_node ) {
229
230 return new Nuclide( a_node );
231}
232
233} // End of namespace TargetInfo.
234
235} // End of namespace GIDI.
#define GIDI_isotopicAbundancesChars
Definition GIDI.hpp:471
#define GIDI_targetInfoChars
Definition GIDI.hpp:469
#define GIDI_atomFractionChars
Definition GIDI.hpp:470
#define GIDI_pidChars
Definition GIDI.hpp:454
#define LUPI_maybeUnused
#define PoPI_symbolChars
Definition PoPI.hpp:40
#define PoPI_chemicalElementsChars
Definition PoPI.hpp:41
#define PoPI_nuclidesChars
Definition PoPI.hpp:48
Nuclide const * operator[](std::string const &a_pid) const
ChemicalElement(HAPI::Node const &a_node)
std::string const & symbol() const
Definition GIDI.hpp:2963
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
ChemicalElement const * operator[](std::string const &a_symbol) const
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
void initialize(HAPI::Node const &a_node)
double atomFraction() const
Definition GIDI.hpp:2937
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Nuclide(HAPI::Node const &a_node)
std::string const & pid() const
Definition GIDI.hpp:2936
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
void parseEvaluatedTargetInfo(HAPI::Node const &a_node)
std::string const & moniker() const
Definition GUPI.hpp:102
Ancestry(std::string const &a_moniker, std::string const &a_attribute="")
std::string attribute() const
Definition GUPI.hpp:107
Entry(std::string const &a_moniker, std::string const &a_keyName, std::string const &a_keyValue)
Definition GUPI_entry.cc:25
void addNodeStarterEnder(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:57
void addNodeEnder(std::string const &a_moniker)
Definition GUPI.hpp:59
std::string incrementalIndent(std::string const &indent)
Definition GUPI.hpp:52
void addNodeStarter(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:55
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
Definition GUPI.hpp:60
Node child(const char *name) const
Definition HAPI_Node.cc:72
Definition GIDI.hpp:32
Definition GUPI.hpp:20
std::string doubleToShortestString(double a_value, int a_significantDigits=15, int a_favorEFormBy=0)
Definition LUPI_misc.cc:349