From d37a09fd4d01b0fa40049dffc54a6d3bdb5fbc46 Mon Sep 17 00:00:00 2001 From: deserevi <deserevi@nptool> Date: Fri, 4 Feb 2011 14:05:41 +0000 Subject: [PATCH] * Update NPOptionManager class + when input files are not found, does not exist sytematically + it is done manually in Simulation.cc --- NPLib/IORoot/RootOutput.cxx | 4 +- NPLib/Tools/NPOptionManager.cxx | 72 ++++++++++++++++++++++++++++++--- NPLib/Tools/NPOptionManager.h | 4 ++ NPSimulation/Simulation.cc | 4 ++ 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/NPLib/IORoot/RootOutput.cxx b/NPLib/IORoot/RootOutput.cxx index 32a145fcc..fe1966ce3 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 51ff1e822..11f743eca 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 3265ffb8a..704fbf661 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 36079094b..28880753a 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(); -- GitLab