CMS 3D CMS Logo

TimeOfDay.cc
Go to the documentation of this file.
2 #include <iomanip>
3 #include <locale>
4 #include <ostream>
5 #include <ctime>
6 
7 namespace {
8  int const power[] = {1000 * 1000, 100 * 1000, 10 * 1000, 1000, 100, 10, 1};
9 }
10 
11 namespace edm {
12 
13  TimeOfDay::TimeOfDay() : tv_(TimeOfDay::setTime_()) {}
14 
15  TimeOfDay::TimeOfDay(struct timeval const& tv) : tv_(tv) {}
16 
17  timeval TimeOfDay::setTime_() {
18  timeval tv;
19  gettimeofday(&tv, nullptr);
20  return tv;
21  }
22 
23  std::ostream& operator<<(std::ostream& os, TimeOfDay const& tod) {
24  std::ios::fmtflags oldflags = os.flags(); // Save stream formats so they can be left unchanged.
25  struct tm timebuf;
26  localtime_r(&tod.tv_.tv_sec, &timebuf);
27  typedef std::ostreambuf_iterator<char, std::char_traits<char> > Iter;
28  std::time_put<char, Iter> const& tp = std::use_facet<std::time_put<char, Iter> >(std::locale());
29  int precision = os.precision();
30  Iter begin(os);
31  if (precision == 0) {
32  char const pattern[] = "%d-%b-%Y %H:%M:%S %Z";
33  tp.put(begin, os, ' ', &timebuf, pattern, pattern + sizeof(pattern) - 1);
34  } else {
35  char const pattern[] = "%d-%b-%Y %H:%M:%S.";
36  tp.put(begin, os, ' ', &timebuf, pattern, pattern + sizeof(pattern) - 1);
37  precision = std::min(precision, 6);
38  os << std::setfill('0') << std::setw(precision) << tod.tv_.tv_usec / power[precision] << ' ';
39  tp.put(begin, os, ' ', &timebuf, 'Z');
40  }
41  os.flags(oldflags);
42  return os;
43  }
44 } // namespace edm
static struct timeval setTime_()
Definition: TimeOfDay.cc:17
T min(T a, T b)
Definition: MathUtil.h:58
struct timeval tv_
Definition: TimeOfDay.h:12
#define begin
Definition: vmac.h:32
HLT enums.
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.