ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GIDI.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4GIDI.cc
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 # <<BEGIN-copyright>>
28 # <<END-copyright>>
29 */
30 #include <iostream>
31 
32 #include "G4GIDI.hh"
33 
34 using namespace std;
35 using namespace GIDI;
36 
37 /*
38 ***************************************************************
39 */
40 G4GIDI::G4GIDI( int ip, string &dataDirectory ) {
41 
42  init( ip );
43  addDataDirectory( dataDirectory );
44 }
45 /*
46 ***************************************************************
47 */
48 G4GIDI::G4GIDI( int ip, list<string> &dataDirectoryList ) {
49 
50  list<string>::iterator iter;
51 
52  init( ip );
53  for( iter = dataDirectoryList.begin( ); iter != dataDirectoryList.end( ); ++iter ) addDataDirectory( *iter );
54 }
55 /*
56 ***************************************************************
57 */
58 G4GIDI::~G4GIDI( void ) {
59 
61  list<G4GIDI_map *>::iterator iter;
62 
63  while( targets.size( ) > 0 ) {
64  target = targets.back( );
65  targets.pop_back( );
66  delete target;
67  } // Loop checking, 11.06.2015, T. Koi
68 
69  while( ( iter = dataDirectories.begin( ) ) != dataDirectories.end( ) ) {
70  delete *iter;
71  dataDirectories.pop_front( );
72  }// Loop checking, 11.06.2015, T. Koi
73 }
74 /*
75 ***************************************************************
76 */
77 int G4GIDI::init( int ip ) {
78 
79  projectileID = ip;
80  if( ip == 0 ) {
81  projectile = string( "g" ); }
82  else if( ip == 1 ) {
83  projectile = string( "n" ); }
84  else if( ip == 2 ) {
85  projectile = string( "p" ); }
86  else if( ip == 3 ) {
87  projectile = string( "d" ); }
88  else if( ip == 4 ) {
89  projectile = string( "t" ); }
90  else if( ip == 5 ) {
91  projectile = string( "h" ); }
92  else if( ip == 6 ) {
93  projectile = string( "a" ); }
94  else {
95  printf( "Invalid projectile ID = %d\n", ip );
96  throw 1;
97  }
98  return( 0 );
99 }
100 /*
101 ***************************************************************
102 */
104 
105  return( dataDirectories.size( ) );
106 }
107 /*
108 ***************************************************************
109 */
110 int G4GIDI::addDataDirectory( string &dataDirectory ) {
111 
112  list<G4GIDI_map *>::iterator iter;
113 
114  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
115  if( (*iter)->path( ) == dataDirectory ) return( 0 );
116  }
117 
118  G4GIDI_map *map = new G4GIDI_map( dataDirectory );
119  dataDirectories.push_back( map );
120 
121  return( 0 );
122 }
123 /*
124 ***************************************************************
125 */
126 int G4GIDI::removeDataDirectory( string &dataDirectory ) {
127 
128  list<G4GIDI_map *>::iterator iter;
129 
130  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
131  if( dataDirectory == (*iter)->path( ) ) {
132 
133  }
134  }
135  return( 0 );
136 }
137 /*
138 ***************************************************************
139 */
140 string G4GIDI::getDataDirectoryAtIndex( int index ) {
141 
142  list<G4GIDI_map *>::iterator iter;
143  unsigned i = (unsigned) index;
144 
145  if( index >= 0 ) {
146  if( i >= dataDirectories.size( ) ) return( "" );
147  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, index-- ) {
148  if( index == 0 ) return( (*iter)->fileName( ) );
149  }
150  }
151 
152  return( "" );
153 }
154 /*
155 ***************************************************************
156 */
157 vector<string> *G4GIDI::getDataDirectories( void ) {
158 
159  int i = 0;
160  list<G4GIDI_map *>::iterator iter;
161  vector<string> *v = new vector<string>( numberOfDataDirectories( ) );
162 
163  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, i++ ) (*v)[i] = string( (*iter)->fileName( ) );
164  return( v );
165 }
166 /*
167 ***************************************************************
168 */
169 bool G4GIDI::isThisDataAvailable( string &lib_name, int iZ, int iA, int iM ) {
170 
171  bool b;
172  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
173 
174  if( targetName == NULL ) return( false );
175  string targetSymbol( targetName );
176  b = isThisDataAvailable( lib_name, targetSymbol );
177  smr_freeMemory( (void **) &targetName );
178  return( b );
179 }
180 /*
181 ***************************************************************
182 */
183 bool G4GIDI::isThisDataAvailable( string &lib_name, string &targetName ) {
184 
185  char *path = dataFilename( lib_name, targetName );
186 
187  if( path != NULL ) {
188  smr_freeMemory( (void **) &path );
189  return( true );
190  }
191  return( false );
192 }
193 /*
194 ***************************************************************
195 */
196 char *G4GIDI::dataFilename( string &lib_name, int iZ, int iA, int iM ) {
197 
198  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM ), *fileName;
199 
200  if( targetName == NULL ) return( NULL );
201  string targetSymbol( targetName );
202  fileName = dataFilename( lib_name, targetSymbol );
203  smr_freeMemory( (void **) &targetName );
204  return( fileName );
205 }
206 /*
207 ***************************************************************
208 */
209 char *G4GIDI::dataFilename( string &lib_name, string &targetSymbol ) {
210 
211 /*
212  char *path;
213  list<G4GIDI_map *>::iterator iter;
214 
215  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
216  if( ( path = MCGIDI_map_findTarget( &((*iter)->smr), (*iter)->map, lib_name.c_str( ), projectile.c_str( ), targetSymbol.c_str( ) ) ) != NULL ) {
217  return( path );
218  }
219  }
220  return( NULL );
221 */
222 //150121
223 //
224  char *path;
225  list<G4GIDI_map *>::iterator iter;
226 
227  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
228  if( ( path = MCGIDI_map_findTarget( NULL, (*iter)->map, lib_name.c_str(), projectile.c_str( ), targetSymbol.c_str( ) ) ) != NULL ) {
229  return( path );
230  }
231  }
232  return( NULL );
233 }
234 /*
235 ***************************************************************
236 */
237 vector<string> *G4GIDI::getNamesOfAvailableLibraries( int iZ, int iA, int iM ) {
238 
239  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
240  vector<string> *listOfLibraries;
241 
242  if( targetName == NULL ) return( new vector<string>( ) );
243  string targetSymbol( targetName );
244  listOfLibraries = getNamesOfAvailableLibraries( targetSymbol );
245  smr_freeMemory( (void **) &targetName );
246  return( listOfLibraries );
247 }
248 /*
249 ***************************************************************
250 */
251 vector<string> *G4GIDI::getNamesOfAvailableLibraries( string &targetName ) {
252 
253  list<G4GIDI_map *>::iterator iter;
254  vector<string> *listOfLibraries = new vector<string>( );
255 
256  MCGIDI_map *map;
257  MCGIDI_mapEntry *entry;
258 
259  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
260  map = MCGIDI_map_findAllOfTarget( &((*iter)->smr), (*iter)->map, projectile.c_str( ), targetName.c_str( ) );
261  for( entry = MCGIDI_map_getFirstEntry( map ); entry != NULL; entry = MCGIDI_map_getNextEntry( entry ) ) {
262  listOfLibraries->push_back( entry->evaluation );
263  }
264  MCGIDI_map_free( NULL, map );
265  }
266  return( listOfLibraries );
267 }
268 /*
269 ***************************************************************
270 */
271 vector<string> *G4GIDI::getNamesOfAvailableTargets( void ) {
272 
273  vector<string> *listOfTargets;
274  list<G4GIDI_map *>::iterator iter_map;
275 
276  listOfTargets = new vector<string>( );
277  if( listOfTargets == NULL ) return( NULL );
278  for( iter_map = dataDirectories.begin( ); iter_map != dataDirectories.end( ); iter_map++ ) {
279  if( MCGIDI_map_walkTree( NULL, (*iter_map)->map, getNamesOfAvailableTargets_walker, (void *) listOfTargets ) != 0 ) {
280  delete listOfTargets;
281  return( NULL );
282  }
283  }
284  return( listOfTargets );
285 }
286 /*
287 ***************************************************************
288 */
289 G4GIDI_target *G4GIDI::readTarget( string &lib_name, int iZ, int iA, int iM, bool bind ) {
290 
291  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
293 
294  if( targetName == NULL ) return( NULL );
295  string targetSymbol( targetName );
296  target = readTarget( lib_name, targetSymbol, bind );
297  smr_freeMemory( (void **) &targetName );
298  return( target );
299 }
300 /*
301 ***************************************************************
302 */
303 G4GIDI_target *G4GIDI::readTarget( string &lib_name, string &targetName, bool bind ) {
304 
305  vector<G4GIDI_target *>::iterator iter_targets;
306 
307  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
308  if( (*iter_targets)->name == targetName ) return( NULL );
309  }
310  char *path = dataFilename( lib_name, targetName );
311  if( path == NULL ) return( NULL );
312 
313  G4GIDI_target *target = new G4GIDI_target( path );
314  if( bind ) targets.push_back( target );
315  smr_freeMemory( (void **) &path );
316  return( target );
317 }
318 /*
319 ***************************************************************
320 */
321 G4GIDI_target *G4GIDI::getAlreadyReadTarget( int iZ, int iA, int iM ) {
322 
323  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
325 
326  if( targetName == NULL ) return( NULL );
327  string targetSymbol( targetName );
328  target = getAlreadyReadTarget( targetSymbol );
329  smr_freeMemory( (void **) &targetName );
330  return( target );
331 }
332 /*
333 ***************************************************************
334 */
335 G4GIDI_target *G4GIDI::getAlreadyReadTarget( string &targetSymbol ) {
336 
337  vector<G4GIDI_target *>::iterator iter_targets;
338 
339  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
340  if( ( (*iter_targets)->name == targetSymbol ) ) return( *iter_targets );
341  }
342  return( NULL );
343 }
344 /*
345 ***************************************************************
346 */
348 
349  vector<G4GIDI_target *>::iterator iter_targets;
350 
351  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
352  if( *iter_targets == target ) {
353  targets.erase( iter_targets );
354  delete target;
355  return( 0 );
356  }
357  }
358  return( 1 );
359 }
360 /*
361 ***************************************************************
362 */
363 int G4GIDI::freeTarget( int iZ, int iA, int iM ) {
364 
365  int status;
366  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
367 
368  if( targetName == NULL ) return( 1 );
369  string targetSymbol( targetName );
370  status = freeTarget( targetSymbol );
371  smr_freeMemory( (void **) &targetName );
372  return( status );
373 }
374 /*
375 ***************************************************************
376 */
377 int G4GIDI::freeTarget( string &targetSymbol ) {
378 
379  vector<G4GIDI_target *>::iterator iter_targets;
380 
381  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
382  if( (*iter_targets)->name == targetSymbol ) return( freeTarget( *iter_targets ) );
383  }
384  return( 1 );
385 }
386 /*
387 ***************************************************************
388 */
389 vector<string> *G4GIDI::getListOfReadTargetsNames( void ) {
390 
391  vector<G4GIDI_target *>::iterator iter_targets;
392  vector<string> *listOfTargets;
393 
394  listOfTargets = new vector<string>( );
395  if( listOfTargets == NULL ) return( NULL );
396  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
397  listOfTargets->push_back( *(*iter_targets)->getName( ) );
398  }
399  return( listOfTargets );
400 }