Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI::FlattenedArrayData Class Reference

#include <GIDI.hpp>

Inheritance diagram for GIDI::FlattenedArrayData:

Public Member Functions

 FlattenedArrayData (HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_dimensions, int a_useSystem_strtod)
 ~FlattenedArrayData ()
std::vector< std::size_t > const & shape () const
void setToValueInFlatRange (std::size_t a_start, std::size_t a_end, double a_value)
void toXMLList (GUPI::WriteInfo &a_writeInfo, std::string const &a_indent) const
Public Member Functions inherited from GIDI::Form
 Form (FormType a_type)
 Form (std::string const &a_moniker, FormType a_type, std::string const &a_label)
 Form (HAPI::Node const &a_node, SetupInfo &a_setupInfo, FormType a_type, Suite *a_suite=nullptr)
 Form (Form const &a_form)
virtual ~Form ()
Formoperator= (Form const &a_rhs)
Suiteparent () const
std::string const & label () const
void setLabel (std::string const &a_label)
virtual std::string actualMoniker () const
std::string const & keyName () const
void setKeyName (std::string const &a_keyName)
std::string const & keyValue () const
virtual void setKeyValue (std::string const &a_keyName) const
FormType type () const
Form const * sibling (std::string a_label) const
GUPI::AncestryfindInAncestry3 (LUPI_maybeUnused std::string const &a_item)
GUPI::Ancestry const * findInAncestry3 (LUPI_maybeUnused std::string const &a_item) const
std::string xlinkItemKey () const
Public Member Functions inherited from GUPI::Ancestry
 Ancestry (std::string const &a_moniker, std::string const &a_attribute="")
virtual ~Ancestry ()
Ancestryoperator= (Ancestry const &a_ancestry)
std::string const & moniker () const
void setMoniker (std::string const &a_moniker)
Ancestryancestor ()
Ancestry const * ancestor () const
void setAncestor (Ancestry *a_ancestor)
std::string attribute () const
Ancestryroot ()
Ancestry const * root () const
bool isChild (Ancestry *a_instance)
bool isParent (Ancestry *a_parent)
bool isRoot () const
AncestryfindInAncestry (std::string const &a_href)
Ancestry const * findInAncestry (std::string const &a_href) const
virtual AncestryfindInAncestry3 (std::string const &a_item)=0
virtual Ancestry const * findInAncestry3 (std::string const &a_item) const =0
virtual LUPI_HOST void serialize (LUPI::DataBuffer &a_buffer, LUPI::DataBuffer::Mode a_mode)
std::string toXLink () const
void printXML () const

Public Attributes

std::vector< std::size_t > m_shape
std::size_t m_numberOfStarts
std::size_t m_numberOfLengths
nf_Buffer< int > m_starts
nf_Buffer< int > m_lengths
nf_Buffer< double > m_dValues

Additional Inherited Members

Static Public Member Functions inherited from GUPI::Ancestry
static std::string buildXLinkItemKey (std::string const &a_name, std::string const &a_key)

Detailed Description

Definition at line 942 of file GIDI.hpp.

Constructor & Destructor Documentation

◆ FlattenedArrayData()

GIDI::FlattenedArrayData::FlattenedArrayData ( HAPI::Node const & a_node,
SetupInfo & a_setupInfo,
int a_dimensions,
int a_useSystem_strtod )

Function to parse a flattened array of dimension a_dimensions.

Parameters
a_node[in] The HAPI::Node to be parsed.
a_setupInfo[in] Information create my the Protare constructor to help in parsing.
a_dimensions[in] The dimension of the flattened array to be parsed.
a_useSystem_strtod[in] Flag passed to the function nfu_stringToListOfDoubles.

Definition at line 237 of file GIDI_arrays.cc.

