Geant4 Cross Reference |
1 /* 1 /* 2 # <<BEGIN-copyright>> 2 # <<BEGIN-copyright>> 3 # <<END-copyright>> 3 # <<END-copyright>> 4 */ 4 */ 5 #include <string.h> 5 #include <string.h> 6 #include <limits.h> 6 #include <limits.h> 7 #include <PoPs.h> 7 #include <PoPs.h> 8 #include "MCGIDI_map.h" 8 #include "MCGIDI_map.h" 9 #include <xDataTOM_importXML_private.h> 9 #include <xDataTOM_importXML_private.h> 10 10 11 #ifndef PATH_MAX 11 #ifndef PATH_MAX 12 #define PATH_MAX 4096 12 #define PATH_MAX 4096 13 #endif 13 #endif 14 14 15 #if defined(WIN32) || defined(__MINGW32__) << 15 #ifdef WIN32 16 #include <windows.h> 16 #include <windows.h> 17 #define realpath( a, b ) GetFullPathName( a, P 17 #define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL ) 18 #endif 18 #endif 19 19 20 static int aliasesNeeded = 1; 20 static int aliasesNeeded = 1; 21 21 22 #if defined __cplusplus 22 #if defined __cplusplus 23 extern "C" { 23 extern "C" { 24 namespace GIDI { 24 namespace GIDI { 25 using namespace GIDI; 25 using namespace GIDI; 26 #endif 26 #endif 27 static MCGIDI_mapEntry *_MCGIDI_map_addEntry( 27 static MCGIDI_mapEntry *_MCGIDI_map_addEntry( statusMessageReporting *smr, MCGIDI_map *map, enum MCGIDI_mapEntry_type type, const char *schema, const char *path, 28 const char *evaluation, const char *projec 28 const char *evaluation, const char *projectile, const char *target ); 29 static char *_MCGIDI_map_findTargetViaPoPIDs2( 29 static char *_MCGIDI_map_findTargetViaPoPIDs2( statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, 30 int projectile_PoPID, int target_P 30 int projectile_PoPID, int target_PoPID ); 31 static int _MCGIDI_map_findAllOfTargetViaPoPID 31 static int _MCGIDI_map_findAllOfTargetViaPoPIDs2( statusMessageReporting *smr, MCGIDI_map *mapAllOfTarget, MCGIDI_map *map, 32 int projectile_PoPID, int target_PoPID 32 int projectile_PoPID, int target_PoPID ); 33 static int _MCGIDI_map_walkTree2( statusMessag 33 static int _MCGIDI_map_walkTree2( statusMessageReporting *smr, MCGIDI_map *map, int level, int (*handler)( MCGIDI_mapEntry *entry, int level, void *userData), 34 void *userData ); 34 void *userData ); 35 static void _MCGIDI_map_simpleWrite2( FILE *f, 35 static void _MCGIDI_map_simpleWrite2( FILE *f, MCGIDI_map *map, int level ); 36 static char *_MCGIDI_map_smrUserInterface( voi 36 static char *_MCGIDI_map_smrUserInterface( void *userData ); 37 #if defined __cplusplus 37 #if defined __cplusplus 38 } 38 } 39 } 39 } 40 #endif 40 #endif 41 41 42 #if defined __cplusplus 42 #if defined __cplusplus 43 namespace GIDI { 43 namespace GIDI { 44 using namespace GIDI; 44 using namespace GIDI; 45 #endif 45 #endif 46 /* 46 /* 47 ********************************************** 47 ************************************************************ 48 */ 48 */ 49 MCGIDI_map *MCGIDI_map_new( statusMessageRepor 49 MCGIDI_map *MCGIDI_map_new( statusMessageReporting *smr ) { 50 50 51 MCGIDI_map *map; 51 MCGIDI_map *map; 52 52 53 if( ( map = (MCGIDI_map *) smr_malloc2( sm 53 if( ( map = (MCGIDI_map *) smr_malloc2( smr, sizeof( MCGIDI_map ), 0, "map" ) ) == NULL ) return( NULL ); 54 if( MCGIDI_map_initialize( smr, map ) ) ma 54 if( MCGIDI_map_initialize( smr, map ) ) map = (MCGIDI_map *) MCGIDI_map_free( NULL, map ); 55 return( map ); 55 return( map ); 56 } 56 } 57 /* 57 /* 58 ********************************************** 58 ************************************************************ 59 */ 59 */ 60 int MCGIDI_map_initialize( statusMessageReport 60 int MCGIDI_map_initialize( statusMessageReporting *smr, MCGIDI_map *map ) { 61 61 62 memset( map, 0, sizeof( MCGIDI_map ) ); 62 memset( map, 0, sizeof( MCGIDI_map ) ); 63 map->status = MCGIDI_map_status_Ok; 63 map->status = MCGIDI_map_status_Ok; 64 map->smrUserInterface.smrUserInterface = _ 64 map->smrUserInterface.smrUserInterface = _MCGIDI_map_smrUserInterface; 65 map->smrUserInterface.map = map; 65 map->smrUserInterface.map = map; 66 map->path = NULL; 66 map->path = NULL; 67 map->mapFileName = NULL; 67 map->mapFileName = NULL; 68 map->numberOfEntries = 0; 68 map->numberOfEntries = 0; 69 map->mapEntries = NULL; 69 map->mapEntries = NULL; 70 70 71 /* 71 /* 72 * Add some default aliases. This is a kludge 72 * Add some default aliases. This is a kludge until aliases are fully supported. 73 */ 73 */ 74 if( aliasesNeeded ) { /* Support all meta-stab 74 if( aliasesNeeded ) { /* Support all meta-stables in ENDF/B-VII.1 */ 75 char const *aliases[] = { "Co58m1", "Ag11 75 char const *aliases[] = { "Co58m1", "Ag110m1", "Cd115m1", "Te127m1", "Te129m1", "Pm148m1", "Ho166m1", "Am242m1", "Am244m1", "Es254m1" }; 76 char const *targets[] = { "Co58_e1", "Ag11 76 char const *targets[] = { "Co58_e1", "Ag110_e2", "Cd115_e1", "Te127_e2", "Te129_e1", "Pm148_e2", "Ho166_e1", "Am242_e2", "Am244_e1", "Es254_e2" }; 77 int i1, n1 = sizeof( aliases ) / sizeof( a 77 int i1, n1 = sizeof( aliases ) / sizeof( aliases[1] ); 78 78 79 79 80 for( i1 = 0; i1 < n1; i1++ ) { 80 for( i1 = 0; i1 < n1; i1++ ) { 81 lPoPs_addParticleIfNeeded( smr, target 81 lPoPs_addParticleIfNeeded( smr, targets[i1], NULL ); 82 if( !smr_isOk( smr ) ) return( 1 ); 82 if( !smr_isOk( smr ) ) return( 1 ); 83 PoPs_addAliasIfNeeded( smr, targets[i1 83 PoPs_addAliasIfNeeded( smr, targets[i1], aliases[i1] ); 84 if( !smr_isOk( smr ) ) return( 1 ); 84 if( !smr_isOk( smr ) ) return( 1 ); 85 } 85 } 86 aliasesNeeded = 0; 86 aliasesNeeded = 0; 87 } 87 } 88 return( 0 ); 88 return( 0 ); 89 } 89 } 90 /* 90 /* 91 ********************************************** 91 ************************************************************ 92 */ 92 */ 93 MCGIDI_map *MCGIDI_map_readFile( statusMessage 93 MCGIDI_map *MCGIDI_map_readFile( statusMessageReporting *smr, const char *basePath, const char *mapFileName ) { 94 /* 94 /* 95 * If an error occurrs, map is freed and NULL 95 * If an error occurrs, map is freed and NULL is returned. 96 */ 96 */ 97 int n = 0; 97 int n = 0; 98 xDataXML_document *doc; 98 xDataXML_document *doc; 99 xDataXML_element *element; 99 xDataXML_element *element; 100 xDataXML_element *child; 100 xDataXML_element *child; 101 MCGIDI_map *map; 101 MCGIDI_map *map; 102 const char *evaluation, *projectile, *targ 102 const char *evaluation, *projectile, *targetName, *path, *schema; 103 char realPath[2 * ( PATH_MAX + 1 )], *p = 103 char realPath[2 * ( PATH_MAX + 1 )], *p = &(realPath[PATH_MAX+1]); 104 104 105 if( ( map = MCGIDI_map_new( smr ) ) == NUL 105 if( ( map = MCGIDI_map_new( smr ) ) == NULL ) return( NULL ); 106 106 107 if( ( basePath == NULL ) || ( mapFileName[ 107 if( ( basePath == NULL ) || ( mapFileName[0] == '/' ) ) { 108 strcpy( realPath, mapFileName ); } 108 strcpy( realPath, mapFileName ); } 109 else { 109 else { 110 strcpy( realPath, basePath ); 110 strcpy( realPath, basePath ); 111 strcat( realPath, "/" ); 111 strcat( realPath, "/" ); 112 strcat( realPath, mapFileName ); 112 strcat( realPath, mapFileName ); 113 } 113 } 114 if( realpath( realPath, p ) == NULL ) { 114 if( realpath( realPath, p ) == NULL ) { 115 smr_setReportError2( smr, smr_unknownI 115 smr_setReportError2( smr, smr_unknownID, MCGIDI_map_status_mapParsing, "No map file %s\n", mapFileName ); 116 return( (MCGIDI_map *) MCGIDI_map_free 116 return( (MCGIDI_map *) MCGIDI_map_free( NULL, map ) ); 117 } 117 } 118 n = (int) strlen( p ) + 2; 118 n = (int) strlen( p ) + 2; 119 if( ( map->path = (char *) smr_malloc2( sm 119 if( ( map->path = (char *) smr_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( (MCGIDI_map *) MCGIDI_map_free( NULL, map ) ); 120 map->mapFileName = &(map->path[n + 1]); 120 map->mapFileName = &(map->path[n + 1]); 121 strcpy( map->mapFileName, p ); 121 strcpy( map->mapFileName, p ); 122 strcpy( map->path, p ); 122 strcpy( map->path, p ); 123 if( ( p = strrchr( map->path, '/' ) ) != N 123 if( ( p = strrchr( map->path, '/' ) ) != NULL ) { 124 *p = 0; } 124 *p = 0; } 125 else { 125 else { 126 strcpy( map->path, "." ); 126 strcpy( map->path, "." ); 127 } 127 } 128 128 129 if( ( doc = xDataXML_importFile2( smr, map 129 if( ( doc = xDataXML_importFile2( smr, map->mapFileName ) ) == NULL ) return( (MCGIDI_map *) MCGIDI_map_free( NULL, map ) ); 130 130 131 element = xDataXML_getDocumentsElement( do 131 element = xDataXML_getDocumentsElement( doc ); 132 for( child = xDataXML_getFirstElement( ele 132 for( child = xDataXML_getFirstElement( element ); child != NULL; child = xDataXML_getNextElement( child ) ) { 133 if( strcmp( child->name, "path" ) == 0 133 if( strcmp( child->name, "path" ) == 0 ) { 134 if( ( path = xDataXML_getAttribute 134 if( ( path = xDataXML_getAttributesValueInElement( child , "path" ) ) == NULL ) { 135 smr_setReportError3p( smr, &(m 135 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "path missing path attribute" ); 136 break; 136 break; 137 } 137 } 138 MCGIDI_map_addPath( smr, map, path 138 MCGIDI_map_addPath( smr, map, path ); } 139 else if( strcmp( child->name, "target" 139 else if( strcmp( child->name, "target" ) == 0 ) { 140 if( ( schema = xDataXML_getAttribu 140 if( ( schema = xDataXML_getAttributesValueInElement( child , "schema" ) ) == NULL ) { 141 smr_setReportError3p( smr, &(m 141 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "target missing 'schema' attribute" ); 142 break; 142 break; 143 } 143 } 144 if( ( path = xDataXML_getAttribute 144 if( ( path = xDataXML_getAttributesValueInElement( child , "path" ) ) == NULL ) { 145 smr_setReportError3p( smr, &(m 145 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "target missing 'path' attribute" ); 146 break; 146 break; 147 } 147 } 148 if( ( evaluation = xDataXML_getAtt 148 if( ( evaluation = xDataXML_getAttributesValueInElement( child , "evaluation" ) ) == NULL ) { 149 smr_setReportError3p( smr, &(m 149 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "target missing 'evaluation' attribute" ); 150 break; 150 break; 151 } 151 } 152 if( ( projectile = xDataXML_getAtt 152 if( ( projectile = xDataXML_getAttributesValueInElement( child , "projectile" ) ) == NULL ) { 153 smr_setReportError3p( smr, &(m 153 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "target missing 'projectile' attribute" ); 154 break; 154 break; 155 } 155 } 156 if( ( targetName = xDataXML_getAtt 156 if( ( targetName = xDataXML_getAttributesValueInElement( child , "target" ) ) == NULL ) { 157 smr_setReportError3p( smr, &(m 157 smr_setReportError3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "target missing 'target' attribute" ); 158 break; 158 break; 159 } 159 } 160 MCGIDI_map_addTarget( smr, map, sc 160 MCGIDI_map_addTarget( smr, map, schema, path, evaluation, projectile, targetName ); } 161 else { 161 else { 162 smr_setReportError3( smr, &(map->s 162 smr_setReportError3( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_mapParsing, "invalid element = %s", child->name ); 163 } 163 } 164 if( !smr_isOk( smr ) ) break; 164 if( !smr_isOk( smr ) ) break; 165 } 165 } 166 xDataXML_freeDoc( smr, doc ); 166 xDataXML_freeDoc( smr, doc ); 167 if( !smr_isOk( smr ) ) map = (MCGIDI_map * 167 if( !smr_isOk( smr ) ) map = (MCGIDI_map *) MCGIDI_map_free( NULL, map ); 168 return( map ); 168 return( map ); 169 } 169 } 170 /* 170 /* 171 ********************************************** 171 ************************************************************ 172 */ 172 */ 173 void *MCGIDI_map_free( statusMessageReporting 173 void *MCGIDI_map_free( statusMessageReporting *smr, MCGIDI_map *map ) { 174 174 175 MCGIDI_map_release( smr, map ); 175 MCGIDI_map_release( smr, map ); 176 smr_freeMemory( (void **) &map ); 176 smr_freeMemory( (void **) &map ); 177 return( NULL ); 177 return( NULL ); 178 } 178 } 179 /* 179 /* 180 ********************************************** 180 ************************************************************ 181 */ 181 */ 182 void MCGIDI_map_release( statusMessageReportin 182 void MCGIDI_map_release( statusMessageReporting *smr, MCGIDI_map *map ) { 183 183 184 MCGIDI_mapEntry *entry, *next; 184 MCGIDI_mapEntry *entry, *next; 185 185 186 if( map->path != NULL ) smr_freeMemory( (v 186 if( map->path != NULL ) smr_freeMemory( (void **) &(map->path) ); 187 for( entry = map->mapEntries; entry != NUL 187 for( entry = map->mapEntries; entry != NULL; entry = next ) { 188 next = entry->next; 188 next = entry->next; 189 if( entry->schema != NULL ) smr_freeMe 189 if( entry->schema != NULL ) smr_freeMemory( (void **) &(entry->schema) ); 190 if( entry->path != NULL ) smr_freeMemo 190 if( entry->path != NULL ) smr_freeMemory( (void **) &(entry->path) ); 191 if( entry->evaluation != NULL ) smr_fr 191 if( entry->evaluation != NULL ) smr_freeMemory( (void **) &(entry->evaluation) ); 192 if( entry->projectile != NULL ) smr_fr 192 if( entry->projectile != NULL ) smr_freeMemory( (void **) &(entry->projectile) ); 193 if( entry->targetName != NULL ) smr_fr 193 if( entry->targetName != NULL ) smr_freeMemory( (void **) &(entry->targetName) ); 194 if( entry->map != NULL ) MCGIDI_map_fr 194 if( entry->map != NULL ) MCGIDI_map_free( smr, entry->map ); 195 smr_freeMemory( (void **) &entry ); 195 smr_freeMemory( (void **) &entry ); 196 } 196 } 197 map->numberOfEntries = 0; 197 map->numberOfEntries = 0; 198 map->mapEntries = NULL; 198 map->mapEntries = NULL; 199 map->status = MCGIDI_map_status_Ok; 199 map->status = MCGIDI_map_status_Ok; 200 } 200 } 201 /* 201 /* 202 ********************************************** 202 ************************************************************ 203 */ 203 */ 204 MCGIDI_mapEntry *MCGIDI_map_getFirstEntry( MCG 204 MCGIDI_mapEntry *MCGIDI_map_getFirstEntry( MCGIDI_map *map ) { 205 205 206 return( map->mapEntries ); 206 return( map->mapEntries ); 207 } 207 } 208 /* 208 /* 209 ********************************************** 209 ************************************************************ 210 */ 210 */ 211 MCGIDI_mapEntry *MCGIDI_map_getNextEntry( MCGI 211 MCGIDI_mapEntry *MCGIDI_map_getNextEntry( MCGIDI_mapEntry *entry ) { 212 212 213 return( entry->next ); 213 return( entry->next ); 214 } 214 } 215 /* 215 /* 216 ********************************************** 216 ************************************************************ 217 */ 217 */ 218 int MCGIDI_map_addTarget( statusMessageReporti 218 int MCGIDI_map_addTarget( statusMessageReporting *smr, MCGIDI_map *map, const char *schema, const char *path, const char *evaluation, const char *projectile, const char *target ) { 219 219 220 return( _MCGIDI_map_addEntry( smr, map, MC 220 return( _MCGIDI_map_addEntry( smr, map, MCGIDI_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL ); 221 } 221 } 222 /* 222 /* 223 ********************************************** 223 ************************************************************ 224 */ 224 */ 225 int MCGIDI_map_addPath( statusMessageReporting 225 int MCGIDI_map_addPath( statusMessageReporting *smr, MCGIDI_map *map, const char *path ) { 226 226 227 MCGIDI_mapEntry *entry = _MCGIDI_map_addEn 227 MCGIDI_mapEntry *entry = _MCGIDI_map_addEntry( smr, map, MCGIDI_mapEntry_type_path, NULL, path, NULL, NULL, NULL ); 228 228 229 if( entry != NULL ) { 229 if( entry != NULL ) { 230 if( ( entry->map = MCGIDI_map_readFile 230 if( ( entry->map = MCGIDI_map_readFile( smr, map->path, entry->path ) ) == NULL ) entry = NULL; 231 } 231 } 232 return( entry != NULL ); 232 return( entry != NULL ); 233 } 233 } 234 /* 234 /* 235 ********************************************** 235 ************************************************************ 236 */ 236 */ 237 static MCGIDI_mapEntry *_MCGIDI_map_addEntry( 237 static MCGIDI_mapEntry *_MCGIDI_map_addEntry( statusMessageReporting *smr, MCGIDI_map *map, enum MCGIDI_mapEntry_type type, const char *schema, 238 const char *path, const char *evaluation, 238 const char *path, const char *evaluation, const char *projectile, const char *targetName ) { 239 239 240 MCGIDI_mapEntry *p; 240 MCGIDI_mapEntry *p; 241 MCGIDI_mapEntry *entry; 241 MCGIDI_mapEntry *entry; 242 242 243 if( ( entry = (MCGIDI_mapEntry * ) smr_mal 243 if( ( entry = (MCGIDI_mapEntry * ) smr_malloc2( smr, sizeof( MCGIDI_mapEntry ), 1, "entry" ) ) == NULL ) return( NULL ); 244 entry->next = NULL; 244 entry->next = NULL; 245 entry->type = type; 245 entry->type = type; 246 entry->parent = map; 246 entry->parent = map; 247 entry->schema = NULL; 247 entry->schema = NULL; 248 entry->path = NULL; 248 entry->path = NULL; 249 entry->evaluation = NULL; 249 entry->evaluation = NULL; 250 entry->projectile = NULL; 250 entry->projectile = NULL; 251 entry->targetName = NULL; 251 entry->targetName = NULL; 252 entry->globalPoPsIndexProjectile = entry-> 252 entry->globalPoPsIndexProjectile = entry->globalPoPsIndexTarget = -1; 253 entry->map = NULL; 253 entry->map = NULL; 254 254 255 if( path != NULL ) { 255 if( path != NULL ) { 256 if( ( entry->path = (char *) smr_mallo 256 if( ( entry->path = (char *) smr_malloc2( smr, strlen( path ) + 1, 0, "path" ) ) == NULL ) goto err; 257 strcpy( entry->path, path ); 257 strcpy( entry->path, path ); 258 } 258 } 259 259 260 if( evaluation != NULL ) { 260 if( evaluation != NULL ) { 261 if( ( entry->evaluation = (char *) smr 261 if( ( entry->evaluation = (char *) smr_malloc2( smr, strlen( evaluation ) + 1, 0, "evaluation" ) ) == NULL ) goto err; 262 strcpy( entry->evaluation, evaluation 262 strcpy( entry->evaluation, evaluation ); 263 } 263 } 264 264 265 if( projectile != NULL ) { 265 if( projectile != NULL ) { 266 if( ( entry->globalPoPsIndexProjectile 266 if( ( entry->globalPoPsIndexProjectile = lPoPs_addParticleIfNeeded( smr, projectile, "LLNL" ) ) < 0 ) goto err; 267 if( ( entry->projectile = (char *) smr 267 if( ( entry->projectile = (char *) smr_malloc2( smr, strlen( projectile ) + 1, 0, "projectile" ) ) == NULL ) goto err; 268 strcpy( entry->projectile, projectile 268 strcpy( entry->projectile, projectile ); 269 } 269 } 270 270 271 if( targetName != NULL ) { 271 if( targetName != NULL ) { 272 if( ( entry->globalPoPsIndexTarget = l 272 if( ( entry->globalPoPsIndexTarget = lPoPs_addParticleIfNeeded( smr, targetName, "LLNL" ) ) < 0 ) goto err; 273 if( ( entry->targetName = (char *) smr 273 if( ( entry->targetName = (char *) smr_malloc2( smr, strlen( targetName ) + 1, 0, "target" ) ) == NULL ) goto err; 274 strcpy( entry->targetName, targetName 274 strcpy( entry->targetName, targetName ); 275 } 275 } 276 276 277 if( schema != NULL ) { 277 if( schema != NULL ) { 278 if( ( entry->schema = (char *) smr_mal 278 if( ( entry->schema = (char *) smr_malloc2( smr, strlen( schema ) + 1, 0, "schema" ) ) == NULL ) goto err; 279 strcpy( entry->schema, schema ); 279 strcpy( entry->schema, schema ); 280 } 280 } 281 281 282 if( map->mapEntries == NULL ) { 282 if( map->mapEntries == NULL ) { 283 map->mapEntries = entry; } 283 map->mapEntries = entry; } 284 else { 284 else { 285 for( p = map->mapEntries; p->next != N 285 for( p = map->mapEntries; p->next != NULL; p = p->next ); 286 p->next = entry; 286 p->next = entry; 287 } 287 } 288 map->numberOfEntries++; 288 map->numberOfEntries++; 289 return( entry ); 289 return( entry ); 290 290 291 err: 291 err: 292 smr_freeMemory( (void **) &(entry->path) ) 292 smr_freeMemory( (void **) &(entry->path) ); 293 smr_freeMemory( (void **) &(entry->evaluat 293 smr_freeMemory( (void **) &(entry->evaluation) ); 294 smr_freeMemory( (void **) &(entry->project 294 smr_freeMemory( (void **) &(entry->projectile) ); 295 smr_freeMemory( (void **) &(entry->targetN 295 smr_freeMemory( (void **) &(entry->targetName) ); 296 smr_freeMemory( (void **) &entry ); 296 smr_freeMemory( (void **) &entry ); 297 return( NULL ); 297 return( NULL ); 298 } 298 } 299 /* 299 /* 300 ********************************************** 300 ************************************************************ 301 */ 301 */ 302 char *MCGIDI_map_findTargetViaPoPIDs( statusMe 302 char *MCGIDI_map_findTargetViaPoPIDs( statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, 303 int projectile_PoPID, int target_PoPID ) { 303 int projectile_PoPID, int target_PoPID ) { 304 /* 304 /* 305 * Calling routine must free returned pointer. 305 * Calling routine must free returned pointer. 306 */ 306 */ 307 char *path; 307 char *path; 308 char const *projectileName = PoPs_getName_ 308 char const *projectileName = PoPs_getName_atIndex( smr, projectile_PoPID ); 309 char const *targetName = PoPs_getName_atIn 309 char const *targetName = PoPs_getName_atIndex( smr, target_PoPID ); 310 310 311 if( !smr_isOk( smr ) ) return( NULL ); 311 if( !smr_isOk( smr ) ) return( NULL ); 312 if( map->status != MCGIDI_map_status_Ok ) 312 if( map->status != MCGIDI_map_status_Ok ) return( NULL ); 313 313 314 path = _MCGIDI_map_findTargetViaPoPIDs2( s 314 path = _MCGIDI_map_findTargetViaPoPIDs2( smr, map, evaluation, projectile_PoPID, target_PoPID ); 315 if( ( path == NULL ) && smr_isOk( smr ) ) 315 if( ( path == NULL ) && smr_isOk( smr ) ) { 316 if( evaluation == NULL ) { 316 if( evaluation == NULL ) { 317 smr_setReportInfo3( smr, &(map->sm 317 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, 1, "target %s for projectile %s not found", 318 targetName, projectileName ); 318 targetName, projectileName ); } 319 else { 319 else { 320 smr_setReportInfo3( smr, &(map->sm 320 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, 1, "target %s for projectile %s and evaluation %s not found", 321 targetName, projectileName, ev 321 targetName, projectileName, evaluation ); 322 } 322 } 323 } 323 } 324 return( path ); 324 return( path ); 325 } 325 } 326 /* 326 /* 327 ********************************************** 327 ************************************************************ 328 */ 328 */ 329 static char *_MCGIDI_map_findTargetViaPoPIDs2( 329 static char *_MCGIDI_map_findTargetViaPoPIDs2( statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, 330 int projectile_PoPID, int target_P 330 int projectile_PoPID, int target_PoPID ) { 331 331 332 MCGIDI_mapEntry *entry; 332 MCGIDI_mapEntry *entry; 333 char *path = NULL; 333 char *path = NULL; 334 int n, status; 334 int n, status; 335 335 336 if( evaluation != NULL ) { 336 if( evaluation != NULL ) { 337 if( strlen( evaluation ) == 0 ) evalua 337 if( strlen( evaluation ) == 0 ) evaluation = NULL; 338 } 338 } 339 339 340 for( entry = map->mapEntries; entry != NUL 340 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 341 switch( entry->type ) { 341 switch( entry->type ) { 342 case MCGIDI_mapEntry_type_target : 342 case MCGIDI_mapEntry_type_target : 343 if( ( projectile_PoPID == entry->g 343 if( ( projectile_PoPID == entry->globalPoPsIndexProjectile ) && ( target_PoPID == entry->globalPoPsIndexTarget ) ) { 344 if( evaluation == NULL ) { 344 if( evaluation == NULL ) { 345 status = 1; } 345 status = 1; } 346 else { 346 else { 347 status = strcmp( evaluatio 347 status = strcmp( evaluation, entry->evaluation ) == 0; 348 } 348 } 349 if( status ) { 349 if( status ) { 350 n = (int) strlen( map->pat 350 n = (int) strlen( map->path ) + 1 + (int) strlen( entry->path ) + 1; 351 if( ( path = (char * ) smr 351 if( ( path = (char * ) smr_malloc2( smr, n, 0, "path" ) ) == NULL ) return( NULL ); 352 strcpy( path, map->path ); 352 strcpy( path, map->path ); 353 strcat( path, "/" ); 353 strcat( path, "/" ); 354 if( entry->path[0] == '/' 354 if( entry->path[0] == '/' ) { 355 strcpy( path, entry->p 355 strcpy( path, entry->path ); } 356 else { 356 else { 357 strcat( path, entry->p 357 strcat( path, entry->path ); 358 } 358 } 359 return( path ); 359 return( path ); 360 } 360 } 361 } 361 } 362 break; 362 break; 363 case MCGIDI_mapEntry_type_path : 363 case MCGIDI_mapEntry_type_path : 364 if( ( path = _MCGIDI_map_findTarge 364 if( ( path = _MCGIDI_map_findTargetViaPoPIDs2( smr, entry->map, evaluation, projectile_PoPID, target_PoPID ) ) != NULL ) return( path ); 365 break; 365 break; 366 default : 366 default : 367 smr_setReportInfo3( smr, &(map->sm 367 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_UnknownType, "unknown type = %d", entry->type ); 368 return( NULL ); 368 return( NULL ); 369 } 369 } 370 } 370 } 371 return( NULL ); 371 return( NULL ); 372 } 372 } 373 /* 373 /* 374 ********************************************** 374 ************************************************************ 375 */ 375 */ 376 char *MCGIDI_map_findTarget( statusMessageRepo 376 char *MCGIDI_map_findTarget( statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, const char *projectile, const char *targetName ) { 377 377 378 int projectile_PoPID, target_PoPID; 378 int projectile_PoPID, target_PoPID; 379 379 380 if( ( projectile_PoPID = lPoPs_addParticle 380 if( ( projectile_PoPID = lPoPs_addParticleIfNeeded( smr, projectile, "LLNL" ) ) < 0 ) return( NULL ); 381 if( ( target_PoPID = lPoPs_addParticle 381 if( ( target_PoPID = lPoPs_addParticleIfNeeded( smr, targetName, "LLNL" ) ) < 0 ) return( NULL ); 382 return( MCGIDI_map_findTargetViaPoPIDs( sm 382 return( MCGIDI_map_findTargetViaPoPIDs( smr, map, evaluation, projectile_PoPID, target_PoPID ) ); 383 } 383 } 384 /* 384 /* 385 ********************************************** 385 ************************************************************ 386 */ 386 */ 387 MCGIDI_map *MCGIDI_map_findAllOfTargetViaPoPID 387 MCGIDI_map *MCGIDI_map_findAllOfTargetViaPoPIDs( statusMessageReporting *smr, MCGIDI_map *map, int projectile_PoPID, 388 int target_PoPID ) { 388 int target_PoPID ) { 389 /* 389 /* 390 * Calling routine must free returned pointer. 390 * Calling routine must free returned pointer. 391 */ 391 */ 392 int status; 392 int status; 393 MCGIDI_map *mapAllOfTarget; 393 MCGIDI_map *mapAllOfTarget; 394 394 395 if( map->status != MCGIDI_map_status_Ok ) 395 if( map->status != MCGIDI_map_status_Ok ) return( NULL ); 396 if( ( mapAllOfTarget = MCGIDI_map_new( smr 396 if( ( mapAllOfTarget = MCGIDI_map_new( smr ) ) == NULL ) return( NULL ); 397 status = _MCGIDI_map_findAllOfTargetViaPoP 397 status = _MCGIDI_map_findAllOfTargetViaPoPIDs2( smr, mapAllOfTarget, map, projectile_PoPID, target_PoPID ); 398 if( ( status != 0 ) ) mapAllOfTarget = (MC 398 if( ( status != 0 ) ) mapAllOfTarget = (MCGIDI_map *) MCGIDI_map_free( smr, mapAllOfTarget ); 399 return( mapAllOfTarget ); 399 return( mapAllOfTarget ); 400 } 400 } 401 /* 401 /* 402 ********************************************** 402 ************************************************************ 403 */ 403 */ 404 static int _MCGIDI_map_findAllOfTargetViaPoPID 404 static int _MCGIDI_map_findAllOfTargetViaPoPIDs2( statusMessageReporting *smr, MCGIDI_map *mapAllOfTarget, MCGIDI_map *map, 405 int projectile_PoPID, int target_PoPID 405 int projectile_PoPID, int target_PoPID ) { 406 406 407 MCGIDI_mapEntry *entry; 407 MCGIDI_mapEntry *entry; 408 408 409 for( entry = map->mapEntries; entry != NUL 409 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 410 switch( entry->type ) { 410 switch( entry->type ) { 411 case MCGIDI_mapEntry_type_target : 411 case MCGIDI_mapEntry_type_target : 412 if( ( projectile_PoPID == entry->g 412 if( ( projectile_PoPID == entry->globalPoPsIndexProjectile ) && ( target_PoPID == entry->globalPoPsIndexTarget ) ) { 413 if( _MCGIDI_map_addEntry( smr, 413 if( _MCGIDI_map_addEntry( smr, mapAllOfTarget, entry->type, entry->schema, entry->path, entry->evaluation, entry->projectile, 414 entry->targetName ) == NUL 414 entry->targetName ) == NULL ) return( 1 ); 415 } 415 } 416 break; 416 break; 417 case MCGIDI_mapEntry_type_path : 417 case MCGIDI_mapEntry_type_path : 418 if( _MCGIDI_map_findAllOfTargetVia 418 if( _MCGIDI_map_findAllOfTargetViaPoPIDs2( smr, mapAllOfTarget, entry->map, projectile_PoPID, target_PoPID ) != 0 ) return( 1 ); 419 break; 419 break; 420 default : 420 default : 421 smr_setReportInfo3( smr, &(map->sm 421 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_UnknownType, "unknown type = %d", entry->type ); 422 return( 1 ); 422 return( 1 ); 423 } 423 } 424 } 424 } 425 return( 0 ); 425 return( 0 ); 426 } 426 } 427 /* 427 /* 428 ********************************************** 428 ************************************************************ 429 */ 429 */ 430 MCGIDI_map *MCGIDI_map_findAllOfTarget( status 430 MCGIDI_map *MCGIDI_map_findAllOfTarget( statusMessageReporting *smr, MCGIDI_map *map, const char *projectile, const char *targetName ) { 431 431 432 int projectile_PoPID, target_PoPID; 432 int projectile_PoPID, target_PoPID; 433 433 434 if( ( projectile_PoPID = lPoPs_addParticle 434 if( ( projectile_PoPID = lPoPs_addParticleIfNeeded( smr, projectile, "LLNL" ) ) < 0 ) return( NULL ); 435 if( ( target_PoPID = lPoPs_addParticle 435 if( ( target_PoPID = lPoPs_addParticleIfNeeded( smr, targetName, "LLNL" ) ) < 0 ) return( NULL ); 436 return( MCGIDI_map_findAllOfTargetViaPoPID 436 return( MCGIDI_map_findAllOfTargetViaPoPIDs( smr, map, projectile_PoPID, target_PoPID ) ); 437 } 437 } 438 /* 438 /* 439 ********************************************** 439 ************************************************************ 440 */ 440 */ 441 char *MCGIDI_map_getFullPath( statusMessageRep 441 char *MCGIDI_map_getFullPath( statusMessageReporting *smr, MCGIDI_map *map, const char *endPath ) { 442 442 443 char *path; 443 char *path; 444 444 445 if( endPath[0] == '/' ) { 445 if( endPath[0] == '/' ) { 446 if( ( path = (char *) smr_malloc2( smr 446 if( ( path = (char *) smr_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL ); 447 path[0] = 0; } 447 path[0] = 0; } 448 else { 448 else { 449 if( ( path = (char *) smr_malloc2( smr 449 if( ( path = (char *) smr_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 0, "path" ) ) == NULL ) return( NULL ); 450 strcpy( path, map->path ); 450 strcpy( path, map->path ); 451 strcat( path, "/" ); 451 strcat( path, "/" ); 452 } 452 } 453 strcat( path, endPath ); 453 strcat( path, endPath ); 454 return( path ); 454 return( path ); 455 } 455 } 456 /* 456 /* 457 ********************************************** 457 ************************************************************ 458 */ 458 */ 459 char *MCGIDI_map_getTargetsFullPath( statusMes 459 char *MCGIDI_map_getTargetsFullPath( statusMessageReporting *smr, MCGIDI_mapEntry *target ) { 460 460 461 char *path = NULL; 461 char *path = NULL; 462 MCGIDI_map *map = target->parent; 462 MCGIDI_map *map = target->parent; 463 463 464 switch( target->type ) { 464 switch( target->type ) { 465 case MCGIDI_mapEntry_type_target : 465 case MCGIDI_mapEntry_type_target : 466 path = MCGIDI_map_getFullPath( smr, ma 466 path = MCGIDI_map_getFullPath( smr, map, target->path ); 467 break; 467 break; 468 case MCGIDI_mapEntry_type_path : 468 case MCGIDI_mapEntry_type_path : 469 smr_setReportInfo3p( smr, &(map->smrUs 469 smr_setReportInfo3p( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_UnknownType, "path type not allowed" ); 470 break; 470 break; 471 default : 471 default : 472 smr_setReportInfo3( smr, &(map->smrUse 472 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_UnknownType, "unknown type = %d", target->type ); 473 break; 473 break; 474 } 474 } 475 return( path ); 475 return( path ); 476 } 476 } 477 /* 477 /* 478 ********************************************** 478 ************************************************************ 479 */ 479 */ 480 static int _MCGIDI_map_walkTree2( statusMessag 480 static int _MCGIDI_map_walkTree2( statusMessageReporting *smr, MCGIDI_map *map, int level, int (*handler)( MCGIDI_mapEntry *entry, int level, void *userData), 481 void *userData ) { 481 void *userData ) { 482 482 483 MCGIDI_mapEntry *entry; 483 MCGIDI_mapEntry *entry; 484 484 485 for( entry = map->mapEntries; entry != NUL 485 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 486 if( handler( entry, level, userData ) 486 if( handler( entry, level, userData ) != 0 ) return( 1 ); 487 if( entry->type == MCGIDI_mapEntry_typ 487 if( entry->type == MCGIDI_mapEntry_type_path ) if( _MCGIDI_map_walkTree2( smr, entry->map, level + 1, handler, userData ) != 0 ) return( 1 ); 488 } 488 } 489 return( 0 ); 489 return( 0 ); 490 } 490 } 491 /* 491 /* 492 ********************************************** 492 ************************************************************ 493 */ 493 */ 494 int MCGIDI_map_walkTree( statusMessageReportin 494 int MCGIDI_map_walkTree( statusMessageReporting *smr, MCGIDI_map *map, int (*handler)( MCGIDI_mapEntry *entry, int level, void *userData), void *userData ) { 495 495 496 return( _MCGIDI_map_walkTree2( smr, map, 0 496 return( _MCGIDI_map_walkTree2( smr, map, 0, handler, userData ) ); 497 } 497 } 498 /* 498 /* 499 ********************************************** 499 ************************************************************ 500 */ 500 */ 501 char *MCGIDI_map_toXMLString( statusMessageRep 501 char *MCGIDI_map_toXMLString( statusMessageReporting *smr, MCGIDI_map *map ) { 502 502 503 MCGIDI_mapEntry *entry; 503 MCGIDI_mapEntry *entry; 504 char *s, *p; 504 char *s, *p; 505 char targetFormat[] = "<target schema=\"%s 505 char targetFormat[] = "<target schema=\"%s\" evaluation=\"%s\" projectile=\"%s\" target=\"%s\" path=\"%s\"/>\n"; 506 char pathFormat[] = "<path projectile=\"%s 506 char pathFormat[] = "<path projectile=\"%s\" path=\"%s\"/>\n"; 507 char start[] = "<map>\n"; 507 char start[] = "<map>\n"; 508 char end[] = "</map>"; 508 char end[] = "</map>"; 509 int n = 0, nStart = (int) strlen( start ), 509 int n = 0, nStart = (int) strlen( start ), nEnd = (int) strlen( end ); 510 int nTarget = (int) strlen( targetFormat ) 510 int nTarget = (int) strlen( targetFormat ) - 10, nPath = (int) strlen( pathFormat ) - 4; 511 511 512 if( map->status != MCGIDI_map_status_Ok ) 512 if( map->status != MCGIDI_map_status_Ok ) return( NULL ); 513 513 514 n = nStart + nEnd + 1; 514 n = nStart + nEnd + 1; 515 for( entry = map->mapEntries; entry != NUL 515 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 516 switch( entry->type ) { 516 switch( entry->type ) { 517 case MCGIDI_mapEntry_type_target : 517 case MCGIDI_mapEntry_type_target : 518 n += (int) ( strlen( entry->schema 518 n += (int) ( strlen( entry->schema ) + strlen( entry->path ) + strlen( entry->evaluation ) + strlen( entry->projectile ) + strlen( entry->targetName ) + nTarget ); 519 break; 519 break; 520 case MCGIDI_mapEntry_type_path : 520 case MCGIDI_mapEntry_type_path : 521 n += (int ) strlen( entry->path ) 521 n += (int ) strlen( entry->path ) + (int ) strlen( entry->projectile ) + nPath; 522 break; 522 break; 523 default : 523 default : 524 smr_setReportInfo3( smr, &(map->sm 524 smr_setReportInfo3( smr, &(map->smrUserInterface), smr_unknownID, MCGIDI_map_status_UnknownType, "unknown type = %d", entry->type ); 525 return( NULL ); 525 return( NULL ); 526 } 526 } 527 } 527 } 528 528 529 if( ( s = (char *) smr_malloc2( smr, n, 0, 529 if( ( s = (char *) smr_malloc2( smr, n, 0, "xml string" ) ) == NULL ) return( NULL ); 530 p = s; 530 p = s; 531 strcpy( p, start ); 531 strcpy( p, start ); 532 while( *p ) p++; // Loop checking, 11.06.2 532 while( *p ) p++; // Loop checking, 11.06.2015, T. Koi 533 for( entry = map->mapEntries; entry != NUL 533 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 534 switch( entry->type ) { 534 switch( entry->type ) { 535 case MCGIDI_mapEntry_type_target : 535 case MCGIDI_mapEntry_type_target : 536 snprintf( p, sizeof start, targetF << 536 sprintf( p, targetFormat, entry->schema, entry->evaluation, entry->projectile, entry->targetName, entry->path ); 537 break; 537 break; 538 case MCGIDI_mapEntry_type_path : 538 case MCGIDI_mapEntry_type_path : 539 snprintf( p, sizeof start, pathFor << 539 sprintf( p, pathFormat, entry->projectile, entry->path ); 540 break; 540 break; 541 } 541 } 542 while( *p ) p++; // Loop checking, 11. 542 while( *p ) p++; // Loop checking, 11.06.2015, T. Koi 543 } 543 } 544 strcpy( p, end ); 544 strcpy( p, end ); 545 return( s ); 545 return( s ); 546 } 546 } 547 /* 547 /* 548 ********************************************** 548 ************************************************************ 549 */ 549 */ 550 void MCGIDI_map_simpleWrite( FILE *f, MCGIDI_m 550 void MCGIDI_map_simpleWrite( FILE *f, MCGIDI_map *map ) { _MCGIDI_map_simpleWrite2( f, map, 0 ); } 551 /* 551 /* 552 ********************************************** 552 ************************************************************ 553 */ 553 */ 554 static void _MCGIDI_map_simpleWrite2( FILE *f, 554 static void _MCGIDI_map_simpleWrite2( FILE *f, MCGIDI_map *map, int level ) { 555 555 556 MCGIDI_mapEntry *entry; 556 MCGIDI_mapEntry *entry; 557 char sLevel[] = " " 557 char sLevel[] = " "; 558 int n = (int ) strlen( sLevel ) / 4; 558 int n = (int ) strlen( sLevel ) / 4; 559 559 560 if( map->status != MCGIDI_map_status_Ok ) 560 if( map->status != MCGIDI_map_status_Ok ) { 561 fprintf( f, "Bad map status = %d\n", m 561 fprintf( f, "Bad map status = %d\n", map->status ); 562 return; 562 return; 563 } 563 } 564 if( level < n ) sLevel[4 * level] = 0; 564 if( level < n ) sLevel[4 * level] = 0; 565 fprintf( f, "%smap->path = %s\n", sLevel, 565 fprintf( f, "%smap->path = %s\n", sLevel, map->path ); 566 fprintf( f, "%smap->mapFileName = %s\n", s 566 fprintf( f, "%smap->mapFileName = %s\n", sLevel, map->mapFileName ); 567 for( entry = map->mapEntries; entry != NUL 567 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 568 switch( entry->type ) { 568 switch( entry->type ) { 569 case MCGIDI_mapEntry_type_target : 569 case MCGIDI_mapEntry_type_target : 570 fprintf( f, "%sType = target: sche 570 fprintf( f, "%sType = target: schema = %s: evaluation = %s: projectile = %s: target = %s: path = %s\n", sLevel, entry->schema, 571 entry->evaluation, entry->proj 571 entry->evaluation, entry->projectile, entry->targetName, entry->path ); 572 break; 572 break; 573 case MCGIDI_mapEntry_type_path : 573 case MCGIDI_mapEntry_type_path : 574 fprintf( f, "%sType = path: path 574 fprintf( f, "%sType = path: path = %s\n", sLevel, entry->path ); 575 _MCGIDI_map_simpleWrite2( f, entry 575 _MCGIDI_map_simpleWrite2( f, entry->map, level + 1 ); 576 break; 576 break; 577 default : 577 default : 578 fprintf( f, "%sUnknown type = %d\n 578 fprintf( f, "%sUnknown type = %d\n", sLevel, entry->type ); 579 } 579 } 580 } 580 } 581 } 581 } 582 /* 582 /* 583 ********************************************** 583 ************************************************************ 584 */ 584 */ 585 static char *_MCGIDI_map_smrUserInterface( voi 585 static char *_MCGIDI_map_smrUserInterface( void *userData ) { 586 586 587 MCGIDI_map_smr *smrUserInterface = (MCGIDI 587 MCGIDI_map_smr *smrUserInterface = (MCGIDI_map_smr *) userData; 588 588 589 return( smr_allocateFormatMessage( "map fi 589 return( smr_allocateFormatMessage( "map file = %s", smrUserInterface->map->mapFileName ) ); 590 } 590 } 591 591 592 #if defined __cplusplus 592 #if defined __cplusplus 593 } 593 } 594 #endif 594 #endif 595 595 596 596