From 210dc29093b0059e19a2460bd9fd402ce7b82f0b Mon Sep 17 00:00:00 2001
From: matta adrien <matta@m23server2>
Date: Mon, 5 Dec 2016 13:02:45 +0100
Subject: [PATCH] * npsimulation now exit with error if the provided macro does
 not work:         - However does not check that the provided file make sense
 for           G4.

---
 NPLib/Core/NPOptionManager.cxx | 25 +++++++++++++++++++++++++
 NPLib/Core/NPOptionManager.h   |  1 +
 2 files changed, 26 insertions(+)

diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx
index 55f186538..8ec2720fc 100644
--- a/NPLib/Core/NPOptionManager.cxx
+++ b/NPLib/Core/NPOptionManager.cxx
@@ -200,6 +200,7 @@ NPOptionManager::NPOptionManager(string arg){
 void NPOptionManager::CheckArguments(){
   CheckEventGenerator();
   CheckDetectorConfiguration();
+  CheckG4Macro();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -263,6 +264,21 @@ void NPOptionManager::CheckDetectorConfiguration(){
 
 }
 
+////////////////////////////////////////////////////////////////////////////////
+void NPOptionManager::CheckG4Macro(){
+  if(IsDefault("G4MacroPath"))
+    return ;
+
+  // ifstream to configfile
+  ifstream MacroFile( fG4MacroPath );
+
+  if (!MacroFile.is_open()) {
+    SendErrorAndExit("G4MacroPath");
+  }
+  
+}
+
+
 
 ////////////////////////////////////////////////////////////////////////////////
 // This method tests if the input files are the default ones
@@ -324,6 +340,15 @@ void NPOptionManager::SendErrorAndExit(const char* type) const{
   }
   else if (stype == "RunToTreat") {
   }
+  else if (stype == "G4MacroPath") {
+    cout << endl;
+    cout << "***********************************       Error       ***********************************" << endl;
+    cout << "*                  No Geant4 macro file found in the provided path                      *" << endl;
+    cout << "*****************************************************************************************" << endl;
+    cout << endl;
+    exit(1);
+  }
+
   else {
     cout << "NPOptionManager::SendErrorAndExit() unkwown keyword" << endl;
   }
diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h
index b6b6308dd..dc9941ceb 100644
--- a/NPLib/Core/NPOptionManager.h
+++ b/NPLib/Core/NPOptionManager.h
@@ -71,6 +71,7 @@ class NPOptionManager{
       void CheckArguments();
       void CheckEventGenerator();
       void CheckDetectorConfiguration();
+      void CheckG4Macro();
 
    public:
       bool IsDefault(const char* type) const;
-- 
GitLab