CMS 3D CMS Logo

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