diff --git a/source/branches/BaM_Dev/Model/XS/XSM_MLP.cxx b/source/branches/BaM_Dev/Model/XS/XSM_MLP.cxx index e5ec0fd535b0f0443ed48e00b8bc9293416f1a7f..f009774bbda7640b07176f7c8caec7fca99f9820 100644 --- a/source/branches/BaM_Dev/Model/XS/XSM_MLP.cxx +++ b/source/branches/BaM_Dev/Model/XS/XSM_MLP.cxx @@ -36,10 +36,11 @@ XSM_MLP::XSM_MLP(string TMVA_Weight_Directory,string InformationFile, bool IsTimeStep):XSModel(new CLASSLogger("XSM_MLP.log")) { - fIsStepTime=IsTimeStep; + fIsStepTime = IsTimeStep; fTMVAWeightFolder = TMVA_Weight_Directory; + if(InformationFile=="") - fInformationFile = TMVA_Weight_Directory+"/Data_Base_Info.nfo"; + fInformationFile = TMVA_Weight_Directory + "/Data_Base_Info.nfo"; else fInformationFile = fTMVAWeightFolder+InformationFile; @@ -79,127 +80,85 @@ XSM_MLP::XSM_MLP(CLASSLogger* Log,string TMVA_Weight_Directory,string Informatio //________________________________________________________________________ XSM_MLP::~XSM_MLP() { + DBGL fMapOfTMVAVariableNames.clear(); + fDKeyword.clear(); + DBGL } +void XSM_MLP::LoadKeyword() +{ + DBGL + fDKeyword.insert( pair<string, DMthPtr>( "k_timestep", & XSM_MLP::ReadTimeSteps)); + fDKeyword.insert( pair<string, DMthPtr>( "k_zainame", & XSM_MLP::ReadZAIName) ); + DBGL +} + -//________________________________________________________________________ -void XSM_MLP::ReadLine(string line) +void XSM_MLP::ReadZAIName(const string &line) { DBGL + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); + if( keyword != "k_zainame" ) // Check the keyword + { + ERROR << " Bad keyword : \"k_zainame\" not found !" << endl; + exit(1); + } + + int Z = atoi(StringLine::NextWord(line, pos, ' ').c_str()); + int A = atoi(StringLine::NextWord(line, pos, ' ').c_str()); + int I = atoi(StringLine::NextWord(line, pos, ' ').c_str()); - int start = 0; - string keyword = tlc(StringLine::NextWord(line, start, ' ')); - (this->*fKeyword[ keyword ])(line); + string name = StringLine::NextWord(line, pos, ' '); + + fMapOfTMVAVariableNames.insert( pair<ZAI,string>( ZAI(Z, A, I), name ) ); DBGL } +void XSM_MLP::ReadTimeSteps(const string &line) +{ + DBGL + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); + if( keyword != "k_timestep" ) // Check the keyword + { + ERROR << " Bad keyword : \"k_timestep\" not found !" << endl; + exit(1); + } + + while( pos < (int)line.size() ) + fMLP_Time.push_back( atof( (StringLine::NextWord(line,pos,' ')).c_str() )); + + DBGL +} //________________________________________________________________________ -void XSM_MLP::GetDataBaseInformation() +void XSM_MLP::ReadLine(string line) { - ifstream FILE(fInformationFile.c_str()); + DBGL - if(FILE.good()) - { - while(!FILE.eof()) - { - string line; - getline(FILE, line); - size_t foundRType = line.find("ReactorType :"); - size_t foundFType = line.find("FuelType :"); - size_t foundHM = line.find("Heavy Metal (t) :"); - size_t foundPower = line.find("Thermal Power (W) :"); - size_t foundTime = line.find("Time (s) :"); - size_t foundZAI = line.find("Z A I Name (input MLP) :"); - size_t foundDomain = line.find("Fuel range (Z A I min max) :"); - - int pos=0; - if(foundRType != std::string::npos) - { StringLine::NextWord(line,pos,':'); - fDBRType = atof( (StringLine::NextWord(line,pos,':')).c_str() ); - } - pos=0; - if(foundFType != std::string::npos) - { StringLine::NextWord(line,pos,':'); - fDBFType = atof( (StringLine::NextWord(line,pos,':')).c_str() ); - } - pos=0; - if(foundHM != std::string::npos) - { StringLine::NextWord(line,pos,':'); - fDBHMMass = atof( (StringLine::NextWord(line,pos,':')).c_str() ); - } - pos=0; - if(foundPower !=std::string::npos) - { StringLine::NextWord(line,pos,':'); - fDBPower = atof( (StringLine::NextWord(line,pos,':') ).c_str() ); - } - pos=0; - if(foundTime!=std::string::npos) - { - StringLine::NextWord(line,pos,':'); - while( pos< (int)line.size() ) - fMLP_Time.push_back( atof( (StringLine::NextWord(line,pos,' ')).c_str() )); - } - pos=0; - if(foundZAI != std::string::npos) - { string Z; - string A; - string I; - string Name; - int posoflinebeforbadline=0; - do - { posoflinebeforbadline = FILE.tellg(); - getline(FILE, line); - stringstream ssline; - ssline<<line; - ssline>>Z>>A>>I>>Name; - if(StringLine::IsDouble(Z) && StringLine::IsDouble(A) && StringLine::IsDouble(I) ) - { - fMapOfTMVAVariableNames.insert( pair<ZAI,string>(ZAI(atoi(Z.c_str()),atoi(A.c_str()),atoi(I.c_str())),Name) ); - } - - }while((StringLine::IsDouble(Z) && StringLine::IsDouble(A) && StringLine::IsDouble(I)) && !FILE.eof()); - - FILE.seekg(posoflinebeforbadline); //return one line before - - } - if(foundDomain != std::string::npos) - { string Z; - string A; - string I; - string min; - string max; - int posoflinebeforbadline=0; - do - { posoflinebeforbadline = FILE.tellg(); - getline(FILE, line); - stringstream ssline; - ssline<<line; - ssline>>Z>>A>>I>>min>>max; - if(StringLine::IsDouble(Z) && StringLine::IsDouble(A) && StringLine::IsDouble(I) && StringLine::IsDouble(min) && StringLine::IsDouble(max) ) - { - fZAILimits.insert( pair<ZAI,pair<double,double> >(ZAI(atoi(Z.c_str()),atoi(A.c_str()),atoi(I.c_str())),make_pair(atof(min.c_str()),atof(max.c_str()))) ); - } - - } - while((StringLine::IsDouble(Z) && StringLine::IsDouble(A) && StringLine::IsDouble(I) )&& !FILE.eof()); - FILE.seekg(posoflinebeforbadline); //return one line before - - } - - } - } - else - { - ERROR << "Can't find/open file " << fInformationFile << endl; - exit(0); - } + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); - /********DEBUG*************************************/ + map<string, DMthPtr>::iterator it = fDKeyword.find(keyword); + + if(it != fDKeyword.end()) + (this->*(it->second))( line ); + + DBGL +} + + + + + +//________________________________________________________________________ +/*void XSM_MLP::GetDataBaseInformation() +{ INFO<<"\tMLP XS Data Base Information : "<<endl; INFO<<"\t\tHeavy Metal (t) :"<<fDBHMMass<<endl; INFO<<"\t\tThermal Power (W) :"<<fDBPower<<endl; @@ -219,6 +178,8 @@ void XSM_MLP::GetDataBaseInformation() } + */ + //________________________________________________________________________ void XSM_MLP::GetMLPWeightFiles() { diff --git a/source/branches/BaM_Dev/Model/XS/XSM_MLP.hxx b/source/branches/BaM_Dev/Model/XS/XSM_MLP.hxx index 4142b3cad9ec9bc6dc705d92cd44971c796cc657..22ab951bb7b86ff3aeb1a796526e62b5ac4f92b8 100644 --- a/source/branches/BaM_Dev/Model/XS/XSM_MLP.hxx +++ b/source/branches/BaM_Dev/Model/XS/XSM_MLP.hxx @@ -8,6 +8,7 @@ \brief Header file for XSM_MLP class. + @authors BaM @authors BLG @version 1.0 */ @@ -18,6 +19,8 @@ #include <iostream> #include <map> #include <vector> + + typedef long long int cSecond; using namespace std; @@ -75,7 +78,11 @@ class XSM_MLP : public XSModel ~XSM_MLP(); //@} - void LoadKeyword() {} + void LoadKeyword(); + + void ReadTimeSteps(const string &line); + void ReadZAIName(const string &line); + EvolutionData GetCrossSections(IsotopicVector IV,double t=0); //!< Return calculated cross section by the MLP regression @@ -83,8 +90,6 @@ class XSM_MLP : public XSModel private : - void GetDataBaseInformation(); //!< Read information file and fill Reactor Type, Fuel type, HM mass, Power, time vector, and TMVA input variables names - void GetMLPWeightFiles(); //!< Find all .xml file in TMVA_Weight_Directory EvolutionData GetCrossSectionsStep(IsotopicVector IV); //!< Return calculated cross section by the MLP regression when fIsTimeStep==true EvolutionData GetCrossSectionsTime(IsotopicVector IV); //!< Return calculated cross section by the MLP regression when fIsTimeStep==false diff --git a/source/branches/BaM_Dev/include/XSModel.hxx b/source/branches/BaM_Dev/include/XSModel.hxx index 719fe067239d904c2d628624eb2a6c834c0dea6a..0c1b755d7808ca8bf1c37664258a00759ee664ef 100644 --- a/source/branches/BaM_Dev/include/XSModel.hxx +++ b/source/branches/BaM_Dev/include/XSModel.hxx @@ -9,7 +9,7 @@ @author BaM @author BLG - @version 1.0 + @version 2 */ #include "EvolutionData.hxx" #include "CLASSObject.hxx" @@ -40,7 +40,7 @@ typedef void (XSModel::*MthPtr)( const string & ) ; @author BaM @author BLG - @version 1.0 + @version 2 */ //________________________________________________________________________ diff --git a/source/branches/BaM_Dev/src/XSModel.cxx b/source/branches/BaM_Dev/src/XSModel.cxx index d83064ca38c775368571797bc1e05c2e080ba02a..24b0acea8cfc411bc0d3ee0eb32bdcab14b14efd 100644 --- a/source/branches/BaM_Dev/src/XSModel.cxx +++ b/source/branches/BaM_Dev/src/XSModel.cxx @@ -58,12 +58,15 @@ void XSModel::ReadLine(string line) if (!freaded) { - int start = 0; - string keyword = tlc(StringLine::NextWord(line, start, ' ')); + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); + + map<string, MthPtr>::iterator it = fKeyword.find(keyword); - (this->*fKeyword[ keyword ])(line); - freaded = true; + if(it != fKeyword.end()) + (this->*(it->second))( line ); + freaded = true; ReadLine(line); } @@ -88,17 +91,17 @@ void XSModel::LoadKeyword() void XSModel::ReadRParam(const string &line) { DBGL - int start = 0; - string keyword = tlc(StringLine::NextWord(line, start, ' ')); + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); if( keyword != "k_power" || keyword != "k_mass" ) // Check the keyword { ERROR << " Bad keyword : " << keyword << " Not found !" << endl; exit(1); } if( keyword == "k_mass" ) - fDBHMMass = atof(StringLine::NextWord(line, start, ' ').c_str()); + fDBHMMass = atof(StringLine::NextWord(line, pos, ' ').c_str()); else if( keyword == "k_mass" ) - fDBPower = atof(StringLine::NextWord(line, start, ' ').c_str()); + fDBPower = atof(StringLine::NextWord(line, pos, ' ').c_str()); DBGL } @@ -107,17 +110,17 @@ void XSModel::ReadRParam(const string &line) void XSModel::ReadType(const string &line) { DBGL - int start = 0; - string keyword = tlc(StringLine::NextWord(line, start, ' ')); + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); if( keyword != "k_fuel" || keyword != "k_reactor" ) // Check the keyword { ERROR << " Bad keyword : " << keyword << " Not found !" << endl; exit(1); } if( keyword == "k_fuel" ) - fDBFType = StringLine::NextWord(line, start, ' '); + fDBFType = StringLine::NextWord(line, pos, ' '); else if( keyword == "k_reactor" ) - fDBRType = StringLine::NextWord(line, start, ' '); + fDBRType = StringLine::NextWord(line, pos, ' '); DBGL } @@ -126,20 +129,20 @@ void XSModel::ReadType(const string &line) void XSModel::ReadZAIlimits(const string &line) { DBGL - int start = 0; - string keyword = tlc(StringLine::NextWord(line, start, ' ')); + int pos = 0; + string keyword = tlc(StringLine::NextWord(line, pos, ' ')); if( keyword != "k_zail" ) // Check the keyword { ERROR << " Bad keyword : \"k_zail\" not found !" << endl; exit(1); } - int Z = atoi(StringLine::NextWord(line, start, ' ').c_str()); - int A = atoi(StringLine::NextWord(line, start, ' ').c_str()); - int I = atoi(StringLine::NextWord(line, start, ' ').c_str()); + int Z = atoi(StringLine::NextWord(line, pos, ' ').c_str()); + int A = atoi(StringLine::NextWord(line, pos, ' ').c_str()); + int I = atoi(StringLine::NextWord(line, pos, ' ').c_str()); - double upLimit = atof(StringLine::NextWord(line, start, ' ').c_str()); - double downLimit = atof(StringLine::NextWord(line, start, ' ').c_str()); + double upLimit = atof(StringLine::NextWord(line, pos, ' ').c_str()); + double downLimit = atof(StringLine::NextWord(line, pos, ' ').c_str()); DBGL }