From 30cdbbe6019e93453288ddf69ef2424bc1a379ff Mon Sep 17 00:00:00 2001 From: matta <matta@npt> Date: Thu, 18 Nov 2010 13:06:08 +0000 Subject: [PATCH] * Modifing code of the Reaction and Detector Manager so you can also put absolute or relative path to the different file - Still support the use of environment path - Transparent for user, the two way are equivalent --- NPAnalysis/10He_Riken/src/Analysis.cc | 24 +++++-------------- NPLib/Tools/NPReaction.cxx | 34 ++++++++++++++++++--------- NPLib/VDetector/DetectorManager.cxx | 25 +++++++++++++------- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/NPAnalysis/10He_Riken/src/Analysis.cc b/NPAnalysis/10He_Riken/src/Analysis.cc index 0ecb75fb4..ad4118dd3 100644 --- a/NPAnalysis/10He_Riken/src/Analysis.cc +++ b/NPAnalysis/10He_Riken/src/Analysis.cc @@ -4,28 +4,16 @@ using namespace std; int main(int argc,char** argv) { - -// if(argc!=4) -// { -// cout << -// "you need to specify both a Reaction file and a Detector file such as : Analysis myReaction.reaction myDetector.detector runToRead.run" -// << endl; -// return 0; -// } -// -// string detectorfileName = argv[1] ; -// string calibrationfileName = argv[2] ; -// string runToReadfileName = argv[3] ; - - NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv); - string detectorfileName = myOptionManager->GetDetectorFilePath() ; - string calibrationfileName = myOptionManager->GetCalibrationFilePath() ; - string runToReadfileName = myOptionManager->GetRunToReadFilePath() ; + + NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv) ; + string detectorfileName = myOptionManager->GetDetectorFilePath() ; + string calibrationfileName = myOptionManager->GetCalibrationFilePath() ; + string runToReadfileName = myOptionManager->GetRunToReadFilePath() ; // First of All instantiate RootInput and Output // Detector will be attached later RootInput:: getInstance(runToReadfileName) ; - RootOutput::getInstance("Analysis/10HeRiken_AnalyzedData", "AnalyzedTree") ; + RootOutput::getInstance("Analysis/10HeRiken_AnalyzedData", "AnalyzedTree") ; // Instantiate some Reaction NPL::Reaction* He10Reaction = new Reaction ; diff --git a/NPLib/Tools/NPReaction.cxx b/NPLib/Tools/NPReaction.cxx index 140776985..1697f5828 100644 --- a/NPLib/Tools/NPReaction.cxx +++ b/NPLib/Tools/NPReaction.cxx @@ -92,12 +92,20 @@ void Reaction::SetEveryThing(string name1, string name2, string name3, string na ///Read the differential cross section string GlobalPath = getenv("NPTOOL"); - Path = GlobalPath + "/Inputs/CrossSection/" + Path; + string StandardPath = GlobalPath + "/Inputs/CrossSection/" + Path; ifstream CSFile; - CSFile.open( Path.c_str() ); + CSFile.open( StandardPath.c_str() ); - if(CSFile.is_open()) { cout << "Reading Cross Section File " << Path << endl;} - else {cout << "Cross Section File " << Path << " not found" << endl;return;} + if(CSFile.is_open()) cout << "Reading Cross Section File " << Path << endl; + + // In case the file is not found in the standard path, the programm try to interpret the file name as an absolute or relative file path. + else + { + CSFile.open( Path.c_str() ); + if(CSFile.is_open()) { cout << "Reading Cross Section File " << Path << endl;} + + else {cout << "Cross Section File " << Path << " not found" << endl;return;} + } double CSBuffer,AngleBuffer; vector<double> CrossSectionBuffer ; @@ -262,15 +270,19 @@ void Reaction::ReadConfigurationFile(string Path) ////////////////////////////////////////////////////////////////////////////////////////// ifstream ReactionFile; string GlobalPath = getenv("NPTOOL"); - Path = GlobalPath + "/Inputs/EventGenerator/" + Path; - ReactionFile.open(Path.c_str()); + string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + Path; + ReactionFile.open(StandardPath.c_str()); if (ReactionFile.is_open()) {cout << "Reading Reaction File " << Path << endl ;} - else - { - cout << "Reaction File " << Path << " not Found! " << endl ; - return; - } + + // In case the file is not found in the standard path, the programm try to interpret the file name as an absolute or relative file path. + else + { + ReactionFile.open( Path.c_str() ); + if(ReactionFile.is_open()) { cout << "Reading Reaction File " << Path << endl;} + + else {cout << "Reaction File " << Path << " not found" << endl;return;} + } while (!ReactionFile.eof()) { //Pick-up next line diff --git a/NPLib/VDetector/DetectorManager.cxx b/NPLib/VDetector/DetectorManager.cxx index a1cd19be3..3041dcf83 100644 --- a/NPLib/VDetector/DetectorManager.cxx +++ b/NPLib/VDetector/DetectorManager.cxx @@ -49,18 +49,27 @@ void DetectorManager::ReadConfigurationFile(string Path) ////////////////////////////////////////////////////////////////////////////////////////// string GlobalPath = getenv("NPTOOL"); - Path = GlobalPath + "/Inputs/DetectorConfiguration/" + Path; + string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + Path; ifstream ConfigFile; - ConfigFile.open(Path.c_str()); + ConfigFile.open(StandardPath.c_str()); - if (ConfigFile.is_open()) { + if (ConfigFile.is_open()) + { cout << "/////////////////////////////" << endl; cout << " Configuration file " << Path << " loading " << endl; - } - else { - cout << " Error, no configuration file" << Path << " found" << endl; - return; - } + Path = StandardPath; + } + + else + { + ConfigFile.open( Path.c_str() ); + if(ConfigFile.is_open()) { + cout << "/////////////////////////////" << endl; + cout << " Configuration file " << Path << " loading " << endl; + } + + else {cout << "Configuration File " << Path << " not found" << endl;return;} + } while (!ConfigFile.eof()) { -- GitLab