From ccb5d86b5879e57cd1e4cb4eeaacc02b5f561902 Mon Sep 17 00:00:00 2001 From: adrien matta <matta@lpccaen.in2p3.fr> Date: Tue, 17 Jul 2018 09:58:39 +0200 Subject: [PATCH] * Fixing issue with MultiThreading - The event rate display was wrong on Linux system when using MT - Event rate is now correct - Improved Thread Scheduling for slightly faster analysis - add Option to switch off MT at compilation - Improve CATS performance dramatically (3 time faster) - remove a few using namespace std laying around --- NPLib/CMakeLists.txt | 10 +- NPLib/Core/NPCalibrationManager.cxx | 16 +- NPLib/Core/NPDetectorManager.cxx | 165 +++++++----------- NPLib/Core/NPDetectorManager.h | 11 +- NPLib/Core/RootOutput.cxx | 1 - NPLib/Detectors/CATS/TCATSData.cxx | 23 +-- NPLib/Detectors/CATS/TCATSData.h | 16 +- NPLib/Detectors/CATS/TCATSPhysics.cxx | 2 +- NPLib/Detectors/CATS/TCATSPhysics.h | 14 +- NPLib/Detectors/MDM/MDMTrace.cpp | 6 +- NPLib/Detectors/MDM/TMDMPhysics.cxx | 2 +- NPLib/Utility/npanalysis.cxx | 68 ++++++-- .../CMake/NPTool_CMake_Preamble.cmake | 2 + 13 files changed, 167 insertions(+), 169 deletions(-) diff --git a/NPLib/CMakeLists.txt b/NPLib/CMakeLists.txt index 6aba8713f..c8adca66d 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 395617e99..0b03b3a59 100644 --- a/NPLib/Core/NPCalibrationManager.cxx +++ b/NPLib/Core/NPCalibrationManager.cxx @@ -259,13 +259,11 @@ double CalibrationManager::ApplyResistivePositionCalibration(const std::string& return DeltaRawValue ; } - std::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 ; } @@ -315,20 +313,16 @@ bool CalibrationManager::ApplyThreshold(const std::string& ParameterPath, const return false; } - // Else we take the second part of the element (first is index, ie: parameter path) - // Second is the std::vector of Coeff - std::vector<double> Coeff = it->second ; - // 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]; } diff --git a/NPLib/Core/NPDetectorManager.cxx b/NPLib/Core/NPDetectorManager.cxx index 9ba19f299..9303331bc 100644 --- a/NPLib/Core/NPDetectorManager.cxx +++ b/NPLib/Core/NPDetectorManager.cxx @@ -60,13 +60,14 @@ NPL::DetectorManager::DetectorManager(){ } m_WindowsThickness=0; m_WindowsMaterial=""; + } /////////////////////////////////////////////////////////////////////////////// // Default Desstructor NPL::DetectorManager::~DetectorManager(){ -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING StopThread(); #endif if(m_SpectraServer) @@ -99,8 +100,8 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { if(starget.size()==1){ if(NPOptionManager::getInstance()->GetVerboseLevel()){ - std::cout << "//// TARGET ////" << std::endl; - std::cout << "//// Solid Target found " << std::endl; + std::cout << "//// TARGET ////" << std::endl; + std::cout << "//// Solid Target found " << std::endl; } std::vector<std::string> token = {"Thickness","Radius","Material","Angle","X","Y","Z"}; if(starget[0]->HasTokenList(token)){ @@ -119,7 +120,7 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { else if(ctarget.size()==1){ if(NPOptionManager::getInstance()->GetVerboseLevel()) std::cout << "//// Cryogenic Target found " << std::endl; - + std::vector<std::string> token = {"Thickness","Radius","Material","Density","WindowsThickness","WindowsMaterial","Angle","X","Y","Z"}; if(ctarget[0]->HasTokenList(token)){ m_TargetThickness= ctarget[0]->GetDouble("Thickness","micrometer"); @@ -147,31 +148,27 @@ void NPL::DetectorManager::ReadConfigurationFile(std::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()){ - std::cout << "/////////////////////////////////////////" << std::endl; - std::cout << "//// Adding Detector " << token[i] << std::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()) - std::cout << "/////////////////////////////////////////" << std::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 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(); @@ -180,7 +177,7 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { CalibrationManager::getInstance()->LoadParameterFromFile(); // Start the thread if multithreading supported -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING InitThreadPool(); #endif @@ -189,32 +186,21 @@ void NPL::DetectorManager::ReadConfigurationFile(std::string Path) { /////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::BuildPhysicalEvent(){ -#if __cplusplus > 199711L - // add new job -//std::cout << "TEST0a" << std::endl; - std::map<std::string,VDetector*>::iterator it; - unsigned int i = 0; - for (it = m_Detector.begin(); it != m_Detector.end(); ++it) { -//std::cout << "TEST0" << std::endl; - m_Ready[i++]=true; - } -//std::cout << "TEST1" << std::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(); -//std::cout << "TEST2" << std::endl; while(!IsDone()){ -//std::cout << "TEST2a" << std::endl; - //std::this_thread::yield(); - } -//std::cout << "TEST2b" << std::endl; + std::this_thread::yield(); + } #else -//std::cout << "TEST3" << std::endl; - std::map<std::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){ @@ -224,21 +210,7 @@ void NPL::DetectorManager::BuildPhysicalEvent(){ } } #endif -} - -/////////////////////////////////////////////////////////////////////////////// -void NPL::DetectorManager::BuildSimplePhysicalEvent(){ - ClearEventPhysics(); - std::map<std::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; } /////////////////////////////////////////////////////////////////////////////// @@ -282,10 +254,10 @@ NPL::VDetector* NPL::DetectorManager::GetDetector(std::string name){ 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 << " 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); @@ -311,15 +283,15 @@ 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()"); } 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)"); } /////////////////////////////////////////////////////////////////////////////// @@ -353,7 +325,8 @@ std::vector<std::string> NPL::DetectorManager::GetDetectorList(){ return DetectorList; } -#if __cplusplus > 199711L +#if __cplusplus > 199711L && NPMULTITHREADING + //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::InitThreadPool(){ StopThread(); @@ -377,34 +350,30 @@ void NPL::DetectorManager::InitThreadPool(){ //////////////////////////////////////////////////////////////////////////////// void NPL::DetectorManager::StartThread(NPL::VDetector* det,unsigned int id){ - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - std::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 -////std::cout << "WWWW" << std::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; + } } } //////////////////////////////////////////////////////////////////////////////// @@ -412,20 +381,16 @@ void NPL::DetectorManager::StopThread(){ // make sure the last thread are schedule before stopping; std::this_thread::yield(); m_stop=true; - m_CV.notify_all(); + std::this_thread::yield(); } //////////////////////////////////////////////////////////////////////////////// bool NPL::DetectorManager::IsDone(){ -int ijk=0; -//std::cout << m_Ready.size() << " !" << std::endl; - for(std::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++; -//std::cout << *it << std::endl; -//std::cout << ijk << std::endl; return false; -} } return true; } @@ -439,7 +404,7 @@ void NPL::DetectorManager::SetSpectraServer(){ 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 @@ -453,7 +418,7 @@ void NPL::DetectorManager::StopSpectraServer(){ m_SpectraServer->Destroy(); else std::cout <<"WARNING: requesting to stop spectra server, which is not started" << std::endl; - + } //////////////////////////////////////////////////////////////////////////////// diff --git a/NPLib/Core/NPDetectorManager.h b/NPLib/Core/NPDetectorManager.h index 49d35eec7..7f2dfccbc 100644 --- a/NPLib/Core/NPDetectorManager.h +++ b/NPLib/Core/NPDetectorManager.h @@ -49,7 +49,6 @@ namespace NPL{ public: void ReadConfigurationFile(std::string Path); void BuildPhysicalEvent(); - void BuildSimplePhysicalEvent(); void InitializeRootInput(); void InitializeRootOutput(); void AddDetector(std::string,VDetector*); @@ -80,13 +79,11 @@ namespace NPL{ VDetector_FuncPtr m_FillSpectra; VDetector_FuncPtr m_CheckSpectra; - #if __cplusplus > 199711L + #if __cplusplus > 199711L && NPMULTITHREADING private: // Thread Pool defined if C++11 is available 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(); @@ -116,9 +113,9 @@ namespace NPL{ public: double GetTargetThickness() {return m_TargetThickness;} - std::string GetTargetMaterial() {return m_TargetMaterial;} - double GetWindowsThickness(){return m_WindowsThickness;} - std::string GetWindowsMaterial() {return m_WindowsMaterial;} + 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/RootOutput.cxx b/NPLib/Core/RootOutput.cxx index 433665ebc..27d60c5d9 100644 --- a/NPLib/Core/RootOutput.cxx +++ b/NPLib/Core/RootOutput.cxx @@ -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); diff --git a/NPLib/Detectors/CATS/TCATSData.cxx b/NPLib/Detectors/CATS/TCATSData.cxx index d3cc32c30..35d95af29 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 4b166849a..69dcc4974 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 7cfc5aa9e..e96e1ab05 100644 --- a/NPLib/Detectors/CATS/TCATSPhysics.cxx +++ b/NPLib/Detectors/CATS/TCATSPhysics.cxx @@ -418,7 +418,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 64fd27f7c..7fff80d6b 100644 --- a/NPLib/Detectors/CATS/TCATSPhysics.h +++ b/NPLib/Detectors/CATS/TCATSPhysics.h @@ -170,7 +170,7 @@ class TCATSPhysics : public TObject, public NPL::VDetector void SetRawDataPointer(TCATSData* rawDataPointer) {m_EventData = 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(); @@ -212,12 +212,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 c375887cc..1ddee6584 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 b495ef650..a2e8de768 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/Utility/npanalysis.cxx b/NPLib/Utility/npanalysis.cxx index 972ee77ad..d5cb6126c 100644 --- a/NPLib/Utility/npanalysis.cxx +++ b/NPLib/Utility/npanalysis.cxx @@ -12,12 +12,14 @@ #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 @@ -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(); @@ -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 - //std::cout << "!" << std::endl; Chain -> GetEntry(i); - //std::cout << "!!" << std::endl; // Build the current event myDetector->BuildPhysicalEvent(); - //std::cout << "!!!" << std::endl; // User Analysis UserAnalysis->TreatEvent(); - //std::cout << "!!!!" << std::endl; // Fill the tree tree->Fill(); - //std::cout << "!!!!!" << std::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 3589e9dd8..53b09109c 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) -- GitLab