Ignore:
Timestamp:
Nov 5, 2010, 3:45:55 PM (14 years ago)
Author:
garnier
Message:

update ti head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/global/management/src/G4PhysicsTable.cc

    r1337 r1340  
    2525//
    2626//
    27 // $Id: G4PhysicsTable.cc,v 1.15 2007/11/13 17:35:06 gcosmo Exp $
    28 // GEANT4 tag $Name: geant4-09-04-beta-01 $
     27// $Id: G4PhysicsTable.cc,v 1.17 2010/11/01 13:55:53 gcosmo Exp $
     28// GEANT4 tag $Name: global-V09-03-22 $
    2929//
    3030//
     
    3636// ------------------------------------------------------------
    3737
    38 #include "G4PhysicsVector.hh"
    39 #include "G4PhysicsTable.hh"
    4038#include <iostream>
    4139#include <fstream>
    4240#include <iomanip>
    4341
    44 G4PhysicsTable::G4PhysicsTable()
    45   : G4PhysCollection()
    46 {
    47 }
    48 
    49 G4PhysicsTable::G4PhysicsTable(size_t cap)
    50   : G4PhysCollection()
    51 {
    52   reserve(cap);
    53   vecFlag.reserve(cap);
    54 }
    55 
    56 G4PhysicsTable::G4PhysicsTable(const G4PhysicsTable& right)
    57   : G4PhysCollection()
    58 {
    59   *this = right;
    60 }
    61 
    62 G4PhysicsTable& G4PhysicsTable::operator=(const G4PhysicsTable& right)
    63 {
    64   if (this != &right)
    65   {
    66     size_t idx = 0;
    67     for (G4PhysCollection::const_iterator itr=right.begin();
    68          itr!=right.end(); ++itr )
    69     {
    70       G4PhysCollection::push_back(*itr);
    71       vecFlag.push_back(right.GetFlag(idx));
    72       idx +=1;
    73     }
    74   }
    75   return *this;
    76 }
    77 
    78 G4PhysicsTable::~G4PhysicsTable()
    79 {
    80   G4PhysCollection::clear();
    81   vecFlag.clear();
    82 }
    83  
    84 void   G4PhysicsTable::resize(size_t siz, G4PhysicsVector* vec)
    85 {
    86   G4PhysCollection::resize(siz, vec);
    87   vecFlag.resize(siz, true);
    88 }
    89 
    90 G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
    91                                          G4bool          ascii)
    92 {
    93   std::ofstream fOut; 
    94  
    95   // open output file //
    96   if (!ascii)
    97     { fOut.open(fileName, std::ios::out|std::ios::binary); }
    98   else
    99     { fOut.open(fileName, std::ios::out); }
    100 
    101   // check if the file has been opened successfully
    102   if (!fOut)
    103   {
    104 #ifdef G4VERBOSE 
    105     G4cerr << "G4PhysicsTable::StorePhysicsTable  ";
    106     G4cerr << " Can not open file " << fileName << G4endl;
    107 #endif
    108     fOut.close();
    109     return false;
    110   }
    111 
    112   // Number of elements
    113   size_t tableSize = size();
    114   if (!ascii)
    115   {
    116     fOut.write( (char*)(&tableSize), sizeof tableSize);
    117   }
    118   else
    119   {
    120     fOut << tableSize << G4endl;
    121   }
    122 
    123   // Physics Vector
    124   for (G4PhysicsTableIterator itr=begin(); itr!=end(); ++itr)
    125   {
    126     G4int vType = (*itr)->GetType();
    127     if (!ascii)
    128     {
    129       fOut.write( (char*)(&vType), sizeof vType);
    130     }
    131     else
    132     {
    133       fOut << vType << G4endl;
    134     }
    135     (*itr)->Store(fOut,ascii);
    136   }
    137   fOut.close();
    138   return true;
    139 }
    140 
    141 
    142 G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
    143 {
    144   std::ifstream fIn; 
    145   G4bool value=true;
    146   // open input file
    147   fIn.open(fileName,std::ios::in);
    148 
    149   // check if the file has been opened successfully
    150   if (!fIn)
    151   {
    152     value = false;
    153   }
    154   fIn.close();
    155   return value;
    156 }
    157    
    158 G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
    159                                             G4bool          ascii)
    160 {
    161   std::ifstream fIn; 
    162   // open input file
    163   if (ascii)
    164     { fIn.open(fileName,std::ios::in|std::ios::binary); }
    165   else
    166     { fIn.open(fileName,std::ios::in);}
    167 
    168   // check if the file has been opened successfully
    169   if (!fIn)
    170   {
    171 #ifdef G4VERBOSE 
    172     G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
    173     G4cerr << " Can not open file " << fileName << G4endl;
    174 #endif
    175     fIn.close();
    176     return false;
    177   }
    178 
    179   // clear
    180   clearAndDestroy();
    181  
    182   // Number of elements
    183   size_t tableSize=0;
    184   if (!ascii)
    185   {
    186     fIn.read((char*)(&tableSize), sizeof tableSize);
    187   }
    188   else
    189   {
    190     fIn >> tableSize;
    191   }
    192   reserve(tableSize);
    193   vecFlag.clear();
    194 
    195   // Physics Vector
    196   for (size_t idx=0; idx<tableSize; ++idx)
    197   {
    198     G4int vType=0;
    199     if (!ascii)
    200     {
    201       fIn.read( (char*)(&vType), sizeof vType);
    202     }
    203     else
    204     {
    205       fIn >>  vType;
    206     }
    207     G4PhysicsVector* pVec = CreatePhysicsVector(vType);
    208     if (pVec==0)
    209     {
    210 #ifdef G4VERBOSE 
    211       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
    212       G4cerr << " illegal Physics Vector type " << vType << " in  ";
    213       G4cerr << fileName << G4endl;
    214 #endif         
    215       fIn.close();
    216       return false;
    217     }
    218 
    219     if (! (pVec->Retrieve(fIn,ascii)) )
    220     {
    221 #ifdef G4VERBOSE 
    222       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
    223       G4cerr << " error in retreiving " << idx << "-th Physics Vector from file ";
    224       G4cerr << fileName << G4endl;
    225 #endif         
    226       fIn.close();
    227       return false;
    228     }
    229 
    230     // add a PhysicsVector to this PhysicsTable
    231     G4PhysCollection::push_back(pVec);
    232     vecFlag.push_back(true);
    233    
    234   }
    235   fIn.close();
    236   return true;
    237 }
    238 
    239 std::ostream& operator<<(std::ostream& out,
    240                          G4PhysicsTable& right)
    241 {
    242   // Printout Physics Vector
    243   size_t i=0;
    244   for (G4PhysicsTableIterator itr=right.begin(); itr!=right.end(); ++itr)
    245   {
    246     out << std::setw(8) << i << "-th Vector   ";
    247     out << ": Type    " << G4int((*itr)->GetType()) ;
    248     out << ": Flag    ";
    249     if (right.GetFlag(i))
    250     {
    251       out << " T";
    252     }
    253     else
    254     {
    255       out << " F";
    256     }
    257     out << G4endl;
    258     out << *(*itr);
    259     i +=1;
    260   }
    261   out << G4endl;
    262   return out;
    263 }
    264 
    265 void G4PhysicsTable::ResetFlagArray()
    266 {
    267   size_t tableSize = G4PhysCollection::size();
    268   vecFlag.clear();
    269   for (size_t idx=0; idx<tableSize; idx++)
    270   {
    271     vecFlag.push_back(true);
    272   }
    273 }
    274 
     42#include "G4PhysicsVector.hh"
     43#include "G4PhysicsTable.hh"
    27544#include "G4PhysicsVectorType.hh"
    27645#include "G4LPhysicsFreeVector.hh"
     
    28150#include "G4PhysicsLnVector.hh"
    28251 
     52G4PhysicsTable::G4PhysicsTable()
     53  : G4PhysCollection()
     54{
     55}
     56
     57G4PhysicsTable::G4PhysicsTable(size_t cap)
     58  : G4PhysCollection()
     59{
     60  reserve(cap);
     61  vecFlag.reserve(cap);
     62}
     63
     64G4PhysicsTable::G4PhysicsTable(const G4PhysicsTable& right)
     65  : G4PhysCollection()
     66{
     67  *this = right;
     68}
     69
     70G4PhysicsTable& G4PhysicsTable::operator=(const G4PhysicsTable& right)
     71{
     72  if (this != &right)
     73  {
     74    size_t idx = 0;
     75    for (G4PhysCollection::const_iterator itr=right.begin();
     76         itr!=right.end(); ++itr )
     77    {
     78      G4PhysCollection::push_back(*itr);
     79      vecFlag.push_back(right.GetFlag(idx));
     80      idx +=1;
     81    }
     82  }
     83  return *this;
     84}
     85
     86G4PhysicsTable::~G4PhysicsTable()
     87{
     88  G4PhysCollection::clear();
     89  vecFlag.clear();
     90}
     91 
     92void   G4PhysicsTable::resize(size_t siz, G4PhysicsVector* vec)
     93{
     94  G4PhysCollection::resize(siz, vec);
     95  vecFlag.resize(siz, true);
     96}
     97
     98G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
     99                                         G4bool          ascii)
     100{
     101  std::ofstream fOut; 
     102 
     103  // open output file //
     104  if (!ascii)
     105    { fOut.open(fileName, std::ios::out|std::ios::binary); }
     106  else
     107    { fOut.open(fileName, std::ios::out); }
     108
     109  // check if the file has been opened successfully
     110  if (!fOut)
     111  {
     112#ifdef G4VERBOSE 
     113    G4cerr << "G4PhysicsTable::StorePhysicsTable():";
     114    G4cerr << " Cannot open file: " << fileName << G4endl;
     115#endif
     116    fOut.close();
     117    return false;
     118  }
     119
     120  // Number of elements
     121  size_t tableSize = size();
     122  if (!ascii)
     123  {
     124    fOut.write( (char*)(&tableSize), sizeof tableSize);
     125  }
     126  else
     127  {
     128    fOut << tableSize << G4endl;
     129  }
     130
     131  // Physics Vector
     132  for (G4PhysicsTableIterator itr=begin(); itr!=end(); ++itr)
     133  {
     134    G4int vType = (*itr)->GetType();
     135    if (!ascii)
     136    {
     137      fOut.write( (char*)(&vType), sizeof vType);
     138    }
     139    else
     140    {
     141      fOut << vType << G4endl;
     142    }
     143    (*itr)->Store(fOut,ascii);
     144  }
     145  fOut.close();
     146  return true;
     147}
     148
     149
     150G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
     151{
     152  std::ifstream fIn; 
     153  G4bool value=true;
     154  // open input file
     155  fIn.open(fileName,std::ios::in);
     156
     157  // check if the file has been opened successfully
     158  if (!fIn)
     159  {
     160    value = false;
     161  }
     162  fIn.close();
     163  return value;
     164}
     165   
     166G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
     167                                            G4bool          ascii)
     168{
     169  std::ifstream fIn; 
     170  // open input file
     171  if (ascii)
     172    { fIn.open(fileName,std::ios::in|std::ios::binary); }
     173  else
     174    { fIn.open(fileName,std::ios::in);}
     175
     176  // check if the file has been opened successfully
     177  if (!fIn)
     178  {
     179#ifdef G4VERBOSE 
     180    G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
     181    G4cerr << " Cannot open file: " << fileName << G4endl;
     182#endif
     183    fIn.close();
     184    return false;
     185  }
     186
     187  // clear
     188  clearAndDestroy();
     189 
     190  // Number of elements
     191  G4int tableSize=0;
     192  if (!ascii)
     193  {
     194    fIn.read((char*)(&tableSize), sizeof tableSize);
     195  }
     196  else
     197  {
     198    fIn >> tableSize;
     199  }
     200  if (tableSize<=0)
     201  {
     202#ifdef G4VERBOSE 
     203    G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
     204    G4cerr << " Invalid table size: " << tableSize << G4endl;
     205#endif
     206    return false;
     207  }
     208  reserve(tableSize);
     209  vecFlag.clear();
     210
     211  // Physics Vector
     212  for (G4int idx=0; idx<tableSize; ++idx)
     213  {
     214    G4int vType=0;
     215    if (!ascii)
     216    {
     217      fIn.read( (char*)(&vType), sizeof vType);
     218    }
     219    else
     220    {
     221      fIn >>  vType;
     222    }
     223    G4PhysicsVector* pVec = CreatePhysicsVector(vType);
     224    if (pVec==0)
     225    {
     226#ifdef G4VERBOSE 
     227      G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
     228      G4cerr << " Illegal Physics Vector type: " << vType << " in: ";
     229      G4cerr << fileName << G4endl;
     230#endif         
     231      fIn.close();
     232      return false;
     233    }
     234
     235    if (! (pVec->Retrieve(fIn,ascii)) )
     236    {
     237#ifdef G4VERBOSE 
     238      G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
     239      G4cerr << " Rrror in retreiving " << idx
     240             << "-th Physics Vector from file: ";
     241      G4cerr << fileName << G4endl;
     242#endif         
     243      fIn.close();
     244      return false;
     245    }
     246
     247    // add a PhysicsVector to this PhysicsTable
     248    G4PhysCollection::push_back(pVec);
     249    vecFlag.push_back(true);
     250   
     251  }
     252  fIn.close();
     253  return true;
     254}
     255
     256std::ostream& operator<<(std::ostream& out,
     257                         G4PhysicsTable& right)
     258{
     259  // Printout Physics Vector
     260  size_t i=0;
     261  for (G4PhysicsTableIterator itr=right.begin(); itr!=right.end(); ++itr)
     262  {
     263    out << std::setw(8) << i << "-th Vector   ";
     264    out << ": Type    " << G4int((*itr)->GetType()) ;
     265    out << ": Flag    ";
     266    if (right.GetFlag(i))
     267    {
     268      out << " T";
     269    }
     270    else
     271    {
     272      out << " F";
     273    }
     274    out << G4endl;
     275    out << *(*itr);
     276    i +=1;
     277  }
     278  out << G4endl;
     279  return out;
     280}
     281
     282void G4PhysicsTable::ResetFlagArray()
     283{
     284  size_t tableSize = G4PhysCollection::size();
     285  vecFlag.clear();
     286  for (size_t idx=0; idx<tableSize; idx++)
     287  {
     288    vecFlag.push_back(true);
     289  }
     290}
     291
    283292G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type)
    284293{
Note: See TracChangeset for help on using the changeset viewer.