Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 # <<BEGIN-copyright>>
28 # Copyright (c) 2010, Lawrence Livermore National Security, LLC.
29 # Produced at the Lawrence Livermore National Laboratory
30 # Written by Bret R. Beck, beck6@llnl.gov.
31 # CODE-461393
32 # All rights reserved.
33 #
34 # This file is part of GIDI. For details, see nuclear.llnl.gov.
35 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
36 #
37 # Redistribution and use in source and binary forms, with or without modification,
38 # are permitted provided that the following conditions are met:
39 #
40 # 1) Redistributions of source code must retain the above copyright notice,
41 # this list of conditions and the disclaimer below.
42 # 2) Redistributions in binary form must reproduce the above copyright notice,
43 # this list of conditions and the disclaimer (as noted below) in the
44 # documentation and/or other materials provided with the distribution.
45 # 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
46 # used to endorse or promote products derived from this software without
47 # specific prior written permission.
48 #
49 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
50 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
52 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
53 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
56 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
58 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 # <<END-copyright>>
60 */
61 
62 #include <iostream>
63 
64 #include "G4GIDI.hh"
65 
66 using namespace std;
67 using namespace GIDI;
68 
69 /*
70 ***************************************************************
71 */
72 G4GIDI::G4GIDI( int ip, string &dataDirectory ) {
73 
74  init( ip );
75  addDataDirectory( dataDirectory );
76 }
77 /*
78 ***************************************************************
79 */
80 G4GIDI::G4GIDI( int ip, list<string> &dataDirectoryList ) {
81 
82  list<string>::iterator iter;
83 
84  init( ip );
85  for( iter = dataDirectoryList.begin( ); iter != dataDirectoryList.end( ); ++iter ) addDataDirectory( *iter );
86 }
87 /*
88 ***************************************************************
89 */
90 G4GIDI::~G4GIDI( void ) {
91 
93  list<G4GIDI_map *>::iterator iter;
94 
95  while( targets.size( ) > 0 ) {
96  target = targets.back( );
97  targets.pop_back( );
98  delete target;
99  }
100 
101  while( ( iter = dataDirectories.begin( ) ) != dataDirectories.end( ) ) {
102  delete *iter;
103  dataDirectories.pop_front( );
104  }
105 }
106 /*
107 ***************************************************************
108 */
109 int G4GIDI::init( int ip ) {
110 
111  projectileID = ip;
112  return( 0 );
113 }
114 /*
115 ***************************************************************
116 */
118 
119  return( dataDirectories.size( ) );
120 }
121 /*
122 ***************************************************************
123 */
124 int G4GIDI::addDataDirectory( string &dataDirectory ) {
125 
126  list<G4GIDI_map *>::iterator iter;
127 
128  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
129  if( (*iter)->path( ) == dataDirectory ) return( 0 );
130  }
131 
132  G4GIDI_map *map = new G4GIDI_map( dataDirectory );
133  dataDirectories.push_back( map );
134 
135  return( 0 );
136 }
137 /*
138 ***************************************************************
139 */
140 int G4GIDI::removeDataDirectory( string &dataDirectory ) {
141 
142  list<G4GIDI_map *>::iterator iter;
143 
144  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
145  if( dataDirectory == (*iter)->path( ) ) {
146 
147  }
148  }
149  return( 0 );
150 }
151 /*
152 ***************************************************************
153 */
154 //string G4GIDI::getDataDirectoryAtIndex( int index ) {
156 
157 #if 0
158  list<G4GIDI_map *>::iterator iter;
159  unsigned i = (unsigned) index;
160 
161  if( i < 0 ) return( "" );
162  if( i >= dataDirectories.size( ) ) return( "" );
163  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, i-- ) {
164  if( i == 0 ) return( (*iter)->fileName( ) );
165  }
166 #endif
167  return( "" );
168 }
169 /*
170 ***************************************************************
171 */
172 vector<string> *G4GIDI::getDataDirectories( void ) {
173 
174  int i = 0;
175  list<G4GIDI_map *>::iterator iter;
176  vector<string> *v = new vector<string>( numberOfDataDirectories( ) );
177 
178  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++, i++ ) (*v)[i] = string( (*iter)->fileName( ) );
179  return( v );
180 }
181 /*
182 ***************************************************************
183 */
184 bool G4GIDI::isThisDataAvailable( string &lib_name, int iZ, int iA, int iM ) {
185 
186  bool b;
187  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
188 
189  if( targetName == NULL ) return( false );
190  string targetSymbol( targetName );
191  b = isThisDataAvailable( lib_name, targetSymbol );
192  xData_free( NULL, targetName );
193  return( b );
194 }
195 /*
196 ***************************************************************
197 */
198 bool G4GIDI::isThisDataAvailable( string &lib_name, string &targetName ) {
199 
200  char *path = dataFilename( lib_name, targetName );
201 
202  if( path != NULL ) {
203  xData_free( NULL, path );
204  return( true );
205  }
206  return( false );
207 }
208 /*
209 ***************************************************************
210 */
211 char *G4GIDI::dataFilename( string &lib_name, int iZ, int iA, int iM ) {
212 
213  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM ), *fileName;
214 
215  if( targetName == NULL ) return( NULL );
216  string targetSymbol( targetName );
217  fileName = dataFilename( lib_name, targetSymbol );
218  xData_free( NULL, targetName );
219  return( fileName );
220 }
221 /*
222 ***************************************************************
223 */
224 char *G4GIDI::dataFilename( string &lib_name, string &targetSymbol ) {
225 
226  //char *path, *projectile = "n_1";
227  char *path, *projectile = (char*)"n_1";
228  list<G4GIDI_map *>::iterator iter;
229 
230  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
231  if( ( path = tpia_map_findTarget( &((*iter)->smr), (*iter)->map, lib_name.c_str( ), projectile, targetSymbol.c_str( ) ) ) != NULL ) {
232  return( path );
233  }
234  }
235  return( NULL );
236 }
237 /*
238 ***************************************************************
239 */
240 vector<string> *G4GIDI::getNamesOfAvailableLibraries( int iZ, int iA, int iM ) {
241 
242  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
243  vector<string> *listOfLibraries;
244 
245  if( targetName == NULL ) return( new vector<string>( ) );
246  string targetSymbol( targetName );
247  listOfLibraries = getNamesOfAvailableLibraries( targetSymbol );
248  xData_free( NULL, targetName );
249  return( listOfLibraries );
250 }
251 /*
252 ***************************************************************
253 */
254 vector<string> *G4GIDI::getNamesOfAvailableLibraries( string &targetName ) {
255 
256  //char *projectile = "n_1";
257  char *projectile = (char*)"n_1";
258  list<G4GIDI_map *>::iterator iter;
259  vector<string> *listOfLibraries = new vector<string>( );
260 
261  tpia_map *map;
262  tpia_mapEntry *entry;
263  for( iter = dataDirectories.begin( ); iter != dataDirectories.end( ); iter++ ) {
264  map = tpia_map_findAllOfTarget( &((*iter)->smr), (*iter)->map, projectile, targetName.c_str( ) );
265  for( entry = tpia_map_getFirstEntry( map ); entry != NULL; entry = tpia_map_getNextEntry( entry ) ) {
266  listOfLibraries->push_back( entry->evaluation );
267  }
268  tpia_map_free( NULL, map );
269  }
270  return( listOfLibraries );
271 }
272 /*
273 ***************************************************************
274 */
275 vector<string> *G4GIDI::getNamesOfAvailableTargets( void ) {
276 
277  vector<string> *listOfTargets;
278  list<G4GIDI_map *>::iterator iter_map;
279 
280  listOfTargets = new vector<string>( );
281  if( listOfTargets == NULL ) return( NULL );
282  for( iter_map = dataDirectories.begin( ); iter_map != dataDirectories.end( ); iter_map++ ) {
283  if( tpia_map_walkTree( NULL, (*iter_map)->map, getNamesOfAvailableTargets_walker, (void *) listOfTargets ) != 0 ) {
284  delete listOfTargets;
285  return( NULL );
286  }
287  }
288  return( listOfTargets );
289 }
290 /*
291 ***************************************************************
292 */
293 G4GIDI_target *G4GIDI::readTarget( string &lib_name, int iZ, int iA, int iM, bool bind ) {
294 
295  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
297 
298  if( targetName == NULL ) return( NULL );
299  string targetSymbol( targetName );
300  target = readTarget( lib_name, targetSymbol, bind );
301  xData_free( NULL, targetName );
302  return( target );
303 }
304 /*
305 ***************************************************************
306 */
307 G4GIDI_target *G4GIDI::readTarget( string &lib_name, string &targetName, bool bind ) {
308 
309  vector<G4GIDI_target *>::iterator iter_targets;
310 
311  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
312  if( (*iter_targets)->name == targetName ) return( NULL );
313  }
314  char *path = dataFilename( lib_name, targetName );
315  if( path == NULL ) return( NULL );
316 
317  G4GIDI_target *target = new G4GIDI_target( path );
318  if( bind ) targets.push_back( target );
319  xData_free( NULL, path );
320  return( target );
321 }
322 /*
323 ***************************************************************
324 */
325 G4GIDI_target *G4GIDI::getAlreadyReadTarget( int iZ, int iA, int iM ) {
326 
327  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
329 
330  if( targetName == NULL ) return( NULL );
331  string targetSymbol( targetName );
332  target = getAlreadyReadTarget( targetSymbol );
333  xData_free( NULL, targetName );
334  return( target );
335 }
336 /*
337 ***************************************************************
338 */
339 G4GIDI_target *G4GIDI::getAlreadyReadTarget( string &targetSymbol ) {
340 
341  vector<G4GIDI_target *>::iterator iter_targets;
342 
343  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
344  if( ( (*iter_targets)->name == targetSymbol ) ) return( *iter_targets );
345  }
346  return( NULL );
347 }
348 /*
349 ***************************************************************
350 */
352 
353  vector<G4GIDI_target *>::iterator iter_targets;
354 
355  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
356  if( *iter_targets == target ) {
357  targets.erase( iter_targets );
358  delete target;
359  return( 0 );
360  }
361  }
362  return( 1 );
363 }
364 /*
365 ***************************************************************
366 */
367 int G4GIDI::freeTarget( int iZ, int iA, int iM ) {
368 
369  int status;
370  char *targetName = G4GIDI_Misc_Z_A_m_ToName( iZ, iA, iM );
371 
372  if( targetName == NULL ) return( 1 );
373  string targetSymbol( targetName );
374  status = freeTarget( targetSymbol );
375  xData_free( NULL, targetName );
376  return( status );
377 }
378 /*
379 ***************************************************************
380 */
381 int G4GIDI::freeTarget( string &targetSymbol ) {
382 
383  vector<G4GIDI_target *>::iterator iter_targets;
384 
385  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
386  if( (*iter_targets)->name == targetSymbol ) return( freeTarget( *iter_targets ) );
387  }
388  return( 1 );
389 }
390 /*
391 ***************************************************************
392 */
393 vector<string> *G4GIDI::getListOfReadTargetsNames( void ) {
394 
395  vector<G4GIDI_target *>::iterator iter_targets;
396  vector<string> *listOfTargets;
397 
398  listOfTargets = new vector<string>( );
399  if( listOfTargets == NULL ) return( NULL );
400  for( iter_targets = targets.begin( ); iter_targets != targets.end( ); iter_targets++ ) {
401  listOfTargets->push_back( *(*iter_targets)->getName( ) );
402  }
403  return( listOfTargets );
404 }
char * dataFilename(std::string &lib_name, int iZ, int iA, int iM=0)
Definition: G4GIDI.cc:211
std::vector< std::string > * getDataDirectories(void)
Definition: G4GIDI.cc:172
std::string getDataDirectoryAtIndex(int index)
Definition: G4GIDI.cc:155
G4GIDI_target * getAlreadyReadTarget(int iZ, int iA, int iM=0)
Definition: G4GIDI.cc:325
int tpia_map_walkTree(statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
Definition: tpia_map.cc:457
tpia_mapEntry * tpia_map_getFirstEntry(tpia_map *map)
Definition: tpia_map.cc:215
int numberOfDataDirectories(void)
Definition: G4GIDI.cc:117
const XML_Char * target
void * xData_free(statusMessageReporting *smr, void *p)
Definition: xDataMisc.cc:89
tpia_map * tpia_map_findAllOfTarget(statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName)
Definition: tpia_map.cc:393
int getNamesOfAvailableTargets_walker(GIDI::tpia_mapEntry *entry, int level, void *userData)
char * G4GIDI_Misc_Z_A_m_ToName(int iZ, int iA, int im=0)
Definition: G4GIDI_Misc.cc:76
int freeTarget(int iZ, int iA, int iM=0)
Definition: G4GIDI.cc:367
std::vector< std::string > * getNamesOfAvailableLibraries(int iZ, int iA, int iM=0)
Definition: G4GIDI.cc:240
bool isThisDataAvailable(std::string &lib_name, int iZ, int iA, int iM=0)
Definition: G4GIDI.cc:184
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:184
int status
Definition: tracer.cxx:24
std::vector< std::string > * getListOfReadTargetsNames(void)
Definition: G4GIDI.cc:393
char * evaluation
Definition: tpia_map.h:67
~G4GIDI()
Definition: G4GIDI.cc:90
G4GIDI_target * readTarget(std::string &lib_name, int iZ, int iA, int iM=0, bool bind=true)
Definition: G4GIDI.cc:293
tpia_mapEntry * tpia_map_getNextEntry(tpia_mapEntry *entry)
Definition: tpia_map.cc:222
G4GIDI(int ip, std::string &dataDirectory)
Definition: G4GIDI.cc:72
int removeDataDirectory(std::string &dataDirectory)
Definition: G4GIDI.cc:140
int addDataDirectory(std::string &dataDirectory)
Definition: G4GIDI.cc:124
Definition: tpia_map.h:62
char * tpia_map_findTarget(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
Definition: tpia_map.cc:327
std::vector< std::string > * getNamesOfAvailableTargets(void)
Definition: G4GIDI.cc:275