From 568667fe37e1fda3455a0bb6a6a5e49fdaaf3e38 Mon Sep 17 00:00:00 2001 From: matta <matta@npt> Date: Thu, 10 Feb 2011 23:48:50 +0000 Subject: [PATCH] * change for enhance security problem - further test need to be done to test the new way to acces detector via the detector manager * the map of detector manager is now private and acces via a GetDetector Method - If the detector does not exist, the programm issued an error message and exit --- NPAnalysis/Template/src/Analysis.cc | 9 ------ NPAnalysis/must2/src/Analysis.cc | 2 +- NPLib/IORoot/RootInput.cxx | 46 ++++++++++++++++++----------- NPLib/VDetector/DetectorManager.cxx | 17 ++++++++++- NPLib/VDetector/DetectorManager.h | 21 ++++++------- 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/NPAnalysis/Template/src/Analysis.cc b/NPAnalysis/Template/src/Analysis.cc index a8e22c0c7..2dbcabf3d 100644 --- a/NPAnalysis/Template/src/Analysis.cc +++ b/NPAnalysis/Template/src/Analysis.cc @@ -12,10 +12,6 @@ int main(int argc, char** argv) RootInput:: getInstance(runToReadfileName); // if input files are not given, use those from TAsciiFile - if (myOptionManager->IsDefault("EventGenerator")) { - string name = RootInput::getInstance()->DumpAsciiFile("EventGenerator"); - myOptionManager->SetReactionFile(name); - } if (myOptionManager->IsDefault("DetectorConfiguration")) { string name = RootInput::getInstance()->DumpAsciiFile("DetectorConfiguration"); myOptionManager->SetDetectorFile(name); @@ -25,15 +21,10 @@ int main(int argc, char** argv) RootOutput::getInstance("Analysis/Template_AnalyzedData", "AnalysedTree"); // get input files from NPOptionManager - string reactionfileName = myOptionManager->GetReactionFile(); string detectorfileName = myOptionManager->GetDetectorFile(); string calibrationfileName = myOptionManager->GetCalibrationFile(); string OutputfileName = myOptionManager->GetOutputFile(); - // Instantiate a Reaction - NPL::Reaction* myReaction = new Reaction(); - myReaction->ReadConfigurationFile(reactionfileName); - // Instantiate the detector using a file NPA::DetectorManager* myDetector = new DetectorManager(); myDetector->ReadConfigurationFile(detectorfileName); diff --git a/NPAnalysis/must2/src/Analysis.cc b/NPAnalysis/must2/src/Analysis.cc index 83abf769f..7b0e4d8ae 100644 --- a/NPAnalysis/must2/src/Analysis.cc +++ b/NPAnalysis/must2/src/Analysis.cc @@ -87,7 +87,7 @@ int main(int argc,char** argv) Chain->SetBranchStatus("InitialConditions", 1); // Get TMust2Physics pointer - TMust2Physics *M2 = (TMust2Physics*) myDetector -> m_Detector["MUST2"] ; + TMust2Physics *M2 = (TMust2Physics*) myDetector -> GetDetector("MUST2") ; // define user spectra TH2F* DE_E_protons = new TH2F("DE_E_protons", "DE_E et cut protons", 1000, 0, 25000, 1000, 0, 25000); diff --git a/NPLib/IORoot/RootInput.cxx b/NPLib/IORoot/RootInput.cxx index 1e18c5f46..7838d255f 100644 --- a/NPLib/IORoot/RootInput.cxx +++ b/NPLib/IORoot/RootInput.cxx @@ -209,32 +209,42 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder) string stype = type; if (stype == "EventGenerator") { TAsciiFile *aFile = (TAsciiFile*)pRootFile->Get(stype.c_str()); - // build file name - string title = aFile->GetTitle(); - unsigned int pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); - else name = sfolder + "/" + title; - aFile->WriteToFile(name.c_str()); + + if(aFile) + { + // build file name + string title = aFile->GetTitle(); + unsigned int pos = title.rfind("/"); + if (pos != string::npos) name = sfolder + title.substr(pos); + else name = sfolder + "/" + title; + aFile->WriteToFile(name.c_str()); + } } else if (stype == "DetectorConfiguration") { TAsciiFile *aFile = (TAsciiFile*)pRootFile->Get(stype.c_str()); - // build file name - string title = aFile->GetTitle(); - unsigned int pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); - else name = sfolder + "/" + title; - aFile->WriteToFile(name.c_str()); + if(aFile) + { + // build file name + string title = aFile->GetTitle(); + unsigned int pos = title.rfind("/"); + if (pos != string::npos) name = sfolder + title.substr(pos); + else name = sfolder + "/" + title; + aFile->WriteToFile(name.c_str()); + } } else if (stype == "Calibration") { TAsciiFile *aFile = (TAsciiFile*)pRootFile->Get(stype.c_str()); - // build file name - string title = aFile->GetTitle(); - unsigned int pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); - else name = sfolder + "/" + title; - aFile->WriteToFile(name.c_str()); + if(aFile) + { + // build file name + string title = aFile->GetTitle(); + unsigned int pos = title.rfind("/"); + if (pos != string::npos) name = sfolder + title.substr(pos); + else name = sfolder + "/" + title; + aFile->WriteToFile(name.c_str()); + } } else if (stype == "RunToTreat") { diff --git a/NPLib/VDetector/DetectorManager.cxx b/NPLib/VDetector/DetectorManager.cxx index 5749c8e56..356ee830c 100644 --- a/NPLib/VDetector/DetectorManager.cxx +++ b/NPLib/VDetector/DetectorManager.cxx @@ -398,7 +398,22 @@ void DetectorManager::AddDetector(string DetectorName , VDetector* newDetector) newDetector->AddParameterToCalibrationManager(); } - +///////////////////////////////////////////////////////////////////////////////////////////////// +VDetector* DetectorManager::GetDetector(string name) +{ + map<string,VDetector*>::iterator it; + it = m_Detector.find(name); + if ( it!=m_Detector.end() ) return it->second; + else{ + cout << endl; + cout << "********************************** Error **********************************" << endl; + cout << " No Detector " << name << " found in the Detector Manager" << endl; + cout << "***************************************************************************************" << endl; + cout << endl; + exit(1); + } + +} ///////////////////////////////////////////////////////////////////////////////////////////////// void DetectorManager::ClearEventPhysics() diff --git a/NPLib/VDetector/DetectorManager.h b/NPLib/VDetector/DetectorManager.h index 3b272c991..edeaddc42 100644 --- a/NPLib/VDetector/DetectorManager.h +++ b/NPLib/VDetector/DetectorManager.h @@ -22,16 +22,17 @@ namespace NPA public: // Read stream at Path and pick-up Token declaration of Detector - void ReadConfigurationFile(string Path); - void BuildPhysicalEvent(); - void BuildSimplePhysicalEvent(); - void InitializeRootInput(); - void InitializeRootOutput(); - void AddDetector(string,VDetector*); - void ClearEventPhysics(); - void ClearEventData(); - - public: + void ReadConfigurationFile(string Path); + void BuildPhysicalEvent(); + void BuildSimplePhysicalEvent(); + void InitializeRootInput(); + void InitializeRootOutput(); + void AddDetector(string,VDetector*); + VDetector* GetDetector(string); + void ClearEventPhysics(); + void ClearEventData(); + + private: // The map containning all detectors // Using a Map one can access to any detector using its name map<string,VDetector*> m_Detector; -- GitLab