Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
tpia_map.h File Reference
#include <xData.h>

Go to the source code of this file.

Classes

struct  tpia_map_smr_s
 
struct  tpia_mapEntry_s
 
struct  tpia_map_s
 

Typedefs

typedef struct tpia_map_s tpia_map
 
typedef struct tpia_mapEntry_s tpia_mapEntry
 
typedef struct tpia_map_smr_s tpia_map_smr
 

Enumerations

enum  tpia_map_status { tpia_map_status_Ok , tpia_map_status_memory , tpia_map_status_mapParsing , tpia_map_status_UnknownType }
 
enum  tpia_mapEntry_type { tpia_mapEntry_type_target , tpia_mapEntry_type_path }
 

Functions

tpia_maptpia_map_create (statusMessageReporting *smr)
 
int tpia_map_initialize (statusMessageReporting *smr, tpia_map *map)
 
tpia_maptpia_map_readFile (statusMessageReporting *smr, const char *basePath, const char *mapFileName)
 
void * tpia_map_free (statusMessageReporting *smr, tpia_map *map)
 
void tpia_map_release (statusMessageReporting *smr, tpia_map *map)
 
tpia_mapEntrytpia_map_getFirstEntry (tpia_map *map)
 
tpia_mapEntrytpia_map_getNextEntry (tpia_mapEntry *entry)
 
int tpia_map_addTarget (statusMessageReporting *smr, tpia_map *map, const char *method, const char *path, const char *evaluation, const char *projectile, const char *targetName)
 
int tpia_map_addPath (statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile)
 
char * tpia_map_findTarget (statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
 
tpia_maptpia_map_findAllOfTarget (statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName)
 
char * tpia_map_getFullPath (statusMessageReporting *smr, tpia_map *map, const char *endPath)
 
int tpia_map_walkTree (statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
 
char * tpia_map_toXMLString (statusMessageReporting *smr, tpia_map *map)
 
void tpia_map_simpleWrite (FILE *f, tpia_map *map)
 

Typedef Documentation

◆ tpia_map

typedef struct tpia_map_s tpia_map

Definition at line 53 of file tpia_map.h.

◆ tpia_map_smr

typedef struct tpia_map_smr_s tpia_map_smr

Definition at line 55 of file tpia_map.h.

◆ tpia_mapEntry

Definition at line 54 of file tpia_map.h.

Enumeration Type Documentation

◆ tpia_map_status

Enumerator
tpia_map_status_Ok 
tpia_map_status_memory 
tpia_map_status_mapParsing 
tpia_map_status_UnknownType 

Definition at line 49 of file tpia_map.h.

@ tpia_map_status_memory
Definition: tpia_map.h:49
@ tpia_map_status_UnknownType
Definition: tpia_map.h:50
@ tpia_map_status_Ok
Definition: tpia_map.h:49
@ tpia_map_status_mapParsing
Definition: tpia_map.h:49

◆ tpia_mapEntry_type

Enumerator
tpia_mapEntry_type_target 
tpia_mapEntry_type_path 

Definition at line 51 of file tpia_map.h.

@ tpia_mapEntry_type_target
Definition: tpia_map.h:51
@ tpia_mapEntry_type_path
Definition: tpia_map.h:51

Function Documentation

◆ tpia_map_addPath()

int tpia_map_addPath ( statusMessageReporting smr,
tpia_map map,
const char *  path,
const char *  projectile 
)

Definition at line 236 of file tpia_map.cc.

236 {
237
238 tpia_mapEntry *entry = _tpia_map_addEntry( smr, map, tpia_mapEntry_type_path, NULL, path, NULL, projectile, NULL );
239
240 if( entry != NULL ) {
241 if( ( entry->map = tpia_map_readFile( smr, map->path, entry->path ) ) == NULL ) entry = NULL;
242 }
243 return( entry != NULL );
244}
char * path
Definition: tpia_map.h:66
tpia_map * map
Definition: tpia_map.h:70
char * path
Definition: tpia_map.h:76
tpia_map * tpia_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
Definition: tpia_map.cc:88

Referenced by tpia_map_readFile().

◆ tpia_map_addTarget()

int tpia_map_addTarget ( statusMessageReporting smr,
tpia_map map,
const char *  method,
const char *  path,
const char *  evaluation,
const char *  projectile,
const char *  targetName 
)

Definition at line 229 of file tpia_map.cc.

229 {
230
231 return( _tpia_map_addEntry( smr, map, tpia_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL );
232}

Referenced by tpia_map_readFile().

◆ tpia_map_create()

tpia_map * tpia_map_create ( statusMessageReporting smr)

Definition at line 59 of file tpia_map.cc.

59 {
60
61 tpia_map *map;
62
63 //if( ( map = xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL );
64 if( ( map = (tpia_map*) xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL );
65 //if( tpia_map_initialize( smr, map ) ) map = tpia_map_free( NULL, map );
66 if( tpia_map_initialize( smr, map ) ) map = (tpia_map*) tpia_map_free( NULL, map );
67 return( map );
68}
int tpia_map_initialize(statusMessageReporting *, tpia_map *map)
Definition: tpia_map.cc:73
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:184
#define xData_malloc2(smr, size, zero, forItem)
Definition: xData.h:313

Referenced by tpia_map_findAllOfTarget(), and tpia_map_readFile().

◆ tpia_map_findAllOfTarget()

tpia_map * tpia_map_findAllOfTarget ( statusMessageReporting smr,
tpia_map map,
const char *  projectile,
const char *  targetName 
)

Definition at line 393 of file tpia_map.cc.

393 {
394/*
395* Calling routine must free returned pointer.
396*/
397 int status;
398 tpia_map *mapAllOfTarget;
399
400 if( map->status != tpia_map_status_Ok ) return( NULL );
401 if( ( mapAllOfTarget = tpia_map_create( smr ) ) == NULL ) return( NULL );
402 status = _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, map, projectile, targetName );
403 //if( ( status != 0 ) ) mapAllOfTarget = tpia_map_free( smr, mapAllOfTarget );
404 if( ( status != 0 ) ) mapAllOfTarget = (tpia_map*) tpia_map_free( smr, mapAllOfTarget );
405 return( mapAllOfTarget );
406}
enum tpia_map_status status
Definition: tpia_map.h:74
tpia_map * tpia_map_create(statusMessageReporting *smr)
Definition: tpia_map.cc:59

Referenced by G4GIDI::getNamesOfAvailableLibraries().

◆ tpia_map_findTarget()

char * tpia_map_findTarget ( statusMessageReporting smr,
tpia_map map,
const char *  evaluation,
const char *  projectile,
const char *  targetName 
)

Definition at line 327 of file tpia_map.cc.

327 {
328/*
329* Calling routine must free returned pointer.
330*/
331 char *path;
332
333 if( map->status != tpia_map_status_Ok ) return( NULL );
334
335 path = _tpia_map_findTarget2( smr, map, evaluation, projectile, targetName );
336 if( ( path == NULL ) && smr_isOk( smr ) ) {
337 if( evaluation == NULL ) {
338 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, "target %s for projectile %s not found", targetName, projectile ); }
339 else {
340 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, "target %s for projectile %s and evaluation %s not found", targetName, projectile, evaluation );
341 }
342 }
343 return( path );
344}
int smr_setMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isOk(statusMessageReporting *smr)
tpia_map_smr smrUserInterface
Definition: tpia_map.h:75

Referenced by G4GIDI::dataFilename(), tpia_target_createReadFromMap(), and tpia_target_readFromMap().

◆ tpia_map_free()

void * tpia_map_free ( statusMessageReporting smr,
tpia_map map 
)

Definition at line 184 of file tpia_map.cc.

184 {
185
186 tpia_map_release( smr, map );
187 xData_free( smr, map );
188 return( NULL );
189}
void tpia_map_release(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:193
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89

Referenced by G4GIDI::getNamesOfAvailableLibraries(), tpia_depot_freeMap(), tpia_depot_release(), tpia_map_create(), tpia_map_findAllOfTarget(), tpia_map_readFile(), tpia_map_release(), and G4GIDI_map::~G4GIDI_map().

◆ tpia_map_getFirstEntry()

tpia_mapEntry * tpia_map_getFirstEntry ( tpia_map map)

Definition at line 215 of file tpia_map.cc.

215 {
216
217 return( map->mapEntries );
218}
tpia_mapEntry * mapEntries
Definition: tpia_map.h:79

Referenced by G4GIDI::getNamesOfAvailableLibraries().

◆ tpia_map_getFullPath()

char * tpia_map_getFullPath ( statusMessageReporting smr,
tpia_map map,
const char *  endPath 
)

Definition at line 437 of file tpia_map.cc.

437 {
438
439 char *path;
440
441 if( endPath[0] == '/' ) {
442 //if( ( path = xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL );
443 if( ( path = (char*) xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL );
444 path[0] = 0; }
445 else {
446 //if( ( path = xData_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 0, "path" ) ) == NULL ) return( NULL );
447 if( ( path = (char*) xData_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 0, "path" ) ) == NULL ) return( NULL );
448 strcpy( path, map->path );
449 strcat( path, "/" );
450 }
451 strcat( path, endPath );
452 return( path );
453}

◆ tpia_map_getNextEntry()

tpia_mapEntry * tpia_map_getNextEntry ( tpia_mapEntry entry)

Definition at line 222 of file tpia_map.cc.

222 {
223
224 return( entry->next );
225}
tpia_mapEntry * next
Definition: tpia_map.h:63

Referenced by G4GIDI::getNamesOfAvailableLibraries().

◆ tpia_map_initialize()

int tpia_map_initialize ( statusMessageReporting smr,
tpia_map map 
)

Definition at line 73 of file tpia_map.cc.

73 {
74
75 memset( map, 0, sizeof( tpia_map ) );
77 map->smrUserInterface.smrUserInterface = _tpia_map_smrUserInterface;
78 map->smrUserInterface.map = map;
79 map->path = NULL;
80 map->mapFileName = NULL;
81 map->numberOfEntries = 0;
82 map->mapEntries = NULL;
83 return( 0 );
84}
char * mapFileName
Definition: tpia_map.h:77
int numberOfEntries
Definition: tpia_map.h:78
tpia_map * map
Definition: tpia_map.h:59
smr_userInterface smrUserInterface
Definition: tpia_map.h:58

Referenced by tpia_map_create().

◆ tpia_map_readFile()

tpia_map * tpia_map_readFile ( statusMessageReporting smr,
const char *  basePath,
const char *  mapFileName 
)

Definition at line 88 of file tpia_map.cc.

88 {
89/*
90* If an error occurrs, map is freed and NULL is returned.
91*/
92 int n = 0;
93 xData_document *doc;
94 xData_element *element;
95 xData_element *child;
96 tpia_map *map;
97 const char *evaluation, *projectile, *targetName, *path, *schema;
98#ifndef WIN32
99 char realPath[2 * ( PATH_MAX + 1 )], *p = &(realPath[PATH_MAX+1]);
100#endif
101#ifdef WIN32
102 char realPath[2 * ( _MAX_PATH + 1 )], *p = &(realPath[_MAX_PATH+1]);
103#endif
104
105 if( ( map = tpia_map_create( smr ) ) == NULL ) return( NULL );
106
107 if( ( basePath == NULL ) || ( mapFileName[0] == '/' ) ) {
108 strcpy( realPath, mapFileName ); }
109 else {
110 strcpy( realPath, basePath );
111 strcat( realPath, "/" );
112 strcat( realPath, mapFileName );
113 }
114#ifndef WIN32
115 if( realpath( realPath, p ) == NULL ) {
116 smr_setMessageError( smr, NULL, __FILE__, __LINE__, tpia_map_status_mapParsing, "No map file %s\n", mapFileName );
117 //return( tpia_map_free( NULL, map ) );
118 return( (tpia_map*) tpia_map_free( NULL, map ) );
119 }
120#endif
121 n = strlen( p ) + 2;
122 //if( ( map->path = xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) );
123 //if( ( map->path = (char*) xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) );
124 if( ( map->path = (char*) xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( (tpia_map*) tpia_map_free( NULL, map ) );
125 map->mapFileName = &(map->path[n + 1]);
126 strcpy( map->mapFileName, p );
127 strcpy( map->path, p );
128 if( ( p = strrchr( map->path, '/' ) ) != NULL ) {
129 *p = 0; }
130 else {
131 strcpy( map->path, "." );
132 }
133
134 //if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( tpia_map_free( NULL, map ) );
135 if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( (tpia_map*) tpia_map_free( NULL, map ) );
136
137 element = xData_getDocumentsElement( doc );
138 for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) {
139 if( !strcmp( child->name, "path" ) ) {
140 if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) {
141 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing path attribute" );
142 break;
143 }
144 if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) {
145 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing projectile attribute" );
146 break;
147 }
148 tpia_map_addPath( smr, map, path, projectile ); }
149 else if( !strcmp( child->name, "target" ) ) {
150 if( ( schema = xData_getAttributesValueInElement( child , "schema" ) ) == NULL ) {
151 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'schema' attribute" );
152 break;
153 }
154 if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) {
155 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'path' attribute" );
156 break;
157 }
158 if( ( evaluation = xData_getAttributesValueInElement( child , "evaluation" ) ) == NULL ) {
159 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'evaluation' attribute" );
160 break;
161 }
162 if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) {
163 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'projectile' attribute" );
164 break;
165 }
166 if( ( targetName = xData_getAttributesValueInElement( child , "target" ) ) == NULL ) {
167 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'target' attribute" );
168 break;
169 }
170 tpia_map_addTarget( smr, map, schema, path, evaluation, projectile, targetName ); }
171 else {
172 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "invalid element = %s", child->name );
173 }
174 if( !smr_isOk( smr ) ) break;
175 }
176 xData_parseFree( smr, doc );
177 //if( !smr_isOk( smr ) ) map = tpia_map_free( NULL, map );
178 if( !smr_isOk( smr ) ) map = (tpia_map*) tpia_map_free( NULL, map );
179 return( map );
180}
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
char * name
Definition: xData.h:184
int tpia_map_addPath(statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile)
Definition: tpia_map.cc:236
int tpia_map_addTarget(statusMessageReporting *smr, tpia_map *map, const char *schema, const char *path, const char *evaluation, const char *projectile, const char *target)
Definition: tpia_map.cc:229
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
Definition: xData.cc:546
void * xData_parseFree(statusMessageReporting *smr, xData_document *xData_doc)
Definition: xData.cc:208
xData_element * xData_getNextElement(xData_element *element)
Definition: xData.cc:478
xData_element * xData_getDocumentsElement(xData_document *xData_doc)
Definition: xData.cc:476
xData_element * xData_getFirstElement(xData_element *element)
Definition: xData.cc:477
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
Definition: xData.cc:84

Referenced by G4GIDI_map::G4GIDI_map(), tpia_depot_setMapFromFilename(), and tpia_map_addPath().

◆ tpia_map_release()

void tpia_map_release ( statusMessageReporting smr,
tpia_map map 
)

Definition at line 193 of file tpia_map.cc.

193 {
194
195 tpia_mapEntry *entry, *next;
196
197 if( map->path != NULL ) xData_free( NULL, map->path );
198 for( entry = map->mapEntries; entry != NULL; entry = next ) {
199 next = entry->next;
200 if( entry->schema != NULL ) xData_free( NULL, entry->schema );
201 if( entry->path != NULL ) xData_free( NULL, entry->path );
202 if( entry->evaluation != NULL ) xData_free( NULL, entry->evaluation );
203 if( entry->projectile != NULL ) xData_free( NULL, entry->projectile );
204 if( entry->targetName != NULL ) xData_free( NULL, entry->targetName );
205 if( entry->map != NULL ) tpia_map_free( smr, entry->map );
206 xData_free( NULL, entry );
207 }
208 map->numberOfEntries = 0;
209 map->mapEntries = NULL;
211}
char * projectile
Definition: tpia_map.h:68
char * evaluation
Definition: tpia_map.h:67
char * schema
Definition: tpia_map.h:65
char * targetName
Definition: tpia_map.h:69

Referenced by tpia_map_free().

◆ tpia_map_simpleWrite()

void tpia_map_simpleWrite ( FILE *  f,
tpia_map map 
)

Definition at line 527 of file tpia_map.cc.

527{ _tpia_map_simpleWrite2( f, map, 0 ); }

◆ tpia_map_toXMLString()

char * tpia_map_toXMLString ( statusMessageReporting smr,
tpia_map map 
)

Definition at line 478 of file tpia_map.cc.

478 {
479
480 tpia_mapEntry *entry;
481 char *s, *p;
482 char targetFormat[] = "<target schema=\"%s\" evaluation=\"%s\" projectile=\"%s\" target=\"%s\" path=\"%s\"/>\n";
483 char pathFormat[] = "<path projectile=\"%s\" path=\"%s\"/>\n";
484 char start[] = "<map>\n";
485 char end[] = "</map>";
486 int n = 0, nStart = strlen( start ), nEnd = strlen( end );
487 int nTarget = strlen( targetFormat ) - 10, nPath = strlen( pathFormat ) - 4;
488
489 if( map->status != tpia_map_status_Ok ) return( NULL );
490
491 n = nStart + nEnd + 1;
492 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
493 switch( entry->type ) {
495 n += strlen( entry->schema ) + strlen( entry->path ) + strlen( entry->evaluation ) + strlen( entry->projectile ) + strlen( entry->targetName ) + nTarget;
496 break;
498 n += strlen( entry->path ) + strlen( entry->projectile ) + nPath;
499 break;
500 default :
501 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, "unknown type = %d", entry->type );
502 return( NULL );
503 }
504 }
505
506 if( ( s = (char *) xData_malloc2( smr, n, 0, "xml string" ) ) == NULL ) return( NULL );
507 p = s;
508 strcpy( p, start );
509 while( *p ) p++;
510 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
511 switch( entry->type ) {
513 sprintf( p, targetFormat, entry->schema, entry->evaluation, entry->projectile, entry->targetName, entry->path );
514 break;
516 sprintf( p, pathFormat, entry->projectile, entry->path );
517 break;
518 }
519 while( *p ) p++;
520 }
521 strcpy( p, end );
522 return( s );
523}
enum tpia_mapEntry_type type
Definition: tpia_map.h:64

◆ tpia_map_walkTree()

int tpia_map_walkTree ( statusMessageReporting smr,
tpia_map map,
int(*)(tpia_mapEntry *entry, int level, void *userData handler,
void *  userData 
)

Definition at line 457 of file tpia_map.cc.

457 {
458
459 return( _tpia_map_walkTree2( smr, map, 0, handler, userData ) );
460}
#define userData
Definition: xmlparse.cc:555

Referenced by G4GIDI::getNamesOfAvailableTargets().