Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleHPManager.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 // Class Description
27 // Manager of NetronHP
28 //
29 // 121031 First implementation done by T. Koi (SLAC/PPA)
30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
31 //
32 #include "G4ParticleHPManager.hh"
34 #include "G4ParticleHPMessenger.hh"
35 #include "G4HadronicException.hh"
36 
37 //G4ThreadLocal G4ParticleHPManager* G4ParticleHPManager::instance = NULL;
38 G4ParticleHPManager* G4ParticleHPManager::instance = G4ParticleHPManager::GetInstance();
39 
40 G4ParticleHPManager::G4ParticleHPManager()
41 :/*RWB(NULL),*/
42  verboseLevel(1)
43 ,USE_ONLY_PHOTONEVAPORATION(false)
44 ,SKIP_MISSING_ISOTOPES(false)
45 ,NEGLECT_DOPPLER(false)
46 ,DO_NOT_ADJUST_FINAL_STATE(false)
47 ,PRODUCE_FISSION_FRAGMENTS(false)
48 ,theElasticCrossSections(NULL)
49 ,theCaptureCrossSections(NULL)
50 //,theInelasticCrossSections(NULL)
51 ,theFissionCrossSections(NULL)
52 ,theElasticFSs(NULL)
53 //,theInelasticFSs(NULL)
54 ,theCaptureFSs(NULL)
55 ,theFissionFSs(NULL)
56 ,theTSCoherentCrossSections(NULL)
57 ,theTSIncoherentCrossSections(NULL)
58 ,theTSInelasticCrossSections(NULL)
59 ,theTSCoherentFinalStates(NULL)
60 ,theTSIncoherentFinalStates(NULL)
61 ,theTSInelasticFinalStates(NULL)
62 {
63  messenger = new G4ParticleHPMessenger( this );
64  if ( getenv( "G4NEUTRONHP_DO_NOT_ADJUST_FINAL_STATE" ) || getenv("G4PHP_DO_NOT_ADJUST_FINAL_STATE") ) DO_NOT_ADJUST_FINAL_STATE = true;
65  if ( getenv( "G4NEUTRONHP_USE_ONLY_PHOTONEVAPORATION" ) ) USE_ONLY_PHOTONEVAPORATION = true;
66  if ( getenv( "G4NEUTRONHP_NEGLECT_DOPPLER" ) || getenv("G4PHP_NEGLECT_DOPPLER") ) NEGLECT_DOPPLER = true;
67  if ( getenv( "G4NEUTRONHP_SKIP_MISSING_ISOTOPES" ) ) SKIP_MISSING_ISOTOPES = true;
68  if ( getenv( "G4NEUTRONHP_PRODUCE_FISSION_FRAGMENTS" ) ) PRODUCE_FISSION_FRAGMENTS = true;
69 }
70 G4ParticleHPManager::~G4ParticleHPManager()
71 {
72  delete messenger;
73 }
75 {
76 // if ( RWB != NULL ) {
77 // G4cout << "Warning: G4ParticleHPReactionWhiteBoard is tried doubly opening" << G4endl;
78 // RWB = new G4ParticleHPReactionWhiteBoard();
79 // }
80 //
81 // RWB = new G4ParticleHPReactionWhiteBoard();
83 }
85 {
86 // if ( RWB == NULL ) {
87 // G4cout << "Warning: try to access G4ParticleHPReactionWhiteBoard before opening" << G4endl;
88 // RWB = new G4ParticleHPReactionWhiteBoard();
89 // }
90 // return RWB;
92 }
94 {
96 }
97 
98 #include "zlib.h"
99 #include <fstream>
100 void G4ParticleHPManager::GetDataStream( G4String filename , std::istringstream& iss )
101 {
102  G4String* data=NULL;
103  G4String compfilename(filename);
104  compfilename += ".z";
105  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
106  if ( in->good() )
107  {
108 // Use the compressed file
109  G4int file_size = in->tellg();
110  in->seekg( 0 , std::ios::beg );
111  Bytef* compdata = new Bytef[ file_size ];
112 
113  while ( *in ) { // Loop checking, 11.05.2015, T. Koi
114  in->read( (char*)compdata , file_size );
115  }
116 
117  uLongf complen = (uLongf) ( file_size*4 );
118  Bytef* uncompdata = new Bytef[complen];
119 
120  while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) ) { // Loop checking, 11.05.2015, T. Koi
121  //G4cout << "Too small, retry 2 times bigger size." << G4endl;
122  delete[] uncompdata;
123  complen *= 2;
124  uncompdata = new Bytef[complen];
125  }
126  delete [] compdata;
127  // Now "complen" has uncomplessed size
128  data = new G4String ( (char*)uncompdata , (G4long)complen );
129  delete [] uncompdata;
130  } else {
131 // Use regular text file
132  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
133  if ( thefData.good() ) {
134  G4int file_size = thefData.tellg();
135  thefData.seekg( 0 , std::ios::beg );
136  char* filedata = new char[ file_size ];
137  while ( thefData ) { // Loop checking, 11.05.2015, T. Koi
138  thefData.read( filedata , file_size );
139  }
140  thefData.close();
141  data = new G4String ( filedata , file_size );
142  delete [] filedata;
143  } else {
144 // found no data file
145 // set error bit to the stream
146  iss.setstate( std::ios::badbit );
147  }
148  }
149  if ( data != NULL ) {
150  iss.str(*data);
151  G4String id;
152  iss >> id;
153  if ( id == "G4NDL" ) {
154  //Register information of file
155  G4String source;
156  iss >> source;
157  register_data_file(filename,source);
158  } else {
159  iss.seekg( 0 , std::ios::beg );
160  }
161  }
162  //G4cout << iss.rdbuf()->in_avail() << G4endl;
163  in->close(); delete in;
164  delete data;
165 }
166 // Checking existance of data file
167 void G4ParticleHPManager::GetDataStream2( G4String filename , std::istringstream& iss )
168 {
169  G4String compfilename(filename);
170  compfilename += ".z";
171  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
172  if ( in->good() )
173  {
174 // Compressed file is exist
175  in->close();
176  } else {
177  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
178  if ( thefData.good() ) {
179 // Regular text file is exist
180  thefData.close();
181  } else {
182 // found no data file
183 // set error bit to the stream
184  iss.setstate( std::ios::badbit );
185  }
186  }
187  delete in;
188 }
189 
191 {
192  G4cout << "You are setting a new verbose level for Particle HP package." << G4endl;
193  G4cout << "the new value will be used in whole of the Particle HP package, i.e., models and cross sections for Capture, Elastic, Fission and Inelastic interaction." << G4endl;
194  verboseLevel = newValue;
195 }
196 
197 void G4ParticleHPManager::register_data_file(G4String filename, G4String source)
198 {
199  mDataEvaluation.insert( std::pair < G4String , G4String > ( filename , source ) );
200 }
201 
203 {
204 
205  G4cout << "Data source of this Partile HP calculation are " << G4endl;
206  for ( std::map< G4String , G4String >::iterator
207  it = mDataEvaluation.begin() ; it != mDataEvaluation.end() ; it++ ) {
208  G4cout << it->first << " " << it->second << G4endl;
209  }
210  G4cout << G4endl;
211 }
212 
214  if ( theInelasticCrossSections.end() != theInelasticCrossSections.find( particle ) )
215  return theInelasticCrossSections.find( particle )->second;
216  else
217  return NULL;
218 }
219 
221  theInelasticCrossSections.insert( std::pair<const G4ParticleDefinition* , G4PhysicsTable* >( particle , val ) );
222 }
223 
224 std::vector<G4ParticleHPChannelList*>* G4ParticleHPManager::GetInelasticFinalStates(const G4ParticleDefinition* particle) {
225  if ( theInelasticFSs.end() != theInelasticFSs.find( particle ) )
226  return theInelasticFSs.find( particle )->second;
227  else
228  return NULL;
229 }
230 
231 void G4ParticleHPManager::RegisterInelasticFinalStates( const G4ParticleDefinition* particle , std::vector<G4ParticleHPChannelList*>* val ) {
232  theInelasticFSs.insert ( std::pair<const G4ParticleDefinition*,std::vector<G4ParticleHPChannelList*>*>( particle , val ) );
233 }
static G4ParticleHPManager * GetInstance()
void RegisterInelasticCrossSections(const G4ParticleDefinition *, G4PhysicsTable *)
static G4ParticleHPThreadLocalManager * GetInstance()
long G4long
Definition: G4Types.hh:80
void GetDataStream(G4String, std::istringstream &iss)
int G4int
Definition: G4Types.hh:78
const XML_Char const XML_Char * data
Definition: expat.h:268
G4GLOB_DLL std::ostream G4cout
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()
void GetDataStream2(G4String, std::istringstream &iss)
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.cc:24
G4PhysicsTable * GetInelasticCrossSections(const G4ParticleDefinition *)
std::vector< G4ParticleHPChannelList * > * GetInelasticFinalStates(const G4ParticleDefinition *)
#define G4endl
Definition: G4ios.hh:61
#define Z_OK
Definition: zlib.h:173
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()
void RegisterInelasticFinalStates(const G4ParticleDefinition *, std::vector< G4ParticleHPChannelList * > *)