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  char theDate[20] ;
62  struct tm *thisTime;
63  time_t aclock;
65  time( &aclock );
66  thisTime = localtime( &aclock );
67 
68  sprintf(theDate,
69  "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
70  thisTime->tm_mon+1,
71  thisTime->tm_mday,
72  thisTime->tm_hour,
73  thisTime->tm_min,
74  thisTime->tm_sec );
75  date = theDate ;
76  //std::cout << "[PixelTimeFormatter::getTime()]\t\t\t\t Time: " << date << std::endl ;
77  return date ;
78  }
79 
80  //---------------------------------------------------------------------------------
81  struct tm * getITime(void)
82  {
83  struct tm *thisTime;
84  time_t aclock;
85  time( &aclock );
86  thisTime = localtime( &aclock );
87  return thisTime ;
88  }
89 
90  //---------------------------------------------------------------------------------
91  static std::string getmSecTime(void)
92  {
93  char theDate[20] ;
94  struct timeval msecTime;
95  gettimeofday(&msecTime, (struct timezone *)nullptr) ;
96 
97  sprintf(theDate,
98  "%d-%d",
99  (unsigned int)msecTime.tv_sec,
100  (unsigned int)msecTime.tv_usec );
101  return std::string(theDate) ;
102  }
103 
104  //---------------------------------------------------------------------------------
105  struct timeval getImSecTime(void)
106  {
107  struct timeval msecTime;
108  gettimeofday(&msecTime, (struct timezone *)nullptr) ;
109 
110  return msecTime ;
111  }
112 /*
113  //---------------------------------------------------------------------------------
114  static double timeDiff(std::string firstTime, std::string secondTime)
115  {
116  time_t rawTime;
117  struct tm * rawTimeInfo;
118 
119  int firstMonth = atoi( firstTime.substr(0,2).c_str()) ;
120  int firstDay = atoi( firstTime.substr(3,2).c_str()) ;
121  int firstYear = atoi( firstTime.substr(6,4).c_str()) ;
122  int secondMonth = atoi(secondTime.substr(0,2).c_str()) ;
123  int secondDay = atoi(secondTime.substr(3,2).c_str()) ;
124  int secondYear = atoi(secondTime.substr(6,4).c_str()) ;
125 
126  time(&rawTime);
127  rawTimeInfo = localtime(&rawTime);
128  rawTimeInfo->tm_mon = firstMonth - 1 ;
129  rawTimeInfo->tm_mday = firstDay ;
130  rawTimeInfo->tm_year = firstYear - 1900 ;
131 
132  time_t ft = mktime( rawTimeInfo ) ;
133 
134  rawTimeInfo = localtime(&rawTime);
135  rawTimeInfo->tm_mon = secondMonth - 1 ;
136  rawTimeInfo->tm_mday = secondDay ;
137  rawTimeInfo->tm_year = secondYear - 1900 ;
138 
139  time_t st = mktime( rawTimeInfo ) ;
140 
141  return difftime(ft, st) ;
142  }
143 */
144  //=================================================================================
145 
146  private:
147 
148  struct timeval startTime_ ;
149  struct timeval endTime_ ;
151  bool verbose_ ;
152  } ;
153 }
154 
155 #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
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.
return(e1-e2)*(e1-e2)+dp *dp
#define USE_TIMER_
static std::string const source
Definition: EdmProvDump.cc:43