Geant4  10.01.p01
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"
33 #include "G4HadronicException.hh"
34 
36 
38 :RWB(NULL),verboseLevel(1)
39 {
40 ;
41 }
43 {
44 ;
45 }
47 {
48  if ( RWB != NULL ) {
49  G4cout << "Warning: G4ParticleHPReactionWhiteBoard is tried doubly opening" << G4endl;
51  }
52 
54 }
56 {
57  if ( RWB == NULL ) {
58  G4cout << "Warning: try to access G4ParticleHPReactionWhiteBoard before opening" << G4endl;
60  }
61  return RWB;
62 }
63 #include "zlib.h"
64 #include <fstream>
65 void G4ParticleHPManager::GetDataStream( G4String filename , std::istringstream& iss )
66 {
67  G4String* data=NULL;
68  G4String compfilename(filename);
69  compfilename += ".z";
70  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
71  if ( in->good() )
72  {
73 // Use the compressed file
74  G4int file_size = in->tellg();
75  in->seekg( 0 , std::ios::beg );
76  Bytef* compdata = new Bytef[ file_size ];
77 
78  while ( *in ) {
79  in->read( (char*)compdata , file_size );
80  }
81 
82  uLongf complen = (uLongf) ( file_size*4 );
83  Bytef* uncompdata = new Bytef[complen];
84 
85  while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) ) {
86  //G4cout << "Too small, retry 2 times bigger size." << G4endl;
87  delete[] uncompdata;
88  complen *= 2;
89  uncompdata = new Bytef[complen];
90  }
91  delete [] compdata;
92  // Now "complen" has uncomplessed size
93  data = new G4String ( (char*)uncompdata , (G4long)complen );
94  delete [] uncompdata;
95  } else {
96 // Use regular text file
97  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
98  if ( thefData.good() ) {
99  G4int file_size = thefData.tellg();
100  thefData.seekg( 0 , std::ios::beg );
101  char* filedata = new char[ file_size ];
102  while ( thefData ) {
103  thefData.read( filedata , file_size );
104  }
105  thefData.close();
106  data = new G4String ( filedata , file_size );
107  delete [] filedata;
108  } else {
109 // found no data file
110 // set error bit to the stream
111  iss.setstate( std::ios::badbit );
112  }
113  }
114  if ( data != NULL ) {
115  iss.str(*data);
116  G4String id;
117  iss >> id;
118  if ( id == "G4NDL" ) {
119  //Register information of file
120  G4String source;
121  iss >> source;
122  register_data_file(filename,source);
123  } else {
124  iss.seekg( 0 , std::ios::beg );
125  }
126  }
127  //G4cout << iss.rdbuf()->in_avail() << G4endl;
128  in->close(); delete in;
129  delete data;
130 }
131 // Checking existance of data file
132 void G4ParticleHPManager::GetDataStream2( G4String filename , std::istringstream& iss )
133 {
134  G4String compfilename(filename);
135  compfilename += ".z";
136  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
137  if ( in->good() )
138  {
139 // Compressed file is exist
140  in->close();
141  } else {
142  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
143  if ( thefData.good() ) {
144 // Regular text file is exist
145  thefData.close();
146  } else {
147 // found no data file
148 // set error bit to the stream
149  iss.setstate( std::ios::badbit );
150  }
151  }
152  delete in;
153 }
154 
156 {
157  G4cout << "You are setting a new verbose level for neutron HP package." << G4endl;
158  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;
159  verboseLevel = newValue;
160 }
161 
163 {
164  mDataEvaluation.insert( std::pair < G4String , G4String > ( filename , source ) );
165 }
167 {
168 
169  G4cout << "Data source of this NeutronHP calculation are " << G4endl;
170  for ( std::map< G4String , G4String >::iterator
171  it = mDataEvaluation.begin() ; it != mDataEvaluation.end() ; it++ ) {
172  G4cout << it->first << " " << it->second << G4endl;
173  }
174  G4cout << G4endl;
175 }
176 
long G4long
Definition: G4Types.hh:80
void GetDataStream(G4String, std::istringstream &iss)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
void GetDataStream2(G4String, std::istringstream &iss)
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.cc:24
void register_data_file(G4String, G4String)
static G4ThreadLocal G4ParticleHPManager * instance
G4ParticleHPReactionWhiteBoard * RWB
#define G4endl
Definition: G4ios.hh:61
std::map< G4String, G4String > mDataEvaluation
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()