Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
GIDI_map.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 <stdlib.h>
11#include <string.h>
12#include <limits.h>
13
14#include "GIDI.hpp"
15#include <HAPI.hpp>
16
17static std::string GIDI_basePath( char const *a_path );
18static std::string GIDI_basePath( std::string const a_path );
19static std::string GIDI_addPaths( std::string const &a_base, std::string const &a_path );
20
21namespace GIDI {
22
23namespace Map {
24
25/* *********************************************************************************************************//**
26 * Returns the type of file for *a_filename*.
27 *
28 * @param a_filename [in] Path of the file.
29 *
30 * @return A **FileType** instance.
31 ***********************************************************************************************************/
32
33static FileType fileType( std::string const &a_path ) {
34
35 if( a_path.compare( a_path.size( ) - 2, 2, "h5" ) == 0 ) return( GIDI::FileType::HDF );
36 return( GIDI::FileType::XML );
37}
38
39/* *********************************************************************************************************//**
40 * User data passed to the Map::directory method. It stores the desired projectile, target, library and evalaute infomation
41 * as a list of found matches. An empty string for the projectile's id matches all projectiles.
42 * A empty string for the target's id matches all targets. An empty evaluation string matches all evaluations.
43 ***********************************************************************************************************/
44
46
47 public:
48 std::string const &m_projectileID; /**< The desired projectile's id. */
49 std::string const &m_targetID; /**< The desired target's id. */
50 std::string const &m_library; /**< The desired library name. */
51 std::string const &m_evaluation; /**< The desired evaluation id. */
52
53 std::vector<ProtareBase const *> m_protareEntries; /**< list of matched protare entries. */
54
55 /* *********************************************************************************************************//**
56 *
57 * @param a_projectileID [in] The projectile's id to match.
58 * @param a_targetID [in] The target's id to match.
59 * @param a_library [in] The library to match.
60 * @param a_evaluation [in] The evaluation to match.
61 ***********************************************************************************************************/
62
63 MapWalkDirectoryCallbackData( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library, std::string const &a_evaluation ) :
64 m_projectileID( a_projectileID ),
65 m_targetID( a_targetID ),
66 m_library( a_library ),
67 m_evaluation( a_evaluation ) {
68
69 }
70};
71
72/* *********************************************************************************************************//**
73 *
74 * @param a_protareEntry [in] The protare entry to compare to the data protare parameters in *a_data*.
75 * @param a_library [in] The library name of the current map file.
76 * @param a_data [in] A MapWalkDirectoryCallbackData instance.
77 * @param a_level [in] Nested level of *this* map file. For internal use.
78 *
79 * @return Always returns true.
80 ***********************************************************************************************************/
81
82bool MapWalkDirectoryCallback( ProtareBase const *a_protareEntry, std::string const &a_library, void *a_data, LUPI_maybeUnused int a_level ) {
83
84 MapWalkDirectoryCallbackData *mapWalkDirectoryCallbackData = static_cast<MapWalkDirectoryCallbackData *>( a_data );
85
86 if( ( mapWalkDirectoryCallbackData->m_projectileID == "" ) ||
87 PoPI::compareSpecialParticleIDs( mapWalkDirectoryCallbackData->m_projectileID, a_protareEntry->projectileID( ) ) ) {
88 if( ( mapWalkDirectoryCallbackData->m_targetID == "" ) || ( mapWalkDirectoryCallbackData->m_targetID == a_protareEntry->targetID( ) ) ) {
89 if( ( mapWalkDirectoryCallbackData->m_library == "" ) || ( mapWalkDirectoryCallbackData->m_library == a_library ) ) {
90 if( ( mapWalkDirectoryCallbackData->m_evaluation == "" ) || ( mapWalkDirectoryCallbackData->m_evaluation == a_protareEntry->evaluation( ) ) ) {
91 mapWalkDirectoryCallbackData->m_protareEntries.push_back( a_protareEntry );
92 }
93 }
94 }
95 }
96 return( true );
97}
98
99/*! \class BaseEntry
100 * This is the virtual base class inherited by all map entry classes.
101 */
102
103/* *********************************************************************************************************//**
104 *
105 * @param a_node [in] The **HAPI::Node** to be parsed.
106 * @param a_basePath [in] A path prepended to this entry's path.
107 * @param a_parent [in] Pointer to the *Map* containing *this*.
108 ***********************************************************************************************************/
109
110BaseEntry::BaseEntry( HAPI::Node const &a_node, std::string const &a_basePath, Map const *a_parent ) :
111 GUPI::Ancestry( a_node.name( ) ),
112 m_name( a_node.name( ) ),
113 m_parent( a_parent ),
114 m_path( a_node.attribute_as_string( GIDI_pathChars ) ),
115 m_cumulativePath( GIDI_addPaths( a_basePath, m_path ) ) {
116
117}
118
119/* *********************************************************************************************************//**
120 ***********************************************************************************************************/
121
125
126/* *********************************************************************************************************//**
127 * Returns either the *entered*, *cumulative* or *realPath* path for the entry.
128 *
129 * @param a_form [in] The type of path to return.
130 * @return The requested path.
131 ***********************************************************************************************************/
132
133std::string BaseEntry::path( PathForm a_form ) const {
134
135 if( a_form == PathForm::entered ) return( m_path );
136 if( a_form == PathForm::cumulative ) return( m_cumulativePath );
137 return( LUPI::FileInfo::realPath( m_cumulativePath ) );
138}
139
140/* *********************************************************************************************************//**
141 * Fills *a_libraries* with the name of all the libraries *this* is contained in. The first library in the list is the
142 * library *this* is defined in and the last is the starting library.
143 *
144 * @param a_libraries [out] The instances that is filled with the library names.
145 ***********************************************************************************************************/
146
147void BaseEntry::libraries( std::vector<std::string> &a_libraries ) const {
148
149 parent( )->libraries( a_libraries );
150}
151
152/* *********************************************************************************************************//**
153 *
154 * @param a_node [in] The **HAPI::Node** to be parsed to contruct a Import instance.
155 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
156 * @param a_basePath [in] A path prepended to this entry's path.
157 * @param a_parent [in] Pointer to the *Map* containing *this*.
158 ***********************************************************************************************************/
159
160Import::Import( HAPI::Node const &a_node, PoPI::Database const &a_pops, std::string const &a_basePath, Map const *a_parent ) :
161 BaseEntry( a_node, a_basePath, a_parent ),
162 m_map( nullptr ) {
163
164 m_map = new Map( path( BaseEntry::PathForm::cumulative ), a_pops, a_parent );
165}
166
167/* *********************************************************************************************************//**
168 ***********************************************************************************************************/
169
171
172 delete m_map;
173}
174
175/* *********************************************************************************************************//**
176 * Returns the Protare entry to the first protare to match *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation*. If
177 * *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are matched.
178 *
179 * @param a_projectileID [in] The projectile's id to match.
180 * @param a_targetID [in] The target's id to match.
181 * @param a_library [in] The library to match.
182 * @param a_evaluation [in] The evaluation to match.
183 *
184 * @return The const pointer **ProtareBase** for the matched protare.
185 ***********************************************************************************************************/
186
187ProtareBase const *Import::findProtareEntry( std::string const &a_projectileID, std::string const &a_targetID,
188 std::string const &a_library, std::string const &a_evaluation ) const {
189
190 return( m_map->findProtareEntry( a_projectileID, a_targetID, a_library, a_evaluation ) );
191}
192
193/* *********************************************************************************************************//**
194 * Returns the list of all Protare entries that match *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation*.
195 * The arguments *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation* can be an C++ regex string. An empty
196 * string for any of the arguments will match all.
197 *
198 * @param a_protareEntries [out] The list of **ProtareBase** found.
199 * @param a_projectileID [in] The projectile's id to match.
200 * @param a_targetID [in] The target's id to match.
201 * @param a_library [in] The library to match.
202 * @param a_evaluation [in] The evaluation to match.
203 ***********************************************************************************************************/
204
205void Import::findProtareEntries( std::vector<ProtareBase const *> &a_protareEntries, std::regex const &a_projectileID,
206 std::regex const &a_targetID, std::regex const &a_library, std::regex const &a_evaluation ) const {
207
208 return( m_map->findProtareEntries( a_protareEntries, a_projectileID, a_targetID, a_library, a_evaluation ) );
209}
210
211/* *********************************************************************************************************//**
212 * Returns the path to the first protare to match *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation*. If
213 * *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are matched.
214 *
215 * @param a_projectileID [in] The projectile's id to match.
216 * @param a_targetID [in] The target's id to match.
217 * @param a_library [in] The library to match.
218 * @param a_evaluation [in] The evaluation to match.
219 * @param a_form [in] Determines the form of the path returned.
220 *
221 * @return The path to the matched protare.
222 ***********************************************************************************************************/
223
224std::string Import::protareFilename( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library,
225 std::string const &a_evaluation, PathForm a_form ) const {
226
227 return( m_map->protareFilename( a_projectileID, a_targetID, a_library, a_evaluation, a_form ) );
228}
229
230/* *********************************************************************************************************//**
231 * Returns a list of all evaluations with a match to *a_projectileID* and *a_targetID*.
232 *
233 * @param a_projectileID [in] The projectile's id to match.
234 * @param a_targetID [in] The target's id to match.
235 * @return List of evaluations.
236 ***********************************************************************************************************/
237
238std::vector<std::string> Import::availableEvaluations( std::string const &a_projectileID, std::string const &a_targetID ) const {
239
240 return( m_map->availableEvaluations( a_projectileID, a_targetID ) );
241}
242
243/* *********************************************************************************************************//**
244 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
245 *
246 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
247 * @param a_indent [in] The amount to indent *this* node.
248 ***********************************************************************************************************/
249
250void Import::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
251
252 std::string attributes;
253
254 attributes = a_writeInfo.addAttribute( GIDI_pathChars, path( ) );
255 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
256}
257
258/* *********************************************************************************************************//**
259 * @param a_node [in] The **HAPI::Node** to be parsed.
260 * @param a_basePath [in] A path prepended to this entry's path.
261 * @param a_parent [in] Pointer to the *Map* containing *this*.
262 ***********************************************************************************************************/
263
264ProtareBase::ProtareBase( HAPI::Node const &a_node, std::string const &a_basePath, Map const *const a_parent ) :
265 BaseEntry( a_node, a_basePath, a_parent ),
266 m_projectileID( a_node.attribute_as_string( GIDI_projectileChars ) ),
267 m_targetID( a_node.attribute_as_string( GIDI_targetChars ) ),
268 m_evaluation( a_node.attribute_as_string( GIDI_evaluationChars ) ),
269 m_interaction( a_node.attribute_as_string( GIDI_interactionChars ) ) {
270
271}
272
273/* *********************************************************************************************************//**
274 ***********************************************************************************************************/
275
279
280/* *********************************************************************************************************//**
281 * Returns the library *this* is contained in.
282 ***********************************************************************************************************/
283
284std::string const &ProtareBase::library( ) const {
285
286 return( parent( )->library( ) );
287}
288
289/* *********************************************************************************************************//**
290 * Returns the resolved library *this* is contained in.
291 ***********************************************************************************************************/
292
293std::string const &ProtareBase::resolvedLibrary( ) const {
294
295 return( parent( )->resolvedLibrary( ) );
296}
297
298/* *********************************************************************************************************//**
299 * Compares *a_projectileID*, *a_targetID* and *a_evaluation* to *this* data and returns true if they match
300 * and false otherwise. If *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are compared.
301 *
302 * @param a_projectileID [in] The projectile's id to match.
303 * @param a_targetID [in] The target's id to match.
304 * @param a_library [in] The library to match.
305 * @param a_evaluation [in] The evaluation to match.
306 *
307 * @return The *this* pointer if *this* matches otherwise a **nullptr**.
308 ***********************************************************************************************************/
309
310ProtareBase const *ProtareBase::findProtareEntry( std::string const &a_projectileID, std::string const &a_targetID,
311 std::string const &a_library, std::string const &a_evaluation ) const {
312
313 if( !PoPI::compareSpecialParticleIDs( a_projectileID, projectileID( ) ) ) return( nullptr );
314 if( a_targetID != targetID( ) ) return( nullptr );
315 if( ( a_library != "" ) && ( parent( )->library( ) != a_library ) ) return( nullptr );
316 if( ( a_evaluation == "" ) || ( a_evaluation == evaluation( ) ) ) return( this );
317 return( nullptr );
318}
319
320/* *********************************************************************************************************//**
321 * Returns the list of all Protare entries that match *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation*.
322 * The arguments *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation* can be an C++ regex string. An empty
323 * string for any of the arguments will match all.
324 *
325 * @param a_protareEntries [out] The list of **ProtareBase** found.
326 * @param a_projectileID [in] The projectile's id to match.
327 * @param a_targetID [in] The target's id to match.
328 * @param a_library [in] The library to match.
329 * @param a_evaluation [in] The evaluation to match.
330 ***********************************************************************************************************/
331
332void ProtareBase::findProtareEntries( std::vector<ProtareBase const *> &a_protareEntries, std::regex const &a_projectileID,
333 std::regex const &a_targetID, std::regex const &a_library, std::regex const &a_evaluation ) const {
334
335 if( regex_match( m_projectileID, a_projectileID ) ) {
336 if( regex_match( m_targetID, a_targetID ) ) {
337 if( regex_match( parent( )->library( ), a_library ) ) {
338 if( regex_match( m_evaluation, a_evaluation ) ) a_protareEntries.push_back( this );
339 }
340 }
341 }
342}
343
344/* *********************************************************************************************************//**
345 * Compares *a_projectileID*, *a_targetID* and *a_evaluation* to *this* data and returns true if they match
346 * and false otherwise. If *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are compared.
347 *
348 * @param a_projectileID [in] The projectile's id to match.
349 * @param a_targetID [in] The target's id to match.
350 * @param a_evaluation [in] The evaluation to match.
351 * @return true if match and false otherwise.
352 ***********************************************************************************************************/
353
354bool ProtareBase::isMatch( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_evaluation ) const {
355
356 if( !PoPI::compareSpecialParticleIDs( a_projectileID, m_projectileID ) ) return( false );
357 if( a_targetID != m_targetID ) return( false );
358 if( a_evaluation == "" ) return( true );
359 return( a_evaluation == m_evaluation );
360}
361
362/* *********************************************************************************************************//**
363 *
364 * @param a_node [in] The **HAPI::Node** to be parsed to contruct a Protare entry instance.
365 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
366 * @param a_basePath [in] A path prepended to this entry's path.
367 * @param a_parent [in] Pointer to the *Map* containing *this*.
368 ***********************************************************************************************************/
369
370Protare::Protare( HAPI::Node const &a_node, PoPI::Database const &a_pops, std::string const &a_basePath, Map const *const a_parent ) :
371 ProtareBase( a_node, a_basePath, a_parent ),
372 m_isPhotoAtomic( false ) {
373
374 if( interaction( ) == "" ) { // Some old GNDS 1.10 files do not have an "interaction" attribute.
376 if( PoPI::IDs::photon == projectileID( ) ) {
377 try {
378 PoPI::Base const &target( a_pops.get<PoPI::Base>( targetID( ) ) );
379 m_isPhotoAtomic = target.isChemicalElement( ); }
380 catch (...) { // Let's ignore, but user must understand that m_interaction and m_isPhotoAtomic may be wrong.
381 }
382 if( m_isPhotoAtomic ) setInteraction( GIDI_MapInteractionAtomicChars );
383 }
384 }
385 m_isPhotoAtomic = interaction( ) == GIDI_MapInteractionAtomicChars;
386}
387
388/* *********************************************************************************************************//**
389 ***********************************************************************************************************/
390
392
393}
394
395/* *********************************************************************************************************//**
396 * Returns a GIDI::Protare instance of the protare reference by the *m_path* member.
397 *
398 * @param a_construction [in] Used to pass user options to the constructor.
399 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
400 * @param a_particleSubstitution [in] Map of particles to substitute with another particles.
401 *
402 * @return Returns the Protare matching the TNSL protare.
403 ***********************************************************************************************************/
404
405GIDI::Protare *Protare::protare( Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution ) const {
406
407 return( protareSingle( a_construction, a_pops, a_particleSubstitution ) );
408}
409
410/* *********************************************************************************************************//**
411 * Returns a GIDI::ProtareSingle instance of the protare reference by the *m_path* member.
412 *
413 * @param a_construction [in] Used to pass user options to the constructor.
414 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
415 * @param a_particleSubstitution [in] Map of particles to substitute with another particles.
416 *
417 * @return Returns the Protare matching the TNSL protare.
418 ***********************************************************************************************************/
419
420GIDI::ProtareSingle *Protare::protareSingle( Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution ) const {
421
422 std::vector<std::string> libraries1;
423 libraries( libraries1 );
424
425 return( new ProtareSingle( a_construction, path( ), fileType( path( ) ), a_pops, a_particleSubstitution, libraries1, interaction( ), true ) );
426}
427
428/* *********************************************************************************************************//**
429 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
430 *
431 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
432 * @param a_indent [in] The amount to indent *this* node.
433 ***********************************************************************************************************/
434
435void Protare::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
436
437 std::string attributes;
438
439 attributes = a_writeInfo.addAttribute( GIDI_projectileChars, projectileID( ) );
440 attributes += a_writeInfo.addAttribute( GIDI_targetChars, targetID( ) );
441 attributes += a_writeInfo.addAttribute( GIDI_evaluationChars, evaluation( ) );
442 attributes += a_writeInfo.addAttribute( GIDI_pathChars, path( PathForm::entered ) );
443 attributes += a_writeInfo.addAttribute( GIDI_interactionChars, interaction( ) );
444 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
445}
446
447/* *********************************************************************************************************//**
448 *
449 * @param a_node [in] The **HAPI::Node** to be parsed to contruct a TNSL entry instance.
450 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
451 * @param a_basePath [in] A path prepended to this entry's path.
452 * @param a_parent [in] Pointer to the *Map* containing *this*.
453 ***********************************************************************************************************/
454
455TNSL::TNSL( HAPI::Node const &a_node, LUPI_maybeUnused PoPI::Database const &a_pops, std::string const &a_basePath, Map const *const a_parent ) :
456 ProtareBase( a_node, a_basePath, a_parent ),
457 m_standardTarget( a_node.attribute_as_string( GIDI_standardTargetChars ) ),
458 m_standardEvaluation( a_node.attribute_as_string( GIDI_standardEvaluationChars ) ) {
459
460 setInteraction( "" );
461
462 HAPI::Node const &protare = a_node.child( GIDI_protareChars ); // Format 0.1 support. This format is deprecated.
463 if( !protare.empty() ) {
464 m_standardTarget = protare.attribute_as_string( GIDI_targetChars );
465 m_standardEvaluation = protare.attribute_as_string( GIDI_evaluationChars );
466 }
467}
468
469/* *********************************************************************************************************//**
470 ***********************************************************************************************************/
471
473
474}
475
476/* *********************************************************************************************************//**
477 * Returns a GIDI::ProtareTNSL instance of the protare reference by the *m_path* member.
478 *
479 * @param a_construction [in] Used to pass user options to the constructor.
480 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
481 * @param a_particleSubstitution [in] Map of particles to substitute with another particles.
482 *
483 * @return Returns the Protare matching the TNSL protare.
484 ***********************************************************************************************************/
485
486GIDI::Protare *TNSL::protare( Construction::Settings const &a_construction, PoPI::Database const &a_pops, LUPI_maybeUnused ParticleSubstitution const &a_particleSubstitution ) const {
487
488 Map const *map = parent( );
489
490 ParticleSubstitution particleSubstitution;
491 std::vector<std::string> libraries1;
492 libraries( libraries1 );
493
494 ProtareSingle *protare1 = new ProtareSingle( a_construction, path( ), fileType( path( ) ), a_pops, particleSubstitution, libraries1, GIDI_MapInteractionTNSLChars, false );
495
496 while( true ) {
497 Map const *parent = map->parent( );
498
499 if( parent == nullptr ) break;
500 map = parent;
501 }
502 ProtareSingle *protare2 = static_cast<ProtareSingle *>( map->protare( a_construction, a_pops, PoPI::IDs::neutron, m_standardTarget, "", m_standardEvaluation ) );
503 if( protare2 == nullptr ) protare2 = static_cast<ProtareSingle *>( map->protare( a_construction, a_pops, PoPI::IDs::neutron, m_standardTarget ) );
504
505 ProtareTNSL *protareTNSL = new ProtareTNSL( a_construction, protare2, protare1 );
506
507 return( protareTNSL );
508}
509
510/* *********************************************************************************************************//**
511 * Returns a GIDI::ProtareSingle instance of the protare reference by the *m_path* member. Note, this is different from the *protare* method
512 * which returns a **GIDI::ProtareTNSL** instance.
513 *
514 * @param a_construction [in] Used to pass user options to the constructor.
515 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
516 * @param a_particleSubstitution [in] Map of particles to substitute with another particles.
517 *
518 * @return Returns the Protare matching the TNSL protare.
519 ***********************************************************************************************************/
520
521GIDI::ProtareSingle *TNSL::protareSingle( Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution ) const {
522
523 std::vector<std::string> libraries1;
524 libraries( libraries1 );
525
526 return( new ProtareSingle( a_construction, path( ), fileType( path( ) ), a_pops, a_particleSubstitution, libraries1, GIDI_MapInteractionTNSLChars, false ) );
527}
528
529/* *********************************************************************************************************//**
530 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
531 *
532 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
533 * @param a_indent [in] The amount to indent *this* node.
534 ***********************************************************************************************************/
535
536void TNSL::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
537
538 std::string attributes;
539
540 attributes = a_writeInfo.addAttribute( GIDI_projectileChars, projectileID( ) );
541 attributes += a_writeInfo.addAttribute( GIDI_targetChars, targetID( ) );
542 attributes += a_writeInfo.addAttribute( GIDI_evaluationChars, evaluation( ) );
543 attributes += a_writeInfo.addAttribute( GIDI_pathChars, path( PathForm::entered ) );
544 attributes += a_writeInfo.addAttribute( GIDI_standardTargetChars, standardTarget( ) );
545 attributes += a_writeInfo.addAttribute( GIDI_standardEvaluationChars, standardEvaluation( ) );
546 a_writeInfo.addNodeStarterEnder( a_indent, moniker( ), attributes );
547}
548/* *********************************************************************************************************//**
549 *
550 * @param a_fileName [in] The path to the map file to parse to construct a Map instance.
551 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
552 * @param a_parent [in] Pointer to the *Map* containing *this*.
553 ***********************************************************************************************************/
554
555Map::Map( std::string const &a_fileName, PoPI::Database const &a_pops, Map const *a_parent ) :
557
558 initialize( a_fileName, a_pops, a_parent );
559}
560
561/* *********************************************************************************************************//**
562 *
563 * @param a_node [in] HAPI::Node corresponding to the map node
564 * @param a_fileName [in] std::string, the name of the file containing this map.
565 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
566 * @param a_parent [in] Pointer to the *Map* containing *this*.
567 ***********************************************************************************************************/
568
569Map::Map( HAPI::Node const &a_node, std::string const &a_fileName, PoPI::Database const &a_pops, Map const *a_parent ) :
570 GUPI::Ancestry( a_node.name( ) ) {
571
572 initialize( a_node, a_fileName, a_pops, a_parent );
573}
574
575/* *********************************************************************************************************//**
576 * This method is called by the fileName constructors, opens the document and calls the other initialize method
577 *
578 * @param a_fileName [in] The path to the map file to parse to construct a Map instance.
579 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
580 * @param a_parent [in] Pointer to the *Map* containing *this*.
581 ***********************************************************************************************************/
582
583void Map::initialize( std::string const &a_fileName, PoPI::Database const &a_pops, Map const *a_parent ) {
584
585 HAPI::File *doc = new HAPI::PugiXMLFile( a_fileName.c_str( ), "Map::initialize" );
586
587 HAPI::Node map = doc->first_child( );
588
589 if( strcmp( map.name( ).c_str( ), GIDI_mapChars ) != 0 ) throw Exception( "Invalid map file " + a_fileName );
590
591 initialize( map, a_fileName, a_pops, a_parent );
592 delete doc;
593}
594
595/* *********************************************************************************************************//**
596 * This method is called either by the constructor or by the other initialize method. Does most of the work of parsing
597 *
598 * @param a_node [in] HAPI::Node corresponding to the map node.
599 * @param a_fileName [in] std::string, the name of the file containing this map
600 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
601 * @param a_parent [in] Pointer to the *Map* containing *this*.
602 ***********************************************************************************************************/
603
604void Map::initialize( HAPI::Node const &a_node, std::string const &a_fileName, PoPI::Database const &a_pops, Map const *a_parent ) {
605
606 m_parent = a_parent;
607 m_fileName = a_fileName;
608 m_realFileName = LUPI::FileInfo::realPath( a_fileName );
609 m_projectilesLoaded = false;
610
611 std::string basePath = GIDI_basePath( m_realFileName );
612
613 std::string format = a_node.attribute_as_string( GIDI_formatChars );
615 if( format != GNDS_formatVersion_2_0Chars ) {
616 if( format != GIDI_mapFormatVersion_0_1Chars ) throw Exception( "Unsupported map format" );
617 }
618
619 m_library = a_node.attribute_as_string( GIDI_libraryChars );
620 for( HAPI::Node child = a_node.first_child( ); !child.empty( ); child.to_next_sibling( ) ) {
621 if( strcmp( child.name( ).c_str( ), GIDI_importChars ) == 0 ) {
622 m_entries.push_back( new Import( child, a_pops, basePath, this ) ); }
623 else if( strcmp( child.name( ).c_str( ), GIDI_protareChars ) == 0 ) {
624 m_entries.push_back( new Protare( child, a_pops, basePath, this ) ); }
625 else if( strcmp( child.name( ).c_str( ), GIDI_TNSLChars ) == 0 ) {
626 m_entries.push_back( new TNSL( child, a_pops, basePath, this ) ); }
627 else {
628 throw Exception( std::string( "Invalid entry '" ) + child.name( ) + std::string( "' in map file " ) + a_fileName );
629 }
630 }
631}
632
633/* *********************************************************************************************************//**
634 ***********************************************************************************************************/
635
637
638 for( std::vector<BaseEntry *>::const_iterator iter = m_entries.begin( ); iter < m_entries.end( ); ++iter ) delete *iter;
639}
640
641/* *********************************************************************************************************//**
642 ***********************************************************************************************************/
643
644std::string const &Map::resolvedLibrary( ) const {
645
646 if( ( m_library == "" ) && ( m_parent != nullptr ) ) return( m_parent->resolvedLibrary( ) );
647 return( m_library );
648}
649
650/* *********************************************************************************************************//**
651 * Fills *a_libraries* with the name of all the libraries *this* is contained in. The first library in the list is the
652 * library *this* is defined in and the last is the starting library.
653 *
654 * @param a_libraries [out] The instances that is filled with the library names.
655 ***********************************************************************************************************/
656
657void Map::libraries( std::vector<std::string> &a_libraries ) const {
658
659 a_libraries.push_back( m_library );
660 if( m_parent != nullptr ) m_parent->libraries( a_libraries );
661}
662
663/* *********************************************************************************************************//**
664 * Returns the Protare to the first protare to match *a_projectileID*, *a_targetID* and *a_evaluation*. If
665 * *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are matched.
666 *
667 * @param a_projectileID [in] The projectile's id to match.
668 * @param a_targetID [in] The target's id to match.
669 * @param a_library [in] The library to match.
670 * @param a_evaluation [in] The evaluation to match.
671 *
672 * @return The const pointer **ProtareBase** for the matched protare.
673 ***********************************************************************************************************/
674
675ProtareBase const *Map::findProtareEntry( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library,
676 std::string const &a_evaluation ) const {
677
678 ProtareBase const *protareEntry = nullptr;
679
680 for( std::vector<BaseEntry *>::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
681 protareEntry = (*iter)->findProtareEntry( a_projectileID, a_targetID, a_library, a_evaluation );
682 if( protareEntry != nullptr ) break;
683 }
684 return( protareEntry );
685}
686
687/* *********************************************************************************************************//**
688 * Returns the list of all Protare entries that match *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation*.
689 * The arguments *a_projectileID*, *a_targetID*, *a_library* and *a_evaluation* can be an C++ regex string. An empty
690 * string for any of the arguments will match all.
691 *
692 * @param a_protareEntries [out] The list of **ProtareBase** found.
693 * @param a_projectileID [in] The projectile's id to match.
694 * @param a_targetID [in] The target's id to match.
695 * @param a_library [in] The library to match.
696 * @param a_evaluation [in] The evaluation to match.
697 ***********************************************************************************************************/
698
699void Map::findProtareEntries( std::vector<ProtareBase const *> &a_protareEntries, std::regex const &a_projectileID,
700 std::regex const &a_targetID, std::regex const &a_library, std::regex const &a_evaluation ) const {
701
702 for( std::vector<BaseEntry *>::const_iterator iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) {
703 (*iter)->findProtareEntries( a_protareEntries, a_projectileID, a_targetID, a_library, a_evaluation );
704 }
705}
706
707/* *********************************************************************************************************//**
708 * Returns the path to the first protare to match *a_projectileID*, *a_targetID* and *a_evaluation*. If
709 * *a_evaluation* is an empty string, only *a_projectileID* and *a_targetID* are matched.
710 *
711 * @param a_projectileID [in] The projectile's id to match.
712 * @param a_targetID [in] The target's id to match.
713 * @param a_library [in] The library to match.
714 * @param a_evaluation [in] The evaluation to match.
715 * @param a_form [in] Determines the form of the path returned.
716 * @return The path to the matched protare.
717 ***********************************************************************************************************/
718
719std::string Map::protareFilename( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library,
720 std::string const &a_evaluation, BaseEntry::PathForm a_form ) const {
721
722 ProtareBase const *protareEntry = findProtareEntry( a_projectileID, a_targetID, a_library, a_evaluation );
723
724 if( protareEntry != nullptr ) return( protareEntry->path( a_form ) );
725 return( GIDI_emptyFileNameChars );
726}
727
728/* *********************************************************************************************************//**
729 * Returns *true* if *a_targetID* is a thermal neutron scattering law (TNSL) target id contained this map, including recursion, and *false* otherwise.
730 *
731 * @param a_targetID [in] The target's id.
732 *
733 * @return *true* if target *a_targetID* is present and is a TNSL target, and *false* otherwise.
734 ***********************************************************************************************************/
735
736bool Map::isTNSL_target( std::string const &a_targetID ) const {
737
738 ProtareBase const *protareEntry = findProtareEntry( PoPI::IDs::neutron, a_targetID );
739
740 if( protareEntry == nullptr ) return( false );
741 if( protareEntry->entryType( ) == EntryType::TNSL ) return( true );
742 return( false );
743}
744
745/* *********************************************************************************************************//**
746 * Returns a list of all evaluations with a match to *a_projectileID* and *a_targetID*.
747 *
748 * @param a_projectileID [in] The projectile's id to match.
749 * @param a_targetID [in] The target's id to match.
750 * @return List of evaluations.
751 ***********************************************************************************************************/
752
753std::vector<std::string> Map::availableEvaluations( std::string const &a_projectileID, std::string const &a_targetID ) const {
754
755 std::vector<std::string> list;
756
757 for( std::vector<BaseEntry *>::const_iterator iter1 = m_entries.begin( ); iter1 != m_entries.end( ); ++iter1 ) {
758 if( (*iter1)->name( ) == GIDI_importChars ) {
759 Import *_mapEntry = static_cast<Import *> (*iter1);
760
761 std::vector<std::string> sub_list = _mapEntry->availableEvaluations( a_projectileID, a_targetID );
762 for( std::vector<std::string>::const_iterator iter2 = sub_list.begin( ); iter2 != sub_list.end( ); ++iter2 )
763 list.push_back( *iter2 ); }
764 else {
765 ProtareBase *protareEntry = static_cast<ProtareBase *> (*iter1);
766
767 if( protareEntry->isMatch( a_projectileID, a_targetID ) ) list.push_back( protareEntry->evaluation( ) );
768 }
769 }
770 return( list );
771}
772
773/* *********************************************************************************************************//**
774 * If a protare matching *a_projectileID*, *a_targetID* and *a_evaluation* is found, the Protare constructor is called with
775 * its fileName.
776 *
777 * @param a_construction [in] Pass to the Protare constructor.
778 * @param a_pops [in] A PoPI::Database instance used to get particle indices and possibly other particle information.
779 * @param a_projectileID [in] The projectile's id to match.
780 * @param a_targetID [in] The target's id to match.
781 * @param a_library [in] The library to match.
782 * @param a_evaluation [in] The evaluation to match.
783 * @param a_targetRequiredInGlobalPoPs [in] If *true*, the target is required to be in **a_pops**.
784 * @param a_ignorePoPs [in] If *true*, no particle is required to be in **a_pops**.
785 ***********************************************************************************************************/
786
787GIDI::Protare *Map::protare( Construction::Settings const &a_construction, PoPI::Database const &a_pops, std::string const &a_projectileID,
788 std::string const &a_targetID, std::string const &a_library, std::string const &a_evaluation, LUPI_maybeUnused bool a_targetRequiredInGlobalPoPs, LUPI_maybeUnused bool a_ignorePoPs ) const {
789
790 std::string targetID( a_targetID );
791 std::string atomicTargetID;
792
793 ParticleSubstitution particleSubstitution;
794 GIDI::Protare *nuclear = nullptr, *atomic = nullptr, *protare;
795
796 if( a_projectileID != PoPI::IDs::neutron ) { // Check if targetID is for TNSL target. If so, and projectile is not a neutron, need to use standardTarget name.
797 ProtareBase const *protareEntry = findProtareEntry( PoPI::IDs::neutron, targetID );
798
799 if( protareEntry != nullptr ) {
800 if( protareEntry->entryType( ) == EntryType::TNSL ) targetID = static_cast<TNSL const *>( protareEntry )->standardTarget( );
801 }
802 }
803
804 if( a_projectileID == PoPI::IDs::photon ) {
805 PoPI::ParseIdInfo parseIdInfo( targetID );
806
807 if( a_construction.photoMode( ) != Construction::PhotoMode::nuclearOnly ) {
808 atomicTargetID = targetID; // Kludge for 99120 and similar targets.
809
810 if( parseIdInfo.isNuclear( ) ) atomicTargetID = parseIdInfo.symbol( );
811 ProtareBase const *protareEntry = findProtareEntry( a_projectileID, atomicTargetID, a_library, a_evaluation );
812 if( protareEntry != nullptr ) {
813 particleSubstitution.insert( { atomicTargetID, ParticleInfo( targetID, a_pops, a_pops, true ) } );
814 atomic = protareEntry->protare( a_construction, a_pops, particleSubstitution );
815 particleSubstitution.clear( );
816 }
817 }
818 if( ( a_construction.photoMode( ) != Construction::PhotoMode::atomicOnly ) && ( targetID != atomicTargetID ) ) {
819 if( parseIdInfo.isSupported( ) ) { // Kludge to ignore 99120 and similar targers.
820 ProtareBase const *protareEntry = findProtareEntry( a_projectileID, targetID, a_library, a_evaluation );
821 if( protareEntry != nullptr ) nuclear = protareEntry->protare( a_construction, a_pops, particleSubstitution );
822 }
823 } }
824 else {
825 ProtareBase const *protareEntry = findProtareEntry( a_projectileID, targetID, a_library, a_evaluation );
826 if( protareEntry != nullptr ) nuclear = protareEntry->protare( a_construction, a_pops, particleSubstitution );
827 }
828
829 if( nuclear == nullptr ) {
830 protare = atomic; }
831 else if( atomic == nullptr ) {
832 protare = nuclear; }
833 else {
834 ProtareComposite *protareComposite = new ProtareComposite( a_construction );
835
836 protareComposite->setProjectile( nuclear->projectile( ) );
837 protareComposite->setTarget( nuclear->target( ) );
838 protareComposite->append( nuclear );
839 protareComposite->append( atomic );
840 protare = protareComposite;
841 }
842
843 return( protare );
844}
845
846/* *********************************************************************************************************//**
847 * Returns a list of all Protare entry's matching the input data.
848 *
849 * @param a_projectileID [in] The projectile's id to match.
850 * @param a_targetID [in] The target's id to match.
851 * @param a_library [in] The library to match.
852 * @param a_evaluation [in] The evaluation to match.
853 * @return List of all Protare entry's matching input parameters.
854 ***********************************************************************************************************/
855
856std::vector<ProtareBase const *> Map::directory( std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library,
857 std::string const &a_evaluation ) const {
858
859 MapWalkDirectoryCallbackData mapWalkDirectoryCallbackData( a_projectileID, a_targetID, a_library, a_evaluation );
860
861 walk( MapWalkDirectoryCallback, &mapWalkDirectoryCallbackData, 0 );
862 return( mapWalkDirectoryCallbackData.m_protareEntries );
863}
864
865/* *********************************************************************************************************//**
866 * A method to walk a map file. For each Protare entry found, the **a_mapWalkCallBack** function is called with
867 * a pointer to the Protare entry and **a_userData** has its arguments.
868 *
869 * @param a_mapWalkCallBack [in] The callback function.
870 * @param a_userData [in] Pointer to user data.
871 * @param a_level [in] Nested level of *this* map file. For internal use.
872 *
873 * @return true if no issue is found and false if an issue is found.
874 ***********************************************************************************************************/
875
876bool Map::walk( MapWalkCallBack a_mapWalkCallBack, void *a_userData, int a_level ) const {
877
878 for( std::size_t i1 = 0; i1 < size( ); ++i1 ) {
879 BaseEntry const *entry = (*this)[i1];
880
881 std::string path = entry->path( BaseEntry::PathForm::cumulative );
882
883 if( entry->name( ) == GIDI_importChars ) {
884 Import const *mapEntry = static_cast<Import const *>( entry );
885 if( !mapEntry->map( )->walk( a_mapWalkCallBack, a_userData, a_level + 1 ) ) return( true ); }
886 else if( ( entry->name( ) == GIDI_protareChars ) || ( entry->name( ) == GIDI_TNSLChars ) ) {
887 if( !a_mapWalkCallBack( static_cast<ProtareBase const *>( entry ), m_library, a_userData, a_level ) ) return( true ); }
888 else {
889 std::cerr << " ERROR: unknown map entry name: " << entry->name( ) << std::endl;
890 }
891 }
892
893 return( true );
894}
895
896/* *********************************************************************************************************//**
897 * Write *this* to a file in GNDS/XML format.
898 *
899 * @param a_fileName [in] Name of file to save XML lines to.
900 ***********************************************************************************************************/
901
902void Map::saveAs( std::string const &a_fileName ) const {
903
904 GUPI::WriteInfo writeInfo;
905
906 toXMLList( writeInfo, "" );
907
908 std::ofstream fileio;
909 fileio.open( a_fileName.c_str( ) );
910 for( std::list<std::string>::iterator iter = writeInfo.m_lines.begin( ); iter != writeInfo.m_lines.end( ); ++iter ) fileio << *iter << std::endl;
911 fileio.close( );
912}
913
914/* *********************************************************************************************************//**
915 * Fills the argument *a_writeInfo* with the XML lines that represent *this*. Recursively enters each sub-node.
916 *
917 * @param a_writeInfo [in/out] Instance containing incremental indentation and other information and stores the appended lines.
918 * @param a_indent [in] The amount to indent *this* node.
919 ***********************************************************************************************************/
920
921void Map::toXMLList( GUPI::WriteInfo &a_writeInfo, std::string const &a_indent ) const {
922
923 std::string indent2 = a_writeInfo.incrementalIndent( a_indent );
924 std::string header = LUPI_XML_verionEncoding;
925 std::string attributes;
926
927 a_writeInfo.push_back( header );
928
929 attributes = a_writeInfo.addAttribute( GIDI_libraryChars, m_library );
930 attributes += a_writeInfo.addAttribute( GIDI_formatChars, GNDS_formatVersion_2_0Chars );
931
932 a_writeInfo.addNodeStarter( a_indent, moniker( ), attributes );
933 for( auto iter = m_entries.begin( ); iter != m_entries.end( ); ++iter ) (*iter)->toXMLList( a_writeInfo, indent2 );
934 a_writeInfo.addNodeEnder( moniker( ) );
935}
936
937/* *********************************************************************************************************//**
938 * Returns the name of the RIS file for *this* map file. All RIS files must have a standard name which is the name of
939 * the map file with its extension replaced with ".ris".
940 *
941 * @return The **std::string** representing the RIS file.
942 ***********************************************************************************************************/
943
944std::string Map::RIS_fileName( ) {
945
946 std::size_t found = m_fileName.rfind( '.' );
947 std::string RIS_fileName( m_fileName.substr( 0, found ) );
948
949 return( RIS_fileName + ".ris" );
950}
951
952/* *********************************************************************************************************//**
953 * Returns **true** if the RIS file for *this* map file exists and **false** otherwise.
954 *
955 * @return A boolean indicating if the RIS file exists or not.
956 ***********************************************************************************************************/
957
959
960 return( LUPI::FileInfo::exists( RIS_fileName( ) ) );
961}
962
963/* *********************************************************************************************************//**
964 * Load the data from the RIS file if it exists. If it does not exists, no error is reported and the returned
965 * **RISI::Projectiles** will be empty.
966 *
967 * @param a_energyUnit [in/out] The unit desired for threshold energies.
968 *
969 * @return A const reference to the **RISI::Projectiles** data.
970 ***********************************************************************************************************/
971
972RISI::Projectiles const &Map::RIS_load( std::string const &a_energyUnit ) {
973
974 if( !m_projectilesLoaded ) {
975 if( RIS_fileExist( ) ) GIDI::RISI::readRIS( RIS_fileName( ), a_energyUnit, m_projectiles );
976 }
977 m_projectilesLoaded = true;
978
979 return( m_projectiles );
980}
981
982/* *********************************************************************************************************//**
983 * If *this* has target *a_target* for projectile *a_projectile*, then *a_target* is returned. If it does not have target *a_target*,
984 * for projectile *a_projectile*, then a reasonable substitute is returned if one can be found in *this*. If no reasonable substitute
985 * is found, an empty string is returned.
986 *
987 *
988 * @param a_pops [in] A PoPI::Database instance used to get information about *a_target*..
989 * @param a_projectile [in] The PoPs id of the projectile.
990 * @param a_target [in] The PoPs id of the target.
991 *
992 * @return The PoPs id of the replacement target.
993 ***********************************************************************************************************/
994
995std::string Map::replacementTarget( PoPI::Database const &a_pops, std::string const &a_projectile, std::string const &a_target ) {
996
997 if( findProtareEntry( a_projectile, a_target ) != nullptr ) return( a_target );
998
999 if( a_pops.exists( a_target ) ) {
1000 std::string particleID = a_pops.final( a_target );
1001 if( a_pops.isParticle( particleID ) ) {
1002 PoPI::Particle const &particle = a_pops.particle( particleID );
1003 if( particle.hasNucleus( ) ) {
1004 PoPI::Nuclide const *nuclide = static_cast<PoPI::Nuclide const *>( &particle );
1005 if( particle.isNucleus( ) ) {
1006 PoPI::Nucleus const *nucleus = static_cast<PoPI::Nucleus const *>( &particle );
1007 nuclide = nucleus->nuclide( );
1008 }
1009 PoPI::Isotope const *isotope = nuclide->isotope( );
1010 std::string targetRegexString( isotope->chemicalElement( )->symbol( ) + "[0-9]+" );
1011
1012 std::vector<ProtareBase const *> protareEntries;
1013 findProtareEntries( protareEntries, std::regex( a_projectile ), std::regex( targetRegexString ) );
1014 if( protareEntries.size( ) > 0 ) {
1015 int offset = 0;
1016 std::map<int, std::string> choices;
1017 for( auto entryIter = protareEntries.begin( ); entryIter != protareEntries.end( ); ++entryIter ) {
1018 PoPI::Nuclide const &nuclide2 = a_pops.get<PoPI::Nuclide const>( (*entryIter)->targetID( ) );
1019 int diffA = nuclide->A( ) - nuclide2.A( );
1020 offset += diffA;
1021 choices[diffA] = nuclide2.ID( );
1022 }
1023 offset = offset < 0 ? -1 : 1;
1024 int diff = 2 * offset;
1025 int step = 2;
1026 for( int doTwo = 0; doTwo < 2; ++doTwo ) {
1027 for( std::size_t index = 0; index < choices.size( ); ++index ) {
1028 auto iter = choices.find( diff );
1029 if( iter != choices.end( ) ) return( (*iter).second );
1030
1031 diff *= -1;
1032 iter = choices.find( diff );
1033 if( iter != choices.end( ) ) return( (*iter).second );
1034
1035 diff = -diff + step * offset;
1036 }
1037 step = 1;
1038 }
1039 }
1040 }
1041 }
1042 }
1043
1044 return( "" );
1045}
1046
1047} // End of namespace Map.
1048
1049} // End of namespace GIDI.
1050
1051/* *********************************************************************************************************//**
1052 * Splits the path at the last path separator (e.g., the '/' charactor on Unix systems) and returns the first (i.e.,
1053 * directory) part. Returns "." is no '/' is present.
1054 *
1055 * @param a_path The path whose directory is to be returned.
1056 *
1057 * @return The directory of file **a_path**
1058 ***********************************************************************************************************/
1059
1060static std::string GIDI_basePath( char const *a_path ) {
1061
1062 char *p1, realPath[LUPI_PATH_MAX+1];
1063
1064 strcpy( realPath, a_path );
1065 if( ( p1 = strrchr( realPath, '/' ) ) != nullptr ) {
1066 *p1 = 0; }
1067 else {
1068 strcpy( realPath, "." );
1069 }
1070 std::string basePath( realPath );
1071 return( basePath );
1072}
1073
1074/* *********************************************************************************************************//**
1075 * Calls GIDI_basePath( char const *a_path ).
1076 *
1077 * @param a_path
1078 * @return
1079 ***********************************************************************************************************/
1080
1081static std::string GIDI_basePath( std::string const a_path ) {
1082
1083 return( GIDI_basePath( a_path.c_str( ) ) );
1084}
1085
1086/* *********************************************************************************************************//**
1087 * If **a_path** is not an absolute path, prepends **a_path** to it.
1088 *
1089 * @param a_base [in] Base path to prepend to **a_path**.
1090 * @param a_path [in] Path
1091 * @return Prepend path.
1092 ***********************************************************************************************************/
1093
1094static std::string GIDI_addPaths( std::string const &a_base, std::string const &a_path ) {
1095
1096 std::string path( a_path );
1097
1098 if( ( a_base.size( ) > 0 ) && ( path[0] != GIDI_FILE_SEPARATOR[0] ) ) path = a_base + GIDI_FILE_SEPARATOR + path;
1099 return( path );
1100}
G4ThreadLocal T * G4GeomSplitter< T >::offset
#define GIDI_MapInteractionTNSLChars
Definition GIDI.hpp:5165
#define GIDI_MapInteractionAtomicChars
Definition GIDI.hpp:5164
#define GIDI_pathChars
Definition GIDI.hpp:450
#define GIDI_projectileChars
Definition GIDI.hpp:413
#define GIDI_evaluationChars
Definition GIDI.hpp:415
#define GIDI_FILE_SEPARATOR
Definition GIDI.hpp:492
#define GIDI_targetChars
Definition GIDI.hpp:414
#define GIDI_mapFormatVersion_0_1Chars
Definition GIDI.hpp:152
#define GIDI_mapChars
Definition GIDI.hpp:162
#define GIDI_TNSLChars
Definition GIDI.hpp:165
#define GIDI_standardTargetChars
Definition GIDI.hpp:417
#define GIDI_protareChars
Definition GIDI.hpp:164
#define GIDI_MapInteractionNuclearChars
Definition GIDI.hpp:5163
#define GIDI_interactionChars
Definition GIDI.hpp:416
#define GIDI_importChars
Definition GIDI.hpp:163
#define GIDI_libraryChars
Definition GIDI.hpp:411
#define GIDI_mapFormatVersion_0_2Chars
Definition GIDI.hpp:153
#define GIDI_emptyFileNameChars
Definition GIDI.hpp:150
#define GIDI_formatChars
Definition GIDI.hpp:167
#define GIDI_standardEvaluationChars
Definition GIDI.hpp:418
#define LUPI_XML_verionEncoding
Definition LUPI.hpp:28
#define GNDS_formatVersion_2_0Chars
Definition LUPI.hpp:49
#define GNDS_formatVersion_2_0_LLNL_4Chars
Definition LUPI.hpp:50
#define LUPI_PATH_MAX
Definition LUPI.hpp:31
#define LUPI_maybeUnused
std::map< G4String, G4ParticleDefinition *, std::less< G4String > > Map
PhotoMode photoMode() const
Definition GIDI.hpp:559
virtual EntryType entryType() const =0
virtual ~BaseEntry()=0
Definition GIDI_map.cc:122
void libraries(std::vector< std::string > &a_libraries) const
Definition GIDI_map.cc:147
std::string const & name() const
Definition GIDI.hpp:5189
BaseEntry(HAPI::Node const &a_node, std::string const &a_basePath, Map const *a_parent)
Definition GIDI_map.cc:110
Map const * parent() const
Definition GIDI.hpp:5190
std::string path(PathForm a_form=PathForm::real) const
Definition GIDI_map.cc:133
std::string protareFilename(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="", PathForm a_form=PathForm::real) const
Definition GIDI_map.cc:224
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_map.cc:250
Map const * map() const
Definition GIDI.hpp:5221
Import(HAPI::Node const &a_node, PoPI::Database const &a_pops, std::string const &a_basePath, Map const *a_parent)
Definition GIDI_map.cc:160
ProtareBase const * findProtareEntry(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="") const
Definition GIDI_map.cc:187
std::vector< std::string > availableEvaluations(std::string const &a_projectileID, std::string const &a_targetID) const
Definition GIDI_map.cc:238
void findProtareEntries(FindProtareEntries &a_protareEntries, std::regex const &a_projectileID, std::regex const &a_targetID, std::regex const &a_library=std::regex(".*"), std::regex const &a_evaluation=std::regex(".*")) const
Definition GIDI_map.cc:205
MapWalkDirectoryCallbackData(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library, std::string const &a_evaluation)
Definition GIDI_map.cc:63
std::vector< ProtareBase const * > m_protareEntries
Definition GIDI_map.cc:53
void libraries(std::vector< std::string > &a_libraries) const
Definition GIDI_map.cc:657
std::size_t size() const
Definition GIDI.hpp:5363
void saveAs(std::string const &a_fileName) const
Definition GIDI_map.cc:902
ProtareBase const * findProtareEntry(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="") const
Definition GIDI_map.cc:675
GIDI::Protare * protare(Construction::Settings const &a_construction, PoPI::Database const &a_pops, std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="", bool a_targetRequiredInGlobalPoPs=true, bool a_requiredInPoPs=true) const
Definition GIDI_map.cc:787
std::string replacementTarget(PoPI::Database const &a_pops, std::string const &a_projectile, std::string const &a_target)
Definition GIDI_map.cc:995
void findProtareEntries(FindProtareEntries &a_protareEntries, std::regex const &a_projectileID, std::regex const &a_targetID, std::regex const &a_library=std::regex(".*"), std::regex const &a_evaluation=std::regex(".*")) const
Definition GIDI_map.cc:699
RISI::Projectiles const & RIS_load(std::string const &a_energyUnit)
Definition GIDI_map.cc:972
std::string const & resolvedLibrary() const
Definition GIDI_map.cc:644
bool RIS_fileExist()
Definition GIDI_map.cc:958
Map(std::string const &a_fileName, PoPI::Database const &a_pops, Map const *a_parent=nullptr)
Definition GIDI_map.cc:555
std::vector< std::string > availableEvaluations(std::string const &a_projectileID, std::string const &a_targetID) const
Definition GIDI_map.cc:753
bool walk(MapWalkCallBack a_mapWalkCallBack, void *a_userData, int a_level=0) const
Definition GIDI_map.cc:876
std::string RIS_fileName()
Definition GIDI_map.cc:944
bool isTNSL_target(std::string const &a_targetID) const
Definition GIDI_map.cc:736
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_map.cc:921
std::string protareFilename(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="", BaseEntry::PathForm a_form=BaseEntry::PathForm::real) const
Definition GIDI_map.cc:719
std::vector< ProtareBase const * > directory(std::string const &a_projectileID="", std::string const &a_targetID="", std::string const &a_library="", std::string const &a_evaluation="") const
Definition GIDI_map.cc:856
std::string const & resolvedLibrary() const
Definition GIDI_map.cc:293
void findProtareEntries(FindProtareEntries &a_protareEntries, std::regex const &a_projectileID, std::regex const &a_targetID, std::regex const &a_library=std::regex(".*"), std::regex const &a_evaluation=std::regex(".*")) const
Definition GIDI_map.cc:332
void setInteraction(std::string const &a_interaction)
Definition GIDI.hpp:5262
std::string const & evaluation() const
Definition GIDI.hpp:5260
virtual GIDI::Protare * protare(Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution) const =0
ProtareBase const * findProtareEntry(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_library="", std::string const &a_evaluation="") const
Definition GIDI_map.cc:310
std::string const & interaction() const
Definition GIDI.hpp:5261
bool isMatch(std::string const &a_projectileID, std::string const &a_targetID, std::string const &a_evaluation="") const
Definition GIDI_map.cc:354
std::string const & library() const
Definition GIDI_map.cc:284
std::string const & projectileID() const
Definition GIDI.hpp:5258
std::string const & targetID() const
Definition GIDI.hpp:5259
ProtareBase(HAPI::Node const &a_node, std::string const &a_basePath, Map const *const a_map)
Definition GIDI_map.cc:264
GIDI::ProtareSingle * protareSingle(Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution) const
Definition GIDI_map.cc:420
GIDI::Protare * protare(Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution) const
Definition GIDI_map.cc:405
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_map.cc:435
GIDI::Protare * protare(Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution) const
Definition GIDI_map.cc:486
std::string const & standardTarget() const
Definition GIDI.hpp:5322
TNSL(HAPI::Node const &a_node, PoPI::Database const &a_pops, std::string const &a_basePath, Map const *const a_parent)
Definition GIDI_map.cc:455
std::string const & standardEvaluation() const
Definition GIDI.hpp:5323
void toXMLList(GUPI::WriteInfo &a_writeInfo, std::string const &a_indent="") const
Definition GIDI_map.cc:536
GIDI::ProtareSingle * protareSingle(Construction::Settings const &a_construction, PoPI::Database const &a_pops, ParticleSubstitution const &a_particleSubstitution) const
Definition GIDI_map.cc:521
void append(Protare *a_protare)
void setTarget(ParticleInfo const &a_target)
Definition GIDI.hpp:4544
void setProjectile(ParticleInfo const &a_projectile)
Definition GIDI.hpp:4542
ParticleInfo const & target() const
Definition GIDI.hpp:4543
ParticleInfo const & projectile() const
Definition GIDI.hpp:4541
std::string const & moniker() const
Definition GUPI.hpp:102
Ancestry(std::string const &a_moniker, std::string const &a_attribute="")
void addNodeStarterEnder(std::string const &indent, std::string const &a_moniker, std::string const &a_attributes="")
Definition GUPI.hpp:57
void push_back(std::string const &a_line)
Definition GUPI.hpp:53
std::list< std::string > m_lines
Definition GUPI.hpp:45
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
std::string attribute_as_string(const char *a_name) const
Definition HAPI.hpp:179
Node first_child() const
Definition HAPI_Node.cc:82
Node child(const char *name) const
Definition HAPI_Node.cc:72
bool isChemicalElement() const
Definition PoPI.hpp:670
bool isNucleus() const
Definition PoPI.hpp:667
std::string const & ID(void) const
Definition PoPI.hpp:652
T const & get(std::string const &a_id) const
std::string final(std::string const &a_id, bool a_returnAtMetaStableAlias=false) const
bool exists(std::string const &a_id) const
bool isParticle(std::string const &a_id) const
Definition PoPI.hpp:1192
Particle const & particle(std::string const &a_id) const
Definition PoPI.hpp:1178
int A(void) const
std::string const & symbol()
Definition PoPI.hpp:289
bool isSupported()
Definition PoPI.hpp:283
bool isNuclear()
Definition PoPI.hpp:285
int hasNucleus(void) const
Definition PoPI.hpp:876
bool MapWalkDirectoryCallback(ProtareBase const *a_protareEntry, std::string const &a_library, void *a_data, LUPI_maybeUnused int a_level)
Definition GIDI_map.cc:82
void readRIS(std::string const &a_fileName, std::string const &a_energyUnit, Projectiles &a_projectiles)
Definition RISI_read.cc:667
Definition GIDI.hpp:32
bool(* MapWalkCallBack)(Map::ProtareBase const *a_protareEntry, std::string const &a_library, void *a_userData, int a_level)
Definition GIDI.hpp:62
std::map< std::string, ParticleInfo > ParticleSubstitution
Definition GIDI.hpp:487
FileType
Definition GIDI.hpp:148
Definition GUPI.hpp:20
bool exists(std::string const &a_path)
Definition LUPI_file.cc:129
std::string realPath(std::string const &a_path)
Definition LUPI_file.cc:63
bool compareSpecialParticleIDs(std::string const &a_id1, std::string const &a_id2)
Definition PoPI_misc.cc:133
static std::string const photon
Definition PoPI.hpp:162
static std::string const neutron
Definition PoPI.hpp:164