Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_misc.cc File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <ctype.h>
#include <unistd.h>
#include <ptwXY.h>
#include <xDataTOM_importXML_private.h>
#include "MCGIDI.h"
#include "MCGIDI_misc.h"
#include "MCGIDI_fromTOM.h"

Go to the source code of this file.

Classes

struct  ZSymbol
 

Functions

int MCGIDI_misc_NumberOfZSymbols (void)
 
const char * MCGIDI_misc_ZToSymbol (int iZ)
 
int MCGIDI_misc_symbolToZ (const char *Z)
 
int MCGIDI_miscNameToZAm (statusMessageReporting *smr, const char *name, int *Z, int *A, int *m, int *level)
 
char const * MCGIDI_misc_pointerToTOMAttributeIfAllOk (statusMessageReporting *smr, const char *path, int required, xDataTOM_attributionList *attributes, const char *name, const char *file, int line)
 
char const * MCGIDI_misc_pointerToAttributeIfAllOk (statusMessageReporting *smr, xDataXML_element *element, const char *path, int required, xDataTOM_attributionList *attributes, const char *name, const char *file, int line)
 
int MCGIDI_misc_setMessageError_Element (statusMessageReporting *smr, void *userInterface, xDataXML_element *element, const char *file, int line, int code, const char *fmt,...)
 
xDataTOM_Int MCGIDI_misc_binarySearch (xDataTOM_Int n, double *ds, double d)
 
char * MCGIDI_misc_getAbsPath (statusMessageReporting *smr, const char *fileName)
 
int MCGIDI_misc_copyXMLAttributesToTOM (statusMessageReporting *smr, xDataTOM_attributionList *TOM, xDataXML_attributionList *XML)
 
enum xDataTOM_frame MCGIDI_misc_getProductFrame (statusMessageReporting *smr, xDataTOM_element *frameElement)
 
int MCGIDI_misc_PQUStringToDouble (statusMessageReporting *smr, char const *str, char const *unit, double conversion, double *value)
 
int MCGIDI_misc_PQUStringToDoubleInUnitOf (statusMessageReporting *smr, char const *str, char const *toUnit, double *value)
 
double MCGIDI_misc_getUnitConversionFactor (statusMessageReporting *smr, char const *fromUnit, char const *toUnit)
 
ptwXYPointsMCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf (statusMessageReporting *smr, xDataTOM_XYs *XYs, ptwXY_interpolation interpolation, char const *toUnits[2])
 
ptwXYPointsMCGIDI_misc_dataFromElement2ptwXYPointsInUnitsOf (statusMessageReporting *smr, xDataTOM_element *linear, char const *toUnits[2])
 
void MCGIDI_misc_updateTransportabilitiesMap (transportabilitiesMap *transportabilities, int PoPID, enum MCGIDI_transportability transportability)
 
void MCGIDI_misc_updateTransportabilitiesMap2 (transportabilitiesMap *transportabilities, int PoPID, int transportable)
 

Function Documentation

◆ MCGIDI_misc_binarySearch()

xDataTOM_Int MCGIDI_misc_binarySearch ( xDataTOM_Int  n,
double *  ds,
double  d 
)

Definition at line 228 of file MCGIDI_misc.cc.

228 {
229/*
230* Returns -2 is d < first point of ds, -1 if > last point of ds and the lower index of ds otherwise.
231*/
232 xDataTOM_Int imin = 0, imid, imax = n - 1;
233
234 if( d < ds[0] ) return( -2 );
235 if( d > ds[n-1] ) return( -1 );
236 while( 1 ) { // Loop checking, 11.06.2015, T. Koi
237 imid = ( imin + imax ) >> 1;
238 if( imid == imin ) break;
239 if( d < ds[imid] ) {
240 imax = imid; }
241 else {
242 imin = imid;
243 }
244 }
245 return( imin );
246}
int xDataTOM_Int
Definition: xDataTOM.h:16

