69 algorithm(argAlgorithm), unitEnergies(argUnitEnergies), unitData(argUnitData)
88 G4String fullFileName(FullFileName(argFileName));
89 std::ifstream in(fullFileName, std::ifstream::binary|std::ifstream::in);
94 message+=fullFileName;
95 message+=
"\" not found";
101 std::vector<G4DataVector *> columns;
102 std::vector<G4DataVector *> log_columns;
104 std::stringstream *stream(
new std::stringstream);
125 while (!stream->eof())
129 while (i>=columns.size())
135 columns[i]->push_back(value);
149 if (value <=0.) value = 1e-300;
150 log_columns[i]->push_back(std::log10(value));
156 stream=
new std::stringstream;
174 if (comment) {
break; }
175 if (space && (!first)) { (*stream) <<
' '; }
183 catch(
const std::ios::failure &e)
191 std::vector<G4DataVector *>::size_type maxI(columns.size());
196 message+=fullFileName;
197 message+=
"\" should have at least two columns";
203 std::vector<G4DataVector*>::size_type i(1);
206 G4DataVector::size_type maxJ(columns[i]->size());
208 if (maxJ!=columns[0]->size())
211 message+=fullFileName;
212 message+=
"\" has lines with a different number of columns";
218 G4DataVector::size_type j(0);
227 argEnergies->push_back(columns[0]->
operator[] (j)*GetUnitEnergies());
228 argData->push_back(columns[i]->
operator[] (j)*GetUnitData());
229 argLogEnergies->push_back(log_columns[0]->
operator[] (j) + std::log10(GetUnitEnergies()));
230 argLogData->push_back(log_columns[i]->
operator[] (j) + std::log10(GetUnitData()));
234 AddComponent(
new G4EMDataSet(i-1, argEnergies, argData, argLogEnergies, argLogData, GetAlgorithm()->Clone(), GetUnitEnergies(), GetUnitData()));
244 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)
341 std::vector<G4DataVector *>::size_type maxI(columns.size());
346 message+=fullFileName;
347 message+=
"\" should have at least two columns";
348 G4Exception(
"G4CrossSectionDataSet::LoadNonLogData",
353 std::vector<G4DataVector*>::size_type i(1);
356 G4DataVector::size_type 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",
368 G4DataVector::size_type j(0);
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()));
407 G4String fullFileName(FullFileName(argFileName));
408 std::ofstream out(fullFileName);
413 message+=fullFileName;
422 G4DataVector::const_iterator * iData(
new G4DataVector::const_iterator[n]);
432 while (iEnergies!=iEnergiesEnd)
437 out << ((*iEnergies)/GetUnitEnergies());
447 out << ((*(iData[k]))/GetUnitData());
464 G4String G4CrossSectionDataSet::FullFileName(
const G4String& argFileName)
const
466 char* path = getenv(
"G4LEDATA");
474 std::ostringstream fullFileName;
476 fullFileName << path <<
"/" << argFileName <<
".dat";
478 return G4String(fullFileName.str().c_str());
487 std::vector<G4VEMDataSet *>::const_iterator i(components.begin());
488 std::vector<G4VEMDataSet *>::const_iterator end(components.end());
492 value+=(*i)->FindValue(argEnergy);
504 G4cout <<
"The data set has " << n <<
" components" <<
G4endl;
520 G4int argComponentId)
530 std::ostringstream message;
531 message <<
"component " << argComponentId <<
" not found";
533 G4Exception(
"G4CrossSectionDataSet::SetEnergiesData",
542 G4int argComponentId)
552 std::ostringstream message;
553 message <<
"component " << argComponentId <<
" not found";
555 G4Exception(
"G4CrossSectionDataSet::SetLogEnergiesData",
560 void G4CrossSectionDataSet::CleanUpComponents()
562 while (!components.empty())
564 if (components.back())
delete components.back();
565 components.pop_back();
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *data, G4int component=0)=0
virtual const G4DataVector & GetEnergies(G4int componentId) const
virtual const G4DataVector & GetData(G4int componentId) const =0
virtual G4bool SaveData(const G4String &argFileName) const
virtual ~G4CrossSectionDataSet()
virtual size_t NumberOfComponents(void) const
virtual void SetEnergiesData(G4DataVector *x, G4DataVector *values, G4int componentId)
virtual G4bool LoadNonLogData(const G4String &argFileName)
virtual void PrintData(void) const
G4CrossSectionDataSet(G4VDataSetAlgorithm *algo, G4double xUnit=CLHEP::MeV, G4double dataUnit=CLHEP::barn)
G4GLOB_DLL std::ostream G4cout
const XML_Char int const XML_Char * value
virtual G4double FindValue(G4double e, G4int componentId=0) const
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *data, G4DataVector *Log_x, G4DataVector *Log_data, G4int component=0)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual void PrintData(void) const =0
virtual const G4VEMDataSet * GetComponent(G4int componentId) const
virtual void AddComponent(G4VEMDataSet *dataSet)
virtual void SetLogEnergiesData(G4DataVector *x, G4DataVector *values, G4DataVector *log_x, G4DataVector *log_values, G4int componentId)
virtual G4bool LoadData(const G4String &argFileName)