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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 6.2)


  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.10 2003/11/04 12:17:30 gcosmo Exp $
 29 //         First implementation based on objec <<  25 // GEANT4 tag $Name: geant4-06-00-patch-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
                                                   >>  30 //
                                                   >>  31 //  G4PhysicsTable
                                                   >>  32 //
                                                   >>  33 // ------------------------------------------------------------
 34                                                    34 
                                                   >>  35 #include "G4PhysicsVector.hh"
                                                   >>  36 #include "G4PhysicsTable.hh"
                                                   >>  37 #include <iostream>
 35 #include <fstream>                                 38 #include <fstream>
 36 #include <iomanip>                                 39 #include <iomanip>
 37 #include <iostream>                            << 
 38                                                    40 
 39 #include "G4PhysicsFreeVector.hh"              <<  41 G4PhysicsTable::G4PhysicsTable()
 40 #include "G4PhysicsLinearVector.hh"            <<  42   : G4PhysCollection()
 41 #include "G4PhysicsLogVector.hh"               << 
 42 #include "G4PhysicsTable.hh"                   << 
 43 #include "G4PhysicsVector.hh"                  << 
 44 #include "G4PhysicsVectorType.hh"              << 
 45                                                << 
 46 // ------------------------------------------- << 
 47 G4PhysicsTable::G4PhysicsTable(std::size_t cap << 
 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 <<  53   : G4PhysCollection()
 62 {                                                  54 {
 63   G4PhysCollection::resize(siz, vec);          <<  55   *this = right;
 64   vecFlag.resize(siz, true);                   << 
 65 }                                                  56 }
 66                                                    57 
 67 // ------------------------------------------- <<  58 G4PhysicsTable& G4PhysicsTable::operator=(const G4PhysicsTable& right)
 68 G4bool G4PhysicsTable::StorePhysicsTable(const << 
 69 {                                                  59 {
 70   std::ofstream fOut;                          <<  60   if (this != &right)
 71                                                << 
 72   // open output file                          << 
 73   if(!ascii)                                   << 
 74   {                                                61   {
 75     fOut.open(fileName, std::ios::out | std::i <<  62     G4PhysCollection::const_iterator itr;
                                                   >>  63     for (itr=right.begin(); itr!=right.end(); ++itr)
                                                   >>  64     {
                                                   >>  65       G4PhysCollection::push_back(*itr);
                                                   >>  66     }
 76   }                                                67   }
                                                   >>  68   return *this;
                                                   >>  69 }
                                                   >>  70 
                                                   >>  71 G4PhysicsTable::~G4PhysicsTable()
                                                   >>  72 {
                                                   >>  73   clear();
                                                   >>  74 }
                                                   >>  75  
                                                   >>  76 
                                                   >>  77 G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
                                                   >>  78            G4bool          ascii)
                                                   >>  79 {
                                                   >>  80   std::ofstream fOut;  
                                                   >>  81   
                                                   >>  82   // open output file //
                                                   >>  83   if (!ascii)
                                                   >>  84     fOut.open(fileName, std::ios::out|std::ios::binary);
 77   else                                             85   else
 78   {                                            << 
 79     fOut.open(fileName, std::ios::out);            86     fOut.open(fileName, std::ios::out);
 80   }                                            << 
 81                                                    87 
 82   // check if the file has been opened success <<  88   // check if the file has been opened successfully 
 83   if(!fOut.is_open())                          <<  89   if (!fOut) {
 84   {                                            <<  90 #ifdef G4VERBOSE  
 85 #ifdef G4VERBOSE                               <<  91     G4cerr << "G4PhysicsTable::::StorePhysicsTable  ";
 86     G4cerr << "G4PhysicsTable::StorePhysicsTab <<  92     G4cerr << " Can not open file " << fileName << G4endl;
 87     G4cerr << " Cannot open file: " << fileNam << 
 88 #endif                                             93 #endif
 89     fOut.close();                                  94     fOut.close();
 90     return false;                                  95     return false;
 91   }                                                96   }
 92                                                    97 
 93   // Number of elements                            98   // Number of elements
 94   std::size_t tableSize = size();              <<  99   size_t tableSize = size(); 
 95   if(!ascii)                                   << 100   if (!ascii){
 96   {                                            << 101     fOut.write( (char*)(&tableSize), sizeof tableSize); 
 97     fOut.write((char*) (&tableSize), sizeof ta << 102   } else {
 98   }                                            << 
 99   else                                         << 
100   {                                            << 
101     fOut << tableSize << G4endl;                  103     fOut << tableSize << G4endl;
102   }                                               104   }
103                                                   105 
104   // Physics Vector                               106   // Physics Vector
105   for(const auto itr : *this)                  << 107   G4PhysicsTableIterator itr;
106   {                                            << 108   for (itr=begin(); itr!=end(); ++itr) {
107     G4int vType = itr->GetType();              << 109     G4int vType = (*itr)->GetType();
108     if(!ascii)                                 << 110     if (!ascii){
109     {                                          << 111       fOut.write( (char*)(&vType), sizeof vType); 
110       fOut.write((char*) (&vType), sizeof vTyp << 112     } else {
111     }                                          << 
112     else                                       << 
113     {                                          << 
114       fOut << vType << G4endl;                    113       fOut << vType << G4endl;
115     }                                             114     }
116     itr->Store(fOut, ascii);                   << 115     (*itr)->Store(fOut,ascii);
117   }                                               116   }
118   fOut.close();                                   117   fOut.close();
119   return true;                                    118   return true;
120 }                                                 119 }
121                                                   120 
122 // ------------------------------------------- << 121 
123 G4bool G4PhysicsTable::ExistPhysicsTable(const    122 G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
124 {                                                 123 {
125   std::ifstream fIn;                           << 124   std::ifstream fIn;  
126   G4bool value = true;                         << 125   G4bool value=true;
127   // open input file                              126   // open input file
128   fIn.open(fileName, std::ios::in);            << 127   fIn.open(fileName,std::ios::in);
129                                                   128 
130   // check if the file has been opened success << 129   // check if the file has been opened successfully 
131   if(!fIn)                                     << 130   if (!fIn) {
132   {                                            << 
133     value = false;                                131     value = false;
134   }                                               132   }
135   fIn.close();                                    133   fIn.close();
136   return value;                                   134   return value;
137 }                                                 135 }
138                                                << 136     
139 // ------------------------------------------- << 
140 G4bool G4PhysicsTable::RetrievePhysicsTable(co    137 G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
141                                             G4 << 138               G4bool          ascii)
142 {                                                 139 {
143   std::ifstream fIn;                           << 140   std::ifstream fIn;  
144   // open input file                              141   // open input file
145   if(ascii)                                    << 142   if (ascii)
146   {                                            << 143     fIn.open(fileName,std::ios::in|std::ios::binary);
147     fIn.open(fileName, std::ios::in | std::ios << 
148   }                                            << 
149   else                                            144   else
150   {                                            << 145     fIn.open(fileName,std::ios::in);
151     fIn.open(fileName, std::ios::in);          << 
152   }                                            << 
153                                                   146 
154   // check if the file has been opened success << 147   // check if the file has been opened successfully 
155   if(!fIn.is_open())                           << 148   if (!fIn) {
156   {                                            << 149 #ifdef G4VERBOSE  
157 #ifdef G4VERBOSE                               << 150     G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
158     G4cerr << "G4PhysicsTable::RetrievePhysics << 151     G4cerr << " Can not open file " << fileName << G4endl;
159     G4cerr << " Cannot open file: " << fileNam << 
160 #endif                                            152 #endif
161     fIn.close();                                  153     fIn.close();
162     return false;                                 154     return false;
163   }                                               155   }
164                                                   156 
165   // clear                                     << 157   // clear 
166   clearAndDestroy();                              158   clearAndDestroy();
167                                                << 159   
168   // Number of elements                           160   // Number of elements
169   std::size_t tableSize = 0;                   << 161   size_t tableSize; 
170   if(!ascii)                                   << 162   if (!ascii){
171   {                                            << 163     fIn.read((char*)(&tableSize), sizeof tableSize); 
172     fIn.read((char*) (&tableSize), sizeof tabl << 164   } else {
173   }                                            << 
174   else                                         << 
175   {                                            << 
176     fIn >> tableSize;                             165     fIn >> tableSize;
177   }                                               166   }
178   reserve(tableSize);                          << 167   reserve(tableSize); 
179   vecFlag.clear();                             << 
180                                                   168 
181   // Physics Vector                               169   // Physics Vector
182   for(std::size_t idx = 0; idx < tableSize; ++ << 170   for (size_t idx=0; idx<tableSize; ++idx) {
183   {                                            << 171     G4int vType;
184     G4int vType = 0;                           << 172     if (!ascii){
185     if(!ascii)                                 << 173       fIn.read( (char*)(&vType), sizeof vType); 
186     {                                          << 174     } else {
187       fIn.read((char*) (&vType), sizeof vType) << 175       fIn >>  vType;
188     }                                             176     }
189     else                                       << 177     G4PhysicsVector* pVec = CreatePhysicsVector(vType);
190     {                                          << 178     if (pVec==0) {
191       fIn >> vType;                            << 179 #ifdef G4VERBOSE  
192     }                                          << 180       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
193     G4PhysicsVector* pVec = CreatePhysicsVecto << 181       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;               182       G4cerr << fileName << G4endl;
200 #endif                                         << 183 #endif          
201       fIn.close();                                184       fIn.close();
202       return false;                               185       return false;
203     }                                             186     }
204                                                   187 
205     if(!(pVec->Retrieve(fIn, ascii)))          << 188     if (! (pVec->Retrieve(fIn,ascii)) ){
206     {                                          << 189 #ifdef G4VERBOSE  
207 #ifdef G4VERBOSE                               << 190       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
208       G4cerr << "G4PhysicsTable::RetrievePhysi << 191       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;               192       G4cerr << fileName << G4endl;
212 #endif                                         << 193 #endif          
213       fIn.close();                                194       fIn.close();
214       return false;                               195       return false;
215     }                                             196     }
216                                                   197 
217     // add a PhysicsVector to this PhysicsTabl    198     // add a PhysicsVector to this PhysicsTable
218     G4PhysCollection::push_back(pVec);         << 199     push_back(pVec);
219     vecFlag.push_back(true);                   << 200   } 
220   }                                            << 
221   fIn.close();                                    201   fIn.close();
222   return true;                                    202   return true;
223 }                                                 203 }
224                                                   204 
225 // ------------------------------------------- << 205 std::ostream& operator<<(std::ostream& out, 
226 std::ostream& operator<<(std::ostream& out, G4 << 206        G4PhysicsTable& right)
227 {                                                 207 {
228   // Printout Physics Vector                      208   // Printout Physics Vector
229   std::size_t i = 0;                           << 209   G4PhysicsTableIterator itr;
230   for(auto itr = right.cbegin(); itr != right. << 210   size_t i=0;
231   {                                            << 211   for (itr=right.begin(); itr!=right.end(); ++itr) {
232     out << std::setw(8) << i << "-th Vector       212     out << std::setw(8) << i << "-th Vector   ";
233     if (nullptr == (*itr)) {                   << 213     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);                               214     out << *(*itr);
250     ++i;                                       << 215     i +=1;
251   }                                               216   }
252   out << G4endl;                                  217   out << G4endl;
253   return out;                                  << 218   return out; 
254 }                                                 219 }
255                                                   220 
256 // ------------------------------------------- << 221 #include "G4PhysicsVectorType.hh"
257 void G4PhysicsTable::ResetFlagArray()          << 222 #include "G4LPhysicsFreeVector.hh"
                                                   >> 223 #include "G4PhysicsLogVector.hh"
                                                   >> 224 #include "G4PhysicsFreeVector.hh"
                                                   >> 225 #include "G4PhysicsOrderedFreeVector.hh"
                                                   >> 226 #include "G4PhysicsLinearVector.hh"
                                                   >> 227 #include "G4PhysicsLnVector.hh"
                                                   >> 228  
                                                   >> 229 G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type)
258 {                                                 230 {
259   size_t tableSize = G4PhysCollection::size(); << 231   G4PhysicsVector* pVector=0;
260   vecFlag.clear();                             << 232   switch (type) {
261   for(std::size_t idx = 0; idx < tableSize; ++ << 
262   {                                            << 
263     vecFlag.push_back(true);                   << 
264   }                                            << 
265 }                                              << 
266                                                   233 
267 // ------------------------------------------- << 234   case T_G4PhysicsLinearVector: 
268 G4PhysicsVector* G4PhysicsTable::CreatePhysics << 235     pVector = new G4PhysicsLinearVector();
269 {                                              << 236     break;
270   G4PhysicsVector* pVector = nullptr;          << 237 
271   switch(type)                                 << 238   case T_G4PhysicsLogVector: 
272   {                                            << 239     pVector = new G4PhysicsLogVector();
273     case T_G4PhysicsLinearVector:              << 240     break;
274       pVector = new G4PhysicsLinearVector(spli << 241 
275       break;                                   << 242   case T_G4PhysicsLnVector: 
276                                                << 243     pVector = new G4PhysicsLnVector();
277     case T_G4PhysicsLogVector:                 << 244     break;
278       pVector = new G4PhysicsLogVector(spline) << 245 
279       break;                                   << 246   case T_G4PhysicsFreeVector: 
280                                                << 247     pVector = new G4PhysicsFreeVector();
281     default:                                   << 248     break;
282       pVector = new G4PhysicsVector(spline);   << 249 
283       break;                                   << 250   case T_G4PhysicsOrderedFreeVector: 
                                                   >> 251     pVector = new G4PhysicsOrderedFreeVector();
                                                   >> 252     break;
                                                   >> 253 
                                                   >> 254   case T_G4LPhysicsFreeVector: 
                                                   >> 255     pVector = new G4LPhysicsFreeVector();
                                                   >> 256     break;
                                                   >> 257   
                                                   >> 258   default:
                                                   >> 259     break;
                                                   >> 260  
284   }                                               261   }
285   return pVector;                                 262   return pVector;
286 }                                                 263 }
                                                   >> 264  
287                                                   265