Referenced by MCGIDI_sampling_doubleDistribution(), MCGIDI_sampling_sampleX_from_pdfOfX(), and MCGIDI_sampling_sampleX_from_pdfsOfXGivenW().

◆ MCGIDI_misc_copyXMLAttributesToTOM()

int MCGIDI_misc_copyXMLAttributesToTOM ( statusMessageReporting smr,
xDataTOM_attributionList TOM,
xDataXML_attributionList XML 
)

Definition at line 296 of file MCGIDI_misc.cc.

296 {
297
298 int i;
299 xDataXML_attribute *attribute;
300
301 xDataTOMAL_initial( smr, TOM );
302 for( i = 0; ; i++ ) {
303 if( ( attribute = xDataXML_attributeByIndex( XML, i ) ) == NULL ) break;
304 if( xDataTOMAL_addAttribute( smr, TOM, attribute->name, attribute->value ) != 0 ) goto err;
305 }
306 return( 0 );
307
308err:
309 xDataTOMAL_release( TOM );
310 return( 1 );
311}
int xDataTOMAL_addAttribute(statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, char const *value)
Definition: xDataTOM.cc:376
void xDataTOMAL_initial(statusMessageReporting *smr, xDataTOM_attributionList *attributes)
Definition: xDataTOM.cc:353
void xDataTOMAL_release(xDataTOM_attributionList *attributes)
Definition: xDataTOM.cc:361
xDataXML_attribute * xDataXML_attributeByIndex(xDataXML_attributionList *attributes, int index)

◆ MCGIDI_misc_dataFromElement2ptwXYPointsInUnitsOf()

ptwXYPoints * MCGIDI_misc_dataFromElement2ptwXYPointsInUnitsOf ( statusMessageReporting smr,
xDataTOM_element linear,
char const *  toUnits[2] 
)

Definition at line 424 of file MCGIDI_misc.cc.

424 {
425
426 int length;
427 double *data;
428 xDataTOM_axes *axes = &(linear->xDataInfo.axes);
429 char const *fromUnits[2];
430 ptwXY_interpolation interpolation;
431
432 if( axes->numberOfAxes != 2 ) {
433 smr_setReportError2( smr, smr_unknownID, 1, "axes must have 2 axis, it has %d", axes->numberOfAxes );
434 return( NULL );
435 }
436
437 if( MCGIDI_fromTOM_interpolation( smr, linear, 0, &interpolation ) != 0 ) return( NULL );
438 fromUnits[0] = axes->axis[0].unit;
439 fromUnits[1] = axes->axis[1].unit;
440
441 length = xDataTOM_XYs_getDataFromXDataInfo( (xDataTOM_xDataInfo *) &(linear->xDataInfo), &data );
442 return( MCGIDI_misc_Data2ptwXYPointsInUnitsOf( smr, interpolation, length, data, fromUnits, toUnits ) );
443}
int MCGIDI_fromTOM_interpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, enum ptwXY_interpolation_e *interpolation)
enum ptwXY_interpolation_e ptwXY_interpolation
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_unknownID
int numberOfAxes
Definition: xDataTOM.h:69
xDataTOM_axis * axis
Definition: xDataTOM.h:70
char * unit
Definition: xDataTOM.h:64
xDataTOM_xDataInfo xDataInfo
Definition: xDataTOM.h:187
xDataTOM_axes axes
Definition: xDataTOM.h:153
int xDataTOM_XYs_getDataFromXDataInfo(xDataTOM_xDataInfo *xDI, double **data)
Definition: xDataTOM_XYs.cc:50

Referenced by MCGIDI_product_parseFromTOM(), and MCGIDI_reaction_parseFromTOM().

◆ MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf()

ptwXYPoints * MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf ( statusMessageReporting smr,
xDataTOM_XYs XYs,
ptwXY_interpolation  interpolation,
char const *  toUnits[2] 
)

