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 {
27  class PixelTimeFormatter {
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;
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
pos::PixelTimeFormatter::getImSecTime
struct timeval getImSecTime(void)
Definition: PixelTimeFormatter.h:104
pos::PixelTimeFormatter::origin_
std::string origin_
Definition: PixelTimeFormatter.h:147
start
Definition: start.py:1
pos::PixelTimeFormatter::PixelTimeFormatter
PixelTimeFormatter(std::string source)
Definition: PixelTimeFormatter.h:29
pos::PixelTimeFormatter::startTime_
struct timeval startTime_
Definition: PixelTimeFormatter.h:145
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PixelConfigKey.h
This class implements the configuration key which actually just is an integer.
pos
Definition: PixelAliasList.h:18
pos::PixelTimeFormatter::verbose_
bool verbose_
Definition: PixelTimeFormatter.h:148
pos::PixelTimeFormatter::~PixelTimeFormatter
virtual ~PixelTimeFormatter()=default
pos::PixelTimeFormatter::getTime
static std::string getTime(void)
Definition: PixelTimeFormatter.h:60
pos::PixelTimeFormatter::getITime
struct tm * getITime(void)
Definition: PixelTimeFormatter.h:84
pos::PixelTimeFormatter::getmSecTime
static std::string getmSecTime(void)
Definition: PixelTimeFormatter.h:93
source
static const std::string source
Definition: EdmProvDump.cc:47
USE_TIMER_
#define USE_TIMER_
Definition: PixelTimeFormatter.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
pos::PixelConfigKey
This class implements..
Definition: PixelConfigKey.h:20
pos::PixelTimeFormatter::writeXMLHeader
virtual void writeXMLHeader(pos::PixelConfigKey key, int version, std::string path, std::ofstream *out, std::ofstream *out1=nullptr, std::ofstream *out2=nullptr) const
Definition: PixelTimeFormatter.h:50
pos::PixelTimeFormatter
Definition: PixelTimeFormatter.h:26
pos::PixelTimeFormatter::stopTimer
void stopTimer(void)
Definition: PixelTimeFormatter.h:40
pos::PixelTimeFormatter::endTime_
struct timeval endTime_
Definition: PixelTimeFormatter.h:146
indexGen.date
date
Definition: indexGen.py:99
PointingDoubleMultiSkim_cfg.out2
out2
Definition: PointingDoubleMultiSkim_cfg.py:85
PointingDoubleMultiSkim_cfg.out1
out1
Definition: PointingDoubleMultiSkim_cfg.py:57
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:29
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
ntuplemaker.time
time
Definition: ntuplemaker.py:310
crabWrapper.key
key
Definition: crabWrapper.py:19
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45