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