Geant4  10.01
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  }
96  else {
97 // Use regular text file
98  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
99  if ( thefData.good() ) {
100  G4int file_size = thefData.tellg();
101  thefData.seekg( 0 , std::ios::beg );
102  char* filedata = new char[ file_size ];
103  while ( thefData ) {
104  thefData.read( filedata , file_size );
105  }
106  thefData.close();
107  data = new G4String ( filedata , file_size );
108  delete [] filedata;
109  } else {
110 // found no data file
111 // set error bit to the stream
112  iss.setstate( std::ios::badbit );
113  }
114  }
115  if (data != NULL) iss.str(*data);
116  //G4cout << iss.rdbuf()->in_avail() << G4endl;
117  in->close(); delete in;
118  delete data;
119 }
120 
122 {
123  G4cout << "You are setting a new verbose level for neutron HP package." << G4endl;
124  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;
125  verboseLevel = newValue;
126 }
long G4long
Definition: G4Types.hh:80
void GetDataStream(G4String, std::istringstream &iss)
#define G4ThreadLocal
Definition: tls.hh:84
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
static G4ThreadLocal G4ParticleHPManager * instance
G4ParticleHPReactionWhiteBoard * RWB
#define G4endl
Definition: G4ios.hh:61
G4ParticleHPReactionWhiteBoard * GetReactionWhiteBoard()