//*-- Modified : v0.48 01/06/00 by D. Buskulic (parts borrowed from DMT/John Zweizig)//*-- Author : Damir Buskulic 10/05/00//////////////////////////////////////////////////////////////////////////// //// GPS Time //// //// Time defined by GPS standard //// ////////////////////////////////////////////////////////////////////////////
#include "VGPSTime.h"
#include "TString.h"
ClassImp(VGPSTime)
static const long iStoNS = 1000000000;
static const double dStoNS = 1000000000.;
static const double dNStoS = 0.000000001;
//______________________________________________________________________________VGPSTime& VGPSTime::operator =(const VGPSTime& gpst)
{
// Assignement operatormSec = gpst.mSec;
mNsec = gpst.mNsec;
return (*this);
}
//______________________________________________________________________________VGPSTime& VGPSTime::operator =(double& gpstd)
{
// Assignement operatorSetTimeD(gpstd);
return (*this);
}
//______________________________________________________________________________VGPSTimeVGPSTime::operator +=(double interval)
{
// += operator. Adds a time interval to the GPS timelong intervalS = (long)(floor(interval));
long intervalNS = (long)((interval-intervalS)*1e9+0.5); // +0.5 to avoid rounding errors
mNsec += intervalNS;
if ((long)mNsec >= iStoNS) {
mNsec -= iStoNS;
intervalS++;
}
if (intervalS >= 0) {
mSec += intervalS;
} else if ((long)mSec >= -intervalS) {
mSec -= (-intervalS);
} else {
mNsec = 0;
mSec = 0;
}
return (*this);
}
//______________________________________________________________________________VGPSTimeVGPSTime::operator -=(double interval)
{
// += operator. Adds a time interval to the GPS timelong intervalS = (long)(floor(interval));
long intervalNS = (long)((interval-intervalS)*1e9+0.5); // +0.5 to avoid rounding errors
if ((long)mNsec >= intervalNS) {
mNsec -= intervalNS;
} else {
intervalS++; // Bump a number to be subtracted.
mNsec += iStoNS - intervalNS;
}
if (intervalS <= 0) {
mSec += -intervalS;
} else if ((long)mSec >= intervalS) {
mSec -= intervalS;
} else {
mSec = 0;
mNsec = 0;
}
return (*this);
}
//______________________________________________________________________________VGPSTime operator +(const VGPSTime& gpst, double interval)
{
VGPSTime gpsnew = gpst;
gpsnew += interval;
return gpsnew;
}
//______________________________________________________________________________VGPSTime operator +(double interval, const VGPSTime& gpst)
{
VGPSTime gpsnew = gpst;
gpsnew += interval;
return gpsnew;
}
//______________________________________________________________________________VGPSTime operator -(const VGPSTime& gpst, double interval)
{
VGPSTime gpsnew = gpst;
gpsnew -= interval;
return gpsnew;
}
//______________________________________________________________________________VGPSTime operator -(double interval, const VGPSTime& gpst)
{
VGPSTime gpsnew = gpst;
gpsnew -= interval;
return gpsnew;
}
//______________________________________________________________________________const Text_t* VGPSTime::ExpressTime(Double_t gpstime, Option_t* fmtopt, Int_t leapS, Int_t local0)
{
// Given a GPS time, expresses it in a convenient format// depending on the chosen options for time format in option// options are "GPS", "LOCAL", "LOCALEUR", "LOCALUS", "UNI",// "UNIEUR", "UNIUS"// If none of these formats is used, the string is interpreted as an// input string to the standard C strftime function. See TAxis::SetTimeFormat// for more information.// ULeapS are the leap seconds needed for the GPS->UTC conversion// (33 seconds as of 1st January 1999, changes aprox. once per year,// given by the frames/ vectors)// local is the difference in multiples of 1800 s between UTC and the local time// Not used for the time being since "local" means local to the machine// on which the display is done and not local to the experiment. May change// in the future but needs to include some info like if there is a daylight// savings time locally on the experiment.
static char out[50];
static char* standname[9] = {"gps", "local", "localeur", "localus", "uni",
"unieur", "unius","eur","us"};
time_t utctimeT;
struct tm* utctis;
int i, okstand, localtime;
TString option = fmtopt;
option.ToLower();
utctimeT = (time_t)(gpstime - leapS + 19 + 315964800 + 0.5); // round to the nearest second
// Protect against wrong local times
if (local0>85200 || local0<0) localtime = 0;
else localtime = local0;
// Test of standard option
okstand = 0;
for (i=0; i<9; i++) {
if (!option.CompareTo(standname[i])) {
okstand = 1;
break;
}
}
// Executes for standard option
if (okstand) {
if (option.Contains("local")) utctimeT += localtime;
utctis = gmtime(&utctimeT);
out[0] = 0;
if (!option.CompareTo("gps")) {
sprintf(out,"%12.2f",gpstime);
} else if (option.Contains("eur")) {
strftime(out,40,"%d/%m/%y %H:%M:%S",utctis);
} else if (option.Contains("us")) {
strftime(out,40,"%m/%d/%y %p %I:%M:%S",utctis);
} else {
strftime(out,40,"%d/%m/%y %H:%M:%S",utctis);
}
} else {
utctis = gmtime(&utctimeT);
strftime(out,40,fmtopt,utctis);
}
return out;
}
//______________________________________________________________________________const Text_t* VGPSTime::ExpandFormat(const char* fmt)
{
// Expands the format fmt, which can be any of// "GPS", "LOCAL", "LOCALEUR", "LOCALUS", "UNI", "UNIEUR", "UNIUS"// If none of these formats is used, the string is interpreted as an// input string to the standard C strftime function. See TAxis::SetTimeFormat// for more information.
static char out[50];
static char* standname[7] = {"gps", "local", "localeur", "localus", "uni",
"unieur", "unius"};
int i, okstand;
TString option = fmt;
// Test of standard option
okstand = 0;
for (i=0; i<7; i++) {
if (!option.CompareTo(standname[i])) {
okstand = 1;
break;
}
}
// Executes for standard option
if (okstand) {
if (option.Contains("eur")) {
sprintf(out,"%%d/%%m/%%y %%H:%%M:%%S");
} else if (option.Contains("us")) {
sprintf(out,"%%m/%%d/%%y %%p %%I:%%M:%%S");
} else {
out[0]=0;
}
} else {
out[0]=0;
}
return out;
}
- ROOT page - VEGA page - Class index - Top of the page This page has been automatically generated. If you have any comments or suggestions
about the page layout send a mail to
, or
contact
with any questions or problems regarding ROOT or VEGA.