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