Definition at line 405 of file MCGIDI_misc.cc.

406 {
407
408 int length;
409 double *data;
410 char const *fromUnits[2];
411
412 fromUnits[0] = xDataTOM_subAxes_getUnit( smr, &(XYs->subAxes), 0 );
413 if( !smr_isOk( smr ) ) return( NULL );
414 fromUnits[1] = xDataTOM_subAxes_getUnit( smr, &(XYs->subAxes), 1 );
415 if( !smr_isOk( smr ) ) return( NULL );
416
417 length = xDataTOM_XYs_getData( XYs, &data );
418
419 return( MCGIDI_misc_Data2ptwXYPointsInUnitsOf( smr, interpolation, length, data, fromUnits, toUnits ) );
420}
int smr_isOk(statusMessageReporting *smr)
xDataTOM_subAxes subAxes
Definition: xDataTOM.h:83
int xDataTOM_XYs_getData(xDataTOM_XYs *XYs, double **data)
Definition: xDataTOM_XYs.cc:42
char const * xDataTOM_subAxes_getUnit(statusMessageReporting *smr, xDataTOM_subAxes *subAxes, int index)

Referenced by MCGIDI_angular_parseFromTOM(), and MCGIDI_fromTOM_pdfsOfXGivenW().

◆ MCGIDI_misc_getAbsPath()

char * MCGIDI_misc_getAbsPath ( statusMessageReporting smr,
const char *  fileName 
)

Definition at line 250 of file MCGIDI_misc.cc.

250 {
251/*
252* User must free returned string.
253*/
254 int n = (int) strlen( fileName ) + 1, nCwd = 0;
255 char *absPath, cwd[4 * 1024] = "", *p, *needle;
256
257 if( fileName[0] != '/' ) {
258 //if( getcwd( cwd, sizeof( cwd ) + 1 ) == NULL ) {
259 //TK modified above line for compiler(gcc.4.8) warning message
260 if( getcwd( cwd, sizeof( cwd ) ) == NULL ) {
261 smr_setReportError2p( smr, smr_unknownID, -1, "hardwired cwd too small" );
262 return( NULL );
263 }
264 nCwd = (int) strlen( cwd );
265 n += nCwd + 1; /* cwd + '/'. */
266 }
267 if( ( absPath = (char *) smr_malloc2( smr, n, 0, "absPath" ) ) == NULL ) return( NULL );
268 if( fileName[0] != '/' ) {
269 strcpy( absPath, cwd );
270 strcat( absPath, "/" );
271 strcat( absPath, fileName ); }
272 else {
273 strcpy( absPath, fileName );
274 }
275
276 while( 1 ) { /* Remove all ./ from path. */ // Loop checking, 11.06.2015, T. Koi
277 if( ( needle = strstr( absPath, "/./" ) ) == NULL ) break;
278 p = needle;
279 for( needle += 2; *needle; p++, needle++ ) *p = *needle;
280 *p = 0;
281 }
282 while( 1 ) { /* Remove all ../ from path. */ // Loop checking, 11.06.2015, T. Koi
283 if( ( needle = strstr( absPath, "/../" ) ) == NULL ) break;
284 p = needle - 1;
285 while( ( p > absPath ) && ( *p != '/' ) ) p--; // Loop checking, 11.06.2015, T. Koi
286 if( *p != '/' ) break; /* This should not happen if path is legit, I think, and I do not know what to do so will leave it. */
287 if( p == absPath ) break; /* Ditto. */
288 for( needle += 3; *needle; p++, needle++ ) *p = *needle;
289 *p = 0;
290 }
291 return( absPath );
292}
#define smr_setReportError2p(smr, libraryID, code, fmt)
#define smr_malloc2(smr, size, zero, forItem)

Referenced by MCGIDI_target_read().

◆ MCGIDI_misc_getProductFrame()

enum xDataTOM_frame MCGIDI_misc_getProductFrame ( statusMessageReporting smr,
xDataTOM_element frameElement 
)

Definition at line 315 of file MCGIDI_misc.cc.

315 {
316
317 char const *frameString;
319
320 if( ( frameString = xDataTOM_getAttributesValueInElement( frameElement, MCGIDI_token_productFrame ) ) != NULL ) {
321 if( ( frame = xDataTOM_axis_stringToFrame( smr, frameString ) ) == xDataTOM_frame_invalid ) {
322 smr_setReportError2( smr, smr_unknownID, 1, "Invalid frame = '%s'", frameString );
323 }
324 }
325 return( frame );
326}
#define MCGIDI_token_productFrame
enum xDataTOM_frame xDataTOM_axis_stringToFrame(statusMessageReporting *smr, char const *frame)
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
Definition: xDataTOM.cc:286
xDataTOM_frame
Definition: xDataTOM.h:23
@ xDataTOM_frame_invalid
Definition: xDataTOM.h:23

Referenced by MCGIDI_angular_parseFromTOM(), MCGIDI_energy_parseFromTOM(), and MCGIDI_KalbachMann_parseFromTOM().

◆ MCGIDI_misc_getUnitConversionFactor()

double MCGIDI_misc_getUnitConversionFactor ( statusMessageReporting smr,
char const *  fromUnit,
char const *  toUnit 
)

Definition at line 381 of file MCGIDI_misc.cc.

381 {
382/*
383* This is a kludge until units are better supported.
384*/
385 if( strcmp( fromUnit, toUnit ) == 0 ) return( 1.0 );
386
387 if( strcmp( fromUnit, "eV" ) == 0 ) {
388 if( strcmp( toUnit, "MeV" ) == 0 ) return( 1e-6 ); }
389 else if( strcmp( fromUnit, "MeV" ) == 0 ) {
390 if( strcmp( toUnit, "eV" ) == 0 ) return( 1e+6 ); }
391 else if( strcmp( fromUnit, "1/eV" ) == 0 ) {
392 if( strcmp( toUnit, "1/MeV" ) == 0 ) return( 1e+6 ); }
393 else if( strcmp( fromUnit, "1/MeV" ) == 0 ) {
394 if( strcmp( toUnit, "1/eV" ) == 0 ) return( 1e-6 ); }
395 else if( strcmp( fromUnit, "K" ) == 0 ) {
396 if( strcmp( toUnit, "MeV/k" ) == 0 ) return( 8.617343183775137e-11 );
397 }
398
399 smr_setReportError2( smr, smr_unknownID, 1, "Cannot convert unit '%s' to unit '%s'", fromUnit, toUnit );
400 return( 1.0 );
401}

Referenced by MCGIDI_angular_parseFromTOM(), MCGIDI_fromTOM_pdfsOfXGivenW(), MCGIDI_KalbachMann_parseFromTOM(), MCGIDI_misc_PQUStringToDoubleInUnitOf(), and MCGIDI_target_heated_read().

◆ MCGIDI_misc_NumberOfZSymbols()

int MCGIDI_misc_NumberOfZSymbols ( void  )

Definition at line 54 of file MCGIDI_misc.cc.

54 {
55
56 return( sizeof( ZSymbols ) / sizeof( struct ZSymbol ) );
57}

Referenced by MCGIDI_misc_symbolToZ(), and MCGIDI_misc_ZToSymbol().

◆ MCGIDI_misc_pointerToAttributeIfAllOk()

char const * MCGIDI_misc_pointerToAttributeIfAllOk ( statusMessageReporting smr,
xDataXML_element element,
const char *  path,
int  required,
xDataTOM_attributionList attributes,
const char *  name,
const char *  file,
int  line 
)

Definition at line 184 of file MCGIDI_misc.cc.

