68 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
87 G4String fullFileName(FullFileName(argFileName));
88 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
93 message+=fullFileName;
94 message+=
"\" not found";
100 std::vector<G4DataVector *> columns;
101 std::vector<G4DataVector *> log_columns;
103 std::stringstream *stream(
new std::stringstream);
124 while (!stream->eof())
128 while (i>=columns.size())
134 columns[i]->push_back(value);
148 if (value <=0.) value = 1e-300;
149 log_columns[i]->push_back(std::log10(value));
155 stream=
new std::stringstream;
173 if (comment) {
break; }
174 if (space && (!first)) { (*stream) <<
' '; }
182 catch(
const std::ios::failure &e)
195 message+=fullFileName;
196 message+=
"\" should have at least two columns";
205 std::size_t maxJ(columns[i]->size());
207 if (maxJ!=columns[0]->size())
210 message+=fullFileName;
211 message+=
"\" has lines with a different number of columns";
226 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
227 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
228 argLogEnergies->push_back(log_columns[0]->
operator[] (j) + std::log10(GetUnitEnergies()));
229 argLogData->push_back(log_columns[i]->
operator[] (j) + std::log10(GetUnitData()));
233 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
243 delete log_columns[i];
255 G4String fullFileName(FullFileName(argFileName));
256 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
261 message+=fullFileName;
262 message+=
"\" not found";
263 G4Exception(
"G4CrossSectionDataSet::LoadNonLogData",
268 std::vector<G4DataVector *> columns;
270 std::stringstream *stream(
new std::stringstream);
291 while (!stream->eof())
295 while (i>=columns.size())
300 columns[i]->push_back(value);
306 stream=
new std::stringstream;
324 if (comment) {
break; }
325 if (space && (!first)) { (*stream) <<
' '; }
333 catch(
const std::ios::failure &e)
346 message+=fullFileName;
347 message+=
"\" should have at least two columns";
348 G4Exception(
"G4CrossSectionDataSet::LoadNonLogData",
356 std::size_t maxJ(columns[i]->size());
358 if (maxJ!=columns[0]->size())
361 message+=fullFileName;
362 message+=
"\" has lines with a different number of columns";
363 G4Exception(
"G4CrossSectionDataSet::LoadNonLogData",
375 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
376 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
380 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
408 G4String fullFileName(FullFileName(argFileName));
409 std::ofstream out(fullFileName);
414 message+=fullFileName;
423 G4DataVector::const_iterator * iData(
new G4DataVector::const_iterator[n]);
433 while (iEnergies!=iEnergiesEnd)
437 out.setf(std::ofstream::left);
438 out << ((*iEnergies)/GetUnitEnergies());
447 out.setf(std::ofstream::left);
448 out << ((*(iData[k]))/GetUnitData());
466G4String G4CrossSectionDataSet::FullFileName(
const G4String& argFileName)
const
476 std::ostringstream fullFileName;
478 fullFileName << path <<
"/" << argFileName <<
".dat";
480 return G4String(fullFileName.str().c_str());
490 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
491 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
495 value+=(*i)->FindValue(argEnergy);
508 G4cout <<
"The data set has " << n <<
" components" <<
G4endl;
525 G4int argComponentId)
535 std::ostringstream message;
536 message <<
"component " << argComponentId <<
" not found";
538 G4Exception(
"G4CrossSectionDataSet::SetEnergiesData",
548 G4int argComponentId)
558 std::ostringstream message;
559 message <<
"component " << argComponentId <<
" not found";
561 G4Exception(
"G4CrossSectionDataSet::SetLogEnergiesData",
567void G4CrossSectionDataSet::CleanUpComponents()
569 while (!components.empty())
571 if (components.back())
delete components.back();
572 components.pop_back();
const char * G4FindDataDir(const char *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cout
virtual G4bool LoadData(const G4String &argFileName)
virtual G4bool LoadNonLogData(const G4String &argFileName)
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *values, G4int componentId)
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
G4CrossSectionDataSet(G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
virtual G4bool SaveData(const G4String &argFileName) const
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
virtual ~G4CrossSectionDataSet()
virtual const G4DataVector & GetEnergies(G4int componentId) const
virtual G4double FindValue(G4double e, G4int componentId=0) const
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual void PrintData(void) const
virtual size_t NumberOfComponents(void) const
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
virtual void PrintData(void) const =0