NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcTimestamp.h
Go to the documentation of this file.
1#ifndef NcTimestamp_h
2#define NcTimestamp_h
3// Copyright(c) 2005 NCFS/IIHE, All Rights Reserved.
4// See cxx source for full Copyright notice.
5
6#include <iostream>
7#include <fstream>
8
9#include <cstdlib>
10#include <math.h>
11
12#include "TSystem.h"
13#include "TTimeStamp.h"
14#include "TString.h"
15#include "TTree.h"
16
18
19class NcTimestamp : public TTimeStamp
20{
21 public:
22 NcTimestamp(); // Default constructor
23 NcTimestamp(TTimeStamp& t); // Constructor
24 virtual ~NcTimestamp(); // Destructor
25 NcTimestamp(const NcTimestamp& t); // Copy constructor
26 void Date(Int_t mode=3,Double_t offset=0); // Print date/time info
27 Double_t GetJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const; // Julian Date from input args.
28 Double_t GetMJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const;// Modified JD from input args.
29 Double_t GetTJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const;// Truncated JD from input args.
30 Double_t GetJE(Double_t date,TString mode="jd") const; // Julian Epoch corresponding to specified Julian Date
31 Double_t GetBE(Double_t date,TString mode="jd") const; // Besselian Epoch corresponding to specified Julian Date
32 void Convert(Double_t date,Int_t& days,Int_t& secs,Int_t& ns) const;// Convert frac. day count into days, secs and ns
33 Double_t Convert(Int_t days,Int_t secs,Int_t ns) const; // Convert days, secs and ns into frac. day count
34 void Convert(Double_t h,Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps) const;// Convert frac. hour count
35 Double_t Convert(Int_t hh,Int_t mm,Int_t ss,Int_t ns,Int_t ps) const; // Convert hh:mm:ss:ns:ps into frac. hour
36 void Convert(Double_t h,Int_t& hh,Int_t& mm,Double_t& ss) const;// Convert frac. hour count
37 Double_t Convert(Int_t hh,Int_t mm,Double_t ss) const; // Convert hh:mm:ss.s into frac. hours
38 void PrintTime(Double_t h,Int_t ndig=1) const;// Print time in hh:mm:ss.sss format
39 void GetMJD(Int_t& mjd,Int_t& sec,Int_t& ns); // Provide corresponding Modified Julian Date and time
40 Double_t GetMJD(); // Provide corresponding Modified Julian Date in fractional days
41 void GetTJD(Int_t& tjd,Int_t& sec,Int_t& ns); // Provide corresponding Truncated Julian Date and time
42 Double_t GetTJD(); // Provide corresponding Truncated Julian Date in fractional days
43 void GetJD(Int_t& jd,Int_t& sec,Int_t& ns); // Provide corresponding Julian Date and time
44 Double_t GetJD(); // Provide corresponding Julian Date in fractional days
45 Double_t GetJE(); // Provide corresponding Julian Epoch
46 Double_t GetBE(); // Provide corresponding Besselian Epoch
47 Double_t GetJD(Double_t e,TString mode="J") const; // Provide fractional Julian Date from Epoch
48 Double_t GetMJD(Double_t e,TString mode="J") const; // Provide fractional Modified Julian Date from Epoch
49 Double_t GetTJD(Double_t e,TString mode="J") const; // Provide fractional Truncated Julian Date from Epoch
50 void SetMJD(Int_t mjd,Int_t sec,Int_t ns,Int_t ps=0,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Modified Julian Date and time
51 void SetMJD(Double_t mjd,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Modified Julian Date and time
52 void SetJD(Int_t jd,Int_t sec,Int_t ns,Int_t ps=0,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Julian Date and time
53 void SetJD(Double_t jd,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Julian Date and time
54 void SetTJD(Int_t tjd,Int_t sec,Int_t ns,Int_t ps=0,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Truncated Julian Date and time
55 void SetTJD(Double_t tjd,TString utc="U",Int_t leap=0,Double_t dut=0); // Set Truncated Julian Date and time
56 Int_t SetTAI(TString type,TString date,TString time,Int_t mode,TString utc,Int_t leap,Double_t dut=0); // Set specified TAI based date and time
57 Int_t SetTAI(Int_t d,Int_t sec,Int_t ns,Int_t ps,TString utc,Int_t leap,Double_t dut=0,Bool_t tmjd=kFALSE); // Set International Atomic Time (TAI) date and time
58 Int_t SetTAI(Double_t tai,TString utc,Int_t leap,Double_t dut=0,Bool_t tmjd=kFALSE); // Set International Atomic Time (TAI) date and time
59 Int_t SetGPS(Int_t w,Int_t sow,Int_t ns, Int_t ps,TString utc,Int_t leap,Double_t dut=0,Int_t icycle=0); // Set the GPS date/time
60 Int_t SetGPS(Int_t w,Int_t dow,Int_t sod,Int_t ns,Int_t ps,TString utc,Int_t leap,Double_t dut=0,Int_t icycle=0); // Set the GPS date/time
61 Int_t SetUnixTime(Double_t sec,TString utc="A",Int_t leap=0,Double_t dut=0); // Set Unix date and time
62 Int_t GetTAI(Int_t& d,Int_t& sec,Int_t& ns,Int_t& ps,Bool_t tmjd=kTRUE); // Provide corresponding TAI day count and time
63 Double_t GetTAI(Bool_t tmjd=kTRUE); // Provide the corresponding TAI day count in fractional days
64 Int_t GetTAI(Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps,TString type="TAI"); // Provide corresponding TAI time
65 Double_t GetUnixTime(); // Provide the corresponding Unix time (fractional) second count
66 Int_t GetUTCparameters(Int_t& leap,Double_t& dut) const; // Provide the UTC parameters
67 Int_t GetUTCparameters(Int_t mjd,Int_t& leap,Double_t& dut) const; // Provide the UTC parameters for MJD from the IERS data
68 TTree* LoadUTCparameterFiles(TString leapfile="$(NCFS)/IERS/leap.txt",TString dutfile="$(NCFS)/IERS/dut.txt"); // Load IERS data for automatic setting of Leap Seconds and dUT=UT-UTC
69 TTree* GetIERSdatabase() const; // Provide the pointer to the internal IERS database TTree
70 void SetNs(Int_t ns); // Set the remaining fractional number of sec in nanoseconds
71 Int_t GetNs() const; // Provide remaining fractional number of sec in nanoseconds
72 void SetPs(Int_t ps); // Set the remaining fractional number of ns in picoseconds
73 Int_t GetPs() const; // Provide remaining fractional number of ns in picoseconds
74 using TTimeStamp::Add;
75 void Add(Int_t d,Int_t s,Int_t ns,Int_t ps=0); // Add (or subtract) a certain time difference
76 void Add(Double_t hours); // Add (or subtract) a certain time difference
77 void AddSec(Double_t seconds); // Add (or subtract) a certain time difference
78 Int_t GetDifference(NcTimestamp* t,Int_t& days,Int_t& sec,Int_t& ns,Int_t& ps,TString type="UT"); // Provide time difference
79 Int_t GetDifference(NcTimestamp& t,Int_t& days,Int_t& sec,Int_t& ns,Int_t& ps,TString type="UT"); // Provide time difference
80 Double_t GetDifference(NcTimestamp* t,TString u,Int_t mode=1,TString type="UT"); // Provide time diff. in specified units
81 Double_t GetDifference(NcTimestamp& t,TString u,Int_t mode=1,TString type="UT"); // Provide time diff. in specified units
82 void SetUT(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns=0,Int_t ps=0,TString utc="A",Int_t leap=0,Double_t dut=0); // Set specified UT
83 void SetUT(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Double_t s,TString utc="A",Int_t leap=0,Double_t dut=0); // Set specified UT
84 void SetUT(Int_t y,Int_t m,Int_t d,TString time,TString utc="A",Int_t leap=0,Double_t dut=0); // Set specified UT
85 void SetUT(TString date,TString time,Int_t mode,TString utc="A",Int_t leap=0,Double_t dut=0); // Set specified UT
86 void SetUT(Int_t y,Int_t d,Int_t s,Int_t ns=0,Int_t ps=0,TString utc="A",Int_t leap=0,Double_t dut=0); // Set UT based on elapsed days, secs etc...
87 void GetUT(Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps); // Provide corresponding UT
88 Double_t GetUT(); // Provide corresponding UT in fractional hours
89 void GetGMST(Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps); // Corresponding Greenwich Mean Sidereal Time (GMST)
90 Double_t GetGMST(); // Provide corresponding Greenwich Mean Sidereal Time (GMST) in fractional hours
91 Double_t GetGAST(); // Provide corresponding Greenwich Apparent Sidereal Time (GAST) in fractional hours
92 Double_t GetLT(Double_t offset); // Provide corresponding Local Time (LT) in fractional hours
93 Double_t GetLAT(Double_t offset); // Provide corresponding Local Apparent Time (LAT) in fractional hours
94 Double_t GetLMST(Double_t offset); // Provide corresponding Local Mean Sidereal Time (LMST) in fractional hours
95 Double_t GetLAST(Double_t offset); // Provide corresponding Local Apparent Sidereal Time (LAST) in fractional hours
96 void SetLT(Double_t dt,Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns=0,Int_t ps=0,TString utc="A",Int_t leap=0,Double_t dut=0); // Set data according to LT
97 void SetLT(Double_t dt,Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Double_t s,TString utc="A",Int_t leap=0,Double_t dut=0); // Set data according to LT
98 void SetLT(Double_t dt,Int_t y,Int_t m,Int_t d,TString time,TString utc="A",Int_t leap=0,Double_t dut=0); // Set data according to LT
99 void SetLT(Double_t dt,TString date,TString time,Int_t mode,TString utc="A",Int_t leap=0,Double_t dut=0); // Set data according to LT
100 void SetLT(Double_t dt,Int_t y,Int_t d,Int_t s,Int_t ns=0,Int_t ps=0,TString utc="A",Int_t leap=0,Double_t dut=0); // Set data according to LT based on elapsed days, secs etc...
101 Double_t Almanac(Double_t* dpsi=0,Double_t* deps=0,Double_t* eps=0,Double_t* dl=0,TString name="",Double_t* el=0,Double_t* eb=0,Double_t* dr=0,Double_t* value=0,Int_t j=0); // Provide astronomical observables
102 void SetEpoch(Double_t e,TString mode,TString utc="U",Int_t leap=0,Double_t dut=0); // Set time parameters according to the specified epoch
103 Double_t GetEpoch(TString mode); // Provide the requested epoch
104 TString GetDayTimeString(TString mode,Int_t ndig=0,Double_t offset=0,TString* date=0,TString* time=0,Bool_t full=kTRUE); // Provide the date and time in TString format
105 void SetSystemTime(); // Set UTC (or UT1) to the current time of the system clock
106 Bool_t IsUT1() const; // Indicate whether the reference time is UT1 (kTRUE) or UTC (kFALSE)
107
108 protected:
109 Int_t fMJD; // Modified Julian Date
110 Int_t fJsec; // Number of seconds elapsed within the MJD
111 Int_t fJns; // Remaining fractional number of seconds (in nanoseconds) elapsed within the MJD
112 Int_t fJps; // Remaining fractional number of nanoseconds (in picoseconds) elapsed within the MJD
113 Int_t fUtc; // Flag to denote that the UTC related info below has been provided (-1=auto 0=no 1=yes)
114 Int_t fLeap; // The cumulated number of leap seconds at the moment of the timestamp
115 Double_t fDut; // The value of UT-UTC in seconds at the moment of the timestamp
116 Int_t fTmjd; // Number of elapsed TAI days equivalent to MJD counting
117 Int_t fTsec; // Number of seconds elapsed within the TAI day
118 Int_t fTns; // Remaining fractional number of seconds (in nanoseconds) elapsed within the TAI day
119 Int_t fTps; // Remaining fractional number of nanoseconds (in picoseconds) elapsed within the TAI day
120 TTree* fUTCdata; // Internal tree to contain the daily leap second and UT-UTC values
121
122 protected:
123 Int_t SetUTCparameters(TString utc,Int_t leap,Double_t dut); // Setting of the UTC parameters
124
125 private:
126 void AddCalc(Int_t d,Int_t s,Int_t ns,Int_t ps=0,Bool_t utcpar=kTRUE); // Add (or subtract) a certain time difference
127 void AddCalc(Double_t hours,Bool_t utcpar=kTRUE); // Add (or subtract) a certain time difference
128 void AddSecCalc(Double_t seconds,Bool_t utcpar=kTRUE); // Add (or subtract) a certain time difference
129 void FillJulian(); // Calculation and setting of the corresponding Julian parameters
130 void FillTAI(); // Calculation and setting of the corresponding TAI day etc. count
131 Int_t fCalcs; // The TTimeStamp seconds counter value at Julian parameter calculation
132 Int_t fCalcns; // The TTimeStamp nanoseconds counter value at Julian parameter calculation
133
134 ClassDef(NcTimestamp,17) // Handling of timestamps for (astro)particle physics research.
135};
136#endif
virtual ~NcTimestamp()
Double_t GetEpoch(TString mode)
Double_t GetTJD()
Int_t SetUnixTime(Double_t sec, TString utc="A", Int_t leap=0, Double_t dut=0)
Int_t SetTAI(TString type, TString date, TString time, Int_t mode, TString utc, Int_t leap, Double_t dut=0)
Int_t SetGPS(Int_t w, Int_t sow, Int_t ns, Int_t ps, TString utc, Int_t leap, Double_t dut=0, Int_t icycle=0)
void SetLT(Double_t dt, Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss, Int_t ns=0, Int_t ps=0, TString utc="A", Int_t leap=0, Double_t dut=0)
void SetSystemTime()
TString GetDayTimeString(TString mode, Int_t ndig=0, Double_t offset=0, TString *date=0, TString *time=0, Bool_t full=kTRUE)
Double_t Almanac(Double_t *dpsi=0, Double_t *deps=0, Double_t *eps=0, Double_t *dl=0, TString name="", Double_t *el=0, Double_t *eb=0, Double_t *dr=0, Double_t *value=0, Int_t j=0)
Double_t GetLAT(Double_t offset)
TTree * GetIERSdatabase() const
Double_t GetGMST()
Double_t GetLMST(Double_t offset)
Double_t GetUT()
Double_t GetMJD()
Bool_t IsUT1() const
Int_t GetPs() const
Double_t GetLT(Double_t offset)
void AddSecCalc(Double_t seconds, Bool_t utcpar=kTRUE)
Double_t GetBE()
Int_t SetUTCparameters(TString utc, Int_t leap, Double_t dut)
void SetEpoch(Double_t e, TString mode, TString utc="U", Int_t leap=0, Double_t dut=0)
Double_t GetGAST()
void SetUT(Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss, Int_t ns=0, Int_t ps=0, TString utc="A", Int_t leap=0, Double_t dut=0)
void PrintTime(Double_t h, Int_t ndig=1) const
Double_t GetLAST(Double_t offset)
TTree * fUTCdata
TTree * LoadUTCparameterFiles(TString leapfile="$(NCFS)/IERS/leap.txt", TString dutfile="$(NCFS)/IERS/dut.txt")
void SetTJD(Int_t tjd, Int_t sec, Int_t ns, Int_t ps=0, TString utc="U", Int_t leap=0, Double_t dut=0)
void SetMJD(Int_t mjd, Int_t sec, Int_t ns, Int_t ps=0, TString utc="U", Int_t leap=0, Double_t dut=0)
Int_t GetNs() const
Double_t fDut
void SetJD(Int_t jd, Int_t sec, Int_t ns, Int_t ps=0, TString utc="U", Int_t leap=0, Double_t dut=0)
Double_t GetJE()
Double_t GetUnixTime()
void Add(Int_t d, Int_t s, Int_t ns, Int_t ps=0)
void Convert(Double_t date, Int_t &days, Int_t &secs, Int_t &ns) const
Int_t GetUTCparameters(Int_t &leap, Double_t &dut) const
Int_t GetDifference(NcTimestamp *t, Int_t &days, Int_t &sec, Int_t &ns, Int_t &ps, TString type="UT")
void AddSec(Double_t seconds)
void Date(Int_t mode=3, Double_t offset=0)
void AddCalc(Int_t d, Int_t s, Int_t ns, Int_t ps=0, Bool_t utcpar=kTRUE)
Int_t GetTAI(Int_t &d, Int_t &sec, Int_t &ns, Int_t &ps, Bool_t tmjd=kTRUE)
Double_t GetJD()
void SetPs(Int_t ps)
void SetNs(Int_t ns)