237 :
238 Form( a_node, a_setupInfo, FormType::flattenedArrayData ),
239 m_numberOfStarts( 0 ),
241 m_starts( ),
242 m_lengths( ) {
243
244 bool m_dValuesPresent( false );
245
246 std::string shape( a_node.attribute_as_string( GIDI_shapeChars ) );
247 auto shapeItems = LUPI::Misc::splitString( shape, ',', true );
248 for( auto iter = shapeItems.begin( ); iter != shapeItems.end( ); ++iter ) {
249 m_shape.push_back( static_cast<std::size_t>( atoi( (*iter).c_str( ) ) ) );
250 }
251
252 if( a_dimensions != (int) m_shape.size( ) ) throw Exception( "a_dimensions != m_shape.size( )" );
253
254 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
255 std::string name( child.name( ) );
256
257 if( name == GIDI_valuesChars ) {
258 std::string label( child.attribute_as_string( GIDI_labelChars ) );
259 if( label == GIDI_startsChars ) {
260 parseValuesOfInts( child, a_setupInfo, m_starts );
261 m_numberOfStarts = (std::size_t) m_starts.size(); }
262 else if( label == GIDI_lengthsChars ) {
263 parseValuesOfInts( child, a_setupInfo, m_lengths );
264 m_numberOfLengths = (std::size_t) m_lengths.size(); }
265 else if( label == "" ) {
266 m_dValuesPresent = true;
267 parseValuesOfDoubles( child, a_setupInfo, m_dValues, a_useSystem_strtod ); }
268 else {
269 throw Exception( "unknown label for flatteded array sub-element" );
270 } }
271 else {
272 throw Exception( "unknown flattened array sub-element" );
273 }
274 }
275 if( m_starts.data() == nullptr ) throw Exception( "array missing starts element" );
276 if( m_lengths.data() == nullptr ) throw Exception( "array missing lengths element" );
277 if( !m_dValuesPresent ) throw Exception( "array missing dValues element" );
278 if( m_numberOfStarts != m_numberOfLengths ) throw Exception( "m_numberOfStarts != m_numberOfLengths for array" );
279}
#define GIDI_valuesChars
Definition GIDI.hpp:260
#define GIDI_labelChars
Definition GIDI.hpp:438
#define GIDI_shapeChars
Definition GIDI.hpp:261
#define GIDI_startsChars
Definition GIDI.hpp:267
#define GIDI_lengthsChars
Definition GIDI.hpp:268
std::vector< std::size_t > const & shape() const
Definition GIDI.hpp:955
nf_Buffer< int > m_starts
Definition GIDI.hpp:948
nf_Buffer< int > m_lengths
Definition GIDI.hpp:949
std::size_t m_numberOfStarts
Definition GIDI.hpp:946
std::size_t m_numberOfLengths
Definition GIDI.hpp:947
nf_Buffer< double > m_dValues
Definition GIDI.hpp:950
std::vector< std::size_t > m_shape
Definition GIDI.hpp:945
std::string const & label() const
Definition GIDI.hpp:658
Form(FormType a_type)
Definition GIDI_form.cc:25
const char * name(G4int ptype)
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
@ flattenedArrayData
Definition GIDI.hpp:121
void parseValuesOfInts(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, std::vector< int > &a_vector)
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)
Definition LUPI_misc.cc:103

◆ ~FlattenedArrayData()

GIDI::FlattenedArrayData::~FlattenedArrayData ( )

Definition at line 284 of file GIDI_arrays.cc.

284 {
285
286// smr_freeMemory2( m_starts );
287// smr_freeMemory2( m_lengths );
288}

Member Function Documentation

◆ setToValueInFlatRange()

void GIDI::FlattenedArrayData::setToValueInFlatRange ( std::size_t a_start,
std::size_t a_end,
double a_value )

Sets all elements in the range [a_start,a_end) to a_value.

Parameters
a_start[in] The starting flat-cell index of this to fill with a_value.
a_end[in] One after the last flat-cell index of this to fill with a_value.
a_value[in] The value to set each double in the range to.

Definition at line 298 of file GIDI_arrays.cc.

298 {
299
300 std::size_t size = 1;
301 for( auto iter = m_shape.begin( ); iter != m_shape.end( ); ++iter ) size *= *iter;
302 a_end = std::min( a_end, size );
303
304 long numberOfValuesToSet = 0;
305 for( std::size_t startIndex = 0; startIndex < m_numberOfStarts; ++startIndex ) {
306 std::size_t start = static_cast<std::size_t>( m_starts[startIndex] );
307 std::size_t length = static_cast<std::size_t>( m_lengths[startIndex] );
308
309 if( ( start + length ) > a_end ) {
310 if( a_end < start ) break;
311 length = a_end - start;
312 }
313 numberOfValuesToSet += length;
314 }
315
316 for( long index = 0; index < numberOfValuesToSet; ++index ) m_dValues[index] = 0.0;
317}

