diff --git a/NPLib/CMakeLists.txt b/NPLib/CMakeLists.txt index 6aba8713fe3d72bf28656b43a4aafe54c9890c8a..c8adca66df17e389a5bcccddf6f8ba15656317b4 100644 --- a/NPLib/CMakeLists.txt +++ b/NPLib/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required (VERSION 2.8) include(CheckCXXCompilerFlag) project(NPLib CXX) set(CMAKE_BUILD_TYPE Release) - # Setting the policy to match Cmake version cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) @@ -19,6 +18,15 @@ set(NPLIB_VERSION_DETA 45) configure_file(Core/NPLibVersion.h.in Core/NPLibVersion.h @ONLY) set(DETLIST ${ETLIST}) +#activate Multithreading (on by default) +if(NOT NPMULTITHREADING) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPMULTITHREADING=0") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNPMULTITHREADING=1") +endif() + + + string(COMPARE EQUAL "${DETLIST}" "" rdet) if(rdet) message("Building all detectors") diff --git a/NPLib/Core/NPCalibrationManager.cxx b/NPLib/Core/NPCalibrationManager.cxx index 4503a7268a341b7e9d82c43cdc5b88f93ae13a9f..0b03b3a59af944a176c544e73a60a2c439ec7daf 100644 --- a/NPLib/Core/NPCalibrationManager.cxx +++ b/NPLib/Core/NPCalibrationManager.cxx @@ -33,7 +33,7 @@ ////////////////////////////////////////////////////////////////// CalibrationManager* CalibrationManager::instance = 0; -CalibrationManager* CalibrationManager::getInstance(const string& configFileName){ +CalibrationManager* CalibrationManager::getInstance(const std::string& configFileName){ // A new instance of CalibrationManager is created if it does not exist: if (instance == 0) { instance = new CalibrationManager(configFileName); @@ -44,28 +44,28 @@ CalibrationManager* CalibrationManager::getInstance(const string& configFileName } ////////////////////////////////////////////////////////////////// -CalibrationManager::CalibrationManager(string configFileName){ +CalibrationManager::CalibrationManager(std::string configFileName){ // Read configuration file Buffer - string lineBuffer, dataBuffer; + std::string lineBuffer, dataBuffer; // Open file - ifstream inputConfigFile; + std::ifstream inputConfigFile; inputConfigFile.open(configFileName.c_str()); if(!NPOptionManager::getInstance()->IsDefault("Calibration")){ - cout << endl; - cout << "/////////// Calibration Information ///////////" << endl; - cout << "Getting list of calibration files" << endl; + std::cout << std::endl; + std::cout << "/////////// Calibration Information ///////////" << std::endl; + std::cout << "Getting list of calibration files" << std::endl; } if (!inputConfigFile) { if(!NPOptionManager::getInstance()->IsDefault("Calibration")) - cout << "Calibration Path file: " << configFileName << " not found" << endl; + std::cout << "Calibration Path file: " << configFileName << " not found" << std::endl; return; } else { - cout << "Reading list of files from: " << configFileName << endl; + std::cout << "Reading list of files from: " << configFileName << std::endl; while (!inputConfigFile.eof()) { getline(inputConfigFile, lineBuffer); @@ -81,13 +81,13 @@ CalibrationManager::CalibrationManager(string configFileName){ else if (!inputConfigFile.eof()) { AddFile(dataBuffer); - cout << "Adding file " << dataBuffer << " to Calibration" << endl; + std::cout << "Adding file " << dataBuffer << " to Calibration" << std::endl; } } } } } - cout << "/////////////////////////////////" << endl; + std::cout << "/////////////////////////////////" << std::endl; } ////////////////////////////////////////////////////////////////// @@ -95,8 +95,8 @@ CalibrationManager::~CalibrationManager() {} ////////////////////////////////////////////////////////////////// -bool CalibrationManager::AddParameter(string DetectorName , string ParameterName , string Token ){ - string ParameterPath = DetectorName + "/" + ParameterName ; +bool CalibrationManager::AddParameter(std::string DetectorName , std::string ParameterName , std::string Token ){ + std::string ParameterPath = DetectorName + "/" + ParameterName ; fToken[Token] = ParameterPath ; return true; } @@ -107,16 +107,16 @@ void CalibrationManager::ClearCalibration(){ } ///////////////////////////////////////////////////////////////// -vector<double> CalibrationManager::GetCorrection(const string& ParameterPath) const { - vector<double> Coeff ; - map< string , vector<double> >::const_iterator it ; +std::vector<double> CalibrationManager::GetCorrection(const std::string& ParameterPath) const { + std::vector<double> Coeff ; + std::map< std::string , std::vector<double> >::const_iterator it ; it = fCalibrationCoeff.find(ParameterPath) ; if(it == fCalibrationCoeff.end() ) { - /* cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ; - cout << " ERROR: PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << endl ; - cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << endl ;*/ + /* std::cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << std::endl ; + std::cout << " ERROR: PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << std::endl ; + std::cout << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " << std::endl ;*/ return Coeff ; } @@ -129,9 +129,9 @@ vector<double> CalibrationManager::GetCorrection(const string& ParameterPath) co ////////////////////////////////////////////////////////////////// void CalibrationManager::LoadParameterFromFile(){ - ifstream CalibFile ; - string DataBuffer ; - string LineBuffer ; + std::ifstream CalibFile; + std::string DataBuffer; + std::string LineBuffer; // Get pointer to the TAsciifile CalibrationFile in RootOuput TAsciiFile* AcsiiCalibration = RootOutput::getInstance()->GetAsciiFileCalibration(); @@ -140,17 +140,17 @@ void CalibrationManager::LoadParameterFromFile(){ unsigned int sizeF = fFileList.size(); for(unsigned int i = 0 ; i < sizeF ; i++){ CalibFile.open( fFileList[i].c_str() ); - map<string,string>::iterator it ; + std::map<std::string,std::string>::iterator it ; if(!CalibFile){ - ostringstream message; + std::ostringstream message; message << "file " << fFileList[i] << " is missing " ; NPL::SendWarning ("NPL::CalibrationManager" , message.str()); } else { // Append the Calibration File to the RootOuput for Back-up - string comment = "%%% From File " + fFileList[i] + "%%%"; + std::string comment = "%%% From File " + fFileList[i] + "%%%"; AcsiiCalibration->AppendLine(comment.c_str()); AcsiiCalibration->Append(fFileList[i].c_str()); @@ -158,8 +158,8 @@ void CalibrationManager::LoadParameterFromFile(){ // Read the file Line by line getline(CalibFile, LineBuffer); - // Create a istringstream to manipulate the line easely - istringstream theLine (LineBuffer,istringstream::in); + // Create a istd::stringstream to manipulate the line easely + std::istringstream theLine (LineBuffer,std::istringstream::in); theLine >> DataBuffer ; // Comment support, comment symbole is % @@ -170,16 +170,16 @@ void CalibrationManager::LoadParameterFromFile(){ it=fToken.find(DataBuffer); // if the word is find, values are read if( it!=fToken.end() ){ - vector<double> Coeff ; + std::vector<double> Coeff ; while( theLine >> DataBuffer ){ Coeff.push_back( atof(DataBuffer.c_str()) ) ; } // Check this parameter is not already define if( fCalibrationCoeff.find(it->second) != fCalibrationCoeff.end() ) - cout << "WARNING: Parameter " << it->second << " Already found. It will be overwritten. " << endl; + std::cout << "WARNING: Parameter " << it->second << " Already found. It will be overwritten. " << std::endl; - // Add the list of Coeff to the Coeff map using Parameter Path as index + // Add the list of Coeff to the Coeff std::map using Parameter Path as index fCalibrationCoeff[ it->second ] = Coeff ; } } @@ -189,9 +189,9 @@ void CalibrationManager::LoadParameterFromFile(){ } ////////////////////////////////////////////////////////////////// -double CalibrationManager::ApplyCalibration(const string& ParameterPath , const double& RawValue) const { - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +double CalibrationManager::ApplyCalibration(const std::string& ParameterPath , const double& RawValue) const { + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -199,11 +199,11 @@ double CalibrationManager::ApplyCalibration(const string& ParameterPath , const // If the find methods return the end iterator it's mean the parameter was not found if(it == ite ){ //by Shuya 170222 -//cout << ParameterPath << "!" << endl; +//std::cout << ParameterPath << "!" << std::endl; return RawValue ; } - // The vector size give the degree of calibration + // The std::vector size give the degree of calibration // We just apply the coeff it->second and returned the calibrated value double CalibratedValue = 0 ; unsigned int mysize = it->second.size(); @@ -215,9 +215,9 @@ double CalibrationManager::ApplyCalibration(const string& ParameterPath , const } ////////////////////////////////////////////////////////////////// -double CalibrationManager::ApplyCalibrationDebug(const string& ParameterPath , const double& RawValue) const{ - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +double CalibrationManager::ApplyCalibrationDebug(const std::string& ParameterPath , const double& RawValue) const{ + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -225,30 +225,30 @@ double CalibrationManager::ApplyCalibrationDebug(const string& ParameterPath , c // If the find methods return the end iterator it's mean the parameter was not found if(it == ite ){ - cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << endl ; + std::cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << std::endl ; return RawValue ; } // Else we take the second part of the element (first is index, ie: parameter path) - // Second is the vector of Coeff - cout << it->first << " : raw = " << RawValue << " coeff = " ; - vector<double> Coeff = it->second ; + // Second is the std::vector of Coeff + std::cout << it->first << " : raw = " << RawValue << " coeff = " ; + std::vector<double> Coeff = it->second ; - // The vector size give the degree of calibration + // The std::vector size give the degree of calibration // We just apply the coeff and returned the calibrated value double CalibratedValue = 0 ; for(unsigned int i = 0 ; i < Coeff.size() ; i++){ - cout << Coeff[i] << " " ; + std::cout << Coeff[i] << " " ; CalibratedValue += Coeff[i]*pow(RawValue, (double)i); } - cout << "results = " << CalibratedValue << endl ; + std::cout << "results = " << CalibratedValue << std::endl ; return CalibratedValue ; } //////////////////////////////////////////////////////////////////////////////// -double CalibrationManager::ApplyResistivePositionCalibration(const string& ParameterPath , const double& DeltaRawValue) const{ - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +double CalibrationManager::ApplyResistivePositionCalibration(const std::string& ParameterPath , const double& DeltaRawValue) const{ + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -259,21 +259,19 @@ double CalibrationManager::ApplyResistivePositionCalibration(const string& Param return DeltaRawValue ; } - vector<double> Coeff = it->second ; - // Check that the number of coeff is ok if(it->second.size()!=2) return DeltaRawValue ; - double CalibratedValue = (DeltaRawValue-Coeff[0])/(Coeff[1]); + double CalibratedValue = (DeltaRawValue-it->second[0])/(it->second[1]); return CalibratedValue ; } //////////////////////////////////////////////////////////////////////////////// -double CalibrationManager::ApplyResistivePositionCalibrationDebug(const string& ParameterPath , const double& DeltaRawValue) const { - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +double CalibrationManager::ApplyResistivePositionCalibrationDebug(const std::string& ParameterPath , const double& DeltaRawValue) const { + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -281,30 +279,30 @@ double CalibrationManager::ApplyResistivePositionCalibrationDebug(const string& // If the find methods return the end iterator it's mean the parameter was not found if(it == ite ){ - cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << endl ; + std::cout << " PARAMETER " << ParameterPath << " IS NOT FOUND IN THE CALIBRATION DATA BASE " << std::endl ; return DeltaRawValue ; } - vector<double> Coeff = it->second ; + std::vector<double> Coeff = it->second ; // Check that the number of coeff is ok if(Coeff.size()!=2){ - cout << " NUMBER OF COEFF " << Coeff.size() << " IS DIFFERENT THAN TWO " << endl ; + std::cout << " NUMBER OF COEFF " << Coeff.size() << " IS DIFFERENT THAN TWO " << std::endl ; return DeltaRawValue ; } double CalibratedValue = (DeltaRawValue-Coeff[0])/(Coeff[1]); - cout << it->first << " : raw = " << DeltaRawValue << " coeff = " ; - cout << Coeff[0] << " " << Coeff[1] << endl ; - cout << "results = " << CalibratedValue << endl ; + std::cout << it->first << " : raw = " << DeltaRawValue << " coeff = " ; + std::cout << Coeff[0] << " " << Coeff[1] << std::endl ; + std::cout << "results = " << CalibratedValue << std::endl ; return CalibratedValue ; } ////////////////////////////////////////////////////////////////// -bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const double& RawValue) const{ - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +bool CalibrationManager::ApplyThreshold(const std::string& ParameterPath, const double& RawValue) const{ + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -315,20 +313,16 @@ bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const doubl return false; } - // Else we take the second part of the element (first is index, ie: parameter path) - // Second is the vector of Coeff - vector<double> Coeff = it->second ; - - // The vector size give the degree of calibration + // The std::vector size give the degree of calibration // We just apply the coeff and returned the calibrated value - double ThresholdValue = 0 ; + double ThresholdValue ; - if(Coeff.size()==2){ // CATS style - ThresholdValue = Coeff[0] + 3*Coeff[1]; + if(it->second.size()==2){ // CATS style + ThresholdValue = it->second[0] + 3*it->second[1]; } else{ // Standard Threshold - ThresholdValue = Coeff[0]; + ThresholdValue = it->second[0]; } @@ -339,14 +333,14 @@ bool CalibrationManager::ApplyThreshold(const string& ParameterPath, const doubl } ///////////////////////////////////////////////////////////////////////////////////////////// -double CalibrationManager::GetPedestal(const string& ParameterPath) const{ +double CalibrationManager::GetPedestal(const std::string& ParameterPath) const{ return GetValue(ParameterPath,0); } ///////////////////////////////////////////////////////////////////////////////////////////// -double CalibrationManager::GetValue(const string& ParameterPath,const unsigned int& order) const{ - map< string , vector<double> >::const_iterator it ; - static map< string , vector<double> >::const_iterator ite = fCalibrationCoeff.end(); +double CalibrationManager::GetValue(const std::string& ParameterPath,const unsigned int& order) const{ + std::map< std::string , std::vector<double> >::const_iterator it ; + static std::map< std::string , std::vector<double> >::const_iterator ite = fCalibrationCoeff.end(); // Find the good parameter in the Map // Using Find method of stl is the fastest way @@ -357,7 +351,7 @@ double CalibrationManager::GetValue(const string& ParameterPath,const unsigned i return 0; } - // The vector size give the degree of calibration + // The std::vector size give the degree of calibration double Value = 0 ; if(it->second.size()>order){ Value = it->second[order]; diff --git a/NPLib/Core/NPCalibrationManager.h b/NPLib/Core/NPCalibrationManager.h index e99e008fad1fc5f7c0364babe4f05bb3634445ed..2bf88eaad0fb1418bae8659e3db2ee736b7912fb 100644 --- a/NPLib/Core/NPCalibrationManager.h +++ b/NPLib/Core/NPCalibrationManager.h @@ -28,44 +28,43 @@ #include<vector> #include<map> -using namespace std ; class CalibrationManager{ protected: // Constructor and Destructor are protected because the class is a singleton - CalibrationManager(string configFileName); + CalibrationManager(std::string configFileName); ~CalibrationManager(); public: // Accessor // return a pointer to the calibration manager instance. // if the instance does not exist it is created. - static CalibrationManager* getInstance(const string& configFileName="XXX"); + static CalibrationManager* getInstance(const std::string& configFileName="XXX"); private: // the instance // Hold a pointer on itself static CalibrationManager* instance ; public: // File Management - inline void AddFile(string Path) { fFileList.push_back(Path) ;} ; + inline void AddFile(std::string Path) { fFileList.push_back(Path) ;} ; public: // Calibration Parameter Related // call like : myCalibrationManager->AddParameter( "MUST2" ,"Telescope5_Si_X38_E", "T5_Si_X38_E" ) // return false if the token is not found in the file list - bool AddParameter(string DetectorName , string ParameterName , string Token) ; + bool AddParameter(std::string DetectorName , std::string ParameterName , std::string Token) ; // call like : myCalibrationManager->ApplyCalibration( "MUST2/Telescope5_Si_X38_E" , RawEnergy ) // return the Calibrated value - double ApplyCalibration (const string& ParameterPath , const double& RawValue) const ; - double ApplyResistivePositionCalibration (const string& ParameterPath , const double& RawValue) const ; + double ApplyCalibration (const std::string& ParameterPath , const double& RawValue) const ; + double ApplyResistivePositionCalibration (const std::string& ParameterPath , const double& RawValue) const ; // Same but with debug information outputs - double ApplyCalibrationDebug (const string& ParameterPath , const double& RawValue) const ; - double ApplyResistivePositionCalibrationDebug (const string& ParameterPath , const double& RawValue) const ; + double ApplyCalibrationDebug (const std::string& ParameterPath , const double& RawValue) const ; + double ApplyResistivePositionCalibrationDebug (const std::string& ParameterPath , const double& RawValue) const ; - bool ApplyThreshold (const string& ParameterPath, const double& RawValue) const ; - double GetPedestal (const string& ParameterPath) const ; - double GetValue (const string& ParameterPath,const unsigned int& order) const ; + bool ApplyThreshold (const std::string& ParameterPath, const double& RawValue) const ; + double GetPedestal (const std::string& ParameterPath) const ; + double GetValue (const std::string& ParameterPath,const unsigned int& order) const ; public: // To be called after initialisation // Loop over the file list and catch the file used for calibration @@ -74,18 +73,18 @@ class CalibrationManager{ public: //Clear calibration if we have some calibration files to read void ClearCalibration(); - public: //Get correction coefficient vector - vector<double> GetCorrection (const string& ParameterPath) const ; + public: //Get correction coefficient std::vector + std::vector<double> GetCorrection (const std::string& ParameterPath) const ; private: - // This map hold a vector of the calibration coefficient. Index is the Parameter path, like "MUST2/Telescope5_Si_X38_E" + // This std::map hold a std::vector of the calibration coefficient. Index is the Parameter path, like "MUST2/Telescope5_Si_X38_E" - map< string , vector<double> > fCalibrationCoeff ; + std::map< std::string , std::vector<double> > fCalibrationCoeff ; // Hold the path of all the registered file of coeff - vector<string> fFileList ; + std::vector<std::string> fFileList ; // Hold The list of Token. Index is the Token, value the parameter path. - map< string , string > fToken ; + std::map< std::string , std::string > fToken ; }; diff --git a/NPLib/Core/NPDetectorFactory.cxx b/NPLib/Core/NPDetectorFactory.cxx index 5abf466a07396d29ac87d620b4ac1197f404a380..5c42b5f7848ff577a9472f06d3bab52fc776dd75 100644 --- a/NPLib/Core/NPDetectorFactory.cxx +++ b/NPLib/Core/NPDetectorFactory.cxx @@ -57,19 +57,19 @@ void NPL::DetectorFactory::ReadClassList(std::string FileList){ std::ifstream InFile(FileList.c_str()); if(!InFile.is_open()){ - string error = "Detector Class List file " +FileList +" Not found"; + std::string error = "Detector Class List file " +FileList +" Not found"; NPL::SendErrorAndExit("NPL::NPL::DetectorFactory",error); exit(1); } - string Token, LibName; + std::string Token, LibName; while(InFile >> Token >> LibName) m_TokenLib[Token] = LibName; } //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorFactory::CreateClassList(std::string FileList){ - ofstream outFile(FileList.c_str()); - std::map<string,string>::iterator it; + std::ofstream outFile(FileList.c_str()); + std::map<std::string,std::string>::iterator it; for(it = m_TokenLib.begin();it!=m_TokenLib.end();it++){ outFile << it->first << " " << it->second << std::endl; diff --git a/NPLib/Core/NPDetectorManager.cxx b/NPLib/Core/NPDetectorManager.cxx index 0a9002667fb4e2d4b073824aebc65430aeb71f6e..bef210a1feaeeb9d0a4ae77a6727b03a08fad54d 100644 --- a/NPLib/Core/NPDetectorManager.cxx +++ b/NPLib/Core/NPDetectorManager.cxx @@ -59,7 +59,6 @@ NPL::DetectorManager::DetectorManager(){ m_CheckSpectra = &NPL::VDetector::CheckSpectra ; } m_CryoTarget=false; - m_TargetThickness = 0 ; m_TargetAngle = 0 ; m_TargetRadius = 0 ; @@ -85,15 +84,13 @@ NPL::DetectorManager::DetectorManager(){ m_ShieldFrontRadius = 0 ; m_ShieldBackRadius = 0 ; m_ShieldMaterial = "" ; - - } /////////////////////////////////////////////////////////////////////////////// // Default Desstructor NPL::DetectorManager::~DetectorManager(){ -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING StopThread(); #endif if(m_SpectraServer) @@ -102,34 +99,34 @@ NPL::DetectorManager::~DetectorManager(){ /////////////////////////////////////////////////////////////////////////////// // Read stream at ConfigFile and pick-up Token declaration of Detector -void NPL::DetectorManager::ReadConfigurationFile(string Path) { - cout << "\033[1;36m" ; +void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { + std::cout << "\033[1;36m" ; // Instantiate the Calibration Manager // All The detector will then add to it their parameter (see AddDetector) CalibrationManager::getInstance(NPOptionManager::getInstance()->GetCalibrationFile()); // Access the DetectorFactory and ask it to load the Class List - string classlist = getenv("NPTOOL"); + std::string classlist = getenv("NPTOOL"); classlist += "/NPLib/ClassList.txt"; NPL::DetectorFactory* theFactory = NPL::DetectorFactory::getInstance(); theFactory->ReadClassList(classlist); - set<string> check; + std::set<std::string> check; NPL::InputParser parser(Path); //////////////////////////////////////////// //////////// Search for Target ///////////// //////////////////////////////////////////// - vector<NPL::InputBlock*> starget = parser.GetAllBlocksWithToken("Target"); - vector<NPL::InputBlock*> ctarget = parser.GetAllBlocksWithToken("CryogenicTarget"); + std::vector<NPL::InputBlock*> starget = parser.GetAllBlocksWithToken("Target"); + std::vector<NPL::InputBlock*> ctarget = parser.GetAllBlocksWithToken("CryogenicTarget"); if(starget.size()==1){ if(NPOptionManager::getInstance()->GetVerboseLevel()){ - cout << "//// TARGET ////" << endl; - cout << "//// Solid Target found " << endl; + std::cout << "//// TARGET ////" << std::endl; + std::cout << "//// Solid Target found " << std::endl; } - vector<string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"}; + std::vector<std::string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"}; if(starget[0]->HasTokenList(token)){ m_TargetThickness= starget[0]->GetDouble("Thickness","micrometer"); m_TargetAngle=starget[0]->GetDouble("Angle","deg"); @@ -139,19 +136,19 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path) { m_TargetZ=starget[0]->GetDouble("Z","mm"); } else{ - cout << "ERROR: Target token list incomplete, check your input file" << endl; + std::cout << "ERROR: Target token list incomplete, check your input file" << std::endl; exit(1); } } else if(ctarget.size()==1){ if(NPOptionManager::getInstance()->GetVerboseLevel()) - cout << "//// Cryogenic Target found " << endl; + std::cout<< "//// Cryogenic Target found " << std::endl; m_CryoTarget = true; - vector<string> CoreToken = {"NominalThickness","Material","Density","Radius","Angle","X","Y","Z"}; - vector<string> FrontToken = {"FrontDeformation","FrontThickness","FrontRadius","FrontMaterial"}; - vector<string> BackToken = {"BackDeformation","BackThickness","BackRadius","BackMaterial"}; - vector<string> FrameToken = {"FrameRadius","FrameThickness","FrontCone","BackCone","FrameMaterial"}; - vector<string> ShieldToken = {"ShieldInnerRadius","ShieldOuterRadius""ShieldBottomLength","ShieldTopLength","ShieldFrontRadius","ShieldBackRadius","ShieldMaterial"}; + std::vector<std::string> CoreToken = {"NominalThickness","Material","Density","Radius","Angle","X","Y","Z"}; + std::vector<std::string> FrontToken = {"FrontDeformation","FrontThickness","FrontRadius","FrontMaterial"}; + std::vector<std::string> BackToken = {"BackDeformation","BackThickness","BackRadius","BackMaterial"}; + std::vector<std::string> FrameToken = {"FrameRadius","FrameThickness","FrontCone","BackCone","FrameMaterial"}; + std::vector<std::string> ShieldToken = {"ShieldInnerRadius","ShieldOuterRadius""ShieldBottomLength","ShieldTopLength","ShieldFrontRadius","ShieldBackRadius","ShieldMaterial"}; @@ -196,12 +193,11 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path) { m_ShieldMaterial = ctarget[0]->GetString("ShieldMaterial"); } else{ - cout << "ERROR: CryogenicTarget token list incomplete, check your input file" << endl; - exit(1); + std::cout<< "ERROR: CryogenicTarget token list incomplete, check your input file" << std::endl; } } else{ - cout << "ERROR: One and only one target shall be declared in your detector file" << endl; + std::cout << "ERROR: One and only one target shall be declared in your detector file" << std::endl; } //////////////////////////////////////////// @@ -211,31 +207,27 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path) { std::vector<std::string> token = parser.GetAllBlocksToken(); // Look for detectors among them for(unsigned int i = 0 ; i < token.size() ; i++){ - VDetector* detector = theFactory->Construct(token[i]); - if(detector!=NULL && check.find(token[i])==check.end()){ - if(NPOptionManager::getInstance()->GetVerboseLevel()){ - cout << "/////////////////////////////////////////" << endl; - cout << "//// Adding Detector " << token[i] << endl; + VDetector* detector = theFactory->Construct(token[i]); + if(detector!=NULL && check.find(token[i])==check.end()){ + if(NPOptionManager::getInstance()->GetVerboseLevel()){ + std::cout << "/////////////////////////////////////////" << std::endl; + std::cout << "//// Adding Detector " << token[i] << std::endl; + } + detector->ReadConfiguration(parser); + if(NPOptionManager::getInstance()->GetVerboseLevel()) + std::cout << "/////////////////////////////////////////" << std::endl; + + // Add array to the VDetector Vector + AddDetector(token[i], detector); + check.insert(token[i]); } - detector->ReadConfiguration(parser); - if(NPOptionManager::getInstance()->GetVerboseLevel()) - cout << "/////////////////////////////////////////" << endl; - - // Add array to the VDetector Vector - AddDetector(token[i], detector); - check.insert(token[i]); - } - else if(detector!=NULL) - delete detector; + else if(detector!=NULL) + delete detector; } // Now That the detector lib are loaded, we can instantiate the root input - string runToReadfileName = NPOptionManager::getInstance()->GetRunToReadFile(); + std::string runToReadfileName = NPOptionManager::getInstance()->GetRunToReadFile(); RootInput::getInstance(runToReadfileName); - // Now that the detector are all added, they can initialise their Branch to the Root I/O - //InitializeRootInput(); - //InitializeRootOutput(); - // If Requiered, they can also instiantiate their control histogramm if(NPOptionManager::getInstance()->GetGenerateHistoOption()) InitSpectra(); @@ -244,7 +236,7 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path) { CalibrationManager::getInstance()->LoadParameterFromFile(); // Start the thread if multithreading supported -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING InitThreadPool(); #endif @@ -253,32 +245,21 @@ void NPL::DetectorManager::ReadConfigurationFile(string Path) { /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::BuildPhysicalEvent(){ -#if __cplusplus > 199711L - // add new job -//cout << "TEST0a" << endl; - map<string,VDetector*>::iterator it; - unsigned int i = 0; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { -//cout << "TEST0" << endl; - m_Ready[i++]=true; - } -//cout << "TEST1" << endl; - { // aquire the sub thread lock - std::unique_lock<std::mutex> lk(m_ThreadMtx); - } - m_CV.notify_all(); +#if __cplusplus > 199711L && NPMULTITHREADING + // add new job + m_Ready.flip(); + std::this_thread::yield(); -//cout << "TEST2" << endl; while(!IsDone()){ -//cout << "TEST2a" << endl; - //this_thread::yield(); - } -//cout << "TEST2b" << endl; + std::this_thread::yield(); + } #else -//cout << "TEST3" << endl; - map<string,VDetector*>::iterator it; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { + static std::map<std::string,VDetector*>::iterator it; + static std::map<std::string,VDetector*>::iterator begin=m_Detector.begin(); + static std::map<std::string,VDetector*>::iterator end= m_Detector.end(); + + for (it =begin; it != end; ++it) { (it->second->*m_ClearEventPhysicsPtr)(); (it->second->*m_BuildPhysicalPtr)(); if(m_FillSpectra){ @@ -288,21 +269,7 @@ void NPL::DetectorManager::BuildPhysicalEvent(){ } } #endif -} - -/////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::BuildSimplePhysicalEvent(){ - ClearEventPhysics(); - map<string,VDetector*>::iterator it; - - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { - it->second->BuildSimplePhysicalEvent(); - if(NPOptionManager::getInstance()->GetGenerateHistoOption()){ - it->second->FillSpectra(); - if(NPOptionManager::getInstance()->GetCheckHistoOption()) - it->second->CheckSpectra(); - } - } + return; } /////////////////////////////////////////////////////////////////////////////// @@ -311,7 +278,7 @@ void NPL::DetectorManager::InitializeRootInput(){ if( NPOptionManager::getInstance()->GetDisableAllBranchOption() ) RootInput::getInstance()->GetChain()->SetBranchStatus ( "*" , false ) ; - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; if(NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) for (it = m_Detector.begin(); it != m_Detector.end(); ++it) @@ -324,7 +291,7 @@ void NPL::DetectorManager::InitializeRootInput(){ /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::InitializeRootOutput(){ - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; if(!NPOptionManager::getInstance()->GetInputPhysicalTreeOption()) for (it = m_Detector.begin(); it != m_Detector.end(); ++it) @@ -332,26 +299,26 @@ void NPL::DetectorManager::InitializeRootOutput(){ } /////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::AddDetector(string DetectorName , VDetector* newDetector){ +void NPL::DetectorManager::AddDetector(std::string DetectorName , VDetector* newDetector){ m_Detector[DetectorName] = newDetector; newDetector->AddParameterToCalibrationManager(); } /////////////////////////////////////////////////////////////////////////////// -NPL::VDetector* NPL::DetectorManager::GetDetector(string name){ - map<string,VDetector*>::iterator it; +NPL::VDetector* NPL::DetectorManager::GetDetector(std::string name){ + std::map<std::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 << " Available Detectors: " << endl; - for(map<string,VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) { - cout << "\t" << i->first << endl; - } - cout << "***************************************************************************************" << endl; - cout << endl; + std::cout << std::endl; + std::cout << "********************************** Error **********************************" << std::endl; + std::cout << " No Detector " << name << " found in the Detector Manager" << std::endl; + std::cout << " Available Detectors: " << std::endl; + for(std::map<std::string,VDetector*>::iterator i = m_Detector.begin(); i != m_Detector.end(); ++i) { + std::cout << "\t" << i->first << std::endl; + } + std::cout << "***************************************************************************************" << std::endl; + std::cout << std::endl; exit(1); } @@ -359,14 +326,14 @@ NPL::VDetector* NPL::DetectorManager::GetDetector(string name){ /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::ClearEventPhysics(){ - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) (it->second->*m_ClearEventPhysicsPtr)(); } /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::ClearEventData(){ - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) (it->second->*m_ClearEventDataPtr)(); } @@ -375,30 +342,30 @@ void NPL::DetectorManager::ClearEventData(){ void NPL::DetectorManager::InitSpectra(){ bool batch = false; if(gROOT){ - batch = gROOT->IsBatch(); - gROOT->ProcessLine("gROOT->SetBatch()"); + batch = gROOT->IsBatch(); + gROOT->ProcessLine("gROOT->SetBatch()"); } - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) it->second->InitSpectra(); if(gROOT&&!batch) - gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); + gROOT->ProcessLine("gROOT->SetBatch(kFALSE)"); } /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::WriteSpectra(){ - std::cout << endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m"<<flush; - map<string,VDetector*>::iterator it; + std::cout << std::endl << "\r \033[1;36m *** Writing Spectra: this may take a while ***\033[0m"<<std::flush; + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) it->second->WriteSpectra(); - std::cout << "\r " << flush; + std::cout << "\r " << std::flush; } /////////////////////////////////////////////////////////////////////////////// -vector< map< string, TH1* > > NPL::DetectorManager::GetSpectra(){ - vector< map< string, TH1* > > myVector; - map<string,VDetector*>::iterator it; +std::vector< std::map< std::string, TH1* > > NPL::DetectorManager::GetSpectra(){ + std::vector< std::map< std::string, TH1* > > myVector; + std::map<std::string,VDetector*>::iterator it; // loop on detectors for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { myVector.push_back(it->second->GetSpectra()); @@ -408,26 +375,27 @@ vector< map< string, TH1* > > NPL::DetectorManager::GetSpectra(){ } /////////////////////////////////////////////////////////////////////////////// -vector<string> NPL::DetectorManager::GetDetectorList(){ - map<string,VDetector*>::iterator it; - vector<string> DetectorList; +std::vector<std::string> NPL::DetectorManager::GetDetectorList(){ + std::map<std::string,VDetector*>::iterator it; + std::vector<std::string> DetectorList; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { DetectorList.push_back(it->first); } return DetectorList; } -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING + //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::InitThreadPool(){ StopThread(); m_ThreadPool.clear(); m_Ready.clear(); - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; unsigned int i = 0; for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { - m_ThreadPool.push_back( thread( &NPL::DetectorManager::StartThread,this,it->second,i++) ); + m_ThreadPool.push_back( std::thread( &NPL::DetectorManager::StartThread,this,it->second,i++) ); m_Ready.push_back(false); } @@ -436,60 +404,52 @@ void NPL::DetectorManager::InitThreadPool(){ th.detach(); } - cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << endl ; + std::cout << "\033[1;33m**** Detector Manager : Started " << i << " Threads ****\033[0m" << std::endl ; } //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::StartThread(NPL::VDetector* det,unsigned int id){ - this_thread::sleep_for(chrono::milliseconds(1)); - vector<bool>::iterator it = m_Ready.begin()+id; + // Let the main thread start + std::this_thread::sleep_for(std::chrono::milliseconds(100)); while(true){ - { // Aquire the lock -////cout << "WWWW" << endl; - std::unique_lock<std::mutex> lk(m_ThreadMtx); - // wait for work to be given - while(!m_Ready[id]){ - m_CV.wait(lk); - } - + // Do the job if possible + if(m_Ready[id]){ // Do the job (det->*m_ClearEventPhysicsPtr)(); (det->*m_BuildPhysicalPtr)(); if(m_FillSpectra){ (det->*m_FillSpectra)(); - if(m_CheckSpectra) + if(m_CheckSpectra) (det->*m_CheckSpectra)(); } - - // Reset Ready flag - m_Ready[id]=false; - // Quite if stopped - if(m_stop) - return; - - } // Realease the lock - + m_Ready[id].flip(); + std::this_thread::yield(); + } + else{ + std::this_thread::yield(); + } + + // Return if stopped + if(m_stop){ + return; + } } } //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::StopThread(){ // make sure the last thread are schedule before stopping; - this_thread::yield(); + std::this_thread::yield(); m_stop=true; - m_CV.notify_all(); + std::this_thread::yield(); } //////////////////////////////////////////////////////////////////////////////// bool NPL::DetectorManager::IsDone(){ -int ijk=0; -//cout << m_Ready.size() << " !" << endl; - for(vector<bool>::iterator it = m_Ready.begin() ; it!=m_Ready.end() ; it++){ + static std::vector<bool>::iterator it; + static std::vector<bool>::iterator begin = m_Ready.begin(); + static std::vector<bool>::iterator end = m_Ready.end(); + for( it = begin ; it!=end ; it++){ if((*it)) -{ -ijk++; -//cout << *it << endl; -//cout << ijk << endl; return false; -} } return true; } @@ -498,12 +458,12 @@ ijk++; void NPL::DetectorManager::SetSpectraServer(){ m_SpectraServer = NPL::SpectraServer::getInstance(); - map<string,VDetector*>::iterator it; + std::map<std::string,VDetector*>::iterator it; for (it = m_Detector.begin(); it != m_Detector.end(); ++it){ - vector<TCanvas*> canvas = it->second->GetCanvas(); + std::vector<TCanvas*> canvas = it->second->GetCanvas(); size_t mysize = canvas.size(); for (size_t i = 0 ; i < mysize ; i++){} - //m_SpectraServer->AddCanvas(canvas[i]); + //m_SpectraServer->AddCanvas(canvas[i]); } // Avoid warning on gcc @@ -516,8 +476,8 @@ void NPL::DetectorManager::StopSpectraServer(){ if(m_SpectraServer) m_SpectraServer->Destroy(); else - cout <<"WARNING: requesting to stop spectra server, which is not started" << endl; - + std::cout <<"WARNING: requesting to stop spectra server, which is not started" << std::endl; + } //////////////////////////////////////////////////////////////////////////////// @@ -525,7 +485,7 @@ void NPL::DetectorManager::CheckSpectraServer(){ if(m_SpectraServer) m_SpectraServer->CheckRequest(); else - cout <<"WARNING: requesting to check spectra server, which is not started" << endl; + std::cout <<"WARNING: requesting to check spectra server, which is not started" << std::endl; } diff --git a/NPLib/Core/NPDetectorManager.h b/NPLib/Core/NPDetectorManager.h index 7310db00b60ef7ef2228a5dcca2e3f47a8639612..980989f68f42c12f69cafc464f7be49f138f10f3 100644 --- a/NPLib/Core/NPDetectorManager.h +++ b/NPLib/Core/NPDetectorManager.h @@ -29,17 +29,16 @@ // STL #include <string> #include <map> - +#include <vector> #if __cplusplus > 199711L #include <thread> #include <mutex> #include <condition_variable> #endif -using namespace std ; typedef void(NPL::VDetector::*VDetector_FuncPtr)(void); -// This class manage a map of virtual detector +// This class manage a std::map of virtual detector namespace NPL{ class DetectorManager{ public: @@ -47,19 +46,18 @@ namespace NPL{ ~DetectorManager(); public: - void ReadConfigurationFile(string Path); + void ReadConfigurationFile(std::string Path); void BuildPhysicalEvent(); - void BuildSimplePhysicalEvent(); void InitializeRootInput(); void InitializeRootOutput(); - void AddDetector(string,VDetector*); - VDetector* GetDetector(string); + void AddDetector(std::string,VDetector*); + VDetector* GetDetector(std::string); void ClearEventPhysics(); void ClearEventData(); void InitSpectra(); void WriteSpectra(); - vector< map< string, TH1* > > GetSpectra(); - vector<string> GetDetectorList(); + std::vector< std::map< std::string, TH1* > > GetSpectra(); + std::vector<std::string> GetDetectorList(); public: // for online spectra server void SetSpectraServer(); @@ -69,9 +67,9 @@ namespace NPL{ NPL::SpectraServer* m_SpectraServer; private: - // The map containning all detectors + // The std::map containning all detectors // Using a Map one can access to any detector using its name - map<string,VDetector*> m_Detector; + std::map<std::string,VDetector*> m_Detector; private: // Function pointer to accelerate the code execution VDetector_FuncPtr m_BuildPhysicalPtr; @@ -79,14 +77,12 @@ namespace NPL{ VDetector_FuncPtr m_ClearEventDataPtr; VDetector_FuncPtr m_FillSpectra; VDetector_FuncPtr m_CheckSpectra; - -#if __cplusplus > 199711L + + #if __cplusplus > 199711L && NPMULTITHREADING private: // Thread Pool defined if C++11 is available - vector<std::thread> m_ThreadPool; - vector<bool> m_Ready; + std::vector<std::thread> m_ThreadPool; + std::vector<bool> m_Ready; bool m_stop; - std::mutex m_ThreadMtx; - std::condition_variable m_CV; public: // Init the Thread Pool void StopThread(); @@ -101,7 +97,7 @@ namespace NPL{ double m_TargetThickness; double m_TargetAngle; double m_TargetRadius; - string m_TargetMaterial; + std::string m_TargetMaterial; double m_TargetX; double m_TargetY; double m_TargetZ; @@ -112,23 +108,23 @@ namespace NPL{ double m_FrontDeformation; double m_FrontThickness; double m_FrontRadius; - string m_FrontMaterial; + std::string m_FrontMaterial; double m_BackDeformation; double m_BackRadius; double m_BackThickness; - string m_BackMaterial; + std::string m_BackMaterial; double m_FrameRadius; double m_FrameThickness; double m_FrontCone; double m_BackCone; - string m_FrameMaterial; + std::string m_FrameMaterial; double m_ShieldInnerRadius; double m_ShieldOuterRadius; double m_ShieldBottomLength; double m_ShieldTopLength; double m_ShieldFrontRadius; double m_ShieldBackRadius; - string m_ShieldMaterial; + std::string m_ShieldMaterial; public: inline bool IsCryogenic(){return m_CryoTarget;}; @@ -137,31 +133,36 @@ namespace NPL{ inline double GetFrontDeformation () {return m_FrontDeformation;} inline double GetFrontThickness () {return m_FrontThickness;} inline double GetFrontRadius () {return m_FrontRadius;} - inline string GetFrontMaterial () {return m_FrontMaterial;} + inline std::string GetFrontMaterial () {return m_FrontMaterial;} inline double GetBackDeformation () {return m_BackDeformation;} inline double GetBackRadius () {return m_BackRadius;} inline double GetBackThickness () {return m_BackThickness;} - inline string GetBackMaterial () {return m_BackMaterial;} + inline std::string GetBackMaterial () {return m_BackMaterial;} inline double GetFrameRadius () {return m_FrameRadius;} inline double GetFrameThickness () {return m_FrameThickness;} inline double GetFrontCone () {return m_FrontCone;} inline double GetBackCone () {return m_BackCone;} - inline string GetFrameMaterial () {return m_FrameMaterial;} + inline std::string GetFrameMaterial () {return m_FrameMaterial;} inline double GetShieldInnerRadius () {return m_ShieldInnerRadius;} inline double GetShieldOuterRadius () {return m_ShieldOuterRadius;} inline double GetShieldBottomLength () {return m_ShieldBottomLength;} inline double GetShieldTopLength () {return m_ShieldTopLength;} inline double GetShieldFrontRadius () {return m_ShieldFrontRadius;} inline double GetShieldBackRadius () {return m_ShieldBackRadius;} - inline string GetShieldMaterial () {return m_ShieldMaterial;} + inline std::string GetShieldMaterial () {return m_ShieldMaterial;} + double m_WindowsThickness; + std::string m_WindowsMaterial; + // Special treatment for the target for the moment // If necessary we should change it to treat it as // a full "detector" public: - string GetTargetMaterial() {return m_TargetMaterial;} + std::string GetTargetMaterial() {return m_TargetMaterial;} + double GetWindowsThickness() {return m_WindowsThickness;} + std::string GetWindowsMaterial() {return m_WindowsMaterial;} double GetTargetRadius() {return m_TargetRadius;} double GetTargetAngle() {return m_TargetAngle;} double GetTargetX() {return m_TargetX;} diff --git a/NPLib/Core/NPInputParser.cxx b/NPLib/Core/NPInputParser.cxx index 5f1b3fa52ae586d104fdd29275462011af779186..142397e899708e9b67b28972882d9ff3c381d7b4 100644 --- a/NPLib/Core/NPInputParser.cxx +++ b/NPLib/Core/NPInputParser.cxx @@ -143,7 +143,7 @@ double NPL::InputBlock::GetDouble(std::string Token,std::string default_unit){ } if(verbose) - cout << " " << Token << " (" <<default_unit << "): " << val/ApplyUnit(1,default_unit) << endl; + std::cout << " " << Token << " (" <<default_unit << "): " << val/ApplyUnit(1,default_unit) <<std::endl; return val; } @@ -155,7 +155,7 @@ int NPL::InputBlock::GetInt(std::string Token){ iss >> val ; if(verbose) - cout << " " << Token << ": " << val << endl; + std::cout << " " << Token << ": " << val <<std::endl; return val; @@ -164,7 +164,7 @@ int NPL::InputBlock::GetInt(std::string Token){ std::string NPL::InputBlock::GetString(std::string Token){ int verbose = NPOptionManager::getInstance()->GetVerboseLevel(); if(verbose) - cout << " " << Token << ": " << GetValue(Token) << endl; + std::cout << " " << Token << ": " << GetValue(Token) << std::endl; return GetValue(Token); } @@ -190,10 +190,10 @@ TVector3 NPL::InputBlock::GetTVector3(std::string Token,std::string default_uni } if(verbose) - cout << " " << Token << " (" <<default_unit << "): (" + std::cout << " " << Token << " (" <<default_unit << "): (" << x/ApplyUnit(1,default_unit) << " ; " << y/ApplyUnit(1,default_unit) << " ; " - << z/ApplyUnit(1,default_unit) << ")" << endl; + << z/ApplyUnit(1,default_unit) << ")" << std::endl; return TVector3(x,y,z); @@ -211,10 +211,10 @@ std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token){ if(verbose){ - cout << " " << Token << ": "; + std::cout << " " << Token << ": "; for(unsigned int i = 0 ; i < val.size() ; i++) - cout << val[i] << " " ; - cout << endl; + std::cout << val[i] << " " ; + std::cout << std::endl; } return val; } @@ -247,10 +247,10 @@ std::vector<double> NPL::InputBlock::GetVectorDouble(std::string Token,std::stri } if(verbose){ - cout << " " << Token << " (" << default_unit << "): "; + std::cout << " " << Token << " (" << default_unit << "): "; for(unsigned int i = 0 ; i < val.size() ; i++) - cout << val[i]/ApplyUnit(1,default_unit) << " " ; - cout << endl; + std::cout << val[i]/ApplyUnit(1,default_unit) << " " ; + std::cout << std::endl; } return val; @@ -267,10 +267,10 @@ std::vector<int> NPL::InputBlock::GetVectorInt(std::string Token){ val.push_back(buffer); if(verbose){ - cout << " " << Token << ": "; + std::cout << " " << Token << ": "; for(unsigned int i = 0 ; i < val.size() ; i++) - cout << val[i] << " " ; - cout << endl; + std::cout << val[i] << " " ; + std::cout << std::endl; } @@ -363,7 +363,7 @@ void NPL::InputParser::TreatAliases(){ int verbose = NPOptionManager::getInstance()->GetVerboseLevel(); if(verbose) - std::cout << "Using Alias : @" << alias[i]->GetMainValue() << endl; + std::cout << "Using Alias : @" << alias[i]->GetMainValue() << std::endl; std::string name="@"; name += alias[i]->GetMainValue(); @@ -410,7 +410,7 @@ void NPL::InputParser::TreatAliases(){ m_Block[b] = newBlock; } else{ - vector<NPL::InputBlock*>::iterator it = m_Block.begin(); + std::vector<NPL::InputBlock*>::iterator it = m_Block.begin(); m_Block.insert(it+b+a,newBlock); } } diff --git a/NPLib/Core/NPOptionManager.cxx b/NPLib/Core/NPOptionManager.cxx index eb522e198b87a011e66548e37a0e93749954f144..7f299c009373b6dbf07397722074694aa954e379 100644 --- a/NPLib/Core/NPOptionManager.cxx +++ b/NPLib/Core/NPOptionManager.cxx @@ -37,7 +37,7 @@ NPOptionManager* NPOptionManager::getInstance(int argc, char** argv){ } //////////////////////////////////////////////////////////////////////////////// -NPOptionManager* NPOptionManager::getInstance(string arg){ +NPOptionManager* NPOptionManager::getInstance(std::string arg){ if (instance == 0) instance = new NPOptionManager(arg); @@ -45,6 +45,10 @@ NPOptionManager* NPOptionManager::getInstance(string arg){ } void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ + if(argc==1) + DisplayHelp(); + + // Default Setting fDefaultReactionFileName = "defaultReaction.reaction"; fDefaultDetectorFileName = "defaultDetector.detector"; @@ -90,7 +94,7 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ for (int i = 0; i < argc; i++) { - string argument = argv[i]; + std::string argument = argv[i]; if (argument == "-H" || argument == "-h" || argument == "--help") DisplayHelp(); else if (argument == "--event-generator" && argc >= i + 1) fReactionFileName = argv[++i] ; @@ -111,6 +115,8 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ else if (argument == "-R" && argc >= i + 1) fRunToReadFileName = argv[++i] ; + else if (argument == "-T" && argc >= i + 2) CreateRunToTreatFile(argv[++i],argv[++i]); + else if (argument == "--cal" && argc >= i + 1) fCalibrationFileName = argv[++i] ; else if (argument == "-C" && argc >= i + 1) fCalibrationFileName = argv[++i] ; @@ -160,18 +166,34 @@ void NPOptionManager::ReadTheInputArgument(int argc, char** argv){ if(argc!=0) DisplayVersion(); } +//////////////////////////////////////////////////////////////////////////////// +void NPOptionManager::CreateRunToTreatFile(std::string file, std::string tree){ + + std::ofstream run(".RunToTreat.txt"); + if(!run.is_open()) + exit(1); + + run << "TTreeName" << std::endl; + run << " " << tree << std::endl; + run << "RootFileName" << std::endl; + run << " " << file << std::endl << std::endl; + run.close(); + fRunToReadFileName=".RunToTreat.txt"; + } + + //////////////////////////////////////////////////////////////////////////////// void NPOptionManager::DisplayVersion(){ if(fVerboseLevel>0){ - string line; + std::string line; line.resize(80,'*'); - cout << line << endl; - cout << "*********************************** NPTool ***********************************"<< endl; - cout << line << endl; - cout << " NPLib version: nplib-"<< NPL::version_major <<"-" << NPL::version_minor << "-" << NPL::version_deta <<endl; - cout << " Copyright: NPTool Collaboration "<<endl; - cout << " GitHub: http://github.com/adrien-matta/nptool"<<endl; ; - cout << line << endl; + std::cout << line << std::endl; + std::cout << "*********************************** NPTool ***********************************"<< std::endl; + std::cout << line << std::endl; + std::cout << " NPLib version: nplib-"<< NPL::version_major <<"-" << NPL::version_minor << "-" << NPL::version_deta <<std::endl; + std::cout << " Copyright: NPTool Collaboration "<<std::endl; + std::cout << " GitHub: http://github.com/adrien-matta/nptool"<<std::endl; ; + std::cout << line << std::endl; } } @@ -180,11 +202,11 @@ NPOptionManager::NPOptionManager(int argc, char** argv){ ReadTheInputArgument(argc,argv); } //////////////////////////////////////////////////////////////////////////////// -NPOptionManager::NPOptionManager(string arg){ - vector<char *> args; - istringstream iss(arg); +NPOptionManager::NPOptionManager(std::string arg){ + std::vector<char *> args; + std::stringstream iss(arg); - string token; + std::string token; while(iss >> token) { char *arg = new char[token.size() + 1]; copy(token.begin(), token.end(), arg); @@ -211,11 +233,11 @@ void NPOptionManager::CheckEventGenerator(){ bool checkFile = true; // NPTool path - string GlobalPath = getenv("NPTOOL"); - string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + fReactionFileName; + std::string GlobalPath = getenv("NPTOOL"); + std::string StandardPath = GlobalPath + "/Inputs/EventGenerator/" + fReactionFileName; // ifstream to configfile - ifstream ConfigFile; + std::ifstream ConfigFile; // test if config file is in local path ConfigFile.open(fReactionFileName.c_str()); @@ -241,11 +263,11 @@ void NPOptionManager::CheckDetectorConfiguration(){ bool checkFile = true; // NPTool path - string GlobalPath = getenv("NPTOOL"); - string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + fDetectorFileName; + std::string GlobalPath = getenv("NPTOOL"); + std::string StandardPath = GlobalPath + "/Inputs/DetectorConfiguration/" + fDetectorFileName; // ifstream to configfile - ifstream ConfigFile; + std::ifstream ConfigFile; // test if config file is in local path ConfigFile.open(fDetectorFileName.c_str()); @@ -273,7 +295,7 @@ void NPOptionManager::CheckG4Macro(){ return ; // ifstream to configfile - ifstream MacroFile( fG4MacroPath ); + std::ifstream MacroFile( fG4MacroPath ); if (!MacroFile.is_open()) { SendErrorAndExit("G4MacroPath"); @@ -288,7 +310,7 @@ void NPOptionManager::CheckG4Macro(){ bool NPOptionManager::IsDefault(const char* type) const{ bool result = false; - string stype = type; + std::string stype = type; if (stype == "EventGenerator") { if (fReactionFileName == fDefaultReactionFileName) result = true; } @@ -312,7 +334,7 @@ bool NPOptionManager::IsDefault(const char* type) const{ } else { - cout << "NPOptionManager::IsDefault() unkwown keyword" << endl; + std::cout << "NPOptionManager::IsDefault() unkwown keyword" << std::endl; } return result; @@ -322,21 +344,21 @@ bool NPOptionManager::IsDefault(const char* type) const{ //////////////////////////////////////////////////////////////////////////////// // This method tests if the input files are the default ones void NPOptionManager::SendErrorAndExit(const char* type) const{ - string stype = type; + std::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; + std::cout << std::endl; + std::cout << "********************************** Error **********************************" << std::endl; + std::cout << "* No event generator file found in $NPTool/Inputs/EventGenerator or local directories *" << std::endl; + std::cout << "***************************************************************************************" << std::endl; + std::cout << std::endl; exit(1); } else if (stype == "DetectorConfiguration") { - cout << endl; - cout << "*********************************** Error ***********************************" << endl; - cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" << endl; - cout << "*****************************************************************************************" << endl; - cout << endl; + std::cout << std::endl; + std::cout << "*********************************** Error ***********************************" << std::endl; + std::cout << "* No detector geometry file found in $NPTool/Inputs/DetectorConfiguration or local directories *" << std::endl; + std::cout << "*****************************************************************************************" << std::endl; + std::cout << std::endl; exit(1); } else if (stype == "Calibration") { @@ -344,16 +366,16 @@ void NPOptionManager::SendErrorAndExit(const char* type) const{ else if (stype == "RunToTreat") { } else if (stype == "G4MacroPath") { - cout << endl; - cout << "*********************************** Error ***********************************" << endl; - cout << "* No Geant4 macro file found in the provided path *" << endl; - cout << "*****************************************************************************************" << endl; - cout << endl; + std::cout << std::endl; + std::cout << "*********************************** Error ***********************************" << std::endl; + std::cout << "* No Geant4 macro file found in the provided path *" << std::endl; + std::cout << "*****************************************************************************************" << std::endl; + std::cout << std::endl; exit(1); } else { - cout << "NPOptionManager::SendErrorAndExit() unkwown keyword" << endl; + std::cout << "NPOptionManager::SendErrorAndExit() unkwown keyword" << std::endl; } } @@ -361,34 +383,36 @@ void NPOptionManager::SendErrorAndExit(const char* type) const{ //////////////////////////////////////////////////////////////////////////////// void NPOptionManager::DisplayHelp(){ DisplayVersion(); - cout << endl << "----NPOptionManager Help----" << endl << endl ; - cout << "List of Option " << endl ; - cout << "\t--help -H -h\t\t\tDisplay this help message" << endl ; - cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << endl ; - cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << endl ; - cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << endl ; - cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << endl ; - cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<endl; - cout << "\t\t\t\t\tError and warning are not affected" << endl ; - cout << endl << "NPAnalysis only:"<<endl; - cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << endl ; - cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << endl ; - cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" << endl ; - cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << endl ; - cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << endl ; - cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << endl ; - cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << endl ; - cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << endl ; - cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << endl ; - cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << endl ; - cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << endl ; - cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" << endl ; - cout << "\t--online \t\t\tStart the spectra server" << endl ; - cout << endl << "NPSimulation only:"<<endl; - cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << endl ; - cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << endl ; - - cout << endl << endl ; + std::cout << std::endl << "----NPOptionManager Help----" << std::endl << std::endl ; + std::cout << "List of Option " << std::endl ; + std::cout << "\t--help -H -h\t\t\tDisplay this help message" << std::endl ; + std::cout << "\t--detector -D <arg>\t\tSet arg as the detector configuration file" << std::endl ; + std::cout << "\t--event-generator -E <arg>\tSet arg as the event generator file" << std::endl ; + std::cout << "\t--output -O <arg>\t\tSet arg as the Output File Name (output tree)" << std::endl ; + std::cout << "\t--tree-name <arg>\t\tSet arg as the Output Tree Name " << std::endl ; + std::cout << "\t--verbose -V <arg>\t\tSet the verbose level, 0 for nothing, 1 for normal printout."<<std::endl; + std::cout << "\t\t\t\t\tError and warning are not affected" << std::endl ; + std::cout << std::endl << "NPAnalysis only:"<<std::endl; + std::cout << "\t--run -R <arg>\t\t\tSet arg as the run to read file list" << std::endl ; + std::cout << "\t-T <name> <file>\t\tTree <name> from root file <file>" << std::endl ; + + std::cout << "\t--cal -C <arg>\t\t\tSet arg as the calibration file list" << std::endl ; + std::cout << "\t--disable-branch\t\tDisable of branch of Input tree except the one of the detector (faster)" << std::endl ; + std::cout << "\t--generate-histo -GH\t\tInstantiate the T*Spectra class of each detector" << std::endl ; + std::cout << "\t--check-histo -CH\t\tCheck if the Histogram looks ok and change there color if not" << std::endl ; + std::cout << "\t--input-physical -IP\t\tConsider the Input file is containing Physics Class." << std::endl ; + std::cout << "\t-L <arg>\t\t\tLimit the number of events to be analysed to arg" << std::endl ; + std::cout << "\t-F <arg>\t\t\tSet the first event to analyse to arg (analysis goes from F -> L+F)" << std::endl ; + std::cout << "\t--last-sim\t\t\tIgnore the list of Run to treat if any and analysed the last simulated file" << std::endl ; + std::cout << "\t--last-phy\t\t\tIgnore the list of Run to treat if any and analysed the last Physics file" << std::endl ; + std::cout << "\t--last-res\t\t\tIgnore the list of Run to treat if any and analysed the last Result file" << std::endl ; + std::cout << "\t--last-any\t\t\tIgnore the list of Run to treat if any and analysed the last generated root file" << std::endl ; + std::cout << "\t--online \t\t\tStart the spectra server" << std::endl ; + std::cout << std::endl << "NPSimulation only:"<<std::endl; + std::cout << "\t-M <arg>\t\t\tExecute Geant4 macro <arg> at startup" << std::endl ; + std::cout << "\t-B <arg>\t\t\tExecute in batch mode (no ui) with Geant4 macro <arg> at startup" << std::endl ; + + std::cout << std::endl << std::endl ; // exit current program exit(0); @@ -403,8 +427,8 @@ void NPOptionManager::Destroy(){ } } //////////////////////////////////////////////////////////////////////////////// -string NPOptionManager::GetLastFile(){ - string path = getenv("NPTOOL"); +std::string NPOptionManager::GetLastFile(){ + std::string path = getenv("NPTOOL"); if(fLastSimFile) return (path+"/.last_sim_file"); diff --git a/NPLib/Core/NPOptionManager.h b/NPLib/Core/NPOptionManager.h index eaece873a6d061ccc5ac2b20214bc8350a5a2d1e..88fe77f63d89942ce2319cc5b4a6a1c878e73103 100644 --- a/NPLib/Core/NPOptionManager.h +++ b/NPLib/Core/NPOptionManager.h @@ -26,7 +26,6 @@ // C++ headers #include <iostream> #include <string> -using namespace std; class NPOptionManager{ public: @@ -38,7 +37,7 @@ class NPOptionManager{ static NPOptionManager* getInstance(int argc = 0, char** argv = NULL); // Added for compatibility with pROOF - static NPOptionManager* getInstance(string arg); + static NPOptionManager* getInstance(std::string arg); // The analysis class instance can be deleted by calling the Destroy // method (NOTE: The class destructor is protected, and can thus not be @@ -48,7 +47,7 @@ class NPOptionManager{ protected: // Constructor (protected) NPOptionManager(int argc, char** argv); - NPOptionManager(string arg); + NPOptionManager(std::string arg); // Destructor (protected) ~NPOptionManager() {}; @@ -60,7 +59,7 @@ class NPOptionManager{ private: // Read the input argument void ReadTheInputArgument(int argc = 0, char** argv = NULL); - + private: // The static instance of the NPOptionManager class: static NPOptionManager* instance; @@ -72,7 +71,7 @@ class NPOptionManager{ void CheckEventGenerator(); void CheckDetectorConfiguration(); void CheckG4Macro(); - + void CreateRunToTreatFile(std::string file, std::string tree ); public: bool IsDefault(const char* type) const; void SendErrorAndExit(const char* type) const; @@ -80,21 +79,21 @@ class NPOptionManager{ public: // Getters // default values - string GetDefaultReactionFile() {return fDefaultReactionFileName;} - string GetDefaultDetectorFile() {return fDefaultDetectorFileName;} - string GetDefaultRunToReadFile() {return fDefaultRunToReadFileName;} - string GetDefaultCalibrationFile() {return fDefaultCalibrationFileName;} - string GetDefaultOutputFile() {return fDefaultOutputFileName;} - string GetDefaultG4MacroPath() {return fDefaultG4MacroPath;} + std::string GetDefaultReactionFile() {return fDefaultReactionFileName;} + std::string GetDefaultDetectorFile() {return fDefaultDetectorFileName;} + std::string GetDefaultRunToReadFile() {return fDefaultRunToReadFileName;} + std::string GetDefaultCalibrationFile() {return fDefaultCalibrationFileName;} + std::string GetDefaultOutputFile() {return fDefaultOutputFileName;} + std::string GetDefaultG4MacroPath() {return fDefaultG4MacroPath;} // assigned values - string GetReactionFile() {return fReactionFileName;} - string GetDetectorFile() {return fDetectorFileName;} - string GetRunToReadFile() {return fRunToReadFileName;} - string GetCalibrationFile() {return fCalibrationFileName;} - string GetOutputFile() {return fOutputFileName;} - string GetOutputTreeName() {return fOutputTreeName;} - string GetG4MacroPath() {return fG4MacroPath;} + std::string GetReactionFile() {return fReactionFileName;} + std::string GetDetectorFile() {return fDetectorFileName;} + std::string GetRunToReadFile() {return fRunToReadFileName;} + std::string GetCalibrationFile() {return fCalibrationFileName;} + std::string GetOutputFile() {return fOutputFileName;} + std::string GetOutputTreeName() {return fOutputTreeName;} + std::string GetG4MacroPath() {return fG4MacroPath;} bool GetDisableAllBranchOption() {return fDisableAllBranchOption;} bool GetInputPhysicalTreeOption() {return fInputPhysicalTreeOption;} @@ -106,32 +105,32 @@ class NPOptionManager{ int GetVerboseLevel() {return fVerboseLevel;} int GetNumberOfEntryToAnalyse() {return fNumberOfEntryToAnalyse;} int GetFirstEntryToAnalyse() {return fFirstEntryToAnalyse;} - string GetSharedLibExtension() {return fSharedLibExtension;} - string GetLastFile(); + std::string GetSharedLibExtension() {return fSharedLibExtension;} + std::string GetLastFile(); // Setters - void SetReactionFile(string name) {fReactionFileName = name;CheckEventGenerator();} - void SetDetectorFile(string name) {fDetectorFileName = name;CheckDetectorConfiguration();} - void SetRunToReadFile(string name) {fRunToReadFileName = name;} - void SetVerboseLevel(int VerboseLevel) {fVerboseLevel = VerboseLevel;} + void SetReactionFile(const std::string& name) {fReactionFileName = name;CheckEventGenerator();} + void SetDetectorFile(const std::string& name) {fDetectorFileName = name;CheckDetectorConfiguration();} + void SetRunToReadFile(const std::string& name) {fRunToReadFileName = name;} + void SetVerboseLevel(int VerboseLevel) {fVerboseLevel = VerboseLevel;} private: // default values - string fDefaultReactionFileName; - string fDefaultDetectorFileName; - string fDefaultRunToReadFileName; - string fDefaultCalibrationFileName; - string fDefaultOutputFileName; - string fDefaultOutputTreeName; - string fDefaultG4MacroPath; + std::string fDefaultReactionFileName; + std::string fDefaultDetectorFileName; + std::string fDefaultRunToReadFileName; + std::string fDefaultCalibrationFileName; + std::string fDefaultOutputFileName; + std::string fDefaultOutputTreeName; + std::string fDefaultG4MacroPath; // assigned values - string fReactionFileName; - string fDetectorFileName; - string fRunToReadFileName; - string fCalibrationFileName; - string fOutputFileName; - string fOutputTreeName; + std::string fReactionFileName; + std::string fDetectorFileName; + std::string fRunToReadFileName; + std::string fCalibrationFileName; + std::string fOutputFileName; + std::string fOutputTreeName; bool fDisableAllBranchOption; bool fInputPhysicalTreeOption; bool fGenerateHistoOption; @@ -145,8 +144,8 @@ class NPOptionManager{ int fVerboseLevel; // 0 for not talk, 1 for talking int fNumberOfEntryToAnalyse; // use to limit the number of analysed in NPA int fFirstEntryToAnalyse; // use to set the first event analysed in NPA (total: fFirstEntryToAnalyse -> fFirstEntryToAnalyse + fNumberOfEntryToAnalyse) - string fSharedLibExtension; // lib extension is platform dependent - string fG4MacroPath; // Path to a geant4 macro to execute at start of nps + std::string fSharedLibExtension; // lib extension is platform dependent + std::string fG4MacroPath; // Path to a geant4 macro to execute at start of nps bool fG4BatchMode; // Execute geant4 in batch mode, running the given macro }; diff --git a/NPLib/Core/NPVDetector.cxx b/NPLib/Core/NPVDetector.cxx index 1304148c4c9df60ccac029f4128e938807490392..b30be66c33cb731f7d6e9ac65221777b493be1a4 100644 --- a/NPLib/Core/NPVDetector.cxx +++ b/NPLib/Core/NPVDetector.cxx @@ -24,20 +24,14 @@ *****************************************************************************/ #include "NPVDetector.h" #include "NPOptionManager.h" -using namespace NPL ; -ClassImp(VDetector); +ClassImp(NPL::VDetector); // Constructor -VDetector::VDetector(){ +NPL::VDetector::VDetector(){ } // Destructor -VDetector::~VDetector(){ +NPL::VDetector::~VDetector(){ } - -//////////////////////////////////////////////////////////////////////////////// -namespace NPL{ -} - diff --git a/NPLib/Core/NPVSpectra.h b/NPLib/Core/NPVSpectra.h index 36b3339cf7b7a06b809a36e6ea2a0b1840782d86..c9e26adb56d5eb31c73ecf4c052b33c6c3d417c9 100644 --- a/NPLib/Core/NPVSpectra.h +++ b/NPLib/Core/NPVSpectra.h @@ -30,7 +30,6 @@ #include <map> #include <vector> #include <string> -using namespace std; class VSpectra { public: @@ -39,10 +38,10 @@ class VSpectra { virtual ~VSpectra(){}; public: - // Instantiate and register histo to maps - TH1* AddHisto1D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, string family); - TH1* AddHisto2D(string name, string title, Int_t nbinsx, Double_t xlow, Double_t xup, - Int_t nbinsy, Double_t ylow, Double_t yup, string family); + // Instantiate and register histo to std::maps + TH1* AddHisto1D(std::string name, std::string title, Int_t nbinsx, Double_t xlow, Double_t xup, std::string family); + TH1* AddHisto2D(std::string name, std::string title, Int_t nbinsx, Double_t xlow, Double_t xup, + Int_t nbinsy, Double_t ylow, Double_t yup, std::string family); public: // Initialization methods @@ -58,32 +57,32 @@ class VSpectra { virtual void CheckSpectra(){}; public: - // get map histo which will be used for GSpectra in GUser - map< string, TH1* > GetMapHisto() const {return fMapHisto;} - TH1* GetSpectra(const string& family, const string& name); - TH1* GetSpectra(const string& FamilyAndName); + // get std::map histo which will be used for GSpectra in GUser + std::map< std::string, TH1* > GetMapHisto() const {return fMapHisto;} + TH1* GetSpectra(const std::string& family, const std::string& name); + TH1* GetSpectra(const std::string& FamilyAndName); // TEMP FIX -// TH1* GetHisto(const string& family, const string& name){return GetSpectra(family,name);}; -// TH1* GetHisto(const string& FamilyAndName){return GetSpectra(FamilyAndName);}; +// TH1* GetHisto(const std::string& family, const std::string& name){return GetSpectra(family,name);}; +// TH1* GetHisto(const std::string& FamilyAndName){return GetSpectra(FamilyAndName);}; - void FillSpectra(const string& family, const string& name, double val); - void FillSpectra(const string& family, const string& name, double x, double y); - void FillSpectra(const string& familyAndname, double val); - void FillSpectra(const string& familyAndname, double x, double y); + void FillSpectra(const std::string& family, const std::string& name, double val); + void FillSpectra(const std::string& family, const std::string& name, double x, double y); + void FillSpectra(const std::string& familyAndname, double val); + void FillSpectra(const std::string& familyAndname, double x, double y); - void WriteSpectra(string filename = "VOID"); + void WriteSpectra(std::string filename = "VOID"); protected: - // map holding histo pointers and their family names - map< string, TH1* > fMapHisto; + // std::map holding histo pointers and their family names + std::map< std::string, TH1* > fMapHisto; private: // Name of the Detector - string m_name; + std::string m_name; public: - inline void SetName(string name) {m_name=name;} - inline string GetName() {return m_name;} + inline void SetName(std::string name) {m_name=name;} + inline std::string GetName() {return m_name;} }; #endif diff --git a/NPLib/Core/RootInput.cxx b/NPLib/Core/RootInput.cxx index e6393c049a0df1f022e2218ebfe9b6ec0bf63259..bfbb7929572c6198b4e3265b2578435bf4a2bf7b 100644 --- a/NPLib/Core/RootInput.cxx +++ b/NPLib/Core/RootInput.cxx @@ -30,10 +30,11 @@ #include "RootInput.h" #include "TAsciiFile.h" #include "NPOptionManager.h" +#include "NPInputParser.h" RootInput* RootInput::instance = 0; //////////////////////////////////////////////////////////////////////////////// -RootInput* RootInput::getInstance(string configFileName){ +RootInput* RootInput::getInstance(std::string configFileName){ // A new instance of RootInput is created if it does not exist: if (instance == 0) { instance = new RootInput(configFileName); @@ -52,8 +53,8 @@ void RootInput::Destroy(){ } //////////////////////////////////////////////////////////////////////////////// -RootInput::RootInput(string configFileName){ - string lastfile= NPOptionManager::getInstance()->GetLastFile(); +RootInput::RootInput(std::string configFileName){ + std::string lastfile= NPOptionManager::getInstance()->GetLastFile(); if(lastfile!="VOID"){ configFileName = lastfile; } @@ -63,40 +64,36 @@ RootInput::RootInput(string configFileName){ bool CheckRootFileName = false; // Read configuration file Buffer - string lineBuffer, dataBuffer; + std::string lineBuffer, dataBuffer; // Open file - cout << endl; - cout << "/////////// ROOT Input files ///////////" << endl; - cout << "Initializing input TChain" << endl; + std::cout << std::endl; + std::cout << "/////////// ROOT Input files ///////////" << std::endl; + std::cout << "Initializing input TChain using: " << configFileName << std::endl; - ifstream inputConfigFile; + std::ifstream inputConfigFile; inputConfigFile.open(configFileName.c_str()); - pRootFile = NULL; - pRootChain = new TChain(); - if (!inputConfigFile.is_open()) { - cout << "\033[1;31mWarning : Run to Read file: " << configFileName << " not found\033[0m" << endl; + std::cout << "\033[1;31mWarning : Run to Read file: " << configFileName << " not found\033[0m" << std::endl; //exit(1); } else { while (!inputConfigFile.eof()) { getline(inputConfigFile, lineBuffer); - // search for token giving the TTree name if (lineBuffer.compare(0, 9, "TTreeName") == 0) { inputConfigFile >> dataBuffer; // initialize pRootChain - pRootChain->SetName(dataBuffer.c_str()); + pRootChain = new TChain(dataBuffer.c_str()); CheckTreeName = true ; // If the tree come from a simulation, the InteractionCoordinates // and InitialConditions lib are loaded if(dataBuffer=="SimulatedTree"){ - string path = getenv("NPTOOL"); + std::string path = getenv("NPTOOL"); path+="/NPLib/lib/"; - string libName="libNPInteractionCoordinates"+NPOptionManager::getInstance()->GetSharedLibExtension(); + std::string libName="libNPInteractionCoordinates"+NPOptionManager::getInstance()->GetSharedLibExtension(); libName=path+libName; dlopen(libName.c_str(),RTLD_NOW); libName="libNPInitialConditions"+NPOptionManager::getInstance()->GetSharedLibExtension(); @@ -119,16 +116,16 @@ RootInput::RootInput(string configFileName){ else if (!inputConfigFile.eof()) { pRootChain->Add(dataBuffer.c_str()); - cout << "Adding file " << dataBuffer << " to TChain" << endl; + std::cout << "Adding file " << dataBuffer << " to TChain" << std::endl; // Test if the file is a regex or a single file double counts; - string command = "ls " + dataBuffer + " > .ls_return"; + std::string command = "ls " + dataBuffer + " > .ls_return"; counts= system(command.c_str()); - ifstream return_ls(".ls_return"); + std::ifstream return_ls(".ls_return"); - string files; - string firstfile; + std::string files; + std::string firstfile; while(return_ls >> files){ if(counts == 0) firstfile = files; @@ -142,43 +139,43 @@ RootInput::RootInput(string configFileName){ } } if( pRootChain->GetEntries() ==0){ - cout << "\033[1;31m**** ERROR: No entries to analyse ****\033[0m" << endl; + std::cout << "\033[1;31m**** ERROR: No entries to analyse ****\033[0m" << std::endl; exit(1); } else{ - cout << "\033[1;32mROOTInput: " << pRootChain->GetEntries() << " entries loaded in the input chain\033[0m" << endl ; + std::cout << "\033[1;32mROOTInput: " << pRootChain->GetEntries() << " entries loaded in the input chain\033[0m" << std::endl ; } } if (!CheckRootFileName || !CheckTreeName) - cout << "\033[1;33mWARNING: Token not found for InputTree Declaration : Input Tree may not be instantiate properly\033[0m" << endl; + std::cout << "\033[1;33mWARNING: Token not found for InputTree Declaration : Input Tree may not be instantiate properly\033[0m" << std::endl; } //////////////////////////////////////////////////////////////////////////////// -void RootInput::AddFriendChain(string RunToAdd){ +void RootInput::AddFriendChain(std::string RunToAdd){ NumberOfFriend++; - ostringstream suffix_buffer; + std::ostringstream suffix_buffer; suffix_buffer << "_" << NumberOfFriend ; - string suffix = suffix_buffer.str(); + std::string suffix = suffix_buffer.str(); bool CheckTreeName = false; bool CheckRootFileName = false; // Read configuration file Buffer - string lineBuffer, dataBuffer; + std::string lineBuffer, dataBuffer; // Open file - ifstream inputConfigFile; + std::ifstream inputConfigFile; inputConfigFile.open(RunToAdd.c_str()); TChain* localChain = new TChain(); - - cout << "/////////////////////////////////" << endl; - cout << "Adding friend to current TChain" << endl; + + std::cout << "/////////////////////////////////" << std::endl; + std::cout << "Adding friend to current TChain" << std::endl; if (!inputConfigFile) { - cout << "Run to Add file :" << RunToAdd << " not found " << endl; + std::cout << "Run to Add file :" << RunToAdd << " not found " << std::endl; return; } @@ -210,7 +207,7 @@ void RootInput::AddFriendChain(string RunToAdd){ else if (!inputConfigFile.eof()) { localChain->Add(dataBuffer.c_str()); - cout << "Adding file " << dataBuffer << " to TChain" << endl; + std::cout << "Adding file " << dataBuffer << " to TChain" << std::endl; } } } @@ -218,38 +215,38 @@ void RootInput::AddFriendChain(string RunToAdd){ } if (!CheckRootFileName || !CheckTreeName) - cout << "WARNING: Token not found for InputTree Declaration : Input Tree has not be Added to the current Chain" << endl; + std::cout << "WARNING: Token not found for InputTree Declaration : Input Tree has not be Added to the current Chain" << std::endl; else pRootChain->AddFriend( localChain->GetName() ); - cout << "/////////////////////////////////" << endl; + std::cout << "/////////////////////////////////" << std::endl; } //////////////////////////////////////////////////////////////////////////////// -string RootInput::DumpAsciiFile(const char* type, const char* folder){ - string name="fail"; +std::string RootInput::DumpAsciiFile(const char* type, const char* folder){ + std::string name="fail"; - string sfolder = folder; + std::string sfolder = folder; // create folder if not existing // first test if folder exist struct stat dirInfo; int res = stat(folder, &dirInfo); if (res != 0) { // if folder does not exist, create it - string cmd = "mkdir " + sfolder; - if (system(cmd.c_str()) != 0) cout << "RootInput::DumpAsciiFile() problem creating directory" << endl; + std::string cmd = "mkdir " + sfolder; + if (system(cmd.c_str()) != 0) std::cout << "RootInput::DumpAsciiFile() problem creating directory" << std::endl; } - string stype = type; + std::string stype = type; if (stype == "EventGenerator") { TAsciiFile *aFile = (TAsciiFile*)pRootFile->Get(stype.c_str()); if(aFile) { // build file name - string title = aFile->GetTitle(); + std::string title = aFile->GetTitle(); size_t pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); + if (pos != std::string::npos) name = sfolder + title.substr(pos); else name = sfolder + "/" + title; aFile->WriteToFile(name.c_str()); } @@ -260,9 +257,9 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){ if(aFile) { // build file name - string title = aFile->GetTitle(); + std::string title = aFile->GetTitle(); size_t pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); + if (pos != std::string::npos) name = sfolder + title.substr(pos); else name = sfolder + "/" + title; aFile->WriteToFile(name.c_str()); } @@ -273,9 +270,9 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){ if(aFile) { // build file name - string title = aFile->GetTitle(); + std::string title = aFile->GetTitle(); size_t pos = title.rfind("/"); - if (pos != string::npos) name = sfolder + title.substr(pos); + if (pos != std::string::npos) name = sfolder + title.substr(pos); else name = sfolder + "/" + title; aFile->WriteToFile(name.c_str()); } @@ -284,7 +281,7 @@ string RootInput::DumpAsciiFile(const char* type, const char* folder){ else if (stype == "RunToTreat") { } else { - cout << "RootInput::DumpAsciiFile() unkwown keyword" << endl; + std::cout << "RootInput::DumpAsciiFile() unkwown keyword" << std::endl; } return name; @@ -296,17 +293,17 @@ RootInput::~RootInput(){ struct stat dirInfo; int res = stat("./.tmp", &dirInfo); if (res == 0) { // if does exist, delete it - if (system("rm -rf ./.tmp") != 0) cout << "RootInput::~RootInput() problem deleting ./.tmp directory" << endl; + if (system("rm -rf ./.tmp") != 0) std::cout << "RootInput::~RootInput() problem deleting ./.tmp directory" << std::endl; } - cout << endl << "Root Input summary" << endl; - cout << " - Number of bites read: " << pRootFile->GetBytesRead() << endl; - cout << " - Number of transactions: " << pRootFile->GetReadCalls() << endl; + std::cout << std::endl << "Root Input summary" << std::endl; + std::cout << " - Number of bites read: " << pRootFile->GetBytesRead() << std::endl; + std::cout << " - Number of transactions: " << pRootFile->GetReadCalls() << std::endl; // Close the Root file pRootFile->Close(); } //////////////////////////////////////////////////////////////////////////////// -TChain* MakeFriendTrees(string RunToRead1,string RunToRead2){ +TChain* MakeFriendTrees(std::string RunToRead1,std::string RunToRead2){ RootInput:: getInstance(RunToRead1) ; RootInput:: getInstance()->AddFriendChain(RunToRead2); return RootInput:: getInstance()->GetChain(); diff --git a/NPLib/Core/RootInput.h b/NPLib/Core/RootInput.h index 7408ba4025fb3c638c0ad5340ff3647bfad578c6..b9cb0c6d9687f09c2b62458c24289b11b3d9c583 100644 --- a/NPLib/Core/RootInput.h +++ b/NPLib/Core/RootInput.h @@ -30,7 +30,6 @@ #include "TFile.h" #include "TChain.h" -using namespace std; class RootInput @@ -41,7 +40,7 @@ public: // 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 RootInput* getInstance(string configFileName = "configFile"); + static RootInput* getInstance(std::string configFileName = "configFile"); // The analysis class instance can be deleted by calling the Destroy // method (NOTE: The class destructor is protected, and can thus not be @@ -50,7 +49,7 @@ public: protected: // Constructor (protected) - RootInput(string configFileName); + RootInput(std::string configFileName); // Destructor (protected) virtual ~RootInput(); @@ -64,7 +63,7 @@ private: static RootInput* instance; public: - string DumpAsciiFile(const char* type, const char* folder = "./.tmp"); + std::string DumpAsciiFile(const char* type, const char* folder = "./.tmp"); public: // Return the private chain and file @@ -73,7 +72,7 @@ public: void SetChain(TChain* c) {pRootChain = c;} // Add a Friend chain to the input chain - void AddFriendChain(string RunToAdd); + void AddFriendChain(std::string RunToAdd); private: TChain *pRootChain; @@ -83,6 +82,6 @@ private: }; // A convenient function related to Root Input, coded Here so it can be called within ROOT CINT -TChain* MakeFriendTrees(string,string); +TChain* MakeFriendTrees(std::string,std::string); #endif // ROOTINPUT_HH diff --git a/NPLib/Core/RootOutput.cxx b/NPLib/Core/RootOutput.cxx index 6a4ea51986fa49371db932fba15dbfc09f57fe66..27d60c5d924318cf3f248a75b57c12bf42e886fb 100644 --- a/NPLib/Core/RootOutput.cxx +++ b/NPLib/Core/RootOutput.cxx @@ -31,10 +31,10 @@ using namespace std; RootOutput* RootOutput::instance = 0; //////////////////////////////////////////////////////////////////////////////// -RootOutput* RootOutput::getInstance(TString fileNameBase, TString treeNameBase){ +RootOutput* RootOutput::getInstance(std::string fileNameBase, std::string treeNameBase){ // A new instance of RootOutput is created if it does not exist: if (instance == 0) { - instance = new RootOutput(fileNameBase, treeNameBase); + instance = new RootOutput(fileNameBase.c_str(), treeNameBase.c_str()); } // The instance of RootOutput is returned: @@ -50,19 +50,19 @@ void RootOutput::Destroy(){ } //////////////////////////////////////////////////////////////////////////////// -RootOutput::RootOutput(TString fileNameBase, TString treeNameBase){ +RootOutput::RootOutput(std::string fileNameBase, std::string treeNameBase){ TDirectory* currentPath= gDirectory; // The file extension is added to the file name: - TString GlobalPath = getenv("NPTOOL"); + std::string GlobalPath = getenv("NPTOOL"); // The ROOT file is created if(!NPOptionManager::getInstance()->GetPROOF()){ - TString fileName = GlobalPath + "/Outputs/"; - if (fileNameBase.Contains("root")) fileName += fileNameBase; + std::string fileName = GlobalPath + "/Outputs/"; + if (fileNameBase.find("root")!=std::string::npos) fileName += fileNameBase; else fileName += fileNameBase + ".root"; - pRootFile = new TFile(fileName, "RECREATE"); + pRootFile = new TFile(fileName.c_str(), "RECREATE"); if(treeNameBase=="SimulatedTree"){ string path = getenv("NPTOOL"); @@ -118,7 +118,7 @@ RootOutput::RootOutput(TString fileNameBase, TString treeNameBase){ pRootFile = 0 ; } - pRootTree = new TTree(treeNameBase, "Data created / analysed with the NPTool package"); + pRootTree = new TTree(treeNameBase.c_str(), "Data created / analysed with the NPTool package"); pRootList = new TList(); // Init TAsciiFile objects @@ -134,35 +134,35 @@ void RootOutput::InitAsciiFiles(){ // Event generator // Get file name from NPOptionManager - TString fileNameEG = OptionManager->GetReactionFile(); + std::string fileNameEG = OptionManager->GetReactionFile(); pEventGenerator = new TAsciiFile(); - pEventGenerator->SetNameTitle("EventGenerator", fileNameEG.Data()); - pEventGenerator->Append(fileNameEG.Data()); + pEventGenerator->SetNameTitle("EventGenerator", fileNameEG.c_str()); + pEventGenerator->Append(fileNameEG.c_str()); pEventGenerator->Write(0,TAsciiFile::kOverwrite); // Detector configuration // Get file name from NPOptionManager - TString fileNameDC = OptionManager->GetDetectorFile(); + std::string fileNameDC = OptionManager->GetDetectorFile(); pDetectorConfiguration = new TAsciiFile(); - pDetectorConfiguration->SetNameTitle("DetectorConfiguration", fileNameDC.Data()); - pDetectorConfiguration->Append(fileNameDC.Data()); + pDetectorConfiguration->SetNameTitle("DetectorConfiguration", fileNameDC.c_str()); + pDetectorConfiguration->Append(fileNameDC.c_str()); pDetectorConfiguration->Write(0,TAsciiFile::kOverwrite); // Run to treat file // Get file name from NPOptionManager pRunToTreatFile = new TAsciiFile(); if (!OptionManager->IsDefault("RunToTreat")) { - TString fileNameRT = OptionManager->GetRunToReadFile(); - pRunToTreatFile->SetNameTitle("RunToTreat", fileNameRT.Data()); - pRunToTreatFile->Append(fileNameRT.Data()); + std::string fileNameRT = OptionManager->GetRunToReadFile(); + pRunToTreatFile->SetNameTitle("RunToTreat", fileNameRT.c_str()); + pRunToTreatFile->Append(fileNameRT.c_str()); pRunToTreatFile->Write(0,TAsciiFile::kOverwrite); } // Calibration files pCalibrationFile = new TAsciiFile(); if (!OptionManager->IsDefault("Calibration")) { - TString fileNameCal = OptionManager->GetCalibrationFile(); - pCalibrationFile->SetNameTitle("Calibration", fileNameCal.Data()); + std::string fileNameCal = OptionManager->GetCalibrationFile(); + pCalibrationFile->SetNameTitle("Calibration", fileNameCal.c_str()); pCalibrationFile->Write(0,TAsciiFile::kOverwrite); } @@ -197,7 +197,6 @@ RootOutput::~RootOutput(){ cout << endl << "Root Output summary" << endl; cout << " - Number of entries in the Tree: " << pRootTree->GetEntries() << endl; cout << " - Number of bites written to file: " << pRootTree->Write(0, TObject::kOverwrite) << endl; - pRootFile->Flush(); pRootFile->Purge(1); @@ -227,14 +226,14 @@ RootOutput::~RootOutput(){ } //////////////////////////////////////////////////////////////////////////////// -TFile* RootOutput::InitFile(TString fileNameBase){ +TFile* RootOutput::InitFile(std::string fileNameBase){ if(NPOptionManager::getInstance()->GetPROOF()){ - TString GlobalPath = getenv("NPTOOL"); - TString fileName = GlobalPath + "/Outputs/Analysis/"; - if (fileNameBase.Contains("root")) fileName += fileNameBase; + std::string GlobalPath = getenv("NPTOOL"); + std::string fileName = GlobalPath + "/Outputs/Analysis/"; + if (fileNameBase.find("root")!=std::string::npos) fileName += fileNameBase; else fileName += fileNameBase + ".root"; - pRootFile = new TFile(fileName, "RECREATE"); + pRootFile = new TFile(fileName.c_str(), "RECREATE"); pRootFile->Flush(); return pRootFile; } diff --git a/NPLib/Core/RootOutput.h b/NPLib/Core/RootOutput.h index 25fca941286f49ce5ada6bb4bee848d0419f7d01..2ac1db6018403851367dd5f29259c46c369bbc9f 100644 --- a/NPLib/Core/RootOutput.h +++ b/NPLib/Core/RootOutput.h @@ -28,11 +28,10 @@ #include "TAsciiFile.h" // ROOT headers -#include "TString.h" #include "TFile.h" #include "TTree.h" #include "TList.h" - +#include <string> class RootOutput{ public: @@ -41,8 +40,8 @@ public: // 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 RootOutput* getInstance(TString fileNameBase = "Simulation", - TString treeNameBase = "SimulatedTree"); + static RootOutput* getInstance(std::string fileNameBase = "Simulation", + std::string treeNameBase = "SimulatedTree"); // The analysis class instance can be deleted by calling the Destroy // method (NOTE: The class destructor is protected, and can thus not be @@ -51,7 +50,7 @@ public: protected: // Constructor (protected) - RootOutput(TString fileNameBase, TString treeNameBase); + RootOutput(std::string fileNameBase, std::string treeNameBase); // Destructor (protected) virtual ~RootOutput(); @@ -76,7 +75,7 @@ public: TAsciiFile* GetAsciiFileCalibration() {return pCalibrationFile;} TAsciiFile* GetAsciiFileRunToTreat() {return pRunToTreatFile;} TAsciiFile* GetAsciiFileAnalysisConfig() {return pAnalysisConfigFile;} - TFile* InitFile(TString fileNameBase); // use only for proof environment + TFile* InitFile(std::string fileNameBase); // use only for proof environment private: TFile *pRootFile; diff --git a/NPLib/Core/TAsciiFile.h b/NPLib/Core/TAsciiFile.h index 249ab7b66e9f9819a4877a45aa28517f8d37b93e..e1ac5e248db9d62821f1168be0a824d0a76d01f3 100644 --- a/NPLib/Core/TAsciiFile.h +++ b/NPLib/Core/TAsciiFile.h @@ -28,12 +28,11 @@ // C++ headers #include <vector> #include <string> -using namespace std; class TAsciiFile : public TNamed { private : - vector<string> fLines; + std::vector<std::string> fLines; protected : void ReadFile(const char* inputAsciiFile); diff --git a/NPLib/Detectors/CATS/TCATSData.cxx b/NPLib/Detectors/CATS/TCATSData.cxx index d3cc32c309f68fb8f4aa4be57eed5b19ff2862c5..35d95af297c3bb2c699a43a1b01c22ffed68c86f 100644 --- a/NPLib/Detectors/CATS/TCATSData.cxx +++ b/NPLib/Detectors/CATS/TCATSData.cxx @@ -25,22 +25,13 @@ ClassImp(TCATSData) - -TCATSData::TCATSData() -{ - // Default constructor - - Clear(); +//////////////////////////////////////////////////////////////////////////////// +TCATSData::TCATSData(){ } - - - -TCATSData::~TCATSData() -{ +//////////////////////////////////////////////////////////////////////////////// +TCATSData::~TCATSData(){ } - - - +//////////////////////////////////////////////////////////////////////////////// void TCATSData::Clear() { // X @@ -55,9 +46,7 @@ void TCATSData::Clear() fCATS_DetQ.clear(); fCATS_Charge.clear(); } - - - +//////////////////////////////////////////////////////////////////////////////// void TCATSData::Dump() const { cout << "XXXXXXXXXXXXXXXXXXXXXXXX New Event XXXXXXXXXXXXXXXXX" << endl; diff --git a/NPLib/Detectors/CATS/TCATSData.h b/NPLib/Detectors/CATS/TCATSData.h index 4b166849a0afe6465e86cd155769ab7c5a8b0b24..69dcc497462be7996fee8fdf436a491ed831455b 100644 --- a/NPLib/Detectors/CATS/TCATSData.h +++ b/NPLib/Detectors/CATS/TCATSData.h @@ -73,18 +73,18 @@ class TCATSData : public TObject { ///////////////////// GETTERS //////////////////////// // X inline UShort_t GetCATSMultX() const {return fCATS_DetX.size();} - inline UShort_t GetCATSDetX(const Int_t& i) const {return fCATS_DetX.at(i);} - inline UShort_t GetCATSStripX(const Int_t& i) const {return fCATS_StripX.at(i);} - inline UShort_t GetCATSChargeX(const Int_t& i) const {return fCATS_ChargeX.at(i);} + inline UShort_t GetCATSDetX(const Int_t& i) const {return fCATS_DetX[i];} + inline UShort_t GetCATSStripX(const Int_t& i) const {return fCATS_StripX[i];} + inline UShort_t GetCATSChargeX(const Int_t& i) const {return fCATS_ChargeX[i];} // Y inline UShort_t GetCATSMultY() const {return fCATS_DetY.size();} - inline UShort_t GetCATSDetY(const Int_t& i) const {return fCATS_DetY.at(i);} - inline UShort_t GetCATSStripY(const Int_t& i) const {return fCATS_StripY.at(i);} - inline UShort_t GetCATSChargeY(const Int_t& i) const {return fCATS_ChargeY.at(i);} + inline UShort_t GetCATSDetY(const Int_t& i) const {return fCATS_DetY[i];} + inline UShort_t GetCATSStripY(const Int_t& i) const {return fCATS_StripY[i];} + inline UShort_t GetCATSChargeY(const Int_t& i) const {return fCATS_ChargeY[i];} //Q fil inline UShort_t GetCATSMultQ() const {return fCATS_DetQ.size();} - inline UShort_t GetCATSDetQ(const Int_t& i) const {return fCATS_DetQ.at(i);} - inline UShort_t GetCATSCharge(const Int_t& i) const {return fCATS_Charge.at(i);} + inline UShort_t GetCATSDetQ(const Int_t& i) const {return fCATS_DetQ[i];} + inline UShort_t GetCATSCharge(const Int_t& i) const {return fCATS_Charge[i];} ClassDef(TCATSData,2) // CATSData structure }; diff --git a/NPLib/Detectors/CATS/TCATSPhysics.cxx b/NPLib/Detectors/CATS/TCATSPhysics.cxx index 916cb16b978888725d54ed8f57efb4739f35c2b8..68181d8b0761c67b0344f5964f5356bdf55f03bc 100644 --- a/NPLib/Detectors/CATS/TCATSPhysics.cxx +++ b/NPLib/Detectors/CATS/TCATSPhysics.cxx @@ -435,7 +435,7 @@ void TCATSPhysics::Clear(){ } //////////////////////////////////////////////////////////////////////////// -bool TCATSPhysics :: IsValidChannel(const string DetectorType, const int Detector , const int channel) { +bool TCATSPhysics :: IsValidChannel(const string& DetectorType, const int& Detector , const int& channel) { if(DetectorType == "X") return *(m_XChannelStatus[Detector-1].begin()+channel-1); diff --git a/NPLib/Detectors/CATS/TCATSPhysics.h b/NPLib/Detectors/CATS/TCATSPhysics.h index ab5b2860b69d3eca78dcec6548b99e53e60c6211..ee9730b1b5792411594c7792c9b6556a75ca520c 100644 --- a/NPLib/Detectors/CATS/TCATSPhysics.h +++ b/NPLib/Detectors/CATS/TCATSPhysics.h @@ -171,7 +171,7 @@ class TCATSPhysics : public TObject, public NPL::VDetector void SetRawDataPointer(void* rawDataPointer) {m_EventData = (TCATSData*)rawDataPointer;} // Return false if the channel is disabled by user - bool IsValidChannel(const string DetectorType, const int Detector , const int channel); + bool IsValidChannel(const string& DetectorType, const int& Detector , const int& channel); void InitializeStandardParameter(); void AddParameterToCalibrationManager(); void ReadAnalysisConfig(); @@ -213,12 +213,12 @@ namespace CATS_LOCAL{ // tranform an integer to a string string itoa(int value); - double fCATS_X_Q(const TCATSData* Data, const int i); - double fCATS_Y_Q(const TCATSData* Data, const int i); - bool fCATS_Threshold_X(const TCATSData* Data, const int i); - bool fCATS_Threshold_Y(const TCATSData* Data, const int i); - double fCATS_Ped_X(const TCATSData* m_EventData, const int i); - double fCATS_Ped_Y(const TCATSData* m_EventData, const int i); + double fCATS_X_Q(const TCATSData* Data, const int& i); + double fCATS_Y_Q(const TCATSData* Data, const int& i); + bool fCATS_Threshold_X(const TCATSData* Data, const int& i); + bool fCATS_Threshold_Y(const TCATSData* Data, const int& i); + double fCATS_Ped_X(const TCATSData* m_EventData, const int& i); + double fCATS_Ped_Y(const TCATSData* m_EventData, const int& i); } #endif diff --git a/NPLib/Detectors/MDM/MDMTrace.cpp b/NPLib/Detectors/MDM/MDMTrace.cpp index c375887cc87c20e040b259b70d69cbb78ed55da4..1ddee65846811f4039d382d12cb8412c789f4520 100644 --- a/NPLib/Detectors/MDM/MDMTrace.cpp +++ b/NPLib/Detectors/MDM/MDMTrace.cpp @@ -42,7 +42,8 @@ MDMTrace::Rayin::Rayin(const string& filename, bool check): cerr << "Creating link \"rayin.dat\" to the file \"" << filename << "\"...\n"; stringstream sstr; sstr << "ln -fs " <<filename << " rayin.dat"; - system(sstr.str().c_str()); + int ret; + ret = system(sstr.str().c_str()); } } @@ -50,7 +51,8 @@ MDMTrace::Rayin::~Rayin() { if(isOwner) { cerr << "Removing link \"rayin.dat\"...\n"; - system("rm -f rayin.dat"); + int ret; + ret = system("rm -f rayin.dat"); } } diff --git a/NPLib/Detectors/MDM/TMDMPhysics.cxx b/NPLib/Detectors/MDM/TMDMPhysics.cxx index b495ef65087aad6c9820a89b4be8206ec2835504..a2e8de7686437f15cf5ba381dad396f170aba68c 100644 --- a/NPLib/Detectors/MDM/TMDMPhysics.cxx +++ b/NPLib/Detectors/MDM/TMDMPhysics.cxx @@ -546,7 +546,7 @@ proxy_MDM p_MDM; #ifdef HAVE_MINUIT2 -#pragma message "Compiling TMDMPhysics with Minuit2 support" +//#pragma message "Compiling TMDMPhysics with Minuit2 support" // Define real routines using minuit2 // diff --git a/NPLib/Online/NPOnlineGUI.cxx b/NPLib/Online/NPOnlineGUI.cxx index 7cfae0a2c626c024544fd7aecbe5d1d4ff6ea528..77ea3c58f2fd9c8f24128a7b173fcbbfaf73140a 100644 --- a/NPLib/Online/NPOnlineGUI.cxx +++ b/NPLib/Online/NPOnlineGUI.cxx @@ -49,16 +49,17 @@ #include "NPCore.h" ClassImp(NPL::OnlineGUI); //////////////////////////////////////////////////////////////////////////////// -void NPL::ExecuteMacro(string name){ +void NPL::ExecuteMacro(const std::string& name){ static DIR *dir; static struct dirent *ent; - static string path; + static std::string path; path = "./online_macros/"; - name += ".cxx"; + static std::string filename; + filename = name+".cxx"; if ((dir = opendir (path.c_str())) != NULL) { while ((ent = readdir (dir)) != NULL) { - if(ent->d_name==name) - gROOT->ProcessLine(Form(".x online_macros/%s",name.c_str())); + if(ent->d_name==filename) + gROOT->ProcessLine(Form(".x online_macros/%s",filename.c_str())); } closedir (dir); } @@ -160,8 +161,8 @@ void NPL::OnlineGUI::ResetCurrent(){ //////////////////////////////////////////////////////////////////////////////// void NPL::OnlineGUI::Eloging(){ - vector<std::string> attributes; - vector<std::string> val; + std::vector<std::string> attributes; + std::vector<std::string> val; std::map<std::string,TGTextEntry*>::iterator it ; for(it = m_ElogAttributes.begin(); it != m_ElogAttributes.end() ; it++){ @@ -244,9 +245,9 @@ void NPL::OnlineGUI::ApplyRangeCurrent(){ } //////////////////////////////////////////////////////////////////////////////// void NPL::OnlineGUI::FitCurrent(){ - static string gauss_formula = "([0]*[3]/([2]*sqrt(2*3.14159265359)))*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))"; + static std::string gauss_formula = "([0]*[3]/([2]*sqrt(2*3.14159265359)))*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))"; - static string full_formula = gauss_formula +"+[P0]+[P1]*x"; + static std::string full_formula = gauss_formula +"+[P0]+[P1]*x"; TList* list = gPad->GetListOfPrimitives(); int Hsize = list->GetSize(); for(int h = 0 ; h < Hsize ; h++){ @@ -315,8 +316,8 @@ void NPL::OnlineGUI::MakeGui(){ m_ButtonBar->SetLayoutBroken(kTRUE); m_Main->AddFrame(m_ButtonBar,new TGLayoutHints(kLHintsLeft|kLHintsTop)); - string NPLPath = gSystem->Getenv("NPTOOL"); - string path_quit = NPLPath+"/NPLib/Core/icons/power.xpm"; + std::string NPLPath = gSystem->Getenv("NPTOOL"); + std::string path_quit = NPLPath+"/NPLib/Core/icons/power.xpm"; m_Quit = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_quit.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); m_Quit->SetBackgroundColor(m_BgColor); m_Quit->SetToolTipText("Quit"); @@ -324,9 +325,9 @@ void NPL::OnlineGUI::MakeGui(){ m_ButtonBar->AddFrame(m_Quit, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); m_Quit->MoveResize(10,5,32,32); - string path_connect = NPLPath+"/NPLib/Core/icons/plugin.xpm"; + std::string path_connect = NPLPath+"/NPLib/Core/icons/plugin.xpm"; m_Connect = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_connect.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); - string path_connected = NPLPath+"/NPLib/Core/icons/brightness.xpm"; + std::string path_connected = NPLPath+"/NPLib/Core/icons/brightness.xpm"; m_Connect->SetDisabledPicture(gClient->GetPicture(path_connected.c_str())); m_Connect->SetBackgroundColor(m_BgColor); m_Connect->SetForegroundColor(m_BgColor); @@ -335,7 +336,7 @@ void NPL::OnlineGUI::MakeGui(){ m_ButtonBar->AddFrame(m_Connect, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); m_Connect->MoveResize(52,5,32,32); - string path_update = NPLPath+"/NPLib/Core/icons/download.xpm"; + std::string path_update = NPLPath+"/NPLib/Core/icons/download.xpm"; m_Update = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_update.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); m_Update->SetBackgroundColor(m_BgColor); m_Update->SetForegroundColor(m_BgColor); @@ -343,7 +344,7 @@ void NPL::OnlineGUI::MakeGui(){ m_ButtonBar->AddFrame(m_Update, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); m_Update->MoveResize(400,5,32,32); - string path_clock= NPLPath+"/NPLib/Core/icons/clock.xpm"; + std::string path_clock= NPLPath+"/NPLib/Core/icons/clock.xpm"; m_Clock = new TGPictureButton(m_ButtonBar,gClient->GetPicture(path_clock.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); m_Clock->SetBackgroundColor(m_BgColor); m_Clock->SetForegroundColor(m_BgColor); @@ -589,7 +590,7 @@ void NPL::OnlineGUI::MakeGui(){ m_Right->AddFrame(m_SaveAsBar, new TGLayoutHints(kLHintsTop|kLHintsExpandX)); // SaveAs button - string path_print= NPLPath + "/NPLib/Core/icons/print.xpm"; + std::string path_print= NPLPath + "/NPLib/Core/icons/print.xpm"; m_SaveAs= new TGPictureButton(m_SaveAsBar,gClient->GetPicture(path_print.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); m_SaveAs->SetBackgroundColor(m_FgColor); m_SaveAs->SetToolTipText("SaveAs"); @@ -620,15 +621,15 @@ void NPL::OnlineGUI::MakeGui(){ m_Right->AddFrame(m_SaveAsLine, new TGLayoutHints(kLHintsExpandX,2,2,2,2)); // Elog button - string path_elog= NPLPath + "/NPLib/Core/icons/booklet.xpm"; + std::string path_elog= NPLPath + "/NPLib/Core/icons/booklet.xpm"; m_Eloging= new TGPictureButton(m_Right,gClient->GetPicture(path_elog.c_str()),-1,TGPictureButton::GetDefaultGC()(),kChildFrame); m_Eloging->SetBackgroundColor(m_FgColor); m_Eloging->SetToolTipText("Elog"); m_Right->AddFrame(m_Eloging, new TGLayoutHints(kLHintsTop|kLHintsLeft,10,10,10,10)); // Elog attributes menu - std::map<std::string , vector <std::string> > attributes = m_Elog.GetAttributesValues(); - std::map<std::string , vector <std::string> >::iterator it; + std::map<std::string , std::vector <std::string> > attributes = m_Elog.GetAttributesValues(); + std::map<std::string , std::vector <std::string> >::iterator it; for(it = attributes.begin() ; it != attributes.end() ; it++){ TGVerticalFrame* attframe= new TGVerticalFrame(m_Right,10000,80); attframe->SetBackgroundColor(m_FgColor); @@ -733,7 +734,7 @@ NPL::OnlineGUI::~OnlineGUI(){ //////////////////////////////////////////////////////////////////////////////// void NPL::OnlineGUI::Connect(){ - m_Client->SetAddressAndPort((string) m_Address->GetDisplayText().Data(),(int) m_Port->GetNumber()); + m_Client->SetAddressAndPort((std::string) m_Address->GetDisplayText().Data(),(int) m_Port->GetNumber()); m_Client->Connect(); m_CanvasListTree->LoadCanvasList(m_Client->GetSpectra()); } @@ -789,9 +790,9 @@ void NPL::OnlineGUI::AutoUpdate(){ //////////////////////////////////////////////////////////////////////////////// NPL::CanvasList::CanvasList(TGMainFrame* main, TGCanvas* parent,TRootEmbeddedCanvas* canvas,TList* Spectra){ - string NPLPath = gSystem->Getenv("NPTOOL"); - string path_icon = NPLPath+"/NPLib/Core/icons/polaroid.xpm"; - string path_icon_folder = NPLPath+"/NPLib/Core/icons/folder.xpm"; + std::string NPLPath = gSystem->Getenv("NPTOOL"); + std::string path_icon = NPLPath+"/NPLib/Core/icons/polaroid.xpm"; + std::string path_icon_folder = NPLPath+"/NPLib/Core/icons/folder.xpm"; m_popen = gClient->GetPicture(path_icon.c_str()); m_pclose = gClient->GetPicture(path_icon.c_str()); @@ -885,22 +886,22 @@ void NPL::CanvasList::LoadCanvasList(TList* Spectra){ return; Clear(); NPL::InputParser parser("CanvasList.txt",false); - vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Canvas"); - vector<std::string> token = {"Path","Divide","Histo"}; + std::vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Canvas"); + std::vector<std::string> token = {"Path","Divide","Histo"}; gROOT->ProcessLine("gROOT->SetBatch(kTRUE)"); for(unsigned int i = 0 ; i < blocks.size() ; i++){ if(blocks[i]->HasTokenList(token)){ - vector<std::string> path = blocks[i]->GetVectorString("Path"); - vector<int> divide = blocks[i]->GetVectorInt("Divide"); - vector<std::string> histo = blocks[i]->GetVectorString("Histo"); - string name = path[path.size()-1]; + std::vector<std::string> path = blocks[i]->GetVectorString("Path"); + std::vector<int> divide = blocks[i]->GetVectorInt("Divide"); + std::vector<std::string> histo = blocks[i]->GetVectorString("Histo"); + std::string name = path[path.size()-1]; TCanvas* c = new TCanvas(name.c_str(), 5000,5000,0); c->Divide(divide[0],divide[1]); unsigned int size = histo.size(); for(unsigned int h = 0 ; h < size ; h++){ c->cd(h+1); - string padname=name+"_"+NPL::itoa(h); + std::string padname=name+"_"+NPL::itoa(h); gPad->SetName(padname.c_str()); TH1* hist = (TH1*) Spectra->FindObject(histo[h].c_str()); if(hist){ @@ -917,7 +918,7 @@ void NPL::CanvasList::LoadCanvasList(TList* Spectra){ TGListTreeItem* item = NULL; TGListTreeItem* pitem = NULL; - string item_path=""; + std::string item_path=""; for(unsigned int j = 0 ; j < path.size()-1 ; j++){ item_path+="/"+path[j]; item = m_ListTree->FindItemByPathname(item_path.c_str()); diff --git a/NPLib/Online/NPOnlineGUI.h b/NPLib/Online/NPOnlineGUI.h index 0a0b09a11ca9d348d6258d946e5d7e285e9e3c78..1451eda228d5cb39fbe3341f7eeff8fc85ed16c9 100644 --- a/NPLib/Online/NPOnlineGUI.h +++ b/NPLib/Online/NPOnlineGUI.h @@ -43,7 +43,7 @@ #include<map> namespace NPL{ - void ExecuteMacro(std::string name); + void ExecuteMacro(const std::string& name); class CanvasList { RQ_OBJECT("CanvasList") diff --git a/NPLib/Utility/npanalysis.cxx b/NPLib/Utility/npanalysis.cxx index 3863a46d53d44cf0973215ed2f9291a5dcdc8f71..d5cb6126cc5f0fff8c0b514345562d0287134f90 100644 --- a/NPLib/Utility/npanalysis.cxx +++ b/NPLib/Utility/npanalysis.cxx @@ -12,40 +12,42 @@ #include<dlfcn.h> #include<stdlib.h> #include<unistd.h> +#include<sys/time.h> // Root #include"TKey.h" #include"TEnv.h" #include"TROOT.h" void ProgressDisplay(clock_t&,clock_t&,unsigned long&, unsigned long&, unsigned long&, double&, unsigned long&, int&, int&); +void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree); //////////////////////////////////////////////////////////////////////////////// int main(int argc , char** argv){ // command line parsing NPOptionManager* myOptionManager = NPOptionManager::getInstance(argc,argv); - string inputfilename = myOptionManager->GetRunToReadFile(); + std::string inputfilename = myOptionManager->GetRunToReadFile(); // if input files are not given, use those from TAsciiFile if (myOptionManager->IsDefault("DetectorConfiguration")) { - string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("DetectorConfiguration"); + std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("DetectorConfiguration"); if(name!="fail"){ myOptionManager->SetDetectorFile(name); - cout << "\033[1;33mInfo: No Detector file given, using Input tree one \033[0m"<<endl;; + std::cout << "\033[1;33mInfo: No Detector file given, using Input tree one \033[0m" << std::endl;; } } if (myOptionManager->IsDefault("EventGenerator")) { - string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("EventGenerator"); + std::string name = RootInput::getInstance(inputfilename)->DumpAsciiFile("EventGenerator"); if(name!="fail"){ myOptionManager->SetReactionFile(name); - cout << "\033[1;33mInfo: No Event file given, using Input tree one \033[0m"<<endl;; + std::cout << "\033[1;33mInfo: No Event file given, using Input tree one \033[0m" << std::endl;; } } // get input files from NPOptionManager - string detectorfileName = myOptionManager->GetDetectorFile(); - string OutputfileName = myOptionManager->GetOutputFile(); + std::string detectorfileName = myOptionManager->GetDetectorFile(); + std::string OutputfileName = myOptionManager->GetOutputFile(); // Instantiate RootOutput - string TreeName="NPTool_Tree"; + std::string TreeName="NPTool_Tree"; // User decided of the name if(!myOptionManager->IsDefault("TreeName")){ @@ -76,7 +78,7 @@ int main(int argc , char** argv){ myDetector->InitializeRootOutput(); // Attempt to load an analysis NPL::VAnalysis* UserAnalysis = NULL; - string libName = "./libNPAnalysis" + myOptionManager->GetSharedLibExtension(); + std::string libName = "./libNPAnalysis" + myOptionManager->GetSharedLibExtension(); dlopen(libName.c_str(),RTLD_NOW | RTLD_GLOBAL); char* error = dlerror(); if(error==NULL){ @@ -119,6 +121,8 @@ int main(int argc , char** argv){ unsigned long displayed=0; clock_t end; clock_t begin = clock(); + struct timeval tv_end; + struct timeval tv_begin; gettimeofday(&tv_begin,NULL); unsigned long new_nentries = 0 ; int current_tree = 0 ; int total_tree = Chain->GetNtrees(); @@ -136,7 +140,8 @@ int main(int argc , char** argv){ tree->Fill(); current_tree = Chain->GetTreeNumber()+1; - ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); if(myOptionManager->GetOnline() && i%10000==0){ myDetector->CheckSpectraServer(); @@ -161,7 +166,7 @@ int main(int argc , char** argv){ } else{ - cout << "\033[1;31m ERROR: You are requesting to rebuild a Physics Tree without any User Analysis, nothing to be done\033[0m" <<endl; + std::cout << "\033[1;31m ERROR: You are requesting to rebuild a Physics Tree without any User Analysis, nothing to be done\033[0m" << std::endl; // Quit without error exit(0); } @@ -171,22 +176,17 @@ int main(int argc , char** argv){ if(!IsPhysics){ for (unsigned long i = first_entry ; i < nentries + first_entry; i++) { // Get the raw Data - //cout << "!" << endl; Chain -> GetEntry(i); - //cout << "!!" << endl; // Build the current event myDetector->BuildPhysicalEvent(); - //cout << "!!!" << endl; // User Analysis UserAnalysis->TreatEvent(); - //cout << "!!!!" << endl; // Fill the tree tree->Fill(); - //cout << "!!!!!" << endl; current_tree = Chain->GetTreeNumber()+1; - ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); - + //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); if(myOptionManager->GetOnline() && i%10000==0){ myDetector->CheckSpectraServer(); bool first = true; @@ -219,7 +219,8 @@ int main(int argc , char** argv){ tree->Fill(); current_tree = Chain->GetTreeNumber()+1; - ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); if(myOptionManager->GetOnline() && i%10000==0){ myDetector->CheckSpectraServer(); @@ -245,11 +246,14 @@ int main(int argc , char** argv){ UserAnalysis->End(); } -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING myDetector->StopThread(); #endif + current_tree = Chain->GetTreeNumber()+1; - ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + //ProgressDisplay(begin,end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); + + ProgressDisplay(tv_begin,tv_end,treated,inter,nentries,mean_rate,displayed,current_tree,total_tree); if(myOptionManager->GetOnline()){ myDetector->CheckSpectraServer(); @@ -261,10 +265,48 @@ int main(int argc , char** argv){ RootOutput::Destroy(); RootInput::Destroy(); - -return 0; + return 0; } +//////////////////////////////////////////////////////////////////////////////// +void ProgressDisplay(struct timeval& begin, struct timeval& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){ + gettimeofday(&end,NULL); + long double elapsed= end.tv_sec-begin.tv_sec+(end.tv_usec-begin.tv_usec)*1e-6; + if(elapsed>1||treated>=total ){ + displayed++; + double event_rate = inter/elapsed; + mean_rate += (event_rate-mean_rate)/(displayed); + double percent = 100*treated/total; + double remain = (total-treated)/mean_rate; + char* timer; + double check; + int minutes = remain/60.; + int seconds = remain -60*minutes; + if(remain>60) + check=asprintf(&timer,"%dmin%ds",minutes,seconds); + else + check=asprintf(&timer,"%ds",(int)(remain)); + + static char star[10]; + if(displayed%2==0 || treated==total) + sprintf(star,"*******"); + else + sprintf(star,"-------"); + + if(treated!=total) + printf("\r \033[1;31m %s Progress: \033[1;36m%.1f%% \033[1;31m| Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree,total_tree,star); + + else{ + printf("\r \033[1;32m %s Progress: %.1f%% | Rate: %.1fk evt/s | Remain: %s | Tree: %d/%d %s \033[0m ", star,percent,mean_rate/1000.,timer, current_tree, total_tree,star); + } + fflush(stdout); + inter=0; + gettimeofday(&begin,NULL); + } + + treated++; + inter++; +} //////////////////////////////////////////////////////////////////////////////// void ProgressDisplay(clock_t& begin, clock_t& end, unsigned long& treated,unsigned long& inter,unsigned long& total,double& mean_rate,unsigned long& displayed, int& current_tree, int& total_tree){ end = clock(); diff --git a/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake b/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake index 3589e9dd88e0d6c59829194896709c40e98c47db..53b09109cfd198639c7c4ea6d8512494c93e2c1a 100644 --- a/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake +++ b/NPLib/ressources/CMake/NPTool_CMake_Preamble.cmake @@ -10,6 +10,8 @@ include("${NPLIB}/ressources/CMake/Root.cmake") # Setting the policy to match Cmake version cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) + + # This suppress the Up-to-Date message of file installed for cmake 3.1 and above set(CMAKE_INSTALL_MESSAGE LAZY)