From 681e1e06b3164d8371658d996b08cbd8685edbba Mon Sep 17 00:00:00 2001
From: deserevi <deserevi@nptool>
Date: Thu, 3 Feb 2011 21:14:45 +0000
Subject: [PATCH] * New functionalities NPOptionManager class    + search for
 input files in the $NPTOOL/Inputs/* and local directories      is now
 performed in this class    + this search was done previously in
 DetectorConstruction.cc and      PrimaryGeneratorAction.cc files. these files
 have been modified      accordingly.    + If input files are not found,
 program exits

---
 Inputs/DetectorConfiguration/e530.detector |   2 +-
 NPAnalysis/must2/RunToTreat.txt            |   5 +-
 NPLib/Tools/NPOptionManager.cxx            | 211 ++++++++++++++-------
 NPLib/Tools/NPOptionManager.h              |  86 +++++----
 NPSimulation/Simulation.cc                 |   5 +-
 NPSimulation/src/DetectorConstruction.cc   |  23 +--
 NPSimulation/src/PrimaryGeneratorAction.cc |  40 ++--
 7 files changed, 213 insertions(+), 159 deletions(-)

diff --git a/Inputs/DetectorConfiguration/e530.detector b/Inputs/DetectorConfiguration/e530.detector
index 9eae88d6b..c2afc6058 100644
--- a/Inputs/DetectorConfiguration/e530.detector
+++ b/Inputs/DetectorConfiguration/e530.detector
@@ -19,7 +19,7 @@
 GeneralTarget
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
 Target
-	THICKNESS= 10.755
+	THICKNESS= 21.51
 	RADIUS=	1.25
 	MATERIAL= CD2
 	ANGLE= 0
diff --git a/NPAnalysis/must2/RunToTreat.txt b/NPAnalysis/must2/RunToTreat.txt
index 419119e55..62920d22a 100644
--- a/NPAnalysis/must2/RunToTreat.txt
+++ b/NPAnalysis/must2/RunToTreat.txt
@@ -1,5 +1,6 @@
 TTreeName 
 	SimulatedTree
 RootFileName 
-	../../Outputs/Simulation/myResult.root
-%	../../Outputs/Simulation/fe60dp_100ug_resolSiLi22.root
+%	../../Outputs/Simulation/myResult.root
+	../../Outputs/Simulation/pipo.root
+%	../../Outputs/Simulation/fe60dp_1mg.root
diff --git a/NPLib/Tools/NPOptionManager.cxx b/NPLib/Tools/NPOptionManager.cxx
index cec8c6f23..982f267c4 100644
--- a/NPLib/Tools/NPOptionManager.cxx
+++ b/NPLib/Tools/NPOptionManager.cxx
@@ -19,84 +19,157 @@
  *                                                                           *
  *                                                                           *
  *****************************************************************************/
- 
+
 #include "NPOptionManager.h"
- 
+
+#include <fstream>
 #include <cstdlib>
 
 
 NPOptionManager* NPOptionManager::instance = 0 ;
 
