diff --git a/NPLib/IORoot/RootOutput.cxx b/NPLib/IORoot/RootOutput.cxx index 32a145fccda60abe61a5a6d4154dcf3b8f849a57..fe1966ce3e1daf9375d265852cf3d19ffcf90948 100644 --- a/NPLib/IORoot/RootOutput.cxx +++ b/NPLib/IORoot/RootOutput.cxx @@ -91,9 +91,9 @@ void RootOutput::InitAsciiFiles() // Run to treat file // Get file name from NPOptionManager - TString fileNameRT = OptionManager->GetRunToReadFile(); pRunToTreatFile = new TAsciiFile(); - if (fileNameRT != OptionManager->GetDefaultRunToReadFile()) { + if (!OptionManager->IsDefault("RunToTreat")) { + TString fileNameRT = OptionManager->GetRunToReadFile(); pRunToTreatFile->SetNameTitle("RunToTreat", fileNameRT.Data()); pRunToTreatFile->Append(fileNameRT.Data()); } diff --git a/NPLib/Tools/NPOptionManager.cxx b/NPLib/Tools/NPOptionManager.cxx index 51ff1e822ad20bcaf57ca24bfcc8921de362c9b6..11f743eca8e5a5f23bb3815f2e9b5c162092969e 100644 --- a/NPLib/Tools/NPOptionManager.cxx +++ b/NPLib/Tools/NPOptionManager.cxx @@ -112,13 +112,14 @@ void NPOptionManager::CheckEventGenerator() } 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; + if (!ConfigFile.is_open()) { // if not, assign default value + fReactionFileName = fDefaultReactionFileName; +/* 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); + exit(1);*/ } } @@ -144,13 +145,14 @@ void NPOptionManager::CheckDetectorConfiguration() } 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; + if (!ConfigFile.is_open()) { // if not, assign default value + fDetectorFileName = fDefaultDetectorFileName; +/* 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); + exit(1);*/ } } @@ -160,6 +162,64 @@ void NPOptionManager::CheckDetectorConfiguration() +// This method tests if the input files are the default ones +bool NPOptionManager::IsDefault(const char* type) const +{ + bool result = false; + + string stype = type; + if (stype == "EventGenerator") { + if (fReactionFileName == fDefaultReactionFileName) result = true; + } + else if (stype == "DetectorConfiguration") { + if (fDetectorFileName == fDefaultDetectorFileName) result = true; + } + else if (stype == "Calibration") { + if (fCalibrationFileName == fDefaultCalibrationFileName) result = true; + } + else if (stype == "RunToTreat") { + if (fRunToReadFileName == fDefaultRunToReadFileName) result = true; + } + else { + cout << "NPOptionManager::IsDefault() unkwown keyword" << endl; + } + + return result; +} + + + +// This method tests if the input files are the default ones +void NPOptionManager::SendErrorAndExit(const char* type) const +{ + string stype = type; + if (stype == "EventGenerator") { + 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); + } + else if (stype == "DetectorConfiguration") { + 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); + } + else if (stype == "Calibration") { + } + else if (stype == "RunToTreat") { + } + else { + cout << "NPOptionManager::SendErrorAndAbort() unkwown keyword" << endl; + } +} + + + void NPOptionManager::DisplayHelp() { cout << "----NPOptionManager Help----" << endl ; diff --git a/NPLib/Tools/NPOptionManager.h b/NPLib/Tools/NPOptionManager.h index 3265ffb8a7360da4900511e91d52d959ab21f9db..704fbf661af6c7f46f21395159acb635699fc255 100644 --- a/NPLib/Tools/NPOptionManager.h +++ b/NPLib/Tools/NPOptionManager.h @@ -64,6 +64,10 @@ class NPOptionManager void CheckEventGenerator(); void CheckDetectorConfiguration(); + public: + bool IsDefault(const char* type) const; + void SendErrorAndExit(const char* type) const; + public: // default values string GetDefaultReactionFile() {return fDefaultReactionFileName;} diff --git a/NPSimulation/Simulation.cc b/NPSimulation/Simulation.cc index 36079094b8fdb27fd6a13d8492a34292303346d9..28880753a47ce958c783f9f2f87514d9bd3331cf 100644 --- a/NPSimulation/Simulation.cc +++ b/NPSimulation/Simulation.cc @@ -29,6 +29,10 @@ int main(int argc, char** argv) { // Initialize NPOptionManager object NPOptionManager* OptionManager = NPOptionManager::getInstance(argc, argv); + // Test if input files are found. If not, exit + if (OptionManager->IsDefault("EventGenerator")) OptionManager->SendErrorAndExit("EventGenerator"); + if (OptionManager->IsDefault("DetectorConfiguration")) OptionManager->SendErrorAndExit("DetectorConfiguration"); + // case when input files are here G4String EventGeneratorFileName = OptionManager->GetReactionFile(); G4String DetectorFileName = OptionManager->GetDetectorFile();