185 {
186
187 char const *value;
188
189 if( !smr_isOk( smr ) ) return( NULL );
190 if( ( value = xDataTOMAL_getAttributesValue( attributes, name ) ) == NULL ) {
191 if( required ) {
192 if( element != NULL ) {
193 MCGIDI_misc_setMessageError_Element( smr, NULL, element, file, line, 1, "element does not have attribute named %s", name ); }
194 else {
195 smr_setReportError( smr, NULL, file, line, __func__, smr_unknownID, 1, "element does not have attribute named %s for file = %d", name, path );
196 }
197 }
198 }
199 return( value );
200}
int MCGIDI_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xDataXML_element *element, const char *file, int line, int code, const char *fmt,...)
Definition: MCGIDI_misc.cc:204
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
char const * xDataTOMAL_getAttributesValue(xDataTOM_attributionList *attributes, char const *name)
Definition: xDataTOM.cc:403

◆ MCGIDI_misc_pointerToTOMAttributeIfAllOk()

char const * MCGIDI_misc_pointerToTOMAttributeIfAllOk ( statusMessageReporting smr,
const char *  path,
int  required,
xDataTOM_attributionList attributes,
const char *  name,
const char *  file,
int  line 
)

Definition at line 168 of file MCGIDI_misc.cc.

169 {
170
171 char const *value;
172
173 if( !smr_isOk( smr ) ) return( NULL );
174 if( ( value = xDataTOMAL_getAttributesValue( attributes, name ) ) == NULL ) {
175 if( required ) {
176 smr_setReportError( smr, NULL, file, line, __func__, smr_unknownID, 1, "element does not have attribute named %s for file = %d", name, path );
177 }
178 }
179 return( value );
180}

◆ MCGIDI_misc_PQUStringToDouble()

int MCGIDI_misc_PQUStringToDouble ( statusMessageReporting smr,
char const *  str,
char const *  unit,
double  conversion,
double *  value 
)

Definition at line 330 of file MCGIDI_misc.cc.

330 {
331/*
332* Currently, white spaces are not allowed after the unit.
333*
334* Examples of allowed strings are: "2.39e6 eV", " 2.39e6eV" and " 2.39e6 eV".
335*/
336 char const *s = str;
337 char *e;
338
339
340 while( isspace( *s ) ) s++; // Loop checking, 11.06.2015, T. Koi
341 *value = strtod( s, &e ) * conversion;
342 if( e == s ) {
343 smr_setReportError2( smr, smr_unknownID, 1, "no number at start of string = <%s>", str );
344 return( 1 );
345 }
346 while( isspace( *e ) ) e++; // Loop checking, 11.06.2015, T. Koi
347 if( strcmp( e, unit ) != 0 ) {
348 smr_setReportError2( smr, smr_unknownID, 1, "unit = '%s' not '%s' in '%s'", e, unit, str );
349 return( 1 );
350 }
351 return( 0 );
352}

◆ MCGIDI_misc_PQUStringToDoubleInUnitOf()

int MCGIDI_misc_PQUStringToDoubleInUnitOf ( statusMessageReporting smr,
char const *  str,
char const *  toUnit,
double *  value 
)

Definition at line 356 of file MCGIDI_misc.cc.

356 {
357/*
358* Currently, white spaces are not allowed after the unit.
359*
360* Examples of allowed strings are: "2.39e6 eV", " 2.39e6eV" and " 2.39e6 eV".
361*/
362 char const *s1 = str;
363 char *e1;
364 double factor;
365
366 while( isspace( *s1 ) ) s1++; // Loop checking, 11.06.2015, T. Koi
367 *value = strtod( s1, &e1 );
368 if( e1 == s1 ) {
369 smr_setReportError2( smr, smr_unknownID, 1, "no number at start of string = <%s>", str );
370 return( 1 );
371 }
372 while( isspace( *e1 ) ) e1++; // Loop checking, 11.06.2015, T. Koi
373
374 factor = MCGIDI_misc_getUnitConversionFactor( smr, e1, toUnit );
375 *value *= factor;
376 return( !smr_isOk( smr ) );
377}
double MCGIDI_misc_getUnitConversionFactor(statusMessageReporting *smr, char const *fromUnit, char const *toUnit)
Definition: MCGIDI_misc.cc:381

Referenced by MCGIDI_distribution_parseFromTOM(), MCGIDI_outputChannel_parseFromTOM(), and MCGIDI_product_parseFromTOM().

◆ MCGIDI_misc_setMessageError_Element()

int MCGIDI_misc_setMessageError_Element ( statusMessageReporting smr,
void *  userInterface,
xDataXML_element element,
const char *  file,
int  line,
int  code,
const char *  fmt,
  ... 
)

Definition at line 204 of file MCGIDI_misc.cc.

205 {
206
207 int status = 0;
208 va_list args;
209 char *msg;
210
211 va_start( args, fmt );
212 msg = smr_vallocateFormatMessage( fmt, &args );
213 va_end( args );
214 if( msg == NULL ) {
215 status = 1;
216 va_start( args, fmt );
217 smr_vsetReportError( smr, userInterface, file, line, __func__, smr_unknownID, code, fmt, &args );
218 va_end( args ); }
219 else {
220 status = smr_setReportError( smr, userInterface, file, line, __func__, smr_unknownID, code, "%s for element %s", msg, element->name );
221 smr_freeMemory( (void **) &msg );
222 }
223 return( status );
224}
int smr_vsetReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt, va_list *args)
char * smr_vallocateFormatMessage(char const *fmt, va_list *args)
void * smr_freeMemory(void **p)
Definition: inftrees.h:24

Referenced by MCGIDI_misc_pointerToAttributeIfAllOk(), and MCGIDI_target_read().

◆ MCGIDI_misc_symbolToZ()

int MCGIDI_misc_symbolToZ ( const char *  Z)

Definition at line 69 of file MCGIDI_misc.cc.

69 {
70
72
73 for( i = 0; i < n; i++ ) {
74 if( strcmp( Z, ZSymbols[i].symbol ) == 0 ) return( ZSymbols[i].Z );
75 }
76 return( -1 );
77}
const G4int Z[17]
int MCGIDI_misc_NumberOfZSymbols(void)
Definition: MCGIDI_misc.cc:54

Referenced by MCGIDI_miscNameToZAm().

◆ MCGIDI_misc_updateTransportabilitiesMap()

void MCGIDI_misc_updateTransportabilitiesMap ( transportabilitiesMap transportabilities,
int  PoPID,
enum MCGIDI_transportability  transportability 
)

Definition at line 482 of file MCGIDI_misc.cc.

482 {
483
484 transportabilitiesMap::iterator iter = transportabilities->find( PoPID );
485
486 if( iter != transportabilities->end( ) ) {
487 switch ( iter->second ) {
489 break;
491 switch( transportability ) {
494 transportability = MCGIDI_transportability_none;
495 break;
497 break;
499 transportability = MCGIDI_transportability_partial;
500 break;
501 }
502 break;
504 transportability = MCGIDI_transportability_partial;
505 break;
507 switch( transportability ) {
510 transportability = MCGIDI_transportability_partial;
511 break;
514 break;
515 }
516 break;
517 }
518 }
519 (*transportabilities)[PoPID] = transportability;
520}
@ MCGIDI_transportability_unknown
Definition: MCGIDI.h:161
@ MCGIDI_transportability_none
Definition: MCGIDI.h:162
@ MCGIDI_transportability_partial
Definition: MCGIDI.h:163
@ MCGIDI_transportability_full
Definition: MCGIDI.h:164

Referenced by MCGIDI_misc_updateTransportabilitiesMap2(), and MCGIDI_target_heated_read().

◆ MCGIDI_misc_updateTransportabilitiesMap2()

void MCGIDI_misc_updateTransportabilitiesMap2 ( transportabilitiesMap transportabilities,
int  PoPID,
int  transportable 
)

