diff --git a/Armory/AnalysisLib.h b/Armory/AnalysisLib.h index b2c5a40..7944804 100644 --- a/Armory/AnalysisLib.h +++ b/Armory/AnalysisLib.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,27 @@ namespace AnalysisLib { +//*######################################### Execute Python Script +std::vector executePythonScript(std::string command) { + std::vector result; + printf("Python : %s \n", command.c_str()); + FILE* pipe = popen(command.c_str(), "r"); + if (!pipe) { + std::cerr << "Failed to open pipe for command: " << command << std::endl; + return result; + } + + constexpr int buffer_size = 256; + char buffer[buffer_size]; + + while (fgets(buffer, buffer_size, pipe) != nullptr) { + result.emplace_back(buffer); + } + + pclose(pipe); + return result; +} + //*######################################### TRAPEZOID TGraph * TrapezoidFilter(TGraph * trace, int baseLineEnd = 80, int riseTime = 10, int flatTop = 20, float decayTime = 2000){ ///Trapezoid filter https://doi.org/10.1016/0168-9002(94)91652-7 diff --git a/Armory/ClassReactionConfig.h b/Armory/ClassReactionConfig.h index caeb77e..c8e1f72 100644 --- a/Armory/ClassReactionConfig.h +++ b/Armory/ClassReactionConfig.h @@ -225,7 +225,64 @@ inline bool ReactionConfig::LoadReactionConfig(TMacro * macro){ if( recoilLine == 5 ) recoil[ID].decayA = atoi(str[0].c_str()); if( recoilLine == 6 ) recoil[ID].decayZ = atoi(str[0].c_str()); - if( recoilLine > 6 && str.size() == 4) exList[ID].Add( atoi(str[0].c_str()), atoi(str[1].c_str()), atoi(str[2].c_str()), atoi(str[3].c_str())); + if( recoilLine > 6 && str.size() == 4) { + if( str[0] == "IAEA"){ + + exList[ID].Clear(); + + recoil[ID].heavyA = beamA + targetA - recoil[ID].lightA; + recoil[ID].heavyZ = beamZ + targetZ - recoil[ID].lightZ; + printf(">>>>>>>>>>>>> Retrieving Ex data from IAEA website....\n"); + std::string scriptPath = "../WebSimHelper/getEx.py " + std::to_string(recoil[ID].heavyA) + " " + std::to_string(recoil[ID].heavyZ) + " " + str[2]; + std::vector output = AnalysisLib::executePythonScript(scriptPath); + + if( output.size() > 1 ){ + for( size_t dudu = 1 ; dudu < output.size(); dudu ++ ){ + printf("%s", output[dudu].c_str()); + std::vector dondon = AnalysisLib::SplitStr(output[dudu], " "); + + if( str[1].find("all") == std::string::npos){ // only comfirm states + if(dondon[2].find(')') != std::string::npos ) continue; + if(dondon[2].find('N') != std::string::npos ) continue; + // printf("kdlsakdas ---- %s\n", str[1].c_str()); + + if(str[1] == "+" && dondon[2].find('+') != std::string::npos ){ + // printf(" only comfim + states\n"); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + if(str[1] == "-" && dondon[2].find('-') != std::string::npos ){ + // printf(" only comfim - states\n"); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + if( str[1] == "known" ){ + // printf(" All comfim state\n"); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + + }else{ + if(str[1] == "+all" && dondon[2].find('+') != std::string::npos ){ + // printf(" All state : %s\n", str[1].c_str()); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + if(str[1] == "-all" && dondon[2].find('-') != std::string::npos ){ + // printf(" All state : %s\n", str[1].c_str()); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + if( str[1] == "all" ){ + // printf(" All state \n"); + exList[ID].Add( atoi(dondon[1].c_str()), 1.0, 1.0, atoi(str[3].c_str())); + } + + } + } + }else{ + printf(" No states found from IAEA database, assume ground state."); + exList[ID].Add( 0, 1.0, 1.0, 0.01); + } + }else{ + exList[ID].Add( atoi(str[0].c_str()), atoi(str[1].c_str()), atoi(str[2].c_str()), atoi(str[3].c_str())); + } + } } diff --git a/WebSimHelper/getEx.py b/WebSimHelper/getEx.py new file mode 100755 index 0000000..0f93744 --- /dev/null +++ b/WebSimHelper/getEx.py @@ -0,0 +1,18 @@ +#!/usr/bin/env /usr/bin/python3 + +import isotopeLib as iso + +import sys + +if len(sys.argv) < 3: + print("Usage: python getEx.py A Z Ex") + sys.exit(1) + +A = int(sys.argv[1]) +Z = int(sys.argv[2]) +Ex = float(sys.argv[3]) +ASym = iso.GetSymbol(A, Z) + +ExList = iso.GetExList(ASym, Ex) + +print(ExList) \ No newline at end of file diff --git a/WebSimHelper/isotopeLib.py b/WebSimHelper/isotopeLib.py index ed42a40..60b98cd 100755 --- a/WebSimHelper/isotopeLib.py +++ b/WebSimHelper/isotopeLib.py @@ -41,7 +41,7 @@ except FileNotFoundError: ## 'ENSDFauthors', 'Extraction_date'] -def GetExList(ASym : str, maxEx : float): +def GetExList(ASym : str, maxEx : float) ->pd.DataFrame: try: exList = lc_read_csv(livechart + "fields=levels&nuclides=" + ASym) exJpi = exList[['energy', 'jp']]