CMS 3D CMS Logo

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 
16 
17 #include <iostream>
18 #include <sstream>
19 #include <string>
20 #include <ctime>
21 #include <sys/time.h>
22 #include <cstdlib>
23 
24 #define USE_TIMER_ 0
25 
26 namespace pos{
28  {
29  public:
30 
31  //---------------------------------------------------------------------------------
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  virtual ~PixelTimeFormatter() = default;
41 
42  void stopTimer(void)
43  {
44  if( !USE_TIMER_ ) return ;
46  double start = startTime_.tv_sec + startTime_.tv_usec/1000000. ;
47  double stop = endTime_.tv_sec + endTime_.tv_usec/1000000. ;
48  std::cout << "[PixelTimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop-start << " seconds for " << origin_ << std::endl ;
49  }
50 
53  std::ofstream *out,
54  std::ofstream *out1 = nullptr,
55  std::ofstream *out2 = nullptr
56  ) const {;}
57 
58  //---------------------------------------------------------------------------------
59  static std::string getTime(void)
60  {
61  constexpr size_t kBufferLength = 72;
62  char theDate[kBufferLength] ;
63  struct tm *thisTime;
64  time_t aclock;
66  time( &aclock );
67  thisTime = localtime( &aclock );
68 
69  snprintf(theDate,
70  kBufferLength,
71  "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
72  thisTime->tm_mon+1,
73  thisTime->tm_mday,
74  thisTime->tm_hour,
75  thisTime->tm_min,
76  thisTime->tm_sec );
77  date = theDate ;
78  //std::cout << "[PixelTimeFormatter::getTime()]\t\t\t\t Time: " << date << std::endl ;
79  return date ;
80  }
81 
82  //---------------------------------------------------------------------------------
83  struct tm * getITime(void)
84  {
85  struct tm *thisTime;
86  time_t aclock;
87  time( &aclock );
88  thisTime = localtime( &aclock );
89  return thisTime ;
90  }
91 
92  //---------------------------------------------------------------------------------
93  static std::string getmSecTime(void)
94  {
95  constexpr size_t kBufferSize = 20;
96  char theDate[kBufferSize] ;
97  struct timeval msecTime;
98  gettimeofday(&msecTime, (struct timezone *)nullptr) ;
99 
100  snprintf(theDate,
101  kBufferSize,
102  "%d-%d",
103  (unsigned int)msecTime.tv_sec,
104  (unsigned int)msecTime.tv_usec );
105  return std::string(theDate) ;
106  }
107 
108  //---------------------------------------------------------------------------------
109  struct timeval getImSecTime(void)
110  {
111  struct timeval msecTime;
112  gettimeofday(&msecTime, (struct timezone *)nullptr) ;
113 
114  return msecTime ;
115  }
116 /*
117  //---------------------------------------------------------------------------------
118  static double timeDiff(std::string firstTime, std::string secondTime)
119  {
120  time_t rawTime;
121  struct tm * rawTimeInfo;
122 
123  int firstMonth = atoi( firstTime.substr(0,2).c_str()) ;
124  int firstDay = atoi( firstTime.substr(3,2).c_str()) ;
125  int firstYear = atoi( firstTime.substr(6,4).c_str()) ;
126  int secondMonth = atoi(secondTime.substr(0,2).c_str()) ;
127  int secondDay = atoi(secondTime.substr(3,2).c_str()) ;
128  int secondYear = atoi(secondTime.substr(6,4).c_str()) ;
129 
130  time(&rawTime);
131  rawTimeInfo = localtime(&rawTime);
132  rawTimeInfo->tm_mon = firstMonth - 1 ;
133  rawTimeInfo->tm_mday = firstDay ;
134  rawTimeInfo->tm_year = firstYear - 1900 ;
135 
136  time_t ft = mktime( rawTimeInfo ) ;
137 
138  rawTimeInfo = localtime(&rawTime);
139  rawTimeInfo->tm_mon = secondMonth - 1 ;
140  rawTimeInfo->tm_mday = secondDay ;
141  rawTimeInfo->tm_year = secondYear - 1900 ;
142 
143  time_t st = mktime( rawTimeInfo ) ;
144 
145  return difftime(ft, st) ;
146  }
147 */
148  //=================================================================================
149 
150  private:
151 
152  struct timeval startTime_ ;
153  struct timeval endTime_ ;
155  bool verbose_ ;
156  } ;
157 }
158 
159 #endif
Definition: start.py:1
struct timeval getImSecTime(void)
virtual ~PixelTimeFormatter()=default
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const
#define constexpr
static std::string getmSecTime(void)
return((rh^lh)&mask)
PixelTimeFormatter(std::string source)
static std::string getTime(void)
This class implements..
struct tm * getITime(void)
This class implements the configuration key which actually just is an integer.
#define USE_TIMER_
static std::string const source
Definition: EdmProvDump.cc:43