FastJet 3.0.2
CommonUtils.hh
00001 //----------------------------------------------------------------------
00002 // This file distributed with FastJet has been obtained from SpartyJet
00003 // v2.20.0 by Pierre-Antoine Delsart, Kurtis L. Geerlings, Joey
00004 // Huston, Brian T. Martin and Chris Vermilion
00005 // For details, see http://www.pa.msu.edu/~huston/SpartyJet/
00006 //                  http://projects.hepforge.org/spartyjet/
00007 //
00008 // Changes from the original file are listed below.
00009 //----------------------------------------------------------------------
00010 
00011 // History of changes from the original CommonUtils.hh file in
00012 // SpartyJet v2.20
00013 //  
00014 // 2009-01-15  Gregory Soyez  <soyez@fastjet.fr>
00015 // 
00016 //        * put the code in the fastjet::atlas namespace
00017 
00018 #ifndef _JETCOMMONUTILS_HH_
00019 #define _JETCOMMONUTILS_HH_
00020 
00021 #include <ctime>
00022 #include <algorithm>
00023 #include <cmath>
00024 
00025 #include <fastjet/internal/base.hh>
00026 
00027 FASTJET_BEGIN_NAMESPACE
00028 
00029 namespace atlas{
00030 
00031 // **************************************************************
00032 // phi conversions 
00033 // **************************************************************
00034 inline  float to_minusPI_PI(float phi){
00035   while(phi < -M_PI) phi += 2*M_PI;
00036   while(phi >= M_PI) phi -= 2*M_PI;
00037   return phi;
00038 }
00039 inline  float to_zero_2PI(float phi){
00040   while(phi < 0) phi += 2*M_PI;
00041   while(phi >= 2*M_PI) phi -= 2*M_PI;
00042   return phi;
00043 }
00044 
00045 
00046 
00047 // **************************************************************
00048 // List utils
00049 // **************************************************************
00050 // Destroy all pointers in a container, and clear it
00051 // T must be a container of pointers ex. list<T2*>
00052 template<class T>
00053 void clear_list(T & list){
00054   typedef typename T::iterator it_t;
00055   it_t it = list.begin();
00056   it_t itE = list.end();
00057   for(; it != itE; ++it){
00058     delete *it;
00059   }
00060   list.clear();
00061 }
00062 
00063 
00064 
00065 
00066 
00067 // **************************************************************
00068 // timing
00069 // **************************************************************
00070 class stopwatch {
00071 public :
00072   stopwatch() : m_total(0){};
00073   void start(){m_last = std::clock();};
00074   void resume(){m_last = std::clock();};
00075   float pause() {
00076     std::clock_t now=std::clock();
00077     m_total = m_total +  now - m_last;
00078     m_last = now;
00079     return convert();
00080   }
00081   float stop(){float t=pause(); m_total = std::clock_t(0); return t;}
00082 protected:
00083   std::clock_t m_last;
00084   std::clock_t m_total;
00085   
00086   float convert(){ return float(m_total)*1000/CLOCKS_PER_SEC;}
00087 };
00088 
00089 
00090 }  // namespace atlas
00091 
00092 FASTJET_END_NAMESPACE
00093 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends