Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_group.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 Group
16 * Class for the GNDS <**group**> node that resides under the <**transportable**> node.
17 */
18
19/* *********************************************************************************************************//**
20 * @param a_construction [in] Used to pass user options to the constructor.
21 * @param a_node [in] The **HAPI::Node** to be parsed to construct a Group instance.
22 * @param a_setupInfo [in] Information create my the Protare constructor to help in parsing.
23 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
24 ***********************************************************************************************************/
25
26Group::Group( Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, LUPI_maybeUnused PoPI::Database const &a_pops ) :
27 Form( a_node, a_setupInfo, FormType::group ),
28 m_grid( a_node.child( GIDI_gridChars ), a_setupInfo, a_construction.useSystem_strtod( ) ) {
29
30}
31
32/* *********************************************************************************************************//**
33 * Copy constructor.
34 *
35 * @param a_group [in] Group instance to copy.
36 ***********************************************************************************************************/
37
38Group::Group( Group const &a_group ) :
39 Form( a_group ),
40 m_grid( a_group.grid( ) ) {
41
42}
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 Group::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
52
53 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
54
55 a_writeInfo.addNodeStarter( a_indent, moniker( ), a_writeInfo.addAttribute( GIDI_labelChars, label( ) ) );
56 m_grid.toXMLList( a_writeInfo, indent2 );
57 a_writeInfo.addNodeEnder( moniker( ) );
58}
59
60/*! \class Groups
61 * Class for the GNDS <**groups**> node that contains a list of <**group**> nodes.
62 */
63
64/* *********************************************************************************************************//**
65 ***********************************************************************************************************/
66
71
72/* *********************************************************************************************************//**
73 * @param a_fileName [in] File containing a groups node to be parsed.
74 ***********************************************************************************************************/
75
76Groups::Groups( std::string const &a_fileName ) :
78
79 addFile( a_fileName );
80}
81
82/* *********************************************************************************************************//**
83 * Adds the contents of the specified file to *this*.
84 *
85 * @param a_fileName [in] File containing a groups node to be parsed.
86 ***********************************************************************************************************/
87
88void Groups::addFile( std::string const &a_fileName ) {
89
90 HAPI::File *doc = new HAPI::PugiXMLFile( a_fileName.c_str( ), "Groups::addFile" );
91
93
94 std::string name( groups.name( ) );
95 if( name != GIDI_groupsChars ) throw Exception( "Invalid groups node file: file node name is '" + name + "'." );
96
99
100 SetupInfo setupInfo( nullptr );
101
102 std::string formatVersionString = groups.attribute_as_string( GIDI_formatChars );
103 if( formatVersionString == "" ) formatVersionString = GNDS_formatVersion_1_10Chars;
104 LUPI::FormatVersion formatVersion;
105 formatVersion.setFormat( formatVersionString );
106 if( !formatVersion.supported( ) ) throw Exception( "Unsupport GND format version" + formatVersionString );
107 setupInfo.m_formatVersion = formatVersion;
108
109 for( HAPI::Node child = groups.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
110 Group *group = new Group( construction, child, setupInfo, pops );
111
112 add( group );
113 }
114 delete doc;
115}
116
117}
#define GIDI_gridChars
Definition GIDI.hpp:384
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_groupsChars
Definition GIDI.hpp:236
#define GIDI_formatChars
Definition GIDI.hpp:167
#define GNDS_formatVersion_1_10Chars
Definition LUPI.hpp:48
#define LUPI_maybeUnused
std::string const & label() const
Definition GIDI.hpp:658
Form(FormType a_type)
Definition GIDI_form.cc:25
Grid const & grid() const
Definition GIDI.hpp:2893
Group(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, PoPI::Database const &a_pops)
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent) const
Definition GIDI_group.cc:51
void addFile(std::string const &a_fileName)
Definition GIDI_group.cc:88
LUPI::FormatVersion m_formatVersion
Definition GIDI.hpp:599
Suite(std::string const &a_keyName=GIDI_labelChars)
Definition GIDI_suite.cc:22
void add(Form *a_form)
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
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
Definition GUPI.hpp:60
virtual Node first_child()=0
bool empty() const
Definition HAPI_Node.cc:150
Node first_child() const
Definition HAPI_Node.cc:82
bool setFormat(std::string const &a_formatVersion)
Definition GIDI.hpp:32
FormType
Definition GIDI.hpp:118