Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_grid.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 "GIDI.hpp"
11#include <HAPI.hpp>
12
13namespace GIDI {
14
15/*! \class Grid
16 * Class to store a **GNDS grid** node.
17 */
18
19/* *********************************************************************************************************//**
20 *
21 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the Grid.
22 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
23 * @param a_useSystem_strtod [in] Flag passed to the function nfu_stringToListOfDoubles.
24 ***********************************************************************************************************/
25
26Grid::Grid( HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_useSystem_strtod ) :
27 Axis( a_node, a_setupInfo, FormType::grid ),
28 m_style( a_node.attribute_as_string( GIDI_styleChars ) ),
29 m_keyName( GIDI_indexChars ),
30 m_keyValue( a_node.attribute_as_string( GIDI_indexChars ) ),
31 m_interpolation( a_node.attribute_as_string( GIDI_interpolationChars ) ) {
32
33 if( href( ) == "" ) {
34 HAPI::Node values = a_node.first_child( );
35 if( values.name( ) != std::string( GIDI_valuesChars ) ) throw Exception( "grid's first child not values" );
36
37 m_valueType = values.attribute_as_string( GIDI_valueTypeChars );
38
39 parseValuesOfDoubles( values, a_setupInfo, m_values, a_useSystem_strtod );
40 }
41}
42
43/* *********************************************************************************************************//**
44 * Copy constructor for Grid.
45 *
46 * @param a_grid [in] The Grid instance to copy.
47 ***********************************************************************************************************/
48
49Grid::Grid( Grid const &a_grid ) :
50 Axis( a_grid ),
51 m_style( a_grid.style( ) ),
52 m_keyName( a_grid.keyName( ) ),
53 m_keyValue( a_grid.keyValue( ) ),
54 m_valueType( a_grid.valueType( ) ),
55 m_values( a_grid.values( ) ) {
56
57}
58
59/* *********************************************************************************************************//**
60 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
61 *
62 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
63 * @param a_indent [in] The amount to indent *this* node.
64 ***********************************************************************************************************/
65
66void Grid::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
67
68 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
69 std::string attributes = a_writeInfo.addAttribute( GIDI_indexChars, intToString( index( ) ) );
70
71 if( href( ) == "" ) {
72 attributes += a_writeInfo.addAttribute( GIDI_labelChars, label( ) );
73 attributes += a_writeInfo.addAttribute( GIDI_unitChars, unit( ) );
74 attributes += a_writeInfo.addAttribute( GIDI_styleChars, style( ) );
75 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
76 doublesToXMLList( a_writeInfo, indent2, m_values.vector(), 0, true, m_valueType );
77 a_writeInfo.addNodeEnder( moniker( ) ); }
78 else {
79 attributes += a_writeInfo.addAttribute( GIDI_hrefChars, href( ) );
80 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
81 }
82}
83
84}
#define GIDI_hrefChars
Definition GIDI.hpp:440
#define GIDI_valuesChars
Definition GIDI.hpp:260
#define GIDI_unitChars
Definition GIDI.hpp:439
#define GIDI_styleChars
Definition GIDI.hpp:451
#define GIDI_interpolationChars
Definition GIDI.hpp:434
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_indexChars
Definition GIDI.hpp:437
#define GIDI_valueTypeChars
Definition GIDI.hpp:431
std::string const & href() const
Definition GIDI.hpp:815
std::string const & unit() const
Definition GIDI.hpp:813
Axis(HAPI::Node const &a_node, SetupInfo &a_setupInfo, FormType a_type=FormType::axis)
Definition GIDI_axis.cc:42
int index() const
Definition GIDI.hpp:812
std::string const & label() const
Definition GIDI.hpp:658
Grid(HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_useSystem_strtod)
Definition GIDI_grid.cc:26
std::string const & style() const
Definition GIDI.hpp:842
std::string keyName() const
Definition GIDI.hpp:843
std::string keyValue() const
Definition GIDI.hpp:844
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_grid.cc:66
std::string valueType() const
Definition GIDI.hpp:845
nf_Buffer< double > const & values() const
Definition GIDI.hpp:849
std::string const & moniker() const
Definition GUPI.hpp:102
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 first_child() const
Definition HAPI_Node.cc:82
Definition GIDI.hpp:32
void parseValuesOfDoubles(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, nf_Buffer< double > &a_vector)
Definition GIDI_misc.cc:88
FormType
Definition GIDI.hpp:118
void doublesToXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, std::vector< double > const &a_values, std::size_t a_start=0, bool a_newLine=true, std::string const &a_valueType="")
Definition GIDI_misc.cc:180
std::string intToString(int a_value)
Definition GIDI_misc.cc:415