Skip to content
Snippets Groups Projects
Commit 681e1e06 authored by deserevi's avatar deserevi
Browse files

* 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
parent 0ae3d1d5
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@
GeneralTarget
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%1
Target
THICKNESS= 10.755
THICKNESS= 21.51
RADIUS= 1.25
MATERIAL= CD2
ANGLE= 0
......
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
......@@ -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);
}
......
......@@ -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
......@@ -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);
......
......@@ -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
......
......@@ -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()) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment