Geant4  10.00.p02
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"
32 #include "G4HadronicException.hh"
33 
35 
37 :RWB(NULL),verboseLevel(1)
38 {
39 ;
40 }
42 {
43 ;
44 }
46 {
47  if ( RWB != NULL ) {
48  G4cout << "Warning: G4NeutronHPReactionWhiteBoard is tried doubly opening" << G4endl;
50  }
51 
53 }
55 {
56  if ( RWB == NULL ) {
57  G4cout << "Warning: try to access G4NeutronHPReactionWhiteBoard before opening" << G4endl;
59  }
60  return RWB;
61 }
62 #include "zlib.h"
63 #include <fstream>
64 void G4NeutronHPManager::GetDataStream( G4String filename , std::istringstream& iss )
65 {
66  G4String* data=NULL;
67  G4String compfilename(filename);
68  compfilename += ".z";
69  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
70  if ( in->good() )
71  {
72 // Use the compressed file
73  G4int file_size = in->tellg();
74  in->seekg( 0 , std::ios::beg );
75  Bytef* compdata = new Bytef[ file_size ];
76 
77  while ( *in ) {
78  in->read( (char*)compdata , file_size );
79  }
80 
81  uLongf complen = (uLongf) ( file_size*4 );
82  Bytef* uncompdata = new Bytef[complen];
83 
84  while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) ) {
85  //G4cout << "Too small, retry 2 times bigger size." << G4endl;
86  delete[] uncompdata;
87  complen *= 2;
88  uncompdata = new Bytef[complen];
89  }
90  delete [] compdata;
91  // Now "complen" has uncomplessed size
92  data = new G4String ( (char*)uncompdata , (G4long)complen );
93  delete [] uncompdata;
94  }
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) iss.str(*data);
115  //G4cout << iss.rdbuf()->in_avail() << G4endl;
116  in->close(); delete in;
117  delete data;
118 }
119 
121 {
122  G4cout << "You are setting a new verbose level for neutron HP package." << G4endl;
123  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;
124  verboseLevel = newValue;
125 }
G4NeutronHPReactionWhiteBoard * GetReactionWhiteBoard()
long G4long
Definition: G4Types.hh:80
void GetDataStream(G4String, std::istringstream &iss)
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: uncompr.cc:24
void SetVerboseLevel(G4int i)
G4NeutronHPReactionWhiteBoard * RWB
#define G4endl
Definition: G4ios.hh:61
static G4ThreadLocal G4NeutronHPManager * instance