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


  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   for(size_t i=0; i<tLength; ++i) {
 67     for (std::size_t i=0; i<tLength; ++i) {    <<  62     for(size_t j = i+1; j<tLength; ++j) {
 68       CleanTable(i);                           <<  63       if(data[j] == data[i]) { data[j] = nullptr; }
 69     }                                              64     }
 70     delete fMaxXS;                             <<  65     CleanTable(i);
 71     delete fXSpeaks;                           << 
 72   }                                                66   }
 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 }                                                  67 }
 82                                                    68 
 83 //....oooOO0OOooo........oooOO0OOooo........oo     69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 84                                                    70 
 85 std::size_t G4EmDataHandler::SetTable(G4Physic <<  71 size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr)
 86 {                                                  72 {
 87   for (std::size_t i=0; i<tLength; ++i) {      << 
 88     if (ptr == data[i]) { return i; }          << 
 89   }                                            << 
 90   data.push_back(ptr);                             73   data.push_back(ptr);
 91   ++tLength;                                       74   ++tLength;
 92   return tLength-1;                                75   return tLength-1; 
 93 }                                                  76 }
 94                                                    77 
 95 //....oooOO0OOooo........oooOO0OOooo........oo     78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 96                                                    79 
 97 void G4EmDataHandler::UpdateTable(G4PhysicsTab <<  80 void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, size_t idx)
 98 {                                                  81 {
 99   // update table pointer but not delete previ     82   // update table pointer but not delete previous
100   if (idx < tLength) {                         <<  83   if(idx < tLength) { 
101     if (ptr != data[idx]) { data[idx] = ptr; } <<  84     if(ptr != data[idx]) { data[idx] = ptr; }
102     data[idx] = G4PhysicsTableHelper::PrepareP << 
103   } else {                                         85   } else {
104     G4cout << "### G4EmDataHandler::UpdateTabl     86     G4cout << "### G4EmDataHandler::UpdateTable fail for idx=" << idx 
105            << " length=" << tLength << G4endl;     87            << " length=" << tLength << G4endl;
106   }                                                88   }
107 }                                                  89 }
108                                                    90 
109 //....oooOO0OOooo........oooOO0OOooo........oo     91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110                                                    92 
111 void G4EmDataHandler::SaveTable(G4PhysicsTable <<  93 G4PhysicsTable* G4EmDataHandler::MakeTable(size_t i)
112 {                                              << 
113   if (idx < tLength) {                         << 
114     data[idx] = ptr;                           << 
115   }                                            << 
116 }                                              << 
117                                                << 
118 //....oooOO0OOooo........oooOO0OOooo........oo << 
119                                                << 
120 G4PhysicsTable* G4EmDataHandler::MakeTable(std << 
121 {                                                  94 {
122   std::size_t idx = i;                         <<  95   size_t idx = i; 
123   if (idx >= tLength) {                        <<  96   if(idx >= tLength) { 
124     data.push_back(nullptr);                       97     data.push_back(nullptr);
125     idx = tLength;                                 98     idx = tLength;
126     ++tLength;                                     99     ++tLength;
127   }                                               100   }
128   data[idx] = G4PhysicsTableHelper::PreparePhy    101   data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]);
129   return data[idx];                               102   return data[idx];
130 }                                                 103 }
131                                                   104 
132 //....oooOO0OOooo........oooOO0OOooo........oo    105 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133                                                   106 
134 G4PhysicsTable* G4EmDataHandler::MakeTable(G4P << 107 G4PhysicsTable* G4EmDataHandler::MakeTable(G4PhysicsTable* ptr, size_t i)
135 {                                                 108 {
136   std::size_t idx = i;                         << 109   size_t idx = i; 
137   // create new table only if index correspond    110   // create new table only if index corresponds to the
138   // position in the vector                       111   // position in the vector
139   if (idx < tLength) {                         << 112   if(idx < tLength) { 
140     if (ptr != data[idx]) {                    << 113     if(ptr != data[idx]) { 
141       CleanTable(idx);                            114       CleanTable(idx);
142       data[idx] = ptr;                            115       data[idx] = ptr;
143     }                                             116     }
144   } else {                                        117   } else {
145     data.push_back(ptr);                          118     data.push_back(ptr);
146     idx = tLength;                                119     idx = tLength;
147     ++tLength;                                    120     ++tLength;
148   }                                               121   }
149   data[idx] = G4PhysicsTableHelper::PreparePhy << 122   data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(ptr);
150   return data[idx];                               123   return data[idx];
151 }                                                 124 }
152                                                   125 
153 //....oooOO0OOooo........oooOO0OOooo........oo    126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154                                                   127 
155 void G4EmDataHandler::CleanTable(std::size_t i << 128 void G4EmDataHandler::CleanTable(size_t i)
156 {                                                 129 {
157   if (i < tLength && nullptr != data[i]) {     << 130   if(i < tLength && nullptr != data[i]) {
158     auto ptr = data[i];                        << 131     data[i]->clearAndDestroy();
159     ptr->clearAndDestroy();                    << 132     delete data[i];
160     delete ptr;                                << 133     data[i] = nullptr;
161     for (std::size_t j=0; j<tLength; ++j) {    << 
162       if (ptr == data[j]) { data[j] = nullptr; << 
163     }                                          << 
164   }                                               134   }
165 }                                                 135 }
166                                                   136 
167 //....oooOO0OOooo........oooOO0OOooo........oo    137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
168                                                   138 
169 G4bool G4EmDataHandler::StorePhysicsTable(std: << 139 G4bool G4EmDataHandler::StorePhysicsTable(size_t idx,
170                            const G4ParticleDef    140                            const G4ParticleDefinition* part,
171          const G4String& fname,                   141          const G4String& fname, 
172          G4bool ascii)                            142          G4bool ascii)
173 {                                                 143 {
174   G4bool yes = true;                              144   G4bool yes = true;
175   if(nullptr != data[idx]) {                      145   if(nullptr != data[idx]) {
176     yes = data[idx]->StorePhysicsTable(fname,     146     yes = data[idx]->StorePhysicsTable(fname, ascii);
177                                                   147 
178     if ( yes ) {                                  148     if ( yes ) {
179       G4cout << "### Physics table is stored f    149       G4cout << "### Physics table is stored for " 
180        << part->GetParticleName()                 150        << part->GetParticleName()
181              << " <" << fname << "> " << G4end    151              << " <" << fname << "> " << G4endl;
182     } else {                                      152     } else {
183       G4cout << "### Fail to store Physics Tab    153       G4cout << "### Fail to store Physics Table for " 
184              << part->GetParticleName()           154              << part->GetParticleName()
185              << " <" << fname << "> " << G4end    155              << " <" << fname << "> " << G4endl;
186     }                                             156     }
187   }                                               157   }
188   return yes;                                     158   return yes;
189 }                                                 159 }
190                                                   160 
191 //....oooOO0OOooo........oooOO0OOooo........oo    161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
192                                                   162 
193 G4bool G4EmDataHandler::RetrievePhysicsTable(s << 163 G4bool G4EmDataHandler::RetrievePhysicsTable(size_t idx,
194                            const G4ParticleDef    164                            const G4ParticleDefinition* part,
195          const G4String& fname,                   165          const G4String& fname, 
196          G4bool ascii, G4bool spline)             166          G4bool ascii, G4bool spline)
197 {                                                 167 {
198   G4PhysicsTable* table = Table(idx);             168   G4PhysicsTable* table = Table(idx);
199   G4bool yes = G4PhysicsTableHelper::RetrieveP    169   G4bool yes = G4PhysicsTableHelper::RetrievePhysicsTable(table, fname, ascii, spline);
200   G4EmParameters* param = G4EmParameters::Inst    170   G4EmParameters* param = G4EmParameters::Instance();
201   if ( yes ) {                                    171   if ( yes ) {
202     if (0 < param->Verbose()) {                   172     if (0 < param->Verbose()) {
203       G4cout << "### Physics table " << idx <<    173       G4cout << "### Physics table " << idx << " for "  
204        << part->GetParticleName()                 174        << part->GetParticleName()
205        << " is retrieved from <" << fname << "    175        << " is retrieved from <" << fname << ">"
206        << G4endl;                                 176        << G4endl;
207     }                                             177     }
208   } else if (1 < param->Verbose()) {              178   } else if (1 < param->Verbose()) {
209     G4cout << "### Fail to retrieve physics ta    179     G4cout << "### Fail to retrieve physics table " << idx << " for " 
210      << part->GetParticleName() << " from <"      180      << part->GetParticleName() << " from <"
211      << fname << ">" << G4endl;                   181      << fname << ">" << G4endl;
212   }                                               182   }
213   return yes;                                     183   return yes;
214 }                                                 184 }
215                                                   185 
216 //....oooOO0OOooo........oooOO0OOooo........oo    186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
217                                                   187 
218 void G4EmDataHandler::SetMasterProcess(const G    188 void G4EmDataHandler::SetMasterProcess(const G4VEmProcess* ptr)
219 {                                                 189 {
220   masterProcess.push_back(ptr);                   190   masterProcess.push_back(ptr);
221 }                                                 191 }
222                                                   192 
223 //....oooOO0OOooo........oooOO0OOooo........oo    193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
224                                                   194 
225 const G4VEmProcess* G4EmDataHandler::GetMaster << 195 const G4VEmProcess* G4EmDataHandler::GetMasterProcess(size_t idx) const
226 {                                                 196 {
227   return (idx < masterProcess.size()) ? master    197   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 }                                                 198 }
245                                                   199 
246 //....oooOO0OOooo........oooOO0OOooo........oo    200 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
247                                                   201