$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/ConfigurationInterface/TimeFormatter.h" 00002 00003 #include <sys/time.h> 00004 #include <time.h> 00005 #include <cstdio> 00006 #include <cstdlib> 00007 #include <iostream> 00008 #include <sstream> 00009 #include <string> 00010 #include "otsdaq-core/Macros/CoutMacros.h" 00011 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00012 00013 #define USE_TIMER 0 00014 00015 using namespace ots; 00016 00017 //============================================================================== 00018 TimeFormatter::TimeFormatter(std::string source) 00019 { 00020 if(!USE_TIMER) 00021 return; 00022 origin_ = source; 00023 std::cout << __COUT_HDR_FL__ 00024 << "[TimeFormatter::TimeFormatter()]\t\t Time counter started for " 00025 << origin_ << std::endl 00026 << std::endl; 00027 startTime_ = getImSecTime(); 00028 } 00029 00030 //============================================================================== 00031 void TimeFormatter::stopTimer(void) 00032 { 00033 if(!USE_TIMER) 00034 return; 00035 endTime_ = getImSecTime(); 00036 double start = startTime_.tv_sec + startTime_.tv_usec / 1000000.; 00037 double stop = endTime_.tv_sec + endTime_.tv_usec / 1000000.; 00038 std::cout << __COUT_HDR_FL__ 00039 << "[TimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop - start 00040 << " seconds for " << origin_ << std::endl 00041 << std::endl; 00042 } 00043 00044 //============================================================================== 00045 std::string TimeFormatter::getTime(void) 00046 { 00047 char theDate[20]; 00048 struct tm* thisTime; 00049 time_t aclock; 00050 std::string date; 00051 time(&aclock); 00052 thisTime = localtime(&aclock); 00053 00054 sprintf(theDate, 00055 "%d-%02d-%02d %02d:%02d:%02d", 00056 thisTime->tm_year + 1900, 00057 thisTime->tm_mon + 1, 00058 thisTime->tm_mday, 00059 thisTime->tm_hour, 00060 thisTime->tm_min, 00061 thisTime->tm_sec); 00062 date = theDate; 00063 // std::cout << __COUT_HDR_FL__ << "[TimeFormatter::getTime()]\t\t\t\t Time: " << 00064 // date << std::endl << std::endl; 00065 return date; 00066 } 00067 00068 //============================================================================== 00069 struct tm* TimeFormatter::getITime(void) 00070 { 00071 struct tm* thisTime; 00072 time_t aclock; 00073 time(&aclock); 00074 thisTime = localtime(&aclock); 00075 return thisTime; 00076 } 00077 00078 //============================================================================== 00079 std::string getmSecTime(void) 00080 { 00081 char theDate[20]; 00082 struct timeval msecTime; 00083 gettimeofday(&msecTime, (struct timezone*)0); 00084 00085 sprintf( 00086 theDate, "%d-%d", (unsigned int)msecTime.tv_sec, (unsigned int)msecTime.tv_usec); 00087 return std::string(theDate); 00088 } 00089 00090 //============================================================================== 00091 struct timeval TimeFormatter::getImSecTime(void) 00092 { 00093 struct timeval msecTime; 00094 gettimeofday(&msecTime, (struct timezone*)0); 00095 00096 return msecTime; 00097 }