Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
MCGIDI_misc.h File Reference

Go to the source code of this file.

Macros

#define MCGIDI_misc_pointerToTOMAttributeIfAllOk2(smr, required, attributes, name)    MCGIDI_misc_pointerToTOMAttributeIfAllOk( smr, NULL, required, attributes, name, __FILE__, __LINE__ )
 
#define MCGIDI_misc_pointerToTOMAttributeIfAllOk3(smr, path, required, attributes, name)    MCGIDI_misc_pointerToTOMAttributeIfAllOk( smr, path, required, attributes, name, __FILE__, __LINE__ )
 
#define MCGIDI_misc_pointerToAttributeIfAllOk2(smr, element, required, attributes, name)    MCGIDI_misc_pointerToAttributeIfAllOk( smr, element, NULL, required, attributes, name, __FILE__, __LINE__ )
 
#define MCGIDI_misc_pointerToAttributeIfAllOk3(smr, path, required, attributes, name)    MCGIDI_misc_pointerToAttributeIfAllOk( smr, NULL, path, required, attributes, name, __FILE__, __LINE__ )
 

Functions

char const * MCGIDI_misc_pointerToTOMAttributeIfAllOk (statusMessageReporting *smr, char const *path, int required, xDataTOM_attributionList *attributes, char const *name, char const *file, int line)
 
char const * MCGIDI_misc_pointerToAttributeIfAllOk (statusMessageReporting *smr, xDataXML_element *element, char const *path, int required, xDataTOM_attributionList *attributes, char const *name, char const *file, int line)
 
int MCGIDI_misc_setMessageError_Element (statusMessageReporting *smr, void *userInterface, xDataXML_element *element, char const *file, int line, int code, char const *fmt,...)
 
char * MCGIDI_misc_getAbsPath (statusMessageReporting *smr, char const *fileName)
 
int MCGIDI_misc_copyXMLAttributesToTOM (statusMessageReporting *smr, xDataTOM_attributionList *TOM, xDataXML_attributionList *XML)
 
enum xDataTOM_frame MCGIDI_misc_getProductFrame (statusMessageReporting *smr, xDataTOM_element *frameElement)
 
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 *units[2])
 
ptwXYPointsMCGIDI_misc_dataFromElement2ptwXYPointsInUnitsOf (statusMessageReporting *smr, xDataTOM_element *linear, char const *toUnits[2])
 

Macro Definition Documentation

◆ MCGIDI_misc_pointerToAttributeIfAllOk2

#define MCGIDI_misc_pointerToAttributeIfAllOk2 (   smr,
  element,
  required,
  attributes,
  name 
)     MCGIDI_misc_pointerToAttributeIfAllOk( smr, element, NULL, required, attributes, name, __FILE__, __LINE__ )

Definition at line 31 of file MCGIDI_misc.h.

◆ MCGIDI_misc_pointerToAttributeIfAllOk3

#define MCGIDI_misc_pointerToAttributeIfAllOk3 (   smr,
  path,
  required,
  attributes,
  name 
)     MCGIDI_misc_pointerToAttributeIfAllOk( smr, NULL, path, required, attributes, name, __FILE__, __LINE__ )

Definition at line 33 of file MCGIDI_misc.h.

◆ MCGIDI_misc_pointerToTOMAttributeIfAllOk2

#define MCGIDI_misc_pointerToTOMAttributeIfAllOk2 (   smr,
  required,
  attributes,
  name 
)     MCGIDI_misc_pointerToTOMAttributeIfAllOk( smr, NULL, required, attributes, name, __FILE__, __LINE__ )

Definition at line 26 of file MCGIDI_misc.h.

◆ MCGIDI_misc_pointerToTOMAttributeIfAllOk3

#define MCGIDI_misc_pointerToTOMAttributeIfAllOk3 (   smr,
  path,
  required,
  attributes,
  name 
)     MCGIDI_misc_pointerToTOMAttributeIfAllOk( smr, path, required, attributes, name, __FILE__, __LINE__ )

Definition at line 28 of file MCGIDI_misc.h.

Function Documentation

◆ 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 *  units[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,
char const *  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_pointerToAttributeIfAllOk()

char const * MCGIDI_misc_pointerToAttributeIfAllOk ( statusMessageReporting smr,
xDataXML_element element,
char const *  path,
int  required,
xDataTOM_attributionList attributes,
char const *  name,
char const *  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,
char const *  path,
int  required,
xDataTOM_attributionList attributes,
char const *  name,
char const *  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_setMessageError_Element()

int MCGIDI_misc_setMessageError_Element ( statusMessageReporting smr,
void *  userInterface,
xDataXML_element element,
char const *  file,
int  line,
int  code,
char const *  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().