◆ shape()

std::vector< std::size_t > const & GIDI::FlattenedArrayData::shape ( ) const
inline

Definition at line 955 of file GIDI.hpp.

955{ return( m_shape ); }

Referenced by FlattenedArrayData().

◆ toXMLList()

void GIDI::FlattenedArrayData::toXMLList ( GUPI::WriteInfo & a_writeInfo,
std::string const & a_indent ) const
virtual

Fills the argument a_writeInfo with the XML lines that represent this. Recursively enters each sub-node.

Parameters
a_writeInfo[in/out] Instance containing incremental indentation and other information and stores the appended lines.
a_indent[in] The amount to indent this node.

Reimplemented from GUPI::Ancestry.

Definition at line 326 of file GIDI_arrays.cc.

326 {
327
328 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
329 std::vector<int> ints;
330
331 std::string shapeString;
332 std::string sep = "";
333 for( std::size_t i1 = 0; i1 < m_shape.size( ); ++i1 ) {
334 shapeString += sep + intToString( static_cast<int>( m_shape[i1] ) );
335 sep = ",";
336 }
337
338 std::string attributes = a_writeInfo.addAttribute( GIDI_shapeChars, shapeString ) + a_writeInfo.addAttribute( "compression", "flattened" );
339
340 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
341
342 for( std::size_t i1 = 0; i1 < m_numberOfStarts; ++i1 ) ints.push_back( m_starts[i1] );
343 intsToXMLList( a_writeInfo, indent2, ints, " valueType=\"Integer32\" label=\"starts\"" );
344
345 ints.clear( );
346 for( std::size_t i1 = 0; i1 < m_numberOfLengths; ++i1 ) ints.push_back( m_lengths[i1] );
347 intsToXMLList( a_writeInfo, indent2, ints, " valueType=\"Integer32\" label=\"lengths\"" );
348
349 doublesToXMLList( a_writeInfo, indent2, m_dValues.vector() );
350 a_writeInfo.addNodeEnder( moniker( ) );
351}
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
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
void intsToXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, std::vector< int > const &a_values, std::string const &a_attributes)
Definition GIDI_misc.cc:63
std::string intToString(int a_value)
Definition GIDI_misc.cc:415

Member Data Documentation

◆ m_dValues

nf_Buffer<double> GIDI::FlattenedArrayData::m_dValues

The given array data.

Definition at line 950 of file GIDI.hpp.

Referenced by FlattenedArrayData(), GIDI::parseFlattened1d(), setToValueInFlatRange(), and toXMLList().

◆ m_lengths

nf_Buffer<int> GIDI::FlattenedArrayData::m_lengths

The length values.

Definition at line 949 of file GIDI.hpp.

Referenced by FlattenedArrayData(), GIDI::parseFlattened1d(), setToValueInFlatRange(), and toXMLList().

◆ m_numberOfLengths

std::size_t GIDI::FlattenedArrayData::m_numberOfLengths

The number of length values.

Definition at line 947 of file GIDI.hpp.

Referenced by FlattenedArrayData(), and toXMLList().

◆ m_numberOfStarts

std::size_t GIDI::FlattenedArrayData::m_numberOfStarts

The number of start values.

Definition at line 946 of file GIDI.hpp.

Referenced by FlattenedArrayData(), GIDI::parseFlattened1d(), setToValueInFlatRange(), and toXMLList().

◆ m_shape

std::vector<std::size_t> GIDI::FlattenedArrayData::m_shape

The shape of the flattened array.

Definition at line 945 of file GIDI.hpp.

Referenced by FlattenedArrayData(), GIDI::parseFlattened1d(), setToValueInFlatRange(), shape(), and toXMLList().

◆ m_starts

nf_Buffer<int> GIDI::FlattenedArrayData::m_starts

The start values.

Definition at line 948 of file GIDI.hpp.

Referenced by FlattenedArrayData(), GIDI::parseFlattened1d(), setToValueInFlatRange(), and toXMLList().


The documentation for this class was generated from the following files: