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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
 31 using namespace std;
 32 using namespace GIDI;
 33 
 34 /*
 35 ***************************************************************
 36 */
 37 G4GIDI::G4GIDI( G4int ip, const string &dataDirectory ) {
 38 
 39     init( ip );
 40     addDataDirectory( dataDirectory );
 41 }
 42 /*
 43 ***************************************************************
 44 */
 45 G4GIDI::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 */
 54 G4GIDI::~G4GIDI( void ) {
 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 */
 73 G4int 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 */
 99 G4int G4GIDI::numberOfDataDirectories( void ) {
100 
101     return (G4int)dataDirectories.size( );
102 }
103 /*
104 ***************************************************************
105 */
106 G4int G4GIDI::addDataDirectory( const 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 */
120 G4int G4GIDI::removeDataDirectory( const 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 */
132 string G4GIDI::getDataDirectoryAtIndex( G4int index ) {
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 */
147 vector<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 */
159 G4bool G4GIDI::isThisDataAvailable( const 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 */
173 G4bool G4GIDI::isThisDataAvailable( const string &lib_name, const 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 */
186 char *G4GIDI::dataFilename( const 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 */
199 char *G4GIDI::dataFilename( const string &lib_name, const 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 */
212 vector<string> *G4GIDI::getNamesOfAvailableLibraries( G4int iZ, G4int iA, G4int iM ) {
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 */
226 vector<string> *G4GIDI::getNamesOfAvailableLibraries( const 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 */
245 vector<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 */
262 G4GIDI_target *G4GIDI::readTarget( const 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 */
276 G4GIDI_target *G4GIDI::readTarget( const string &lib_name, const 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 */
292 G4GIDI_target *G4GIDI::getAlreadyReadTarget( G4int iZ, G4int iA, G4int iM ) {
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 */
306 G4GIDI_target *G4GIDI::getAlreadyReadTarget( const string &targetSymbol ) {
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 */
316 G4int G4GIDI::freeTarget( G4GIDI_target *target ) {
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 */
330 G4int G4GIDI::freeTarget( G4int iZ, G4int iA, G4int iM ) {
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 */
344 G4int G4GIDI::freeTarget( const 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 */
354 vector<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 }
365