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  * Authors: Dario Menasce, Marco Rovere *
4  ************************************************************************/
5 
6 #ifndef PixelTimeFormatter_h
7 #define PixelTimeFormatter_h
8 
15 #include <iostream>
16 #include <sstream>
17 #include <string>
18 #include <time.h>
19 #include <sys/time.h>
20 #include <cstdlib>
21 
22 #define USE_TIMER_ 0
23 
24 namespace pos{
26  {
27  public:
28 
29  //---------------------------------------------------------------------------------
31  {
32  if( !USE_TIMER_) return ;
33  origin_ = source ;
34  std::cout << "[PixelTimeFormatter::PixelTimeFormatter()]\t\t Time counter started for " << origin_ << std::endl ;
36  }
37 
38  void stopTimer(void)
39  {
40  if( !USE_TIMER_ ) return ;
42  double start = startTime_.tv_sec + startTime_.tv_usec/1000000. ;
43  double stop = endTime_.tv_sec + endTime_.tv_usec/1000000. ;
44  std::cout << "[PixelTimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop-start << " seconds for " << origin_ << std::endl ;
45  }
46 
47  //---------------------------------------------------------------------------------
48  static std::string getTime(void)
49  {
50  char theDate[20] ;
51  struct tm *thisTime;
52  time_t aclock;
53  std::string date ;
54  time( &aclock );
55  thisTime = localtime( &aclock );
56 
57  sprintf(theDate,
58  "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
59  thisTime->tm_mon+1,
60  thisTime->tm_mday,
61  thisTime->tm_hour,
62  thisTime->tm_min,
63  thisTime->tm_sec );
64  date = theDate ;
65  //std::cout << "[PixelTimeFormatter::getTime()]\t\t\t\t Time: " << date << std::endl ;
66  return date ;
67  }
68 
69  //---------------------------------------------------------------------------------
70  struct tm * getITime(void)
71  {
72  struct tm *thisTime;
73  time_t aclock;
74  time( &aclock );
75  thisTime = localtime( &aclock );
76  return thisTime ;
77  }
78 
79  //---------------------------------------------------------------------------------
80  static std::string getmSecTime(void)
81  {
82  char theDate[20] ;
83  struct timeval msecTime;
84  gettimeofday(&msecTime, (struct timezone *)0) ;
85 
86  sprintf(theDate,
87  "%d-%d",
88  (unsigned int)msecTime.tv_sec,
89  (unsigned int)msecTime.tv_usec );
90  return std::string(theDate) ;
91  }
92 
93  //---------------------------------------------------------------------------------
94  struct timeval getImSecTime(void)
95  {
96  struct timeval msecTime;
97  gettimeofday(&msecTime, (struct timezone *)0) ;
98 
99  return msecTime ;
100  }
101 /*
102  //---------------------------------------------------------------------------------
103  static double timeDiff(std::string firstTime, std::string secondTime)
104  {
105  time_t rawTime;
106  struct tm * rawTimeInfo;
107 
108  int firstMonth = atoi( firstTime.substr(0,2).c_str()) ;
109  int firstDay = atoi( firstTime.substr(3,2).c_str()) ;
110  int firstYear = atoi( firstTime.substr(6,4).c_str()) ;
111  int secondMonth = atoi(secondTime.substr(0,2).c_str()) ;
112  int secondDay = atoi(secondTime.substr(3,2).c_str()) ;
113  int secondYear = atoi(secondTime.substr(6,4).c_str()) ;
114 
115  time(&rawTime);
116  rawTimeInfo = localtime(&rawTime);
117  rawTimeInfo->tm_mon = firstMonth - 1 ;
118  rawTimeInfo->tm_mday = firstDay ;
119  rawTimeInfo->tm_year = firstYear - 1900 ;
120 
121  time_t ft = mktime( rawTimeInfo ) ;
122 
123  rawTimeInfo = localtime(&rawTime);
124  rawTimeInfo->tm_mon = secondMonth - 1 ;
125  rawTimeInfo->tm_mday = secondDay ;
126  rawTimeInfo->tm_year = secondYear - 1900 ;
127 
128  time_t st = mktime( rawTimeInfo ) ;
129 
130  return difftime(ft, st) ;
131  }
132 */
133  //=================================================================================
134 
135  private:
136 
137  struct timeval startTime_ ;
138  struct timeval endTime_ ;
140  bool verbose_ ;
141  } ;
142 }
143 
144 #endif
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
struct timeval getImSecTime(void)
static std::string getmSecTime(void)
return((rh^lh)&mask)
PixelTimeFormatter(std::string source)
static std::string getTime(void)
struct tm * getITime(void)
tuple cout
Definition: gather_cfg.py:121
#define USE_TIMER_
static std::string const source
Definition: EdmProvDump.cc:43