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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4PhysicsTable.cc (Version 11.3.0) and /global/management/src/G4PhysicsTable.cc (Version 4.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // G4PhysicsTable class implementation         << 
 27 //                                                 23 //
 28 // Author: G.Cosmo, 2 December 1995            <<  24 // $Id: G4PhysicsTable.cc,v 1.6 2001/07/11 10:00:58 gunter Exp $
 29 //         First implementation based on objec <<  25 // GEANT4 tag $Name: geant4-04-01 $
 30 // Revisions:                                  <<  26 //
 31 // - 1st March 1996, K.Amako: modified         <<  27 // 
 32 // - 24th February 2001, H.Kurashige: migratio <<  28 // ------------------------------------------------------------
 33 // ------------------------------------------- <<  29 //      GEANT 4 class implementation
 34                                                <<  30 //
 35 #include <fstream>                             <<  31 //  G4PhysicsTable
 36 #include <iomanip>                             <<  32 //
 37 #include <iostream>                            <<  33 // ------------------------------------------------------------
 38                                                    34 
 39 #include "G4PhysicsFreeVector.hh"              << 
 40 #include "G4PhysicsLinearVector.hh"            << 
 41 #include "G4PhysicsLogVector.hh"               << 
 42 #include "G4PhysicsTable.hh"                   << 
 43 #include "G4PhysicsVector.hh"                      35 #include "G4PhysicsVector.hh"
 44 #include "G4PhysicsVectorType.hh"              <<  36 #include "G4PhysicsTable.hh"
                                                   >>  37 #include "g4std/iostream"
                                                   >>  38 #include "g4std/fstream"
                                                   >>  39 #include "g4std/iomanip"
 45                                                    40 
 46 // ------------------------------------------- <<  41 G4PhysicsTable::G4PhysicsTable()
 47 G4PhysicsTable::G4PhysicsTable(std::size_t cap <<  42   : G4PhysCollection()
 48 {                                                  43 {
 49   reserve(cap);                                << 
 50   vecFlag.reserve(cap);                        << 
 51 }                                                  44 }
 52                                                    45 
 53 // ------------------------------------------- <<  46 G4PhysicsTable::G4PhysicsTable(size_t capacity)
 54 G4PhysicsTable::~G4PhysicsTable()              <<  47   : G4PhysCollection()
 55 {                                                  48 {
 56   G4PhysCollection::clear();                   <<  49   reserve(capacity);
 57   vecFlag.clear();                             << 
 58 }                                                  50 }
 59                                                    51 
 60 // ------------------------------------------- <<  52 G4PhysicsTable::G4PhysicsTable(const G4PhysicsTable& right)
 61 void G4PhysicsTable::resize(std::size_t siz, G << 
 62 {                                                  53 {
 63   G4PhysCollection::resize(siz, vec);          <<  54   *this = right;
 64   vecFlag.resize(siz, true);                   << 
 65 }                                                  55 }
 66                                                    56 
 67 // ------------------------------------------- <<  57 G4PhysicsTable& G4PhysicsTable::operator=(const G4PhysicsTable& right)
 68 G4bool G4PhysicsTable::StorePhysicsTable(const << 
 69 {                                                  58 {
 70   std::ofstream fOut;                          <<  59   if (this != &right)
 71                                                << 
 72   // open output file                          << 
 73   if(!ascii)                                   << 
 74   {                                                60   {
 75     fOut.open(fileName, std::ios::out | std::i <<  61     G4PhysCollection::const_iterator itr;
                                                   >>  62     for (itr=right.begin(); itr!=right.end(); ++itr)
                                                   >>  63     {
                                                   >>  64       G4PhysCollection::push_back(*itr);
                                                   >>  65     }
 76   }                                                66   }
                                                   >>  67   return *this;
                                                   >>  68 }
                                                   >>  69 
                                                   >>  70 G4PhysicsTable::~G4PhysicsTable()
                                                   >>  71 {
                                                   >>  72   clear();
                                                   >>  73 }
                                                   >>  74  
                                                   >>  75 
                                                   >>  76 G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
                                                   >>  77            G4bool          ascii)
                                                   >>  78 {
                                                   >>  79   G4std::ofstream fOut;  
                                                   >>  80   
                                                   >>  81   // open output file //
                                                   >>  82 #ifdef G4USE_STD_NAMESPACE
                                                   >>  83   if (!ascii)
                                                   >>  84     fOut.open(fileName, G4std::ios::out|G4std::ios::binary);
 77   else                                             85   else
 78   {                                            <<  86 #endif
 79     fOut.open(fileName, std::ios::out);        <<  87     fOut.open(fileName, G4std::ios::out);
 80   }                                            << 
 81                                                    88 
 82   // check if the file has been opened success <<  89   // check if the file has been opened successfully 
 83   if(!fOut.is_open())                          <<  90   if (!fOut) {
 84   {                                            <<  91 #ifdef G4VERBOSE  
 85 #ifdef G4VERBOSE                               <<  92     G4cerr << "G4PhysicsTable::::StorePhysicsTable  ";
 86     G4cerr << "G4PhysicsTable::StorePhysicsTab <<  93     G4cerr << " Can not open file " << fileName << G4endl;
 87     G4cerr << " Cannot open file: " << fileNam << 
 88 #endif                                             94 #endif
 89     fOut.close();                                  95     fOut.close();
 90     return false;                                  96     return false;
 91   }                                                97   }
 92                                                    98 
 93   // Number of elements                            99   // Number of elements
 94   std::size_t tableSize = size();              << 100   size_t tableSize = size(); 
 95   if(!ascii)                                   << 101   if (!ascii){
 96   {                                            << 102     fOut.write( (char*)(&tableSize), sizeof tableSize); 
 97     fOut.write((char*) (&tableSize), sizeof ta << 103   } else {
 98   }                                            << 
 99   else                                         << 
100   {                                            << 
101     fOut << tableSize << G4endl;                  104     fOut << tableSize << G4endl;
102   }                                               105   }
103                                                   106 
104   // Physics Vector                               107   // Physics Vector
105   for(const auto itr : *this)                  << 108   G4PhysicsTableIterator itr;
106   {                                            << 109   for (itr=begin(); itr!=end(); ++itr) {
107     G4int vType = itr->GetType();              << 110     G4int vType = (*itr)->GetType();
108     if(!ascii)                                 << 111     if (!ascii){
109     {                                          << 112       fOut.write( (char*)(&vType), sizeof vType); 
110       fOut.write((char*) (&vType), sizeof vTyp << 113     } else {
111     }                                          << 
112     else                                       << 
113     {                                          << 
114       fOut << vType << G4endl;                    114       fOut << vType << G4endl;
115     }                                             115     }
116     itr->Store(fOut, ascii);                   << 116     (*itr)->Store(fOut,ascii);
117   }                                               117   }
118   fOut.close();                                   118   fOut.close();
119   return true;                                    119   return true;
120 }                                                 120 }
121                                                   121 
122 // ------------------------------------------- << 
123 G4bool G4PhysicsTable::ExistPhysicsTable(const << 
124 {                                              << 
125   std::ifstream fIn;                           << 
126   G4bool value = true;                         << 
127   // open input file                           << 
128   fIn.open(fileName, std::ios::in);            << 
129                                                   122 
130   // check if the file has been opened success << 
131   if(!fIn)                                     << 
132   {                                            << 
133     value = false;                             << 
134   }                                            << 
135   fIn.close();                                 << 
136   return value;                                << 
137 }                                              << 
138                                                   123 
139 // ------------------------------------------- << 
140 G4bool G4PhysicsTable::RetrievePhysicsTable(co    124 G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
141                                             G4 << 125               G4bool          ascii)
142 {                                                 126 {
143   std::ifstream fIn;                           << 127   G4std::ifstream fIn;  
144   // open input file                           << 128   // open input file //
145   if(ascii)                                    << 129 #ifdef G4USE_STD_NAMESPACE
146   {                                            << 130   if (ascii)
147     fIn.open(fileName, std::ios::in | std::ios << 131     fIn.open(fileName,G4std::ios::in|G4std::ios::binary);
148   }                                            << 
149   else                                            132   else
150   {                                            << 133 #endif
151     fIn.open(fileName, std::ios::in);          << 134     fIn.open(fileName,G4std::ios::in);
152   }                                            << 
153                                                   135 
154   // check if the file has been opened success << 136   // check if the file has been opened successfully 
155   if(!fIn.is_open())                           << 137   if (!fIn) {
156   {                                            << 138 #ifdef G4VERBOSE  
157 #ifdef G4VERBOSE                               << 139     G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
158     G4cerr << "G4PhysicsTable::RetrievePhysics << 140     G4cerr << " Can not open file " << fileName << G4endl;
159     G4cerr << " Cannot open file: " << fileNam << 
160 #endif                                            141 #endif
161     fIn.close();                                  142     fIn.close();
162     return false;                                 143     return false;
163   }                                               144   }
164                                                   145 
165   // clear                                     << 146   // clear 
166   clearAndDestroy();                              147   clearAndDestroy();
167                                                << 148   
168   // Number of elements                           149   // Number of elements
169   std::size_t tableSize = 0;                   << 150   size_t tableSize; 
170   if(!ascii)                                   << 151   if (!ascii){
171   {                                            << 152     fIn.read((char*)(&tableSize), sizeof tableSize); 
172     fIn.read((char*) (&tableSize), sizeof tabl << 153   } else {
173   }                                            << 
174   else                                         << 
175   {                                            << 
176     fIn >> tableSize;                             154     fIn >> tableSize;
177   }                                               155   }
178   reserve(tableSize);                          << 156   reserve(tableSize); 
179   vecFlag.clear();                             << 
180                                                   157 
181   // Physics Vector                               158   // Physics Vector
182   for(std::size_t idx = 0; idx < tableSize; ++ << 159   for (size_t idx=0; idx<tableSize; ++idx) {
183   {                                            << 160     G4int vType;
184     G4int vType = 0;                           << 161     if (!ascii){
185     if(!ascii)                                 << 162       fIn.read( (char*)(&vType), sizeof vType); 
186     {                                          << 163     } else {
187       fIn.read((char*) (&vType), sizeof vType) << 164       fIn >>  vType;
188     }                                          << 165     }
189     else                                       << 166     G4PhysicsVector* pVec = CreatePhysicsVector(vType);
190     {                                          << 167     if (pVec==0) {
191       fIn >> vType;                            << 168 #ifdef G4VERBOSE  
192     }                                          << 169       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
193     G4PhysicsVector* pVec = CreatePhysicsVecto << 170       G4cerr << " illegal Physics Vector type " << vType << " in  ";
194     if(pVec == nullptr)                        << 
195     {                                          << 
196 #ifdef G4VERBOSE                               << 
197       G4cerr << "G4PhysicsTable::RetrievePhysi << 
198       G4cerr << " Illegal Physics Vector type: << 
199       G4cerr << fileName << G4endl;               171       G4cerr << fileName << G4endl;
200 #endif                                         << 172 #endif          
201       fIn.close();                                173       fIn.close();
202       return false;                               174       return false;
203     }                                             175     }
204                                                   176 
205     if(!(pVec->Retrieve(fIn, ascii)))          << 177     if (! (pVec->Retrieve(fIn,ascii)) ){
206     {                                          << 178 #ifdef G4VERBOSE  
207 #ifdef G4VERBOSE                               << 179       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
208       G4cerr << "G4PhysicsTable::RetrievePhysi << 180       G4cerr << " error in retreiving " << idx << "-th Physics Vector from file ";
209       G4cerr << " Rrror in retreiving " << idx << 
210              << "-th Physics Vector from file: << 
211       G4cerr << fileName << G4endl;               181       G4cerr << fileName << G4endl;
212 #endif                                         << 182 #endif          
213       fIn.close();                                183       fIn.close();
214       return false;                               184       return false;
215     }                                             185     }
216                                                   186 
217     // add a PhysicsVector to this PhysicsTabl    187     // add a PhysicsVector to this PhysicsTable
218     G4PhysCollection::push_back(pVec);         << 188     push_back(pVec);
219     vecFlag.push_back(true);                   << 189   } 
220   }                                            << 
221   fIn.close();                                    190   fIn.close();
222   return true;                                    191   return true;
223 }                                                 192 }
224                                                   193 
225 // ------------------------------------------- << 194 G4std::ostream& operator<<(G4std::ostream& out, 
226 std::ostream& operator<<(std::ostream& out, G4 << 195          G4PhysicsTable& right)
227 {                                                 196 {
228   // Printout Physics Vector                      197   // Printout Physics Vector
229   std::size_t i = 0;                           << 198   G4PhysicsTableIterator itr;
230   for(auto itr = right.cbegin(); itr != right. << 199   size_t i=0;
231   {                                            << 200   for (itr=right.begin(); itr!=right.end(); ++itr) {
232     out << std::setw(8) << i << "-th Vector    << 201     out << G4std::setw(8) << i << "-th Vector   ";
233     if (nullptr == (*itr)) {                   << 202     out << ": Type    " << G4int((*itr)->GetType()) << G4endl;
234       out << "empty" << G4endl;                << 
235       ++i;                                     << 
236       continue;                                << 
237     }                                          << 
238     out << ": Type    " << G4int((*itr)->GetTy << 
239     out << ": Flag    ";                       << 
240     if(right.GetFlag(i))                       << 
241     {                                          << 
242       out << " T";                             << 
243     }                                          << 
244     else                                       << 
245     {                                          << 
246       out << " F";                             << 
247     }                                          << 
248     out << G4endl;                             << 
249     out << *(*itr);                               203     out << *(*itr);
250     ++i;                                       << 204     i +=1;
251   }                                               205   }
252   out << G4endl;                                  206   out << G4endl;
253   return out;                                  << 207   return out; 
254 }                                              << 
255                                                << 
256 // ------------------------------------------- << 
257 void G4PhysicsTable::ResetFlagArray()          << 
258 {                                              << 
259   size_t tableSize = G4PhysCollection::size(); << 
260   vecFlag.clear();                             << 
261   for(std::size_t idx = 0; idx < tableSize; ++ << 
262   {                                            << 
263     vecFlag.push_back(true);                   << 
264   }                                            << 
265 }                                                 208 }
266                                                   209 
267 // ------------------------------------------- << 210 #include "G4PhysicsVectorType.hh"
268 G4PhysicsVector* G4PhysicsTable::CreatePhysics << 211 #include "G4LPhysicsFreeVector.hh"
269 {                                              << 212 #include "G4PhysicsLogVector.hh"
270   G4PhysicsVector* pVector = nullptr;          << 213 #include "G4PhysicsFreeVector.hh"
271   switch(type)                                 << 214 #include "G4PhysicsOrderedFreeVector.hh"
272   {                                            << 215 #include "G4PhysicsLinearVector.hh"
273     case T_G4PhysicsLinearVector:              << 216 #include "G4PhysicsLnVector.hh"
274       pVector = new G4PhysicsLinearVector(spli << 217  
275       break;                                   << 218 G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type)
276                                                << 219 {
277     case T_G4PhysicsLogVector:                 << 220   G4PhysicsVector* pVector=0;
278       pVector = new G4PhysicsLogVector(spline) << 221   switch (type) {
279       break;                                   << 222 
280                                                << 223   case T_G4PhysicsLinearVector: 
281     default:                                   << 224     pVector = new G4PhysicsLinearVector();
282       pVector = new G4PhysicsVector(spline);   << 225     break;
283       break;                                   << 226 
                                                   >> 227   case T_G4PhysicsLogVector: 
                                                   >> 228     pVector = new G4PhysicsLogVector();
                                                   >> 229     break;
                                                   >> 230 
                                                   >> 231   case T_G4PhysicsLnVector: 
                                                   >> 232     pVector = new G4PhysicsLnVector();
                                                   >> 233     break;
                                                   >> 234 
                                                   >> 235   case T_G4PhysicsFreeVector: 
                                                   >> 236     pVector = new G4PhysicsFreeVector();
                                                   >> 237     break;
                                                   >> 238 
                                                   >> 239   case T_G4PhysicsOrderedFreeVector: 
                                                   >> 240     pVector = new G4PhysicsOrderedFreeVector();
                                                   >> 241     break;
                                                   >> 242 
                                                   >> 243   case T_G4LPhysicsFreeVector: 
                                                   >> 244     pVector = new G4LPhysicsFreeVector();
                                                   >> 245     break;
                                                   >> 246   
                                                   >> 247   default:
                                                   >> 248     break;
                                                   >> 249  
284   }                                               250   }
285   return pVector;                                 251   return pVector;
286 }                                                 252 }
                                                   >> 253  
287                                                   254