Geant4  10.01.p01
G4NeutronHPManager.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 
31 #include "G4NeutronHPManager.hh"
33 #include "G4NeutronHPMessenger.hh"
34 #include "G4HadronicException.hh"
35 
36 //G4ThreadLocal G4NeutronHPManager* G4NeutronHPManager::instance = NULL;
38 
40 //:RWB(NULL),
41 :verboseLevel(1)
42 ,USE_ONLY_PHOTONEVAPORATION(false)
43 ,SKIP_MISSING_ISOTOPES(false)
44 ,NEGLECT_DOPPLER(false)
45 ,DO_NOT_ADJUST_FINAL_STATE(false)
46 ,PRODUCE_FISSION_FRAGMENTS(false)
47 ,theElasticCrossSections(NULL)
48 ,theCaptureCrossSections(NULL)
49 ,theInelasticCrossSections(NULL)
50 ,theFissionCrossSections(NULL)
51 ,theElasticFSs(NULL)
52 ,theInelasticFSs(NULL)
53 ,theCaptureFSs(NULL)
54 ,theFissionFSs(NULL)
55 ,theTSCoherentCrossSections(NULL)
56 ,theTSIncoherentCrossSections(NULL)
57 ,theTSInelasticCrossSections(NULL)
58 ,theTSCoherentFinalStates(NULL)
59 ,theTSIncoherentFinalStates(NULL)
60 ,theTSInelasticFinalStates(NULL)
61 {
62  messenger = new G4NeutronHPMessenger( this );
63  if ( getenv( "G4NEUTRONHP_DO_NOT_ADJUST_FINAL_STATE" ) ) DO_NOT_ADJUST_FINAL_STATE = true;
64  if ( getenv( "G4NEUTRONHP_USE_ONLY_PHOTONEVAPORATION" ) ) USE_ONLY_PHOTONEVAPORATION = true;
65  if ( getenv( "G4NEUTRONHP_NEGLECT_DOPPLER" ) ) NEGLECT_DOPPLER = true;
66  if ( getenv( "G4NEUTRONHP_SKIP_MISSING_ISOTOPES" ) ) SKIP_MISSING_ISOTOPES = true;
67  if ( getenv( "G4NEUTRONHP_PRODUCE_FISSION_FRAGMENTS" ) ) PRODUCE_FISSION_FRAGMENTS = true;
68 }
69 
71 {
72  delete messenger;
73 }
74 
76 {
77 // if ( RWB != NULL ) {
78 // G4cout << "Warning: G4NeutronHPReactionWhiteBoard is tried doubly opening" << G4endl;
79 // RWB = new G4NeutronHPReactionWhiteBoard();
80 // }
81 //
82 // RWB = new G4NeutronHPReactionWhiteBoard();
84 }
85 
87 {
88  //if ( RWB == NULL ) {
89  // G4cout << "Warning: try to access G4NeutronHPReactionWhiteBoard before opening" << G4endl;
90  // RWB = new G4NeutronHPReactionWhiteBoard();
91  //}
92  //return RWB;
94 }
96 {
98 }
99 
100 #include "zlib.h"
101 #include <fstream>
102 void G4NeutronHPManager::GetDataStream( G4String filename , std::istringstream& iss )
103 {
104  G4String* data=NULL;
105  G4String compfilename(filename);
106  compfilename += ".z";
107  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
108  if ( in->good() )
109  {
110 // Use the compressed file
111  G4int file_size = in->tellg();
112  in->seekg( 0 , std::ios::beg );
113  Bytef* compdata = new Bytef[ file_size ];
114 
115  while ( *in ) {
116  in->read( (char*)compdata , file_size );
117  }
118 
119  uLongf complen = (uLongf) ( file_size*4 );
120  Bytef* uncompdata = new Bytef[complen];
121 
122  while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) ) {
123  //G4cout << "Too small, retry 2 times bigger size." << G4endl;
124  delete[] uncompdata;
125  complen *= 2;
126  uncompdata = new Bytef[complen];
127  }
128  delete [] compdata;
129  // Now "complen" has uncomplessed size
130  data = new G4String ( (char*)uncompdata , (G4long)complen );
131  delete [] uncompdata;
132  } else {
133 // Use regular text file
134  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
135  if ( thefData.good() ) {
136  G4int file_size = thefData.tellg();
137  thefData.seekg( 0 , std::ios::beg );
138  char* filedata = new char[ file_size ];
139  while ( thefData ) {
140  thefData.read( filedata , file_size );
141  }
142  thefData.close();
143  data = new G4String ( filedata , file_size );
144  delete [] filedata;
145  } else {
146 // found no data file
147 // set error bit to the stream
148  iss.setstate( std::ios::badbit );
149  }
150  }
151  if ( data != NULL ) {
152  iss.str(*data);
153  G4String id;
154  iss >> id;
155  if ( id == "G4NDL" ) {
156  //Register information of file
157  G4String source;
158  iss >> source;
159  register_data_file(filename,source);
160  } else {
161  iss.seekg( 0 , std::ios::beg );
162  }
163  }
164  //G4cout << iss.rdbuf()->in_avail() << G4endl;
165  in->close(); delete in;
166  delete data;
167 }
168 // Checking existance of data file
169 void G4NeutronHPManager::GetDataStream2( G4String filename , std::istringstream& iss )
170 {
171  G4String compfilename(filename);
172  compfilename += ".z";
173  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
174  if ( in->good() )
175  {
176 // Compressed file is exist
177  in->close();
178  } else {
179  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
180  if ( thefData.good() ) {
181 // Regular text file is exist
182  thefData.close();
183  } else {
184 // found no data file
185 // set error bit to the stream
186  iss.setstate( std::ios::badbit );
187  }
188  }
189  delete in;
190 }
191 
193 {
194  G4cout << "You are setting a new verbose level for neutron HP package." << G4endl;
195  G4cout << "the new value will be used in whole of the neutron HP package, i.e., models and cross sections for Capture, Elastic, Fission and Inelastic interaction." << G4endl;
196  verboseLevel = newValue;
197 }
198 
200 {
201  mDataEvaluation.insert( std::pair < G4String , G4String > ( filename , source ) );
202 }
204 {
205 
206  G4cout << "Data source of this NeutronHP calculation are " << G4endl;
207  for ( std::map< G4String , G4String >::iterator
208  it = mDataEvaluation.begin() ; it != mDataEvaluation.end() ; it++ ) {
209  G4cout << it->first << " " << it->second << G4endl;
210  }
211  G4cout << G4endl;
212 }
G4NeutronHPMessenger * messenger
static G4NeutronHPManager * GetInstance()
G4NeutronHPReactionWhiteBoard * GetReactionWhiteBoard()
long G4long
Definition: G4Types.hh:80
void GetDataStream(G4String, std::istringstream &iss)
static G4NeutronHPThreadLocalManager * GetInstance()
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void register_data_file(G4String, G4String)
static G4NeutronHPManager * instance
void GetDataStream2(G4String, std::istringstream &iss)
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.cc:24
void SetVerboseLevel(G4int i)
std::map< G4String, G4String > mDataEvaluation
#define G4endl
Definition: G4ios.hh:61
G4NeutronHPReactionWhiteBoard * GetReactionWhiteBoard()