From f7d23a53abbf8007c55000bf994470846c4cf828 Mon Sep 17 00:00:00 2001 From: "Ryan@MBA2024" Date: Thu, 4 Jul 2024 18:37:46 -0400 Subject: [PATCH] update code for Mac --- .gitignore | 3 ++- Cleopatra/Cleopatra.C | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 0c0b309..d0ebed1 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ Cleopatra/SimTransfer Cleopatra/SimTransfer_single Cleopatra/Cleopatra -__pycache__ \ No newline at end of file +__pycache__ +*.DS_Store \ No newline at end of file diff --git a/Cleopatra/Cleopatra.C b/Cleopatra/Cleopatra.C index f20b83b..9c9a646 100644 --- a/Cleopatra/Cleopatra.C +++ b/Cleopatra/Cleopatra.C @@ -27,13 +27,14 @@ * ********************************************************************/ #include -#include /* atof */ #include #include #include #include #include #include +#include +#include #include #include #include @@ -42,8 +43,6 @@ #include #include "PlotTGraphTObjArray.h" -using namespace std; - int main (int argc, char *argv[]) { //TODO add angle range printf("=================================================================\n"); @@ -60,7 +59,7 @@ int main (int argc, char *argv[]) { //TODO add angle range } //================= read infile. extract the reactions, write pptolemy infile for each reaction - string readFile = argv[1]; + std::string readFile = argv[1]; double angMin = 0.; double angMax = 180.; double angStep = 1.; @@ -72,19 +71,25 @@ int main (int argc, char *argv[]) { //TODO add angle range angStep = atof(argv[4]); } - string ptolemyInFileName = argv[1]; + std::string ptolemyInFileName = argv[1]; ptolemyInFileName += ".in"; printf("=================== Create InFile\n"); InFileCreator( readFile, ptolemyInFileName, angMin, angMax, angStep); //================= run ptolemy - char command[200]; - string ptolemyOutFileName = argv[1]; - ptolemyOutFileName += ".out"; - sprintf(command, "../Cleopatra/ptolemy <%s> %s", ptolemyInFileName.c_str(), ptolemyOutFileName.c_str()); + std::string ptolemyOutFileName = ptolemyInFileName + ".out"; + std::ostringstream commandStream; + commandStream << "../Cleopatra/ptolemy <" << ptolemyInFileName << " " << ptolemyOutFileName; + std::string command = commandStream.str(); + printf("=================== Run Ptolemy\n"); - printf("%s \n", command); - system(command); + printf("%s \n", command.c_str()); + + int result = std::system(command.c_str()); + if (result == -1) { + std::cerr << "Error executing system command." << std::endl; + return 1; + } //================= extract the Xsec and save as txt and root printf("=================== Extract Cross-section\n"); @@ -92,7 +97,7 @@ int main (int argc, char *argv[]) { //TODO add angle range //================= Call root to plot the d.s.c. printf("=================== Plot Result using ROOT.\n"); - string rootFileName = argv[1]; + std::string rootFileName = argv[1]; rootFileName += ".root"; TApplication app ("app", &argc, argv); PlotTGraphTObjArray(rootFileName);