-NPOptionManager* NPOptionManager::getInstance(int argc,char** argv)
-  {
-    if( instance == 0 ) instance = new NPOptionManager(argc,argv);
-    
-    return instance ;
-  }
-  
-  
-//////////////////////////////////////////////////////
-NPOptionManager::NPOptionManager(int argc,char** argv)
-  {
-    // Default Setting
-    fReactionFileName    = "myReaction.reaction"  ;
-    fDetectorFileName    = "myDetector.detector"  ;
-    fOutputFileName      = "myResult"             ;
-    fRunToReadFileName   = "RunToRead.txt"        ;
-    fCalibrationFileName = "Calibration.txt"      ;
-    fDisableAllBranchOption = false; 
-  
-    for (int i = 0 ; i < argc ; i++)
-      {
-        string argument = argv[i];
-        
-        if(argument == "-H" || argument == "-h" || argument == "--help") 
-          DisplayHelp(); 
-              
-        else if(argument == "--event-generator" && argc>=i+1 )    fReactionFileName    = argv[i+1] ; 
-              
-        else if(argument == "-E" && argc>=i+1 )                  fReactionFileName    = argv[i+1] ;
-        
-        else if(argument == "--detector" && argc>=i+1 )    fDetectorFileName    = argv[i+1] ;
-        
-        else if(argument == "-D" && argc>=i+1 )    fDetectorFileName    = argv[i+1] ;
-        
-        else if(argument == "--output" && argc>=i+1 )    fOutputFileName      = argv[i+1] ;
-        
-        else if(argument == "-O" && argc>=i+1 )    fOutputFileName      = argv[i+1] ;
-        
-        else if(argument == "--run" && argc>=i+1 )  fRunToReadFileName   = argv[i+1] ;
-        
-        else if(argument == "-R" && argc>=i+1 )     fRunToReadFileName   = argv[i+1] ;
-        
-        else if(argument == "--cal" && argc>=i+1 )  fCalibrationFileName = argv[i+1] ;
-        
-        else if(argument == "-C" && argc>=i+1 )     fCalibrationFileName = argv[i+1] ;
-        
-        else if(argument == "--disable-branch" )    fDisableAllBranchOption = true ;
-        
-        else ;
+NPOptionManager* NPOptionManager::getInstance(int argc, char** argv)
+{
+   if (instance == 0) instance = new NPOptionManager(argc, argv);
+
+   return instance ;
+}
+
+
+
+NPOptionManager::NPOptionManager(int argc, char** argv)
+{
+   // Default Setting
+   fReactionFileName    = "myReaction.reaction"  ;
+   fDetectorFileName    = "myDetector.detector"  ;
+   fOutputFileName      = "myResult"             ;
+   fRunToReadFileName   = "RunToRead.txt"        ;
+   fCalibrationFileName = "Calibration.txt"      ;
+   fDisableAllBranchOption = false;
+
+   for (int i = 0; i < argc; i++) {
+      string argument = argv[i];
+
+      if (argument == "-H" || argument == "-h" || argument == "--help") DisplayHelp();
+
+      else if (argument == "--event-generator" && argc >= i + 1)    fReactionFileName    = argv[i+1] ;
+
+      else if (argument == "-E" && argc >= i + 1)                  fReactionFileName    = argv[i+1] ;
+
+      else if (argument == "--detector" && argc >= i + 1)    fDetectorFileName    = argv[i+1] ;
+
+      else if (argument == "-D" && argc >= i + 1)    fDetectorFileName    = argv[i+1] ;
+
+      else if (argument == "--output" && argc >= i + 1)    fOutputFileName      = argv[i+1] ;
+
+      else if (argument == "-O" && argc >= i + 1)    fOutputFileName      = argv[i+1] ;
+
+      else if (argument == "--run" && argc >= i + 1)  fRunToReadFileName   = argv[i+1] ;
+
+      else if (argument == "-R" && argc >= i + 1)     fRunToReadFileName   = argv[i+1] ;
+
+      else if (argument == "--cal" && argc >= i + 1)  fCalibrationFileName = argv[i+1] ;
+
+      else if (argument == "-C" && argc >= i + 1)     fCalibrationFileName = argv[i+1] ;
+
+      else if (argument == "--disable-branch")    fDisableAllBranchOption = true ;
+
+      else ;
+   }
+
+   CheckArguments();
+}
+
+
+
+void NPOptionManager::CheckArguments()
+{
+   CheckEventGenerator();
+   CheckDetectorConfiguration();
+}
+
+
+
+void NPOptionManager::CheckEventGenerator()
+{
+   // NPTool path
+   string GlobalPath = getenv("NPTOOL");
+   string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + fReactionFileName;
+
+   // ifstream to configfile
+   ifstream ConfigFile;
+
+   // test if config file is in standard path
+   ConfigFile.open(StandardPath.c_str());
+   if (ConfigFile.is_open()) {
+      fReactionFileName = StandardPath;
+   }
+   else {   // if not, assume config file is in current directory
+      ConfigFile.open(fReactionFileName.c_str());
+      if (!ConfigFile.is_open()) {  // if not, send error and exit program
+         cout << endl;
+         cout << "**********************************       Error       **********************************" << endl;
+         cout << "* No event generator file found in $NPTool/Inputs/EventGenerator or local directories *" << endl;
+         cout << "***************************************************************************************" << endl;
+         cout << endl;
+         exit(1);
+      }
+   }
+
+   // close ConfigFile
+   ConfigFile.close();
+}
+
+
+
+void NPOptionManager::CheckDetectorConfiguration()
+{
+   // NPTool path
+   string GlobalPath = getenv("NPTOOL");
+   string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + fDetectorFileName;
+
+   // ifstream to configfile
+   ifstream ConfigFile;
+
+   // test if config file is in standard path
+   ConfigFile.open(StandardPath.c_str());
+   if (ConfigFile.is_open()) {
+      fDetectorFileName = StandardPath;
+   }
+   else {   // if not, assume config file is in current directory
+      ConfigFile.open(fDetectorFileName.c_str());
+      if (!ConfigFile.is_open()) {  // if not, send error and exit program
+         cout << endl;
+         cout << "***********************************       Error       ***********************************" << endl;
+         cout << "* No detector geometry file found in $NPTool/Inputs/EventGenerator or local directories *" << endl;
+         cout << "*****************************************************************************************" << endl;
+         cout << endl;
+         exit(1);
       }
-  
-  }
+   }
+
+   // close ConfigFile
+   ConfigFile.close();
+}
+
+
 
-///////////////////////////////////////////////////  
 void NPOptionManager::DisplayHelp()
-  {
-    cout << "----NPOptionManager Help----" << endl ;
-    cout << "List of Option " << endl ;
-    cout << "\t --detector -D <arg>\t \t \t \t \t \t Set arg as the detector configuration file" << endl ;
-    cout << "\t --event-generator -E <arg>\t \t \t \t \t Set arg as the event generator file" << endl ;
-    cout << "\t --cal -C <arg>\t \t \t \t \t \t \t Set arg as the calibration file list" << endl ;
-    cout << "\t --help -H -h\t \t \t \t \t \t \t Display this help message" << endl ;
-    cout << "\t --output -O <arg>\t \t \t \t \t \t Set arg as the Output File Name (output tree)" << endl ;
-    cout << "\t --run -R <arg>\t \t \t \t \t \t \t Set arg as the run to read file list" << endl  ;
-    cout << "\t --disable-branch\t \t \t \t \t \t Disable of branch of Input tree except the one of the detector (faster)" << endl  ;
-    cout << endl << endl ;  
-
-    // exit current program
-    exit(1);
-  }
+{
+   cout << "----NPOptionManager Help----" << endl ;
+   cout << "List of Option " << endl ;
+   cout << "\t --detector -D <arg>\t \t \t \t \t \t Set arg as the detector configuration file" << endl ;
+   cout << "\t --event-generator -E <arg>\t \t \t \t \t Set arg as the event generator file" << endl ;
+   cout << "\t --cal -C <arg>\t \t \t \t \t \t \t Set arg as the calibration file list" << endl ;
+   cout << "\t --help -H -h\t \t \t \t \t \t \t Display this help message" << endl ;
+   cout << "\t --output -O <arg>\t \t \t \t \t \t Set arg as the Output File Name (output tree)" << endl ;
+   cout << "\t --run -R <arg>\t \t \t \t \t \t \t Set arg as the run to read file list" << endl  ;
+   cout << "\t --disable-branch\t \t \t \t \t \t Disable of branch of Input tree except the one of the detector (faster)" << endl  ;
+   cout << endl << endl ;
+
+   // exit current program
+   exit(1);
+}
 
 
 
diff --git a/NPLib/Tools/NPOptionManager.h b/NPLib/Tools/NPOptionManager.h
index 67c5a9eeb..b8ee494a8 100644
--- a/NPLib/Tools/NPOptionManager.h
+++ b/NPLib/Tools/NPOptionManager.h
@@ -23,60 +23,62 @@
  *                                                                           *
  *****************************************************************************/
 
-// STL headers
+// C++ headers
 #include <iostream>
 #include <string>
 using namespace std;
 
 class NPOptionManager
-  {
-    public:
-       // The analysis class is designed to be a singleton (i.e. only one instance
-       // can exist). A member function called Instance is defined, which allows
-       // the user to get a pointer to the existing instance or to create it if
-       // it does not yet exist:
-       // (see the constructor for an explanation of the arguments)
-       static NPOptionManager* getInstance(int argc=0,char** argv=NULL);
+{
+   public:
+      // The analysis class is designed to be a singleton (i.e. only one instance
+      // can exist). A member function called Instance is defined, which allows
+      // the user to get a pointer to the existing instance or to create it if
+      // it does not yet exist:
+      // (see the constructor for an explanation of the arguments)
+      static NPOptionManager* getInstance(int argc = 0, char** argv = NULL);
 
-       // The analysis class instance can be deleted by calling the Destroy
-       // method (NOTE: The class destructor is protected, and can thus not be
-       // called directly):
-       static void Destroy();
+      // The analysis class instance can be deleted by calling the Destroy
+      // method (NOTE: The class destructor is protected, and can thus not be
+      // called directly):
+      static void Destroy();
 
-    protected:
-       // Constructor (protected)
-       NPOptionManager(int argc,char** argv);
+   protected:
+      // Constructor (protected)
+      NPOptionManager(int argc, char** argv);
 
-       // Destructor (protected)
-       ~NPOptionManager() {};
+      // Destructor (protected)
+      ~NPOptionManager() {};
 
-       // Prevent copying
-       NPOptionManager(const NPOptionManager& only);
-       const NPOptionManager& operator=(const NPOptionManager& only);
+      // Prevent copying
+      NPOptionManager(const NPOptionManager& only);
+      const NPOptionManager& operator=(const NPOptionManager& only);
 
-    private:
-       // The static instance of the NPOptionManager class:
-       static NPOptionManager* instance;
+   private:
+      // The static instance of the NPOptionManager class:
+      static NPOptionManager* instance;
 
-    private:
+   private:
       void DisplayHelp();
+      void CheckArguments();
+      void CheckEventGenerator();
+      void CheckDetectorConfiguration();
 
-    public:
-      string GetReactionFilePath()        { return fReactionFileName        ; } ;
-      string GetDetectorFilePath()        { return fDetectorFileName        ; } ;
-      string GetRunToReadFilePath()       { return fRunToReadFileName       ; } ;
-      string GetCalibrationFilePath()     { return fCalibrationFileName     ; } ;
-      string GetOutputFilePath()          { return fOutputFileName          ; } ;
-      bool   GetDisableAllBranchOption()  { return fDisableAllBranchOption  ; } ;
-      
-    private:
-      string fReactionFileName        ;
-      string fDetectorFileName        ;
-      string fRunToReadFileName       ;
-      string fCalibrationFileName     ;
-      string fOutputFileName          ;
-      bool   fDisableAllBranchOption  ;
-    
-  };
+   public:
+      string GetReactionFilePath()        {return fReactionFileName;}
+      string GetDetectorFilePath()        {return fDetectorFileName;}
+      string GetRunToReadFilePath()       {return fRunToReadFileName;}
+      string GetCalibrationFilePath()     {return fCalibrationFileName;}
+      string GetOutputFilePath()          {return fOutputFileName;}
+      bool   GetDisableAllBranchOption()  {return fDisableAllBranchOption;}
+
+   private:
+      string fReactionFileName;
+      string fDetectorFileName;
+      string fRunToReadFileName;
+      string fCalibrationFileName;
+      string fOutputFileName;
+      bool   fDisableAllBranchOption;
+};
 
 #endif
diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc
index 85e57bc36..955073b91 100644
--- a/NPSimulation/Simulation.cc
+++ b/NPSimulation/Simulation.cc
@@ -27,9 +27,10 @@
 
 int main(int argc, char** argv)
 {
-   NPOptionManager* OptionManager = NPOptionManager::getInstance(argc, argv);
+   // Initialize NPOptionManager object
+   NPOptionManager* OptionManager  = NPOptionManager::getInstance(argc, argv);
    G4String EventGeneratorFileName = OptionManager->GetReactionFilePath();
-   G4String DetectorFileName = OptionManager->GetDetectorFilePath();
+   G4String DetectorFileName       = OptionManager->GetDetectorFilePath();
 
    // my Verbose output class
    G4VSteppingVerbose::SetInstance(new SteppingVerbose);
diff --git a/NPSimulation/src/DetectorConstruction.cc b/NPSimulation/src/DetectorConstruction.cc
index a35092c4a..cf656e3bc 100644
--- a/NPSimulation/src/DetectorConstruction.cc
+++ b/NPSimulation/src/DetectorConstruction.cc
@@ -170,26 +170,15 @@ void DetectorConstruction::ReadConfigurationFile(string Path)
    bool cShield          = false;	// Paris Shield CsI
    bool cW1              = false;   // W1 Micron DSSD
    //////////////////////////////////////////////////////////////////////////////////////////
-   string GlobalPath = getenv("NPTOOL");
-   string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + Path;
    ifstream ConfigFile;
-   ConfigFile.open(StandardPath.c_str());
+   ConfigFile.open(Path.c_str());
 
-   if (ConfigFile.is_open())
-      { 
-        cout << " Configuration file " << Path << " loading " << endl;
-        Path=StandardPath;
-      }
-
-   else 
-    {
-      ConfigFile.open( Path.c_str() );
-      if(ConfigFile.is_open()) {
+   if (ConfigFile.is_open()) {   // should be always be true
       cout << " Configuration file " << Path << " loading " << endl;
-      }
-      
-      else { cout << " Error, no configuration file" << Path << " found" << endl;return;}
-    }
+   }
+   else {
+      cout << " Error, no configuration file" << Path << " found" << endl;
+   }
 
    while (!ConfigFile.eof()) {
       //Pick-up next line
diff --git a/NPSimulation/src/PrimaryGeneratorAction.cc b/NPSimulation/src/PrimaryGeneratorAction.cc
index 4e6139893..458bb015f 100644
--- a/NPSimulation/src/PrimaryGeneratorAction.cc
+++ b/NPSimulation/src/PrimaryGeneratorAction.cc
@@ -77,34 +77,22 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 void PrimaryGeneratorAction::ReadEventGeneratorFile(string Path)
 {
-   // added by Nicolas [07/05/09]
-   string GlobalPath = getenv("NPTOOL");
-   string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + Path;
+   bool check_TransfertToResonance = false;
+   bool check_PhaseSpace           = false;
+   bool check_Isotropic            = false;
+   bool check_Transfert            = false;
+   bool check_Beam                 = false;
+
    string LineBuffer;
    ifstream EventGeneratorFile;
-   EventGeneratorFile.open(StandardPath.c_str());
-
-   bool check_TransfertToResonance 	= false   ;
-   bool check_PhaseSpace				 		= false   ;
-   bool check_Isotropic        			= false 	;
-   bool check_Transfert        			= false 	;
-   bool check_Beam                	= false 	;
-
-   if (EventGeneratorFile.is_open()) 
-    {
-      cout << " Event Generator file " << Path << " loading " << endl  ;
-      Path = StandardPath;
-    }
-
-   else 
-    {
-      EventGeneratorFile.open( Path.c_str() );
-      if(EventGeneratorFile.is_open()) {
-      cout << " Event Generator file " << Path << " loading " << endl  ;
-      }
-      
-      else { cout << " Error, Event Generator file " << Path << " found" << endl ; return;}
-    }
+   EventGeneratorFile.open(Path.c_str());
+
+   if (EventGeneratorFile.is_open()) { // should always be true
+      cout << "Event Generator file " << Path << " loading " << endl  ;
+   }
+   else {
+      cout << "Error, Event Generator file " << Path << " found" << endl;
+   }
 
 
    while (!EventGeneratorFile.eof()) {
-- 
GitLab