File indexing completed on 2024-04-06 11:58:13
0001
0002
0003
0004
0005
0006 #ifndef PixelTimeFormatter_h
0007 #define PixelTimeFormatter_h
0008
0009
0010
0011
0012
0013
0014
0015 #include "CalibFormats/SiPixelObjects/interface/PixelConfigKey.h"
0016
0017 #include <iostream>
0018 #include <sstream>
0019 #include <string>
0020 #include <ctime>
0021 #include <sys/time.h>
0022 #include <cstdlib>
0023
0024 #define USE_TIMER_ 0
0025
0026 namespace pos {
0027 class PixelTimeFormatter {
0028 public:
0029
0030 PixelTimeFormatter(std::string source) {
0031 if (!USE_TIMER_)
0032 return;
0033 origin_ = source;
0034 std::cout << "[PixelTimeFormatter::PixelTimeFormatter()]\t\t Time counter started for " << origin_
0035 << std::endl;
0036 startTime_ = getImSecTime();
0037 }
0038
0039 virtual ~PixelTimeFormatter() = default;
0040
0041 void stopTimer(void) {
0042 if (!USE_TIMER_)
0043 return;
0044 endTime_ = getImSecTime();
0045 double start = startTime_.tv_sec + startTime_.tv_usec / 1000000.;
0046 double stop = endTime_.tv_sec + endTime_.tv_usec / 1000000.;
0047 std::cout << "[PixelTimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop - start << " seconds for "
0048 << origin_ << std::endl;
0049 }
0050
0051 virtual void writeXMLHeader(pos::PixelConfigKey key,
0052 int version,
0053 std::string path,
0054 std::ofstream *out,
0055 std::ofstream *out1 = nullptr,
0056 std::ofstream *out2 = nullptr) const {
0057 ;
0058 }
0059
0060
0061 static std::string getTime(void) {
0062 constexpr size_t kBufferLength = 72;
0063 char theDate[kBufferLength];
0064 struct tm *thisTime;
0065 time_t aclock;
0066 std::string date;
0067 time(&aclock);
0068 thisTime = localtime(&aclock);
0069
0070 snprintf(theDate,
0071 kBufferLength,
0072 "%d-%02d-%02d %02d:%02d:%02d",
0073 thisTime->tm_year + 1900,
0074 thisTime->tm_mon + 1,
0075 thisTime->tm_mday,
0076 thisTime->tm_hour,
0077 thisTime->tm_min,
0078 thisTime->tm_sec);
0079 date = theDate;
0080
0081 return date;
0082 }
0083
0084
0085 struct tm *getITime(void) {
0086 struct tm *thisTime;
0087 time_t aclock;
0088 time(&aclock);
0089 thisTime = localtime(&aclock);
0090 return thisTime;
0091 }
0092
0093
0094 static std::string getmSecTime(void) {
0095 constexpr size_t kBufferSize = 20;
0096 char theDate[kBufferSize];
0097 struct timeval msecTime;
0098 gettimeofday(&msecTime, (struct timezone *)nullptr);
0099
0100 snprintf(theDate, kBufferSize, "%d-%d", (unsigned int)msecTime.tv_sec, (unsigned int)msecTime.tv_usec);
0101 return std::string(theDate);
0102 }
0103
0104
0105 struct timeval getImSecTime(void) {
0106 struct timeval msecTime;
0107 gettimeofday(&msecTime, (struct timezone *)nullptr);
0108
0109 return msecTime;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 private:
0146 struct timeval startTime_;
0147 struct timeval endTime_;
0148 std::string origin_;
0149 bool verbose_;
0150 };
0151 }
0152
0153 #endif