g4tools  5.4.0
date
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_wroot_date
5 #define tools_wroot_date
6 
7 //_MSC_VER (= Microsoft VisualC++) :
8 // localtime_r() does not exist on Windows and we can't use the
9 // Windows ::GetLocalTime() since G4 do not want to include windows.h.
10 // Then we stay with the not thread safe localtime().
11 
12 #include <time.h>
13 
14 namespace tools {
15 namespace wroot {
16 
17 typedef unsigned int date;
18 
19 inline date get_date(){
20  // Set Date/Time to current time as reported by the system.
21  // Date and Time are encoded into one single unsigned 32 bit word.
22  // Date is stored with the origin being the 1st january 1995.
23  // Time has 1 second precision.
24  time_t tloc = ::time(0);
25 #ifdef _MSC_VER
26  struct tm *tp = (tm*)::localtime(&tloc); //not thread safe (but exist on Windows).
27 #else
28  struct tm tpa;
29  struct tm *tp = (tm*)::localtime_r(&tloc, &tpa); //does not exist on Windows.
30 #endif
31  unsigned int year = tp->tm_year;
32  unsigned int month = tp->tm_mon + 1;
33  unsigned int day = tp->tm_mday;
34  unsigned int hour = tp->tm_hour;
35  unsigned int min = tp->tm_min;
36  unsigned int sec = tp->tm_sec;
37  return ((year-95)<<26 | month<<22 | day<<17 | hour<<12 | min<<6 | sec);
38 }
39 
40 }}
41 
42 #endif
tools::wroot::get_date
date get_date()
Definition: date:19
tools::wroot::date
unsigned int date
Definition: date:17
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26