Definition at line 524 of file MCGIDI_misc.cc.

524 {
525
527}
void MCGIDI_misc_updateTransportabilitiesMap(transportabilitiesMap *transportabilities, int PoPID, enum MCGIDI_transportability transportability)
Definition: MCGIDI_misc.cc:482

◆ MCGIDI_misc_ZToSymbol()

const char * MCGIDI_misc_ZToSymbol ( int  iZ)

Definition at line 61 of file MCGIDI_misc.cc.

61 {
62
63 if( ( iZ < 0 ) || ( iZ >= MCGIDI_misc_NumberOfZSymbols( ) ) ) return( NULL );
64 return( ZSymbols[iZ].symbol );
65}

Referenced by G4GIDI_Misc_Z_A_m_ToName().

◆ MCGIDI_miscNameToZAm()

int MCGIDI_miscNameToZAm ( statusMessageReporting smr,
const char *  name,
int *  Z,
int *  A,
int *  m,
int *  level 
)

Definition at line 81 of file MCGIDI_misc.cc.

81 {
82
83 const char *p;
84 char s[1024] = "", *q, *e; /* Note 1) routine will fail when parts of a particle name can be longer than 1024. */
85
86 if( strlen( name ) >= ( sizeof( s ) - 1 ) ) {
87 smr_setReportError2( smr, smr_unknownID, 0, "particle name too long: '%s'", name );
88 return( 1 );
89 }
90
91 *Z = *A = *m = *level = 0;
92 if( ( !strncmp( "FissionProduct", name, 14 ) ) || !strncmp( "99120", name, 5 ) ) {
93 *Z = 99;
94 *A = 120;
95 return( 0 );
96 }
97 if( strcmp( "gamma", name ) == 0 ) return( 0 );
98 if( strcmp( "n", name ) == 0 ) { *A = 1; return( 0 ); }
99
100 for( p = name, q = s; ( *p != 0 ) && !isdigit( *p ) && ( *p != '_' ); p++, q++ ) *q = *p; /* '_' only for "natural". */
101 if( *p == 0 ) {
102 smr_setReportError2( smr, smr_unknownID, 0, "unsupported particle name = '%s'", name );
103 return( 1 );
104 }
105 *q = 0;
106 if( ( *Z = MCGIDI_misc_symbolToZ( s ) ) < 0 ) {
107 smr_setReportError2( smr, smr_unknownID, 1, "Particle %s's symbol = '%s' not found", name, s ); }
108 else { /* Getting here implies that *p is a digit. */
109 if( *p == '_' ) {
110 if( strncmp( p, "_natural", 8 ) == 0 ) {
111 p += 8;
112 if( *p ) *level = MCGIDI_miscNameToZAm_getLevel( smr, name, p ); }
113 else {
114 smr_setReportError2( smr, smr_unknownID, 0, "expecting 'natural': %s", name );
115 } }
116 else {
117 for( q = s; isdigit( *p ); p++, q++ ) *q = *p;
118 *q = 0;
119 if( strcmp( s, "natural" ) == 0 ) {
120 e = s;
121 while( *e ) e++; /* Loop checking, 11.06.2015, T. Koi*/ }
122 else {
123 *A = (int) strtol( s, &e, 10 );
124 }
125 if( *e != 0 ) {
126 smr_setReportError2( smr, smr_unknownID, 1, "Failed to convert A to integer in particle name %s", name ); }
127 else { /* Getting here implies that *p == '_' or 0. */
128 if( *p ) *level = MCGIDI_miscNameToZAm_getLevel( smr, name, p );
129 }
130 }
131 }
132
133 return( !smr_isOk( smr ) );
134}
const G4double A[17]
int MCGIDI_misc_symbolToZ(const char *Z)
Definition: MCGIDI_misc.cc:69

Referenced by G4GIDI_Misc_channelCompound(), MCGIDI_particle_getInternalID(), and MCGIDI_POP_new().