28static std::vector<std::size_t> parseArrayShape( HAPI::Node
const &a_node ) {
31 std::vector<std::size_t> shapeInts;
34 for(
auto iter = shapeItems.begin( ); iter != shapeItems.end( ); ++iter ) {
35 shapeInts.push_back(
static_cast<std::size_t
>( atoi( (*iter).c_str( ) ) ) );
57 for(
auto iter = a_shape.begin( ); iter != a_shape.end( ); ++iter )
size *= *iter;
68FullArray::FullArray( std::vector<std::size_t>
const &a_shape, std::vector<double>
const &a_flattenedValues ) :
72 for(
auto iter = a_shape.begin( ); iter != a_shape.end( ); ++iter )
size *= *iter;
74 if(
size !=
static_cast<std::size_t
>( a_flattenedValues.size( ) ) )
throw Exception(
"FullArray::FullArray: a_shape and a_flattenedValues are not the same size." );
77 for( std::size_t index = 0; index <
size; ++index )
m_flattenedValues[index] = a_flattenedValues[index];
92 m_shape( parseArrayShape( a_node ) ),
102 std::string name( child.name( ) );
118 throw Exception(
"Invalid values' label '" + label1 +
"'." );
123 std::string name( child.name( ) );
124 if( name !=
GIDI_arrayChars )
throw Exception(
"For 'embedded' array, child node not 'array' but '" + name +
"'." );
126 m_array.push_back(
new Array( child, a_setupInfo, a_useSystem_strtod ) );
136 for(
auto iter = m_array.begin( ); iter != m_array.end( ); ++iter )
delete *iter;
147 std::size_t size1 = 1;
148 for(
auto iter = m_shape.begin( ); iter != m_shape.end( ); ++iter ) size1 *= *iter;
162 std::vector<double> values(
size( ) );
165 values = m_values.vector( ); }
167 throw Exception(
"Array::constructArray: compression '" + m_compression +
"' not supported." ); }
169 std::size_t index = 0;
170 for( std::size_t index1 = 0; index1 < m_starts.size( ); ++index1 ) {
171 std::size_t length =
static_cast<std::size_t
>( m_length[index1] );
172 std::size_t start =
static_cast<std::size_t
>( m_starts[index1] );
174 for( std::size_t index2 = 0; index2 < length; ++index2, ++index ) values[start+index2] = m_values[index];
177 throw Exception(
"Array::constructArray: compression '" + m_compression +
"' not supported." );
213 std::size_t size = (std::size_t) arrayData.
m_shape[0];
216 std::size_t n1 = 0, n2 = size;
219 for( int32_t i2 = 0; i2 < arrayData.
m_lengths[i1]; ++i2, ++n1, ++
offset ) {
220 if( n1 >= arrayData.
m_dValues.size( ) )
throw Exception(
"Too many values in flattened array." );
244 bool m_dValuesPresent(
false );
248 for(
auto iter = shapeItems.begin( ); iter != shapeItems.end( ); ++iter ) {
249 m_shape.push_back(
static_cast<std::size_t
>( atoi( (*iter).c_str( ) ) ) );
252 if( a_dimensions != (
int)
m_shape.size( ) )
throw Exception(
"a_dimensions != m_shape.size( )" );
255 std::string name( child.name( ) );
265 else if(
label ==
"" ) {
266 m_dValuesPresent =
true;
269 throw Exception(
"unknown label for flatteded array sub-element" );
272 throw Exception(
"unknown flattened array sub-element" );
275 if(
m_starts.data() ==
nullptr )
throw Exception(
"array missing starts element" );
277 if( !m_dValuesPresent )
throw Exception(
"array missing dValues element" );
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 );
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] );
309 if( ( start + length ) > a_end ) {
310 if( a_end < start )
break;
311 length = a_end - start;
313 numberOfValuesToSet += length;
316 for(
long index = 0; index < numberOfValuesToSet; ++index )
m_dValues[index] = 0.0;
329 std::vector<int> ints;
331 std::string shapeString;
332 std::string sep =
"";
333 for( std::size_t i1 = 0; i1 <
m_shape.size( ); ++i1 ) {
343 intsToXMLList( a_writeInfo, indent2, ints,
" valueType=\"Integer32\" label=\"starts\"" );
347 intsToXMLList( a_writeInfo, indent2, ints,
" valueType=\"Integer32\" label=\"lengths\"" );
G4ThreadLocal T * G4GeomSplitter< T >::offset
#define GIDI_startingIndices
#define GIDI_permutationChars
#define GIDI_diagonalChars
#define GIDI_storageOrderChars
#define GIDI_symmetryChars
#define GIDI_flattenedChars
#define GIDI_compressionChars
#define GIDI_lengthsChars
FullArray constructArray() const
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent) const
Array(HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_useSystem_strtod)
std::vector< std::size_t > m_shape
FullArray(std::vector< std::size_t > const &a_shape)
std::vector< double > m_flattenedValues
int useSystem_strtod() const
std::vector< std::size_t > const & shape() const
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent) const
FlattenedArrayData(HAPI::Node const &a_node, SetupInfo &a_setupInfo, int a_dimensions, int a_useSystem_strtod)
nf_Buffer< int > m_starts
nf_Buffer< int > m_lengths
std::size_t m_numberOfStarts
std::size_t m_numberOfLengths
nf_Buffer< double > m_dValues
std::vector< std::size_t > m_shape
void setToValueInFlatRange(std::size_t a_start, std::size_t a_end, double a_value)
void resize(std::size_t a_number, double a_value=0.0)
std::string const & moniker() const
void addNodeEnder(std::string const &a_moniker)
std::string incrementalIndent(std::string const &indent)
void addNodeStarter(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
std::string addAttribute(std::string const &a_name, std::string const &a_value) const
std::string attribute_as_string(const char *a_name) const
void parseValuesOfDoubles(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, nf_Buffer< double > &a_vector)
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="")
void intsToXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent, std::vector< int > const &a_values, std::string const &a_attributes)
void parseValuesOfInts(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, std::vector< int > &a_vector)
int parseFlattened1d(Construction::Settings const &a_construction, HAPI::Node const &a_node, SetupInfo &a_setupInfo, Vector &data)
std::string intToString(int a_value)
std::vector< std::string > splitString(std::string const &a_string, char a_delimiter, bool a_strip=false)