CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PixelTimeFormatter.h
Go to the documentation of this file.
1 /*************************************************************************
2  * XDAQ Components for Pixel Online Software *
3  * Copyright (C) 2007, I.N.F.N. Milano Bicocca *
4  * All rights reserved. *
5  * Authors: Dario Menasce, Marco Rovere *
6  ************************************************************************/
7 
8 #ifndef PixelTimeFormatter_h
9 #define PixelTimeFormatter_h
10 
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 #include <time.h>
21 #include <sys/time.h>
22 #include <cstdlib>
23 
24 #define USE_TIMER_ 0
25 
26 namespace pos{
28  {
29  public:
30 
31  //---------------------------------------------------------------------------------
32  PixelTimeFormatter(std::string source )
33  {
34  if( !USE_TIMER_) return ;
35  origin_ = source ;
36  std::cout << "[PixelTimeFormatter::PixelTimeFormatter()]\t\t Time counter started for " << origin_ << std::endl ;
38  }
39 
40  void stopTimer(void)
41  {
42  if( !USE_TIMER_ ) return ;
44  double start = startTime_.tv_sec + startTime_.tv_usec/1000000. ;
45  double stop = endTime_.tv_sec + endTime_.tv_usec/1000000. ;
46  std::cout << "[PixelTimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop-start << " seconds for " << origin_ << std::endl ;
47  }
48 
49  //---------------------------------------------------------------------------------
50  static std::string getTime(void)
51  {
52  char theDate[20] ;
53  struct tm *thisTime;
54  time_t aclock;
55  std::string date ;
56  time( &aclock );
57  thisTime = localtime( &aclock );
58 
59  sprintf(theDate,
60  "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
61  thisTime->tm_mon+1,
62  thisTime->tm_mday,
63  thisTime->tm_hour,
64  thisTime->tm_min,
65  thisTime->tm_sec );
66  date = theDate ;
67  //std::cout << "[PixelTimeFormatter::getTime()]\t\t\t\t Time: " << date << std::endl ;
68  return date ;
69  }
70 
71  //---------------------------------------------------------------------------------
72  struct tm * getITime(void)
73  {
74  struct tm *thisTime;
75  time_t aclock;
76  time( &aclock );
77  thisTime = localtime( &aclock );
78  return thisTime ;
79  }
80 
81  //---------------------------------------------------------------------------------
82  static std::string getmSecTime(void)
83  {
84  char theDate[20] ;
85  struct timeval msecTime;
86  gettimeofday(&msecTime, (struct timezone *)0) ;
87 
88  sprintf(theDate,
89  "%d-%d",
90  (unsigned int)msecTime.tv_sec,
91  (unsigned int)msecTime.tv_usec );
92  return std::string(theDate) ;
93  }
94 
95  //---------------------------------------------------------------------------------
96  struct timeval getImSecTime(void)
97  {
98  struct timeval msecTime;
99  gettimeofday(&msecTime, (struct timezone *)0) ;
100 
101  return msecTime ;
102  }
103 /*
104  //---------------------------------------------------------------------------------
105  static double timeDiff(std::string firstTime, std::string secondTime)
106  {
107  time_t rawTime;
108  struct tm * rawTimeInfo;
109 
110  int firstMonth = atoi( firstTime.substr(0,2).c_str()) ;
111  int firstDay = atoi( firstTime.substr(3,2).c_str()) ;
112  int firstYear = atoi( firstTime.substr(6,4).c_str()) ;
113  int secondMonth = atoi(secondTime.substr(0,2).c_str()) ;
114  int secondDay = atoi(secondTime.substr(3,2).c_str()) ;
115  int secondYear = atoi(secondTime.substr(6,4).c_str()) ;
116 
117  time(&rawTime);
118  rawTimeInfo = localtime(&rawTime);
119  rawTimeInfo->tm_mon = firstMonth - 1 ;
120  rawTimeInfo->tm_mday = firstDay ;
121  rawTimeInfo->tm_year = firstYear - 1900 ;
122 
123  time_t ft = mktime( rawTimeInfo ) ;
124 
125  rawTimeInfo = localtime(&rawTime);
126  rawTimeInfo->tm_mon = secondMonth - 1 ;
127  rawTimeInfo->tm_mday = secondDay ;
128  rawTimeInfo->tm_year = secondYear - 1900 ;
129 
130  time_t st = mktime( rawTimeInfo ) ;
131 
132  return difftime(ft, st) ;
133  }
134 */
135  //=================================================================================
136 
137  private:
138 
139  struct timeval startTime_ ;
140  struct timeval endTime_ ;
141  std::string origin_ ;
142  bool verbose_ ;
143  } ;
144 }
145 
146 #endif
struct timeval getImSecTime(void)
static std::string getmSecTime(void)
PixelTimeFormatter(std::string source)
static std::string getTime(void)
struct tm * getITime(void)
tuple cout
Definition: gather_cfg.py:121
#define USE_TIMER_