Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GIDI.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27#include <iostream>
28
29#include "G4GIDI.hh"
30
31using namespace std;
32using namespace GIDI;
33
34/*
35***************************************************************
36*/
37G4GIDI::G4GIDI( G4int ip, string &dataDirectory ) {
38
39 init( ip );
40 addDataDirectory( dataDirectory );
41}
42/*
43***************************************************************
44*/
45G4GIDI::G4GIDI( G4int ip, list<string> &dataDirectoryList ) {
46
47 init( ip );
48 for( auto iter = dataDirectoryList.begin( ); iter != dataDirectoryList.end( ); ++iter )
49 addDataDirectory( *iter );
50}
51/*
52***************************************************************
53*/
55
56 G4GIDI_target *target;
57 auto iter = dataDirectories.cbegin();
58
59 while( targets.size( ) > 0 ) {
60 target = targets.back( );
61 targets.pop_back( );
62 delete target;
63 } // Loop checking, 11.06.2015, T. Koi
64
65 while( iter != dataDirectories.cend() ) {
66 delete *iter;
67 dataDirectories.pop_front( );
68 }// Loop checking, 11.06.2015, T. Koi
69}
70/*
71***************************************************************
72*/
73G4int G4GIDI::init( G4int ip ) {
74
75 projectileID = ip;
76 if( ip == 0 ) {
77 projectile = string( "g" ); }
78 else if( ip == 1 ) {
79 projectile = string( "n" ); }
80 else if( ip == 2 ) {
81 projectile = string( "p" ); }
82 else if( ip == 3 ) {
83 projectile = string( "d" ); }
84 else if( ip == 4 ) {
85 projectile = string( "t" ); }
86 else if( ip == 5 ) {
87 projectile = string( "h" ); }
88 else if( ip == 6 ) {
89 projectile = string( "a" ); }
90 else {
91 printf( "Invalid projectile ID = %d\n", ip );
92 throw 1;
93 }
94 return( 0 );
95}
96/*
97***************************************************************
98*/
100
101 return (G4int)dataDirectories.size( );
102}
103/*
104***************************************************************
105*/
106G4int G4GIDI::addDataDirectory( string &dataDirectory ) {
107
108 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter ) {
109 if( (*iter)->path( ) == dataDirectory ) return( 0 );
110 }
111
112 G4GIDI_map *map = new G4GIDI_map( dataDirectory );
113 dataDirectories.push_back( map );
114
115 return( 0 );
116}
117/*
118***************************************************************
119*/
120G4int G4GIDI::removeDataDirectory( string &dataDirectory ) {
121
122 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter ) {
123 if( dataDirectory == (*iter)->path( ) ) {
124
125 }
126 }
127 return( 0 );
128}
129/*
130***************************************************************
131*/
133
134 unsigned i = (unsigned) index;
135
136 if( index >= 0 ) {
137 if( i >= dataDirectories.size( ) ) return( "" );
138 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter, --index )
139 if( index == 0 ) return( (*iter)->fileName( ) );
140 }
141
142 return( "" );
143}
144/*
145***************************************************************
146*/
147vector<string> *G4GIDI::getDataDirectories( void ) {
148
149 std::size_t i = 0;
150 vector<string> *v = new vector<string>( numberOfDataDirectories( ) );
151
152 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter, ++i )
153 (*v)[i] = string( (*iter)->fileName( ) );
154 return( v );
155}
156/*
157***************************************************************
158*/
159G4bool G4GIDI::isThisDataAvailable( string &lib_name, G4int iZ, G4int iA, G4int iM ) {
160
161 G4bool b;
162 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
163
164 if( targetName == nullptr ) return( false );
165 string targetSymbol( targetName );
166 b = isThisDataAvailable( lib_name, targetSymbol );
167 smr_freeMemory( (void **) &targetName );
168 return( b );
169}
170/*
171***************************************************************
172*/
173G4bool G4GIDI::isThisDataAvailable( string &lib_name, string &targetName ) {
174
175 char *path = dataFilename( lib_name, targetName );
176
177 if( path != nullptr ) {
178 smr_freeMemory( (void **) &path );
179 return( true );
180 }
181 return( false );
182}
183/*
184***************************************************************
185*/
186char *G4GIDI::dataFilename( string &lib_name, G4int iZ, G4int iA, G4int iM ) {
187
188 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM ), *fileName;
189
190 if( targetName == nullptr ) return( nullptr );
191 string targetSymbol( targetName );
192 fileName = dataFilename( lib_name, targetSymbol );
193 smr_freeMemory( (void **) &targetName );
194 return( fileName );
195}
196/*
197***************************************************************
198*/
199char *G4GIDI::dataFilename( string &lib_name, string &targetSymbol ) {
200
201 char *path;
202
203 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter )
204 if( ( path = MCGIDI_map_findTarget( nullptr, (*iter)->map, lib_name.c_str(), projectile.c_str( ), targetSymbol.c_str( ) ) ) != nullptr )
205 return( path );
206
207 return( nullptr );
208}
209/*
210***************************************************************
211*/
213
214 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
215 vector<string> *listOfLibraries;
216
217 if( targetName == nullptr ) return( new vector<string>( ) );
218 string targetSymbol( targetName );
219 listOfLibraries = getNamesOfAvailableLibraries( targetSymbol );
220 smr_freeMemory( (void **) &targetName );
221 return( listOfLibraries );
222}
223/*
224***************************************************************
225*/
226vector<string> *G4GIDI::getNamesOfAvailableLibraries( string &targetName ) {
227
228 vector<string> *listOfLibraries = new vector<string>( );
229
230 MCGIDI_map *map;
231 MCGIDI_mapEntry *entry;
232
233 for( auto iter = dataDirectories.cbegin( ); iter != dataDirectories.cend( ); ++iter ) {
234 map = MCGIDI_map_findAllOfTarget( &((*iter)->smr), (*iter)->map, projectile.c_str( ), targetName.c_str( ) );
235 for( entry = MCGIDI_map_getFirstEntry( map ); entry != nullptr; entry = MCGIDI_map_getNextEntry( entry ) ) {
236 listOfLibraries->push_back( entry->evaluation );
237 }
238 MCGIDI_map_free( nullptr, map );
239 }
240 return( listOfLibraries );
241}
242/*
243***************************************************************
244*/
245vector<string> *G4GIDI::getNamesOfAvailableTargets( void ) {
246
247 vector<string> *listOfTargets;
248
249 listOfTargets = new vector<string>( );
250 if( listOfTargets == nullptr ) return( nullptr );
251 for( auto iter_map = dataDirectories.cbegin( ); iter_map != dataDirectories.cend( ); ++iter_map ) {
252 if( MCGIDI_map_walkTree( nullptr, (*iter_map)->map, getNamesOfAvailableTargets_walker, (void *) listOfTargets ) != 0 ) {
253 delete listOfTargets;
254 return( nullptr );
255 }
256 }
257 return( listOfTargets );
258}
259/*
260***************************************************************
261*/
262G4GIDI_target *G4GIDI::readTarget( string &lib_name, G4int iZ, G4int iA, G4int iM, G4bool bind ) {
263
264 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
265 G4GIDI_target *target;
266
267 if( targetName == nullptr ) return( nullptr );
268 string targetSymbol( targetName );
269 target = readTarget( lib_name, targetSymbol, bind );
270 smr_freeMemory( (void **) &targetName );
271 return( target );
272}
273/*
274***************************************************************
275*/
276G4GIDI_target *G4GIDI::readTarget( string &lib_name, string &targetName, G4bool bind ) {
277
278 for( auto iter_targets = targets.cbegin( ); iter_targets != targets.cend( ); ++iter_targets ) {
279 if( (*iter_targets)->name == targetName ) return( nullptr );
280 }
281 char *path = dataFilename( lib_name, targetName );
282 if( path == nullptr ) return( nullptr );
283
284 G4GIDI_target *target = new G4GIDI_target( path );
285 if( bind ) targets.push_back( target );
286 smr_freeMemory( (void **) &path );
287 return( target );
288}
289/*
290***************************************************************
291*/
293
294 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
295 G4GIDI_target *target;
296
297 if( targetName == nullptr ) return( nullptr );
298 string targetSymbol( targetName );
299 target = getAlreadyReadTarget( targetSymbol );
300 smr_freeMemory( (void **) &targetName );
301 return( target );
302}
303/*
304***************************************************************
305*/
307
308 for( auto iter_targets = targets.cbegin( ); iter_targets != targets.cend( ); ++iter_targets ) {
309 if( ( (*iter_targets)->name == targetSymbol ) ) return( *iter_targets );
310 }
311 return( nullptr );
312}
313/*
314***************************************************************
315*/
317
318 for( auto iter_targets = targets.cbegin( ); iter_targets != targets.cend( ); ++iter_targets ) {
319 if( *iter_targets == target ) {
320 targets.erase( iter_targets );
321 delete target;
322 return( 0 );
323 }
324 }
325 return( 1 );
326}
327/*
328***************************************************************
329*/
331
332 G4int status;
333 char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
334
335 if( targetName == nullptr ) return( 1 );
336 string targetSymbol( targetName );
337 status = freeTarget( targetSymbol );
338 smr_freeMemory( (void **) &targetName );
339 return( status );
340}
341/*
342***************************************************************
343*/
344G4int G4GIDI::freeTarget( string &targetSymbol ) {
345
346 for( auto iter_targets = targets.cbegin( ); iter_targets != targets.cend( ); ++iter_targets ) {
347 if( (*iter_targets)->name == targetSymbol ) return( freeTarget( *iter_targets ) );
348 }
349 return( 1 );
350}
351/*
352***************************************************************
353*/
354vector<string> *G4GIDI::getListOfReadTargetsNames( void ) {
355
356 vector<string> *listOfTargets;
357
358 listOfTargets = new vector<string>( );
359 if( listOfTargets == nullptr ) return( nullptr );
360 for( auto iter_targets = targets.cbegin( ); iter_targets != targets.cend( ); ++iter_targets ) {
361 listOfTargets->push_back( *(*iter_targets)->getName( ) );
362 }
363 return( listOfTargets );
364}
int getNamesOfAvailableTargets_walker(GIDI::MCGIDI_mapEntry *entry, int level, void *userData)
char * G4GIDI_Misc_Z_A_m_ToName(int iZ, int iA, int im=0)
Definition: G4GIDI_Misc.cc:44
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
int MCGIDI_map_walkTree(statusMessageReporting *smr, MCGIDI_map *map, int(*handler)(MCGIDI_mapEntry *entry, int level, void *userData), void *userData)
Definition: MCGIDI_map.cc:494
void * MCGIDI_map_free(statusMessageReporting *smr, MCGIDI_map *map)
Definition: MCGIDI_map.cc:173
char * MCGIDI_map_findTarget(statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, const char *projectile, const char *targetName)
Definition: MCGIDI_map.cc:376
MCGIDI_mapEntry * MCGIDI_map_getFirstEntry(MCGIDI_map *map)
Definition: MCGIDI_map.cc:204
MCGIDI_mapEntry * MCGIDI_map_getNextEntry(MCGIDI_mapEntry *entry)
Definition: MCGIDI_map.cc:211
MCGIDI_map * MCGIDI_map_findAllOfTarget(statusMessageReporting *smr, MCGIDI_map *map, const char *projectile, const char *targetName)
Definition: MCGIDI_map.cc:430
G4int removeDataDirectory(std::string &dataDirectory)
Definition: G4GIDI.cc:120
char * dataFilename(std::string &lib_name, G4int iZ, G4int iA, G4int iM=0)
Definition: G4GIDI.cc:186
G4GIDI_target * readTarget(std::string &lib_name, G4int iZ, G4int iA, G4int iM=0, G4bool bind=true)
Definition: G4GIDI.cc:262
G4GIDI_target * getAlreadyReadTarget(G4int iZ, G4int iA, G4int iM=0)
Definition: G4GIDI.cc:292
G4int addDataDirectory(std::string &dataDirectory)
Definition: G4GIDI.cc:106
G4GIDI(G4int ip, std::string &dataDirectory)
Definition: G4GIDI.cc:37
std::vector< std::string > * getNamesOfAvailableTargets(void)
Definition: G4GIDI.cc:245
std::vector< std::string > * getDataDirectories(void)
Definition: G4GIDI.cc:147
~G4GIDI()
Definition: G4GIDI.cc:54
std::vector< std::string > * getListOfReadTargetsNames(void)
Definition: G4GIDI.cc:354
std::string getDataDirectoryAtIndex(G4int index)
Definition: G4GIDI.cc:132
std::vector< std::string > * getNamesOfAvailableLibraries(G4int iZ, G4int iA, G4int iM=0)
Definition: G4GIDI.cc:212
G4int freeTarget(G4int iZ, G4int iA, G4int iM=0)
Definition: G4GIDI.cc:330
G4bool isThisDataAvailable(std::string &lib_name, G4int iZ, G4int iA, G4int iM=0)
Definition: G4GIDI.cc:159
G4int numberOfDataDirectories(void)
Definition: G4GIDI.cc:99
void * smr_freeMemory(void **p)