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