CommonUtils.hh
Go to the documentation of this file.00001
00002
00003 #ifndef _JETCOMMONUTILS_HH_
00004 #define _JETCOMMONUTILS_HH_
00005
00006 #include <ctime>
00007 #include <algorithm>
00008 #include <cmath>
00009
00010 #include <fastjet/internal/base.hh>
00011
00012 FASTJET_BEGIN_NAMESPACE
00013
00014 namespace atlas{
00015
00016
00017
00018
00019 inline float to_minusPI_PI(float phi){
00020 while(phi < -M_PI) phi += 2*M_PI;
00021 while(phi >= M_PI) phi -= 2*M_PI;
00022 return phi;
00023 }
00024 inline float to_zero_2PI(float phi){
00025 while(phi < 0) phi += 2*M_PI;
00026 while(phi >= 2*M_PI) phi -= 2*M_PI;
00027 return phi;
00028 }
00029
00030
00031
00032
00033
00034
00035
00036
00037 template<class T>
00038 void clear_list(T & list){
00039 typedef typename T::iterator it_t;
00040 it_t it = list.begin();
00041 it_t itE = list.end();
00042 for(; it != itE; ++it){
00043 delete *it;
00044 }
00045 list.clear();
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055 class stopwatch {
00056 public :
00057 stopwatch() : m_total(0){};
00058 void start(){m_last = std::clock();};
00059 void resume(){m_last = std::clock();};
00060 float pause() {
00061 std::clock_t now=std::clock();
00062 m_total = m_total + now - m_last;
00063 m_last = now;
00064 return convert();
00065 }
00066 float stop(){float t=pause(); m_total = std::clock_t(0); return t;}
00067 protected:
00068 std::clock_t m_last;
00069 std::clock_t m_total;
00070
00071 float convert(){ return float(m_total)*1000/CLOCKS_PER_SEC;}
00072 };
00073
00074
00075 }
00076
00077 FASTJET_END_NAMESPACE
00078 #endif