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 10.5 ] [ 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 /processes/electromagnetic/utils/src/G4EmDataHandler.cc (Version 11.3.0) and /processes/electromagnetic/utils/src/G4EmDataHandler.cc (Version 10.7.p4)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27 // -------------------------------------------     27 // -------------------------------------------------------------------
 28 //                                                 28 //
 29 // GEANT4 Class file                               29 // GEANT4 Class file
 30 //                                                 30 //
 31 // File name:     G4EmDataHandler                  31 // File name:     G4EmDataHandler
 32 //                                                 32 //
 33 // Author:        V. Ivanchenko                    33 // Author:        V. Ivanchenko 
 34 //                                                 34 // 
 35 // Creation date: 16 August 2017                   35 // Creation date: 16 August 2017
 36 //                                                 36 //
 37 // Modifications:                                  37 // Modifications: 
 38 //                                                 38 //
 39 // -------------------------------------------     39 // -------------------------------------------------------------------
 40 //                                                 40 //
 41 //                                                 41 //    
 42                                                    42 
 43 #include "G4EmDataHandler.hh"                      43 #include "G4EmDataHandler.hh"
 44 #include "G4EmDataRegistry.hh"                 << 
 45 #include "G4ParticleDefinition.hh"                 44 #include "G4ParticleDefinition.hh"
 46 #include "G4EmParameters.hh"                       45 #include "G4EmParameters.hh"
 47 #include "G4PhysicsTableHelper.hh"                 46 #include "G4PhysicsTableHelper.hh"
 48 #include "G4VEmProcess.hh"                         47 #include "G4VEmProcess.hh"
 49 #include "G4VEnergyLossProcess.hh"                 48 #include "G4VEnergyLossProcess.hh"
 50                                                    49 
 51 //....oooOO0OOooo........oooOO0OOooo........oo     50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 52                                                    51 
 53 G4EmDataHandler::G4EmDataHandler(std::size_t n <<  52 G4EmDataHandler::G4EmDataHandler(size_t n) : tLength(n)
 54   : tLength(n), fName(nam)                     << 
 55 {                                                  53 {
 56   data.resize(n, nullptr);                         54   data.resize(n, nullptr);
 57   fMaxXS = new std::vector<G4double>;          << 
 58   fXSpeaks = new std::vector<G4TwoPeaksXS*>;   << 
 59   G4EmDataRegistry::Instance()->Register(this) << 
 60 }                                                  55 }
 61                                                    56 
 62 //....oooOO0OOooo........oooOO0OOooo........oo     57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 63                                                    58 
 64 G4EmDataHandler::~G4EmDataHandler()                59 G4EmDataHandler::~G4EmDataHandler() 
 65 {                                                  60 {
 66   if (!fUseBaseParticleTable) {                <<  61   //std::cout << "G4EmDataHandler::~G4EmDataHandler " 
 67     for (std::size_t i=0; i<tLength; ++i) {    <<  62   //      << tLength << "  "  << this << std::endl;
 68       CleanTable(i);                           <<  63   for(size_t i=0; i<tLength; ++i) { CleanTable(i); }
 69     }                                          << 
 70     delete fMaxXS;                             << 
 71     delete fXSpeaks;                           << 
 72   }                                            << 
 73   if (!fElemSelectors.empty()) {               << 
 74     for (auto const & ptr : fElemSelectors) {  << 
 75       if (nullptr != ptr) {                    << 
 76   for (auto const & p : *ptr) { delete p; }    << 
 77       }                                        << 
 78     }                                          << 
 79   }                                            << 
 80                                                << 
 81 }                                                  64 }
 82                                                    65 
 83 //....oooOO0OOooo........oooOO0OOooo........oo     66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 84                                                    67 
 85 std::size_t G4EmDataHandler::SetTable(G4Physic <<  68 size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr)
 86 {                                                  69 {
 87   for (std::size_t i=0; i<tLength; ++i) {      << 
 88     if (ptr == data[i]) { return i; }          << 
 89   }                                            << 
 90   data.push_back(ptr);                             70   data.push_back(ptr);
 91   ++tLength;                                       71   ++tLength;
 92   return tLength-1;                                72   return tLength-1; 
 93 }                                                  73 }
 94                                                    74 
 95 //....oooOO0OOooo........oooOO0OOooo........oo     75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 96                                                    76 
 97 void G4EmDataHandler::UpdateTable(G4PhysicsTab <<  77 G4PhysicsTable* G4EmDataHandler::MakeTable(size_t i)
 98 {                                              << 
 99   // update table pointer but not delete previ << 
100   if (idx < tLength) {                         << 
101     if (ptr != data[idx]) { data[idx] = ptr; } << 
102     data[idx] = G4PhysicsTableHelper::PrepareP << 
103   } else {                                     << 
104     G4cout << "### G4EmDataHandler::UpdateTabl << 
105            << " length=" << tLength << G4endl; << 
106   }                                            << 
107 }                                              << 
108                                                << 
109 //....oooOO0OOooo........oooOO0OOooo........oo << 
110                                                << 
111 void G4EmDataHandler::SaveTable(G4PhysicsTable << 
112 {                                              << 
113   if (idx < tLength) {                         << 
114     data[idx] = ptr;                           << 
115   }                                            << 
116 }                                              << 
117                                                << 
118 //....oooOO0OOooo........oooOO0OOooo........oo << 
119                                                << 
120 G4PhysicsTable* G4EmDataHandler::MakeTable(std << 
121 {                                                  78 {
122   std::size_t idx = i;                         <<  79   G4PhysicsTable* table = nullptr;
123   if (idx >= tLength) {                        << 
124     data.push_back(nullptr);                   << 
125     idx = tLength;                             << 
126     ++tLength;                                 << 
127   }                                            << 
128   data[idx] = G4PhysicsTableHelper::PreparePhy << 
129   return data[idx];                            << 
130 }                                              << 
131                                                << 
132 //....oooOO0OOooo........oooOO0OOooo........oo << 
133                                                << 
134 G4PhysicsTable* G4EmDataHandler::MakeTable(G4P << 
135 {                                              << 
136   std::size_t idx = i;                         << 
137   // create new table only if index correspond     80   // create new table only if index corresponds to the
138   // position in the vector                        81   // position in the vector
139   if (idx < tLength) {                         <<  82   if(i <= tLength) {
140     if (ptr != data[idx]) {                    <<  83     if(i < tLength) { table = data[i]; }
141       CleanTable(idx);                         <<  84     table = G4PhysicsTableHelper::PreparePhysicsTable(table);
142       data[idx] = ptr;                         <<  85     if(i == tLength) {
143     }                                          <<  86       data.push_back(table);
144   } else {                                     <<  87       ++tLength;
145     data.push_back(ptr);                       <<  88     } else { data[i] = table; }
146     idx = tLength;                             << 
147     ++tLength;                                 << 
148   }                                                89   }
149   data[idx] = G4PhysicsTableHelper::PreparePhy <<  90   return table;
150   return data[idx];                            << 
151 }                                                  91 }
152                                                    92 
153 //....oooOO0OOooo........oooOO0OOooo........oo     93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154                                                    94 
155 void G4EmDataHandler::CleanTable(std::size_t i <<  95 void G4EmDataHandler::CleanTable(size_t i)
156 {                                                  96 {
157   if (i < tLength && nullptr != data[i]) {     <<  97   //std::cout << i << "  " << data[i] << std::endl;
158     auto ptr = data[i];                        <<  98   if(i < tLength && data[i]) {
159     ptr->clearAndDestroy();                    <<  99     data[i]->clearAndDestroy();
160     delete ptr;                                << 100     delete data[i];
161     for (std::size_t j=0; j<tLength; ++j) {    << 101     data[i] = nullptr;
162       if (ptr == data[j]) { data[j] = nullptr; << 
163     }                                          << 
164   }                                               102   }
165 }                                                 103 }
166                                                   104 
167 //....oooOO0OOooo........oooOO0OOooo........oo    105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168                                                   106 
169 G4bool G4EmDataHandler::StorePhysicsTable(std: << 107 G4bool G4EmDataHandler::StorePhysicsTable(size_t idx,
170                            const G4ParticleDef    108                            const G4ParticleDefinition* part,
171          const G4String& fname,                   109          const G4String& fname, 
172          G4bool ascii)                            110          G4bool ascii)
173 {                                                 111 {
174   G4bool yes = true;                              112   G4bool yes = true;
175   if(nullptr != data[idx]) {                   << 113   if(data[idx]) {
176     yes = data[idx]->StorePhysicsTable(fname,     114     yes = data[idx]->StorePhysicsTable(fname, ascii);
177                                                   115 
178     if ( yes ) {                                  116     if ( yes ) {
179       G4cout << "### Physics table is stored f << 117       G4cout << "Physics table is stored for " 
180        << part->GetParticleName()                 118        << part->GetParticleName()
181              << " <" << fname << "> " << G4end    119              << " <" << fname << "> " << G4endl;
182     } else {                                      120     } else {
183       G4cout << "### Fail to store Physics Tab << 121       G4cout << "Fail to store Physics Table for " 
184              << part->GetParticleName()           122              << part->GetParticleName()
185              << " <" << fname << "> " << G4end    123              << " <" << fname << "> " << G4endl;
186     }                                             124     }
187   }                                               125   }
188   return yes;                                     126   return yes;
189 }                                                 127 }
190                                                   128 
191 //....oooOO0OOooo........oooOO0OOooo........oo    129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192                                                   130 
193 G4bool G4EmDataHandler::RetrievePhysicsTable(s << 131 G4bool G4EmDataHandler::RetrievePhysicsTable(size_t idx,
194                            const G4ParticleDef    132                            const G4ParticleDefinition* part,
195          const G4String& fname,                   133          const G4String& fname, 
196          G4bool ascii, G4bool spline)          << 134          G4bool ascii)
197 {                                                 135 {
198   G4PhysicsTable* table = Table(idx);          << 136   G4bool yes = 
199   G4bool yes = G4PhysicsTableHelper::RetrieveP << 137     G4PhysicsTableHelper::RetrievePhysicsTable(data[idx], fname, ascii);
200   G4EmParameters* param = G4EmParameters::Inst    138   G4EmParameters* param = G4EmParameters::Instance();
201   if ( yes ) {                                    139   if ( yes ) {
202     if (0 < param->Verbose()) {                   140     if (0 < param->Verbose()) {
203       G4cout << "### Physics table " << idx << << 141       G4cout << "Physics table " << idx << " for "  
204        << part->GetParticleName()                 142        << part->GetParticleName()
205        << " is retrieved from <" << fname << "    143        << " is retrieved from <" << fname << ">"
206        << G4endl;                                 144        << G4endl;
207     }                                             145     }
                                                   >> 146     if(param->Spline()) {
                                                   >> 147       G4PhysicsTable* table = data[idx];
                                                   >> 148       size_t n = table->length();
                                                   >> 149       for(size_t i=0; i<n; ++i) {
                                                   >> 150   if((*table)[i]) { (*table)[i]->SetSpline(true); } 
                                                   >> 151       }
                                                   >> 152     }
208   } else if (1 < param->Verbose()) {              153   } else if (1 < param->Verbose()) {
209     G4cout << "### Fail to retrieve physics ta << 154     G4cout << "Fail to retrieve physics table " << idx << " for " 
210      << part->GetParticleName() << " from <"      155      << part->GetParticleName() << " from <"
211      << fname << ">" << G4endl;                   156      << fname << ">" << G4endl;
212   }                                               157   }
213   return yes;                                     158   return yes;
214 }                                                 159 }
215                                                   160 
216 //....oooOO0OOooo........oooOO0OOooo........oo    161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217                                                   162 
218 void G4EmDataHandler::SetMasterProcess(const G    163 void G4EmDataHandler::SetMasterProcess(const G4VEmProcess* ptr)
219 {                                                 164 {
220   masterProcess.push_back(ptr);                   165   masterProcess.push_back(ptr);
221 }                                                 166 }
222                                                   167 
223 //....oooOO0OOooo........oooOO0OOooo........oo    168 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224                                                   169 
225 const G4VEmProcess* G4EmDataHandler::GetMaster << 170 const G4VEmProcess* G4EmDataHandler::GetMasterProcess(size_t idx) const
226 {                                                 171 {
227   return (idx < masterProcess.size()) ? master    172   return (idx < masterProcess.size()) ? masterProcess[idx] : nullptr;
228 }                                              << 
229                                                << 
230 //....oooOO0OOooo........oooOO0OOooo........oo << 
231                                                << 
232 void G4EmDataHandler::SetElementSelectors(std: << 
233             std::size_t i)                     << 
234 {                                              << 
235   if (i < eLength) {                           << 
236     if (fElemSelectors[i] != p) {              << 
237       delete fElemSelectors[i];                << 
238     }                                          << 
239     fElemSelectors[i] = p;                     << 
240   } else {                                     << 
241     fElemSelectors.push_back(p);               << 
242     ++eLength;                                 << 
243   }                                            << 
244 }                                                 173 }
245                                                   174 
246 //....oooOO0OOooo........oooOO0OOooo........oo    175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247                                                   176