G4GIDI.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 /*
00027 # <<BEGIN-copyright>>
00028 # Copyright (c) 2010, Lawrence Livermore National Security, LLC. 
00029 # Produced at the Lawrence Livermore National Laboratory 
00030 # Written by Bret R. Beck, beck6@llnl.gov. 
00031 # CODE-461393
00032 # All rights reserved. 
00033 #  
00034 # This file is part of GIDI. For details, see nuclear.llnl.gov. 
00035 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov. 
00036 # 
00037 # Redistribution and use in source and binary forms, with or without modification, 
00038 # are permitted provided that the following conditions are met: 
00039 #
00040 #      1) Redistributions of source code must retain the above copyright notice, 
00041 #         this list of conditions and the disclaimer below.
00042 #      2) Redistributions in binary form must reproduce the above copyright notice, 
00043 #         this list of conditions and the disclaimer (as noted below) in the 
00044 #          documentation and/or other materials provided with the distribution.
00045 #      3) Neither the name of the LLNS/LLNL nor the names of its contributors may be 
00046 #         used to endorse or promote products derived from this software without 
00047 #         specific prior written permission. 
00048 #
00049 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00050 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00051 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT 
00052 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR 
00053 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00054 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00055 # OR SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
00056 # AND ON  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00057 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
00058 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00059 # <<END-copyright>>
00060 */
00061 
00062 #include <iostream>
00063 
00064 #include "G4GIDI.hh"
00065 
00066 using namespace std;
00067 using namespace GIDI;
00068 
00069 /*
00070 ***************************************************************
00071 */
00072 G4GIDI::G4GIDI( int ip, string &dataDirectory ) {
00073 
00074     init( ip );
00075     addDataDirectory( dataDirectory );
00076 }
00077 /*
00078 ***************************************************************
00079 */
00080 G4GIDI::G4GIDI( int ip, list<string> &dataDirectoryList ) {
00081 
00082     list<string>::iterator iter;
00083 
00084     init( ip );
00085     for( iter = dataDirectoryList.begin( ); iter != dataDirectoryList.end( ); ++iter ) addDataDirectory( *iter );
00086 }
00087 /*
00088 ***************************************************************
00089 */
00090 G4GIDI::~G4GIDI( void ) {
00091 
00092     G4GIDI_target *target;
00093     list<G4GIDI_map *>::iterator iter;
00094 
00095     while( targets.size( ) > 0 ) {
00096         target = targets.back( );
00097         targets.pop_back( );
00098         delete target;
00099     }
00100 
00101     while( ( iter = dataDirectories.begin( ) ) != dataDirectories.end( ) ) {
00102         delete *iter;
00103         dataDirectories.pop_front( );
00104     }
00105 }
00106 /*
00107 ***************************************************************
00108 */
00109 int G4GIDI::init( int ip ) {
00110 
00111     projectileID = ip;
00112     return( 0 );
00113 }
00114 /*
00115 ***************************************************************
00116 */
00117 int G4GIDI::numberOfDataDirectories( void ) {
00118 
00119     return( dataDirectories.size( ) );
00120 }
00121 /*
00122 ***************************************************************
00123 */
00124 int G4GIDI::addDataDirectory( string &dataDirectory ) {
00125 
00126     list<G4GIDI_map *>::iterator iter;
00127 
00128     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
00129         if( (*iter)->path( ) == dataDirectory ) return( 0 );
00130     }
00131 
00132     G4GIDI_map *map = new G4GIDI_map( dataDirectory );
00133     dataDirectories.push_back( map );
00134 
00135     return( 0 );
00136 }
00137 /*
00138 ***************************************************************
00139 */
00140 int G4GIDI::removeDataDirectory( string &dataDirectory ) {
00141 
00142     list<G4GIDI_map *>::iterator iter;
00143 
00144     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
00145         if( dataDirectory == (*iter)->path( ) ) {
00146             
00147         }
00148     }
00149     return( 0 );
00150 }
00151 /*
00152 ***************************************************************
00153 */
00154 //string G4GIDI::getDataDirectoryAtIndex( int index ) {
00155 string G4GIDI::getDataDirectoryAtIndex( int ) {
00156 
00157 #if 0
00158     list<G4GIDI_map *>::iterator iter;
00159     unsigned i = (unsigned) index;
00160 
00161     if( i < 0 ) return( "" );
00162     if( i >= dataDirectories.size( ) ) return( "" );
00163     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, i-- ) {
00164         if( i == 0 ) return( (*iter)->fileName( ) );
00165     }
00166 #endif
00167     return( "" );
00168 }
00169 /*
00170 ***************************************************************
00171 */
00172 vector<string> *G4GIDI::getDataDirectories( void ) {
00173 
00174     int i = 0;
00175     list<G4GIDI_map *>::iterator iter;
00176     vector<string> *v = new vector<string>( numberOfDataDirectories( ) );
00177 
00178     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, i++ ) (*v)[i] = string( (*iter)->fileName( ) );
00179     return( v );
00180 }
00181 /*
00182 ***************************************************************
00183 */
00184 bool G4GIDI::isThisDataAvailable( string &lib_name, int iZ, int iA, int iM ) {
00185 
00186     bool b;
00187     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
00188 
00189     if( targetName == NULL ) return( false );
00190     string targetSymbol( targetName );
00191     b = isThisDataAvailable( lib_name, targetSymbol );
00192     xData_free( NULL, targetName );
00193     return( b );
00194 }
00195 /*
00196 ***************************************************************
00197 */
00198 bool G4GIDI::isThisDataAvailable( string &lib_name, string &targetName ) {
00199 
00200     char *path = dataFilename( lib_name, targetName );
00201 
00202     if( path != NULL ) {
00203         xData_free( NULL, path );
00204         return( true );
00205     }
00206     return( false );
00207 }
00208 /*
00209 ***************************************************************
00210 */
00211 char *G4GIDI::dataFilename( string &lib_name, int iZ, int iA, int iM ) {
00212 
00213     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM ), *fileName;
00214 
00215     if( targetName == NULL ) return( NULL );
00216     string targetSymbol( targetName );
00217     fileName = dataFilename( lib_name, targetSymbol );
00218     xData_free( NULL, targetName );
00219     return( fileName );
00220 }
00221 /*
00222 ***************************************************************
00223 */
00224 char *G4GIDI::dataFilename( string &lib_name, string &targetSymbol ) {
00225 
00226     //char *path, *projectile = "n_1";
00227     char *path, *projectile = (char*)"n_1";
00228     list<G4GIDI_map *>::iterator iter;
00229 
00230     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
00231         if( ( path = tpia_map_findTarget( &((*iter)->smr), (*iter)->map, lib_name.c_str( ), projectile, targetSymbol.c_str( ) ) ) != NULL ) {
00232             return( path );
00233         }
00234     }
00235     return( NULL );
00236 }
00237 /*
00238 ***************************************************************
00239 */
00240 vector<string> *G4GIDI::getNamesOfAvailableLibraries( int iZ, int iA, int iM ) {
00241 
00242     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
00243     vector<string> *listOfLibraries;
00244 
00245     if( targetName == NULL ) return( new vector<string>( ) );
00246     string targetSymbol( targetName );
00247     listOfLibraries = getNamesOfAvailableLibraries( targetSymbol );
00248     xData_free( NULL, targetName );
00249     return( listOfLibraries );
00250 }
00251 /*
00252 ***************************************************************
00253 */
00254 vector<string> *G4GIDI::getNamesOfAvailableLibraries( string &targetName ) {
00255 
00256     //char *projectile = "n_1";
00257     char *projectile = (char*)"n_1";
00258     list<G4GIDI_map *>::iterator iter;
00259     vector<string> *listOfLibraries = new vector<string>( );
00260 
00261     tpia_map *map;
00262     tpia_mapEntry *entry;
00263     for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
00264         map = tpia_map_findAllOfTarget( &((*iter)->smr), (*iter)->map, projectile, targetName.c_str( ) );
00265         for( entry = tpia_map_getFirstEntry( map ); entry != NULL; entry = tpia_map_getNextEntry( entry ) ) {
00266             listOfLibraries->push_back( entry->evaluation );
00267         }
00268         tpia_map_free( NULL, map );
00269     }
00270     return( listOfLibraries );
00271 }
00272 /*
00273 ***************************************************************
00274 */
00275 vector<string> *G4GIDI::getNamesOfAvailableTargets( void ) {
00276 
00277     vector<string> *listOfTargets;
00278     list<G4GIDI_map *>::iterator iter_map;
00279 
00280     listOfTargets = new vector<string>( );
00281     if( listOfTargets == NULL ) return( NULL );
00282     for( iter_map = dataDirectories.begin( ); iter_map != dataDirectories.end( ); iter_map++ ) {
00283         if( tpia_map_walkTree( NULL, (*iter_map)->map, getNamesOfAvailableTargets_walker, (void *) listOfTargets ) != 0 ) {
00284             delete listOfTargets;
00285             return( NULL );
00286         }
00287     }
00288     return( listOfTargets );
00289 }
00290 /*
00291 ***************************************************************
00292 */
00293 G4GIDI_target *G4GIDI::readTarget( string &lib_name, int iZ, int iA, int iM, bool bind ) {
00294 
00295     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
00296     G4GIDI_target *target;
00297 
00298     if( targetName == NULL ) return( NULL );
00299     string targetSymbol( targetName );
00300     target = readTarget( lib_name, targetSymbol, bind );
00301     xData_free( NULL, targetName );
00302     return( target );
00303 }
00304 /*
00305 ***************************************************************
00306 */
00307 G4GIDI_target *G4GIDI::readTarget( string &lib_name, string &targetName, bool bind ) {
00308 
00309     vector<G4GIDI_target *>::iterator iter_targets;
00310 
00311     for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
00312         if( (*iter_targets)->name == targetName ) return( NULL );
00313     }
00314     char *path = dataFilename( lib_name, targetName );
00315     if( path == NULL ) return( NULL );
00316 
00317     G4GIDI_target *target = new G4GIDI_target( path );
00318     if( bind ) targets.push_back( target );
00319     xData_free( NULL, path );
00320     return( target );
00321 }
00322 /*
00323 ***************************************************************
00324 */
00325 G4GIDI_target *G4GIDI::getAlreadyReadTarget( int iZ, int iA, int iM ) {
00326 
00327     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
00328     G4GIDI_target *target;
00329 
00330     if( targetName == NULL ) return( NULL );
00331     string targetSymbol( targetName );
00332     target = getAlreadyReadTarget( targetSymbol );
00333     xData_free( NULL, targetName );
00334     return( target );
00335 }
00336 /*
00337 ***************************************************************
00338 */
00339 G4GIDI_target *G4GIDI::getAlreadyReadTarget( string &targetSymbol ) {
00340 
00341     vector<G4GIDI_target *>::iterator iter_targets;
00342 
00343     for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
00344         if( ( (*iter_targets)->name == targetSymbol ) ) return( *iter_targets );
00345     }
00346     return( NULL );
00347 }
00348 /*
00349 ***************************************************************
00350 */
00351 int G4GIDI::freeTarget( G4GIDI_target *target ) {
00352 
00353     vector<G4GIDI_target *>::iterator iter_targets;
00354 
00355     for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
00356         if( *iter_targets == target ) {
00357             targets.erase( iter_targets );
00358             delete target;
00359             return( 0 );
00360         }
00361     }
00362     return( 1 );
00363 }
00364 /*
00365 ***************************************************************
00366 */
00367 int G4GIDI::freeTarget( int iZ, int iA, int iM ) {
00368 
00369     int status;
00370     char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
00371 
00372     if( targetName == NULL ) return( 1 );
00373     string targetSymbol( targetName );
00374     status = freeTarget( targetSymbol );
00375     xData_free( NULL, targetName );
00376     return( status );
00377 }
00378 /*
00379 ***************************************************************
00380 */
00381 int G4GIDI::freeTarget( string &targetSymbol ) {
00382 
00383     vector<G4GIDI_target *>::iterator iter_targets;
00384 
00385     for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
00386         if( (*iter_targets)->name == targetSymbol ) return( freeTarget( *iter_targets ) );
00387     }
00388     return( 1 );
00389 }
00390 /*
00391 ***************************************************************
00392 */
00393 vector<string> *G4GIDI::getListOfReadTargetsNames( void ) {
00394 
00395     vector<G4GIDI_target *>::iterator iter_targets;
00396     vector<string> *listOfTargets;
00397 
00398     listOfTargets = new vector<string>( );
00399     if( listOfTargets == NULL ) return( NULL );
00400     for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
00401         listOfTargets->push_back( *(*iter_targets)->getName( ) );
00402     }
00403     return( listOfTargets );
00404 }

Generated on Mon May 27 17:48:22 2013 for Geant4 by  doxygen 1.4.7