Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/dna/utils/src/G4DNACrossSectionDataSet.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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/dna/utils/src/G4DNACrossSectionDataSet.cc (Version 11.3.0) and /processes/electromagnetic/dna/utils/src/G4DNACrossSectionDataSet.cc (Version 9.5)


  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 // $Id: G4DNACrossSectionDataSet.cc,v 1.11 2009-11-12 10:05:30 sincerti Exp $
                                                   >>  29 // GEANT4 tag $Name: not supported by cvs2svn $
 28 //                                                 30 //
 29 // Author: Riccardo Capra <capra@ge.infn.it>       31 // Author: Riccardo Capra <capra@ge.infn.it>
 30 // Code review by MGP October 2007: removed in     32 // Code review by MGP October 2007: removed inheritance from concrete class
 31 //                                  more impro     33 //                                  more improvements needed
 32 //                                                 34 //
 33 // History:                                        35 // History:
 34 // -----------                                     36 // -----------
 35 // 30 Jun 2005  RC           Created               37 // 30 Jun 2005  RC           Created
 36 // 14 Oct 2007  MGP          Removed inheritan     38 // 14 Oct 2007  MGP          Removed inheritance from concrete class G4ShellEMDataSet
 37 //                                                 39 //
 38 // 15 Jul 2009   N.A.Karakatsanis                  40 // 15 Jul 2009   N.A.Karakatsanis
 39 //                                                 41 //
 40 //                           - LoadNonLogData      42 //                           - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
 41 //                             dataset. It is      43 //                             dataset. It is essentially performing the data loading operations as in the past.
 42 //                                                 44 //
 43 //                           - LoadData method     45 //                           - LoadData method was revised in order to calculate the logarithmic values of the data
 44 //                             It retrieves th     46 //                             It retrieves the data values from the G4EMLOW data files but, then, calculates the
 45 //                             respective log      47 //                             respective log values and loads them to seperate data structures. 
 46 //                                                 48 //
 47 //                           - SetLogEnergiesD     49 //                           - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
 48 //                             The EM data set     50 //                             The EM data sets, initialized this way, contain both non-log and log values.
 49 //                             These initializ     51 //                             These initialized data sets can enhance the computing performance of data interpolation
 50 //                             operations          52 //                             operations
 51 //                                                 53 //
 52 //                                                 54 //
 53 // -------------------------------------------     55 // -------------------------------------------------------------------
 54                                                    56 
 55                                                    57 
 56 #include "G4DNACrossSectionDataSet.hh"             58 #include "G4DNACrossSectionDataSet.hh"
 57 #include "G4VDataSetAlgorithm.hh"                  59 #include "G4VDataSetAlgorithm.hh"
 58 #include "G4EMDataSet.hh"                          60 #include "G4EMDataSet.hh"
 59 #include <vector>                                  61 #include <vector>
 60 #include <fstream>                                 62 #include <fstream>
 61 #include <sstream>                                 63 #include <sstream>
 62                                                    64 
 63                                                    65 
 64 G4DNACrossSectionDataSet::G4DNACrossSectionDat     66 G4DNACrossSectionDataSet::G4DNACrossSectionDataSet(G4VDataSetAlgorithm* argAlgorithm, 
 65                G4double argUnitEnergies,           67                G4double argUnitEnergies, 
 66                G4double argUnitData)               68                G4double argUnitData)
 67   :                                                69   :
 68    algorithm(argAlgorithm), unitEnergies(argUn     70    algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
 69 {                                                  71 {
 70   z = 0;                                           72   z = 0;
 71                                                    73 
 72 }                                                  74 }
 73                                                    75 
 74                                                    76 
 75 G4DNACrossSectionDataSet::~G4DNACrossSectionDa     77 G4DNACrossSectionDataSet::~G4DNACrossSectionDataSet()
 76 {                                                  78 {
 77   CleanUpComponents();                             79   CleanUpComponents();
 78                                                    80  
 79                                                <<  81   if (algorithm)
 80     delete algorithm;                              82     delete algorithm;
 81 }                                                  83 }
 82                                                    84 
 83 G4bool G4DNACrossSectionDataSet::LoadData(cons     85 G4bool G4DNACrossSectionDataSet::LoadData(const G4String & argFileName)
 84 {                                                  86 {
 85   CleanUpComponents();                             87   CleanUpComponents();
 86                                                    88 
 87   G4String fullFileName(FullFileName(argFileNa     89   G4String fullFileName(FullFileName(argFileName));
 88   std::ifstream in(fullFileName, std::ifstream     90   std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
 89                                                    91 
 90   if (!in.is_open())                               92   if (!in.is_open())
 91     {                                              93     {
 92       G4String message("Data file \"");            94       G4String message("Data file \"");
 93       message+=fullFileName;                       95       message+=fullFileName;
 94       message+="\" not found";                     96       message+="\" not found";
 95       G4Exception("G4DNACrossSectionDataSet::L     97       G4Exception("G4DNACrossSectionDataSet::LoadData","em0003",
 96                       FatalException,message);     98                       FatalException,message);
 97       return false;                                99       return false;
 98     }                                             100     }
 99                                                   101 
100   std::vector<G4DataVector *> columns;            102   std::vector<G4DataVector *> columns;
101   std::vector<G4DataVector *> log_columns;        103   std::vector<G4DataVector *> log_columns;
102                                                   104 
103   auto stream(new std::stringstream);          << 105   std::stringstream *stream(new std::stringstream);
104   char c;                                         106   char c;
105   G4bool comment(false);                          107   G4bool comment(false);
106   G4bool space(true);                             108   G4bool space(true);
107   G4bool first(true);                             109   G4bool first(true);
108                                                   110 
109   try                                             111   try
110     {                                             112     {
111       while (!in.eof())                           113       while (!in.eof())
112   {                                               114   {
113     in.get(c);                                    115     in.get(c);
114                                                   116    
115     switch (c)                                    117     switch (c)
116       {                                           118       {
117       case '\r':                                  119       case '\r':
118       case '\n':                                  120       case '\n':
119         if (!first)                               121         if (!first)
120     {                                             122     {
121       unsigned long i(0);                         123       unsigned long i(0);
122       G4double value;                             124       G4double value;
123                                                   125       
124       while (!stream->eof())                      126       while (!stream->eof())
125         {                                         127         {
126           (*stream) >> value;                     128           (*stream) >> value;
127                                                   129        
128           while (i>=columns.size())               130           while (i>=columns.size())
129                         {                         131                         {
130        columns.push_back(new G4DataVector);       132        columns.push_back(new G4DataVector);
131                          log_columns.push_back    133                          log_columns.push_back(new G4DataVector);
132                         }                         134                         }
133                                                   135       
134           columns[i]->push_back(value);           136           columns[i]->push_back(value);
135                                                   137 
136 // N. A. Karakatsanis                             138 // N. A. Karakatsanis
137 // A condition is applied to check if negative    139 // A condition is applied to check if negative or zero values are present in the dataset.
138 // If yes, then a near-zero value is applied t    140 // If yes, then a near-zero value is applied to allow the computation of the logarithmic value
139 // If a value is zero, this simplification is     141 // If a value is zero, this simplification is acceptable
140 // If a value is negative, then it is not acce    142 // If a value is negative, then it is not acceptable and the data of the particular column of
141 // logarithmic values should not be used by in    143 // logarithmic values should not be used by interpolation methods.
142 //                                                144 //
143 // Therefore, G4LogLogInterpolation and G4LinL    145 // Therefore, G4LogLogInterpolation and G4LinLogLogInterpolation should not be used if negative values are present.
144 // Instead, G4LinInterpolation is safe in ever    146 // Instead, G4LinInterpolation is safe in every case
145 // SemiLogInterpolation is safe only if the en    147 // SemiLogInterpolation is safe only if the energy columns are non-negative
146 // G4LinLogInterpolation is safe only if the c    148 // G4LinLogInterpolation is safe only if the cross section data columns are non-negative
147                                                   149 
148                       if (value <=0.) value =     150                       if (value <=0.) value = 1e-300;
149                       log_columns[i]->push_bac    151                       log_columns[i]->push_back(std::log10(value));
150                                                   152        
151           i++;                                    153           i++;
152         }                                         154         }
153                                                   155       
154       delete stream;                              156       delete stream;
155       stream=new std::stringstream;               157       stream=new std::stringstream;
156     }                                             158     }
157                                                   159      
158         first=true;                               160         first=true;
159         comment=false;                            161         comment=false;
160         space=true;                               162         space=true;
161         break;                                    163         break;
162                                                << 164      
163       case '#':                                   165       case '#':
164         comment=true;                             166         comment=true;
165         break;                                    167         break;
166                                                   168      
167       case '\t':                                  169       case '\t':
                                                   >> 170         c=' ';
168       case ' ':                                   171       case ' ':
169         space = true;                          << 172         if (space)
170               break;                           << 173     break;
171                                                << 
172       default:                                    174       default:
173         if (comment) { break; }                << 175         if (comment)
174         if (space && (!first)) { (*stream) <<  << 176     break;
175                                                << 177      
176         first=false;                           << 178         if (c==' ')
177         (*stream) << c;                        << 179     space=true;
178         space=false;                           << 180         else
                                                   >> 181     {
                                                   >> 182       if (space && (!first))
                                                   >> 183         (*stream) << ' ';
                                                   >> 184       
                                                   >> 185       first=false;
                                                   >> 186       (*stream) << c;
                                                   >> 187       space=false;
                                                   >> 188     }
179       }                                           189       }
180   }                                               190   }
181     }                                             191     }
182   catch(const std::ios::failure &e)               192   catch(const std::ios::failure &e)
183     {                                             193     {
184       // some implementations of STL could thr    194       // some implementations of STL could throw a "failture" exception
185       // when read wants read characters after    195       // when read wants read characters after end of file
186     }                                             196     }
187                                                   197  
188   delete stream;                                  198   delete stream;
189                                                   199  
190   std::size_t maxI(columns.size());            << 200   std::vector<G4DataVector *>::size_type maxI(columns.size());
191                                                   201  
192   if (maxI<2)                                     202   if (maxI<2)
193     {                                             203     {
194       G4String message("Data file \"");           204       G4String message("Data file \"");
195       message+=fullFileName;                      205       message+=fullFileName;
196       message+="\" should have at least two co    206       message+="\" should have at least two columns";
197       G4Exception("G4DNACrossSectionDataSet::L    207       G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
198                       FatalException,message);    208                       FatalException,message);
199       return false;                               209       return false;
200     }                                             210     }
201                                                   211  
202   std::size_t i(1);                            << 212   std::vector<G4DataVector*>::size_type i(1);
203   while (i<maxI)                                  213   while (i<maxI)
204     {                                             214     {
205       std::size_t maxJ(columns[i]->size());    << 215       G4DataVector::size_type maxJ(columns[i]->size());
206                                                   216 
207       if (maxJ!=columns[0]->size())               217       if (maxJ!=columns[0]->size())
208   {                                               218   {
209     G4String message("Data file \"");             219     G4String message("Data file \"");
210     message+=fullFileName;                        220     message+=fullFileName;
211     message+="\" has lines with a different nu    221     message+="\" has lines with a different number of columns";
212     G4Exception("G4DNACrossSectionDataSet::Loa    222     G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
213                       FatalException,message);    223                       FatalException,message);
214     return false;                                 224     return false;
215   }                                               225   }
216                                                   226 
217       std::size_t j(0);                        << 227       G4DataVector::size_type j(0);
218                                                   228 
219       auto argEnergies=new G4DataVector;       << 229       G4DataVector *argEnergies=new G4DataVector;
220       auto argData=new G4DataVector;           << 230       G4DataVector *argData=new G4DataVector;
221       auto argLogEnergies=new G4DataVector;    << 231       G4DataVector *argLogEnergies=new G4DataVector;
222       auto argLogData=new G4DataVector;        << 232       G4DataVector *argLogData=new G4DataVector;
223                                                   233 
224       while(j<maxJ)                               234       while(j<maxJ)
225   {                                               235   {
226     argEnergies->push_back(columns[0]->operato    236     argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
227     argData->push_back(columns[i]->operator[]     237     argData->push_back(columns[i]->operator[] (j)*GetUnitData());
228     argLogEnergies->push_back(log_columns[0]->    238     argLogEnergies->push_back(log_columns[0]->operator[] (j) + std::log10(GetUnitEnergies()));
229     argLogData->push_back(log_columns[i]->oper    239     argLogData->push_back(log_columns[i]->operator[] (j) + std::log10(GetUnitData()));
230     j++;                                          240     j++;
231   }                                               241   }
232                                                   242 
233       AddComponent(new G4EMDataSet(G4int(i-1), << 243       AddComponent(new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
234                                                   244   
235       i++;                                        245       i++;
236     }                                             246     }
237                                                   247 
238   i=maxI;                                         248   i=maxI;
239   while (i>0)                                     249   while (i>0)
240     {                                             250     {
241       i--;                                        251       i--;
242       delete columns[i];                          252       delete columns[i];
243       delete log_columns[i];                      253       delete log_columns[i];
244     }                                             254     }
245                                                   255 
246   return true;                                    256   return true;
247 }                                                 257 }
248                                                   258 
249                                                   259 
250 G4bool G4DNACrossSectionDataSet::LoadNonLogDat    260 G4bool G4DNACrossSectionDataSet::LoadNonLogData(const G4String & argFileName)
251 {                                                 261 {
252   CleanUpComponents();                            262   CleanUpComponents();
253                                                   263 
254   G4String fullFileName(FullFileName(argFileNa    264   G4String fullFileName(FullFileName(argFileName));
255   std::ifstream in(fullFileName, std::ifstream    265   std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
256                                                   266 
257   if (!in.is_open())                              267   if (!in.is_open())
258     {                                             268     {
259       G4String message("Data file \"");           269       G4String message("Data file \"");
260       message+=fullFileName;                      270       message+=fullFileName;
261       message+="\" not found";                    271       message+="\" not found";
262       G4Exception("G4DNACrossSectionDataSet::L    272       G4Exception("G4DNACrossSectionDataSet::LoadData","em0003",
263                       FatalException,message);    273                       FatalException,message);
264       return false;                               274       return false;
265     }                                             275     }
266                                                   276 
267   std::vector<G4DataVector *> columns;            277   std::vector<G4DataVector *> columns;
268                                                   278 
269   auto stream(new std::stringstream);          << 279   std::stringstream *stream(new std::stringstream);
270   char c;                                         280   char c;
271   G4bool comment(false);                          281   G4bool comment(false);
272   G4bool space(true);                             282   G4bool space(true);
273   G4bool first(true);                             283   G4bool first(true);
274                                                   284 
275   try                                             285   try
276     {                                             286     {
277       while (!in.eof())                           287       while (!in.eof())
278   {                                               288   {
279     in.get(c);                                    289     in.get(c);
280                                                   290    
281     switch (c)                                    291     switch (c)
282       {                                           292       {
283       case '\r':                                  293       case '\r':
284       case '\n':                                  294       case '\n':
285         if (!first)                               295         if (!first)
286     {                                             296     {
287       unsigned long i(0);                         297       unsigned long i(0);
288       G4double value;                             298       G4double value;
289                                                   299       
290       while (!stream->eof())                      300       while (!stream->eof())
291         {                                         301         {
292           (*stream) >> value;                     302           (*stream) >> value;
293                                                   303        
294           while (i>=columns.size())               304           while (i>=columns.size())
295                         {                         305                         {
296        columns.push_back(new G4DataVector);       306        columns.push_back(new G4DataVector);
297                         }                         307                         }
298                                                   308       
299           columns[i]->push_back(value);           309           columns[i]->push_back(value);
300                                                   310        
301           i++;                                    311           i++;
302         }                                         312         }
303                                                   313       
304       delete stream;                              314       delete stream;
305       stream=new std::stringstream;               315       stream=new std::stringstream;
306     }                                             316     }
307                                                   317      
308         first=true;                               318         first=true;
309         comment=false;                            319         comment=false;
310         space=true;                               320         space=true;
311         break;                                    321         break;
312                                                << 322      
313       case '#':                                   323       case '#':
314         comment=true;                             324         comment=true;
315         break;                                    325         break;
316                                                   326      
317       case '\t':                                  327       case '\t':
                                                   >> 328         c=' ';
318       case ' ':                                   329       case ' ':
319         space = true;                          << 330         if (space)
320               break;                           << 331     break;
321                                                << 
322       default:                                    332       default:
323         if (comment) { break; }                << 333         if (comment)
324         if (space && (!first)) { (*stream) <<  << 334     break;
325                                                << 335      
326         first=false;                           << 336         if (c==' ')
327         (*stream) << c;                        << 337     space=true;
328         space=false;                           << 338         else
                                                   >> 339     {
                                                   >> 340       if (space && (!first))
                                                   >> 341         (*stream) << ' ';
                                                   >> 342       
                                                   >> 343       first=false;
                                                   >> 344       (*stream) << c;
                                                   >> 345       space=false;
                                                   >> 346     }
329       }                                           347       }
330   }                                               348   }
331     }                                             349     }
332   catch(const std::ios::failure &e)               350   catch(const std::ios::failure &e)
333     {                                             351     {
334       // some implementations of STL could thr    352       // some implementations of STL could throw a "failture" exception
335       // when read wants read characters after    353       // when read wants read characters after end of file
336     }                                             354     }
337                                                   355  
338   delete stream;                                  356   delete stream;
339                                                   357  
340   std::size_t maxI(columns.size());            << 358   std::vector<G4DataVector *>::size_type maxI(columns.size());
341                                                   359  
342   if (maxI<2)                                     360   if (maxI<2)
343     {                                             361     {
344       G4String message("Data file \"");           362       G4String message("Data file \"");
345       message+=fullFileName;                      363       message+=fullFileName;
346       message+="\" should have at least two co    364       message+="\" should have at least two columns";
347       G4Exception("G4DNACrossSectionDataSet::L    365       G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
348                       FatalException,message);    366                       FatalException,message);
349       return false;                               367       return false;
350     }                                             368     }
351                                                   369  
352   std::size_t i(1);                            << 370   std::vector<G4DataVector*>::size_type i(1);
353   while (i<maxI)                                  371   while (i<maxI)
354     {                                             372     {
355       std::size_t maxJ(columns[i]->size());    << 373       G4DataVector::size_type maxJ(columns[i]->size());
356                                                   374 
357       if (maxJ!=columns[0]->size())               375       if (maxJ!=columns[0]->size())
358   {                                               376   {
359     G4String message("Data file \"");             377     G4String message("Data file \"");
360     message+=fullFileName;                        378     message+=fullFileName;
361     message+="\" has lines with a different nu    379     message+="\" has lines with a different number of columns.";
362           G4Exception("G4DNACrossSectionDataSe    380           G4Exception("G4DNACrossSectionDataSet::LoadData","em0005",
363                       FatalException,message);    381                       FatalException,message);
364     return false;                                 382     return false;
365   }                                               383   }
366                                                   384 
367       std::size_t j(0);                        << 385       G4DataVector::size_type j(0);
368                                                   386 
369       auto argEnergies=new G4DataVector;       << 387       G4DataVector *argEnergies=new G4DataVector;
370       auto argData=new G4DataVector;           << 388       G4DataVector *argData=new G4DataVector;
371                                                   389 
372       while(j<maxJ)                               390       while(j<maxJ)
373   {                                               391   {
374     argEnergies->push_back(columns[0]->operato    392     argEnergies->push_back(columns[0]->operator[] (j)*GetUnitEnergies());
375     argData->push_back(columns[i]->operator[]     393     argData->push_back(columns[i]->operator[] (j)*GetUnitData());
376     j++;                                          394     j++;
377   }                                               395   }
378                                                   396 
379       AddComponent(new G4EMDataSet(G4int(i-1), << 397       AddComponent(new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
380                                                   398   
381       i++;                                        399       i++;
382     }                                             400     }
383                                                   401 
384   i=maxI;                                         402   i=maxI;
385   while (i>0)                                     403   while (i>0)
386     {                                             404     {
387       i--;                                        405       i--;
388       delete columns[i];                          406       delete columns[i];
389     }                                             407     }
390                                                   408 
391   return true;                                    409   return true;
392 }                                                 410 }
393                                                   411 
394                                                   412 
395 G4bool G4DNACrossSectionDataSet::SaveData(cons    413 G4bool G4DNACrossSectionDataSet::SaveData(const G4String & argFileName) const
396 {                                                 414 {
397   const std::size_t n(NumberOfComponents());   << 415   const size_t n(NumberOfComponents());
398                                                   416  
399   if (n==0)                                       417   if (n==0)
400     {                                             418     {
401       G4Exception("G4DNACrossSectionDataSet::S    419       G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
402                       FatalException,"Expected    420                       FatalException,"Expected at least one component");
403                                                   421 
404       return false;                               422       return false;
405     }                                             423     }
406                                                   424  
407   G4String fullFileName(FullFileName(argFileNa    425   G4String fullFileName(FullFileName(argFileName));
408   std::ofstream out(fullFileName);                426   std::ofstream out(fullFileName);
409                                                   427 
410   if (!out.is_open())                             428   if (!out.is_open())
411     {                                             429     {
412       G4String message("Cannot open \"");         430       G4String message("Cannot open \"");
413       message+=fullFileName;                      431       message+=fullFileName;
414       message+="\"";                              432       message+="\"";
415       G4Exception("G4DNACrossSectionDataSet::S    433       G4Exception("G4DNACrossSectionDataSet::SaveData","em0005",
416                       FatalException,message);    434                       FatalException,message);
417       return false;                               435       return false;
418     }                                             436     }
419                                                   437  
420   auto iEnergies(GetComponent(0)->GetEnergies( << 438   G4DataVector::const_iterator iEnergies(GetComponent(0)->GetEnergies(0).begin());
421   auto iEnergiesEnd(GetComponent(0)->GetEnergi << 439   G4DataVector::const_iterator iEnergiesEnd(GetComponent(0)->GetEnergies(0).end());
422   auto  iData(new G4DataVector::const_iterator << 440   G4DataVector::const_iterator * iData(new G4DataVector::const_iterator[n]);
423                                                   441  
424   std::size_t k(n);                            << 442   size_t k(n);
425                                                   443  
426   while (k>0)                                     444   while (k>0)
427     {                                             445     {
428       k--;                                        446       k--;
429       iData[k]=GetComponent((G4int)k)->GetData << 447       iData[k]=GetComponent(k)->GetData(0).begin();
430     }                                             448     }
431                                                   449  
432   while (iEnergies!=iEnergiesEnd)                 450   while (iEnergies!=iEnergiesEnd)
433     {                                             451     {
434       out.precision(10);                          452       out.precision(10);
435       out.width(15);                              453       out.width(15);
436       out.setf(std::ofstream::left);              454       out.setf(std::ofstream::left);
437       out << ((*iEnergies)/GetUnitEnergies());    455       out << ((*iEnergies)/GetUnitEnergies());
438                                                   456   
439       k=0;                                        457       k=0;
440                                                   458   
441       while (k<n)                                 459       while (k<n)
442   {                                               460   {
443     out << ' ';                                   461     out << ' ';
444     out.precision(10);                            462     out.precision(10);
445     out.width(15);                                463     out.width(15);
446     out.setf(std::ofstream::left);                464     out.setf(std::ofstream::left);
447     out << ((*(iData[k]))/GetUnitData());         465     out << ((*(iData[k]))/GetUnitData());
448                                                   466 
449     iData[k]++;                                   467     iData[k]++;
450     k++;                                          468     k++;
451   }                                               469   }
452                                                   470   
453       out << std::endl;                           471       out << std::endl;
454                                                   472   
455       iEnergies++;                                473       iEnergies++;
456     }                                             474     }
457                                                   475  
458   delete[] iData;                                 476   delete[] iData;
459                                                   477 
460   return true;                                    478   return true;
461 }                                                 479 }
462                                                   480 
463                                                   481 
464 G4String G4DNACrossSectionDataSet::FullFileNam    482 G4String G4DNACrossSectionDataSet::FullFileName(const G4String& argFileName) const
465 {                                                 483 {
466   const char* path = G4FindDataDir("G4LEDATA") << 484   char* path = getenv("G4LEDATA");
467   if (path == nullptr)                         << 485   if (!path)
468   {                                               486   {
469       G4Exception("G4DNACrossSectionDataSet::F    487       G4Exception("G4DNACrossSectionDataSet::FullFileName","em0006",
470                       FatalException,"G4LEDATA    488                       FatalException,"G4LEDATA environment variable not set.");
471                                                   489       
472       return "";                                  490       return "";
473   }                                               491   }
474                                                   492   
475   std::ostringstream fullFileName;                493   std::ostringstream fullFileName;
476                                                   494  
477   fullFileName << path << "/" << argFileName <    495   fullFileName << path << "/" << argFileName << ".dat";
478                                                   496                       
479   return G4String(fullFileName.str().c_str());    497   return G4String(fullFileName.str().c_str());
480 }                                                 498 }
481                                                   499 
482                                                   500 
483 G4double G4DNACrossSectionDataSet::FindValue(G    501 G4double G4DNACrossSectionDataSet::FindValue(G4double argEnergy, G4int /* argComponentId */) const
484 {                                                 502 {
485   // Returns the sum over the shells correspon    503   // Returns the sum over the shells corresponding to e
486   G4double value = 0.;                            504   G4double value = 0.;
487                                                   505 
488   auto i(components.begin());                  << 506   std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
489   auto end(components.end());                  << 507   std::vector<G4VEMDataSet *>::const_iterator end(components.end());
490                                                   508 
491   while (i!=end)                                  509   while (i!=end)
492     {                                             510     {
493       value+=(*i)->FindValue(argEnergy);          511       value+=(*i)->FindValue(argEnergy);
494       i++;                                        512       i++;
495     }                                             513     }
496                                                   514 
497   return value;                                   515   return value;
498 }                                                 516 }
499                                                   517 
500                                                   518 
501 void G4DNACrossSectionDataSet::PrintData() con << 519 void G4DNACrossSectionDataSet::PrintData(void) const
502 {                                                 520 {
503   const auto  n = (G4int)NumberOfComponents(); << 521   const size_t n(NumberOfComponents());
504                                                   522 
505   G4cout << "The data set has " << n << " comp    523   G4cout << "The data set has " << n << " components" << G4endl;
506   G4cout << G4endl;                               524   G4cout << G4endl;
507                                                   525  
508   G4int i(0);                                  << 526   size_t i(0);
509                                                   527  
510   while (i<n)                                     528   while (i<n)
511     {                                             529     {
512       G4cout << "--- Component " << i << " ---    530       G4cout << "--- Component " << i << " ---" << G4endl;
513       GetComponent(i)->PrintData();               531       GetComponent(i)->PrintData();
514       ++i;                                     << 532       i++;
515     }                                             533     }
516 }                                                 534 }
517                                                   535 
518                                                   536 
519 void G4DNACrossSectionDataSet::SetEnergiesData    537 void G4DNACrossSectionDataSet::SetEnergiesData(G4DataVector* argEnergies, 
520            G4DataVector* argData,                 538            G4DataVector* argData, 
521            G4int argComponentId)                  539            G4int argComponentId)
522 {                                                 540 {
523   G4VEMDataSet * component(components[argCompo    541   G4VEMDataSet * component(components[argComponentId]);
524                                                   542  
525   if (component != nullptr)                    << 543   if (component)
526     {                                             544     {
527       component->SetEnergiesData(argEnergies,     545       component->SetEnergiesData(argEnergies, argData, 0);
528       return;                                     546       return;
529     }                                             547     }
530                                                   548 
531   std::ostringstream message;                     549   std::ostringstream message;
532   message << "Component " << argComponentId <<    550   message << "Component " << argComponentId << " not found";
533                                                   551  
534   G4Exception("G4DNACrossSectionDataSet::SetEn    552   G4Exception("G4DNACrossSectionDataSet::SetEnergiesData","em0005",
535                  FatalException,message.str().    553                  FatalException,message.str().c_str());
536                                                   554   
537 }                                                 555 }
538                                                   556 
539                                                   557 
540 void G4DNACrossSectionDataSet::SetLogEnergiesD    558 void G4DNACrossSectionDataSet::SetLogEnergiesData(G4DataVector* argEnergies, 
541            G4DataVector* argData,                 559            G4DataVector* argData,
542                                          G4Dat    560                                          G4DataVector* argLogEnergies,
543                                          G4Dat    561                                          G4DataVector* argLogData, 
544            G4int argComponentId)                  562            G4int argComponentId)
545 {                                                 563 {
546   G4VEMDataSet * component(components[argCompo    564   G4VEMDataSet * component(components[argComponentId]);
547                                                   565  
548   if (component != nullptr)                    << 566   if (component)
549     {                                             567     {
550       component->SetLogEnergiesData(argEnergie    568       component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
551       return;                                     569       return;
552     }                                             570     }
553                                                   571 
554   std::ostringstream message;                     572   std::ostringstream message;
555   message << "Component " << argComponentId <<    573   message << "Component " << argComponentId << " not found";
556                                                   574  
557   G4Exception("G4DNACrossSectionDataSet::SetLo    575   G4Exception("G4DNACrossSectionDataSet::SetLogEnergiesData","em0005",
558                  FatalException,message.str().    576                  FatalException,message.str().c_str());
559                                                   577 
560 }                                                 578 }
561                                                   579 
562                                                   580 
563 void G4DNACrossSectionDataSet::CleanUpComponen    581 void G4DNACrossSectionDataSet::CleanUpComponents()
564 {                                                 582 {
565   while (!components.empty())                     583   while (!components.empty())
566     {                                             584     {
567       if (components.back() != nullptr) delete << 585       if (components.back()) delete components.back();
568       components.pop_back();                      586       components.pop_back();
569     }                                             587     }
570 }                                                 588 }
571                                                   589 
572                                                   590 
573                                                   591