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 
49  std::ofstream *out,
50  std::ofstream *out1 = NULL,
51  std::ofstream *out2 = NULL
52  ) const {;}
53 
54  //---------------------------------------------------------------------------------
55  static std::string getTime(void)
56  {
57  char theDate[20] ;
58  struct tm *thisTime;
59  time_t aclock;
60  std::string date ;
61  time( &aclock );
62  thisTime = localtime( &aclock );
63 
64  sprintf(theDate,
65  "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
66  thisTime->tm_mon+1,
67  thisTime->tm_mday,
68  thisTime->tm_hour,
69  thisTime->tm_min,
70  thisTime->tm_sec );
71  date = theDate ;
72  //std::cout << "[PixelTimeFormatter::getTime()]\t\t\t\t Time: " << date << std::endl ;
73  return date ;
74  }
75 
76  //---------------------------------------------------------------------------------
77  struct tm * getITime(void)
78  {
79  struct tm *thisTime;
80  time_t aclock;
81  time( &aclock );
82  thisTime = localtime( &aclock );
83  return thisTime ;
84  }
85 
86  //---------------------------------------------------------------------------------
87  static std::string getmSecTime(void)
88  {
89  char theDate[20] ;
90  struct timeval msecTime;
91  gettimeofday(&msecTime, (struct timezone *)0) ;
92 
93  sprintf(theDate,
94  "%d-%d",
95  (unsigned int)msecTime.tv_sec,
96  (unsigned int)msecTime.tv_usec );
97  return std::string(theDate) ;
98  }
99 
100  //---------------------------------------------------------------------------------
101  struct timeval getImSecTime(void)
102  {
103  struct timeval msecTime;
104  gettimeofday(&msecTime, (struct timezone *)0) ;
105 
106  return msecTime ;
107  }
108 /*
109  //---------------------------------------------------------------------------------
110  static double timeDiff(std::string firstTime, std::string secondTime)
111  {
112  time_t rawTime;
113  struct tm * rawTimeInfo;
114 
115  int firstMonth = atoi( firstTime.substr(0,2).c_str()) ;
116  int firstDay = atoi( firstTime.substr(3,2).c_str()) ;
117  int firstYear = atoi( firstTime.substr(6,4).c_str()) ;
118  int secondMonth = atoi(secondTime.substr(0,2).c_str()) ;
119  int secondDay = atoi(secondTime.substr(3,2).c_str()) ;
120  int secondYear = atoi(secondTime.substr(6,4).c_str()) ;
121 
122  time(&rawTime);
123  rawTimeInfo = localtime(&rawTime);
124  rawTimeInfo->tm_mon = firstMonth - 1 ;
125  rawTimeInfo->tm_mday = firstDay ;
126  rawTimeInfo->tm_year = firstYear - 1900 ;
127 
128  time_t ft = mktime( rawTimeInfo ) ;
129 
130  rawTimeInfo = localtime(&rawTime);
131  rawTimeInfo->tm_mon = secondMonth - 1 ;
132  rawTimeInfo->tm_mday = secondDay ;
133  rawTimeInfo->tm_year = secondYear - 1900 ;
134 
135  time_t st = mktime( rawTimeInfo ) ;
136 
137  return difftime(ft, st) ;
138  }
139 */
140  //=================================================================================
141 
142  private:
143 
144  struct timeval startTime_ ;
145  struct timeval endTime_ ;
147  bool verbose_ ;
148  } ;
149 }
150 
151 #endif
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
struct timeval getImSecTime(void)
#define NULL
Definition: scimark2.h:8
static std::string getmSecTime(void)
return((rh^lh)&mask)
PixelTimeFormatter(std::string source)
static std::string getTime(void)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
This class implements..
tuple out
Definition: dbtoconf.py:99
struct tm * getITime(void)
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=NULL, std::ofstream *out2=NULL) const
tuple cout
Definition: gather_cfg.py:121
#define USE_TIMER_
static std::string const source
Definition: EdmProvDump.cc:42