Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wroot/date is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_wroot_date
0005 #define tools_wroot_date
0006 
0007 //_MSC_VER (= Microsoft VisualC++) :
0008 //  localtime_r() does not exist on Windows and we can't use the
0009 //  Windows ::GetLocalTime() since G4 do not want to include windows.h.
0010 //  Then we stay with the not thread safe localtime().
0011 
0012 #include <time.h>
0013 
0014 namespace tools {
0015 namespace wroot {
0016 
0017 typedef unsigned int date;
0018 
0019 inline date get_date(){
0020   // Set Date/Time to current time as reported by the system.
0021   // Date and Time are encoded into one single unsigned 32 bit word.
0022   // Date is stored with the origin being the 1st january 1995.
0023   // Time has 1 second precision.
0024   time_t tloc = ::time(0);
0025 #if defined(_MSC_VER) || defined(__MINGW32__)
0026   struct tm *tp = (tm*)::localtime(&tloc); //not thread safe (but exist on Windows).
0027 #else
0028   struct tm tpa;
0029   struct tm *tp = (tm*)::localtime_r(&tloc, &tpa); //does not exist on Windows.
0030 #endif
0031   unsigned int _year   = tp->tm_year;
0032   unsigned int _month  = tp->tm_mon + 1;
0033   unsigned int _day    = tp->tm_mday;
0034   unsigned int _hour   = tp->tm_hour;
0035   unsigned int _min    = tp->tm_min;
0036   unsigned int _sec    = tp->tm_sec;
0037   return ((_year-95)<<26 | _month<<22 | _day<<17 | _hour<<12 | _min<<6 | _sec);
0038 }
0039 
0040 }}
0041 
0042 #endif