Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_axes.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 Axes
16 * Represents a **GNDS axes** node. An axes is a list of Axis and/or Grid nodes. An axes contains a list of *N* independent axis and/or grid nodes,
17 * and a dependent axis node. The dimension of an axes is the number of independent nodes.
18 */
19
20/* *********************************************************************************************************//**
21 ***********************************************************************************************************/
22
28
29/* *********************************************************************************************************//**
30 *
31 * @param a_node [in] The **HAPI::Node** to be parsed and used to construct the Axes.
32 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
33 * @param a_useSystem_strtod [in] Flag passed to the function nfu_stringToListOfDoubles.
34 ***********************************************************************************************************/
35
36Axes::Axes( HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_useSystem_strtod ) :
37 Form( a_node, a_setupInfo, FormType::axes ) {
38
39 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
40 std::string name( child.name( ) );
41
42 if( name == GIDI_axisChars ) {
43 m_axes.push_back( new Axis( child, a_setupInfo ) ); }
44 else if( name == GIDI_gridChars ) {
45 m_axes.push_back( new Grid( child, a_setupInfo, a_useSystem_strtod ) ); }
46 else {
47 throw Exception( "unknown axes sub-element" );
48 }
49 }
50}
51
52/* *********************************************************************************************************//**
53 * Copy constructor for the Axes class.
54 *
55 * @param a_axes [in] The Axes instance to copy.
56 ***********************************************************************************************************/
57
58Axes::Axes( Axes const &a_axes ) :
59 Form( a_axes ) {
60
61 for( std::size_t i1 = 0; i1 < a_axes.size( ); ++i1 ) {
62 Axis const *axis = a_axes[i1];
63
64 if( axis->type( ) == FormType::axis ) {
65 m_axes.push_back( new Axis( *axis ) ); }
66 else {
67 m_axes.push_back( new Grid( static_cast<Grid const &>( *axis ) ) );
68 }
69 }
70}
71
72/* *********************************************************************************************************//**
73 ***********************************************************************************************************/
74
76
77 for( std::size_t i1 = 0; i1 < m_axes.size( ); ++i1 ) delete m_axes[i1];
78}
79
80/* *********************************************************************************************************//**
81 * The assignment operator. This method sets the members of *this* to those of *a_rhs* except for those
82 * not set by base classes.
83 *
84 * @param a_rhs [in] Instance whose member are used to set the members of *this*.
85 ***********************************************************************************************************/
86
87Axes &Axes::operator=( Axes const &a_rhs ) {
88
89 if( this != &a_rhs ) {
90 Form::operator=( a_rhs );
91
92 for( std::size_t index = 0; index < a_rhs.size( ); ++index ) {
93 auto axis = a_rhs[index];
94 if( axis->type( ) == FormType::axis ) {
95 m_axes.push_back( new Axis( *axis ) ); }
96 else {
97 Grid const *grid = static_cast<Grid const *>( axis );
98 m_axes.push_back( new Grid( *grid ) );
99 }
100 }
101 }
102
103 return( *this );
104}
105
106/* *********************************************************************************************************//**
107 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
108 *
109 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
110 * @param a_indent [in] The amount to indent *this* node.
111 ***********************************************************************************************************/
112
113void Axes::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
114
115 if( m_axes.size( ) == 0 ) return;
116
117 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
118
119 a_writeInfo.addNodeStarter( a_indent, moniker( ), "" );
120 for( std::vector<Axis *>::const_iterator iter = m_axes.begin( ); iter != m_axes.end( ); ++iter ) (*iter)->toXMLList( a_writeInfo, indent2 );
121 a_writeInfo.addNodeEnder( moniker( ) );
122}
123
124/* *********************************************************************************************************//**
125 * This is a factory function for the Axes class that creates an Axes instance whose axis data are taken from the
126 * *a_labelsAndUnits* argument. The number of Axis instances created is the size() of *a_labelsAndUnits*. Each
127 * item of *a_labelsAndUnits* specifies the label and unit for an Axis instance.
128 *
129 * @param a_labelsAndUnits [in] The list of labels and units for each axis.
130 ***********************************************************************************************************/
131
132Axes Axes::makeAxes( std::vector<std::pair<std::string, std::string>> const &a_labelsAndUnits ) {
133
134 int index = 0;
135 Axes axes = Axes( );
136
137 for( auto labelAndUnit = a_labelsAndUnits.begin( ); labelAndUnit != a_labelsAndUnits.end( ); ++labelAndUnit, ++index ) {
138 axes.append( new Axis( index, labelAndUnit->first, labelAndUnit->second ) );
139 }
140
141 return( axes );
142}
143
144}
#define GIDI_gridChars
Definition GIDI.hpp:384
#define GIDI_axesChars
Definition GIDI.hpp:382
static Axes makeAxes(std::vector< std::pair< std::string, std::string > > const &a_labelsAndUnits)
Definition GIDI_axes.cc:132
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_axes.cc:113
Axes & operator=(Axes const &a_rhs)
Definition GIDI_axes.cc:87
std::size_t size() const
Definition GIDI.hpp:872
Form & operator=(Form const &a_rhs)
Definition GIDI_form.cc:93
Form(FormType a_type)
Definition GIDI_form.cc:25
void setMoniker(std::string const &a_moniker)
Definition GUPI.hpp:103
std::string const & moniker() const
Definition GUPI.hpp:102
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
bool empty() const
Definition HAPI_Node.cc:150
Node first_child() const
Definition HAPI_Node.cc:82
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668