Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F10664424
CommonUtils.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
CommonUtils.hh
View Options
#ifndef _JETCOMMONUTILS_HH_
#define _JETCOMMONUTILS_HH_
#include
<ctime>
#include
<algorithm>
#include
<cmath>
// **************************************************************
// phi conversions
namespace
SpartyJet
{
// **************************************************************
inline
float
to_minusPI_PI
(
float
phi
){
while
(
phi
<
-
M_PI
)
phi
+=
2
*
M_PI
;
while
(
phi
>=
M_PI
)
phi
-=
2
*
M_PI
;
return
phi
;
}
inline
float
to_zero_2PI
(
float
phi
){
while
(
phi
<
0
)
phi
+=
2
*
M_PI
;
while
(
phi
>=
2
*
M_PI
)
phi
-=
2
*
M_PI
;
return
phi
;
}
// **************************************************************
// List utils
// **************************************************************
// Destroy all pointers in a container, and clear it
// T must be a container of pointers ex. list<T2*>
template
<
class
T
>
void
clear_list
(
T
&
list
){
typedef
typename
T
::
iterator
it_t
;
it_t
it
=
list
.
begin
();
it_t
itE
=
list
.
end
();
for
(;
it
!=
itE
;
++
it
){
delete
*
it
;
}
list
.
clear
();
}
// **************************************************************
// timing
// **************************************************************
class
stopwatch
{
public
:
stopwatch
()
:
m_total
(
0
){};
void
start
(){
m_last
=
std
::
clock
();};
void
resume
(){
m_last
=
std
::
clock
();};
float
pause
()
{
std
::
clock_t
now
=
std
::
clock
();
m_total
=
m_total
+
now
-
m_last
;
m_last
=
now
;
return
convert
();
}
float
stop
(){
float
t
=
pause
();
m_total
=
std
::
clock_t
(
0
);
return
t
;}
protected
:
std
::
clock_t
m_last
;
std
::
clock_t
m_total
;
float
convert
(){
return
float
(
m_total
)
*
1000
/
CLOCKS_PER_SEC
;}
};
}
// namespace SpartyJet
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Apr 24, 6:39 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4817165
Default Alt Text
CommonUtils.hh (1 KB)
Attached To
rSPARTYJETSVN spartyjetsvn
Event Timeline
Log In to Comment