]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliTimestamp.cxx
04-mar-2005 NvE Installation scripts named amdgcclib.sh introduced in all /scripts...
[u/mrichter/AliRoot.git] / RALICE / AliTimestamp.cxx
CommitLineData
3ea81e9c 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17
18///////////////////////////////////////////////////////////////////////////
19// Class AliTimestamp
20// Handling of timestamps for (astro)particle physics reserach.
21//
22// This class is derived from TTimeStamp and provides additional
23// facilities (e.g. Julian date) which are commonly used in the
24// field of (astro)particle physics.
25//
26// The Julian Date (JD) indicates the number of days since noon (UT) on
27// 01 jan -4712 (i.e. noon 01 jan 4713 BC), being day 0 of the Julian calendar.
28//
29// The Modified Julian Date (MJD) indicates the number of days since midnight
30// (UT) on 17-nov-1858, which corresponds to 2400000.5 days after day 0 of the
31// Julian calendar.
32//
33// The Truncated Julian Date (TJD) corresponds to 2440000.5 days after day 0
34// of the Julian calendar and consequently TJD=MJD-40000.
35// This TJD date indication was used by the Vela and Batse missions in
36// view of Gamma Ray Burst investigations.
37//
38// The Julian Epoch (JE) indicates the fractional elapsed year count since
39// midnight (UT) on 01-jan at the start of the Gregorian year count.
40// A year is defined to be 365.25 days, so the integer part of JE corresponds
41// to the usual Gregorian year count.
42// So, 01-jan-1965 00:00:00 UT corresponds to JE=1965.0
43//
44// Because of the fact that the Julian date indicators are all w.r.t. UT
45// they provide an absolute timescale irrespective of timezone or daylight
46// saving time (DST).
47//
48// This AliTimestamp facility allows for nanosecond precision.
49// However, when the fractional JD, MJD and TJD counts are used instead
50// of the integer (days,sec,ns) specification, the nanosecond precision
51// may be lost due to computer accuracy w.r.t. floating point operations.
52//
53// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
54// which corresponds to JD=2440587.5 or the start of MJD=40587 or TJD=587.
55// Using the corresponding MJD of this EPOCH allows construction of
56// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input (M/T)JD and time.
57// Obviously this TTimeStamp implementation would prevent usage of values
58// smaller than JD=2440587.5 or MJD=40587 or TJD=587.
59// However, this AliTimestamp facility provides support for the full range
60// of (M/T)JD values, but the setting of the corresponding TTimeStamp parameters
61// is restricted to the values allowed by the TTimeStamp implementation.
62// For these earlier (M/T)JD values, the standard TTimeStamp parameters will
63// be set corresponding to the start of the TTimeStamp EPOCH.
64// This implies that for these earlier (M/T)JD values the TTimeStamp parameters
65// do not match the Julian parameters of AliTimestamp.
66// As such the standard TTimeStamp parameters do not appear on the print output
67// when invoking the Date() memberfunction for these earlier (M/T)JD values.
68//
69// Examples :
70// ==========
71//
72// Note : All TTimeStamp functionality is available as well.
73//
74// AliTimestamp t;
75//
76// t.Date();
77//
78// // Retrieve Julian Date
79// Int_t jd,jsec,jns;
80// t.GetJD(jd,jsec,jns);
81//
82// // Retrieve fractional Truncated Julian Date
83// Double_t tjd=t.GetTJD();
84//
85// // Retrieve fractional Julian Epoch
86// Double_t je=t.GetJE();
87//
88// // Set to a specific Modified Julian Date
89// Int_t mjd=50537;
90// Int_t mjsec=1528;
91// Int_t mjns=185643;
92// t.SetMJD(mjd,mjsec,mjns);
93//
94// t.Date();
95//
96// // Some practical conversion facilities
97// // Note : They don't influence the actual date/time settings
98// // and as such can also be invoked as AliTimestamp::Convert(...) etc...
99// Int_t y=1921;
100// Int_t m=7;
101// Int_t d=21;
102// Int_t hh=15;
103// Int_t mm=23;
104// Int_t ss=47;
105// Int_t ns=811743;
106// Double_t jdate=t.GetJD(y,m,d,hh,mm,ss,ns);
107//
108// Int_t days,secs,nsecs;
109// Double_t date=421.1949327;
110// t.Convert(date,days,secs,nsecs);
111//
112// days=875;
113// secs=23;
114// nsecs=9118483;
115// date=t.Convert(days,secs,nsecs);
116//
117// Double_t mjdate=40563.823744;
118// Double_t epoch=t.GetJE(mjdate,"mjd");
119//
120//--- Author: Nick van Eijndhoven 28-jan-2005 Utrecht University.
121//- Modified: NvE $Date$ Utrecht University.
122///////////////////////////////////////////////////////////////////////////
123
124#include "AliTimestamp.h"
125#include "Riostream.h"
126
127ClassImp(AliTimestamp) // Class implementation to enable ROOT I/O
128
129AliTimestamp::AliTimestamp() : TTimeStamp()
130{
131// Default constructor
132// Creation of an AliTimestamp object and initialisation of parameters.
133// All attributes are initialised to the current date/time as specified
134// in the docs of TTimeStamp.
135
136 FillJulian();
137}
138///////////////////////////////////////////////////////////////////////////
139AliTimestamp::AliTimestamp(TTimeStamp& t) : TTimeStamp(t)
140{
141// Creation of an AliTimestamp object and initialisation of parameters.
142// All attributes are initialised to the values of the input TTimeStamp.
143
144 FillJulian();
145}
146///////////////////////////////////////////////////////////////////////////
147AliTimestamp::~AliTimestamp()
148{
149// Destructor to delete dynamically allocated memory.
150}
151///////////////////////////////////////////////////////////////////////////
152AliTimestamp::AliTimestamp(const AliTimestamp& t) : TTimeStamp(t)
153{
154// Copy constructor
155
156 fMJD=t.fMJD;
157 fJsec=t.fJsec;
158 fJns=t.fJns;
159 fCalcs=t.fCalcs;
160 fCalcns=t.fCalcns;
161}
162///////////////////////////////////////////////////////////////////////////
163void AliTimestamp::Date(Int_t mode)
164{
165// Print date/time info.
166//
167// mode = 1 ==> Only the TTimeStamp yy-mm-dd hh:mm:ss:ns info is printed
168// 2 ==> Only the Julian parameter info is printed
169// 3 ==> Both the TTimeStamp and Julian parameter info is printed
170//
171// The default is mode=3.
172//
173// Note : In case the (M/T)JD falls outside the TTimeStamp range,
174// the TTimeStamp info will not be printed.
175
176 Int_t mjd,mjsec,mjns;
177 GetMJD(mjd,mjsec,mjns);
178
179 if ((mode==1 || mode==3) && mjd>=40587) cout << " " << AsString() << endl;
180 if (mode==2 || mode==3)
181 {
182 Int_t jd,jsec,jns;
183 GetJD(jd,jsec,jns);
184 Int_t tjd,tjsec,tjns;
185 GetTJD(tjd,tjsec,tjns);
186 cout << " Julian Epoch : " << setprecision(25) << GetJE() << endl;
187 cout << " JD : " << jd << " sec : " << jsec << " ns : " << jns
188 << " Fractional : " << setprecision(25) << GetJD() << endl;
189 cout << " MJD : " << mjd << " sec : " << mjsec << " ns : " << mjns
190 << " Fractional : " << setprecision(25) << GetMJD() << endl;
191 cout << " TJD : " << tjd << " sec : " << tjsec << " ns : " << tjns
192 << " Fractional : " << setprecision(25) << GetTJD() << endl;
193 }
194}
195///////////////////////////////////////////////////////////////////////////
196Double_t AliTimestamp::GetJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const
197{
198// Provide the (fractional) Julian Date (JD) corresponding to the UT date
199// and time in the Gregorian calendar as specified by the input arguments.
200//
201// The input arguments represent the following :
202// y : year in UT (e.g. 1952, 2003 etc...)
203// m : month in UT (1=jan 2=feb etc...)
204// d : day in UT (1-31)
205// hh : elapsed hours in UT (0-23)
206// mm : elapsed minutes in UT (0-59)
207// ss : elapsed seconds in UT (0-59)
208// ns : remaining fractional elapsed second of UT in nanosecond
209//
210// This algorithm is valid for all AD dates in the Gregorian calendar
211// following the recipe of R.W. Sinnott Sky & Telescope 82, (aug. 1991) 183.
212// See also http://scienceworld.wolfram.com/astronomy/JulianDate.html
213//
214// In case of invalid input, a value of -1 is returned.
215//
216// Note :
217// ------
218// This memberfunction only provides the JD corresponding to the
219// UT input arguments. It does NOT set the corresponding Julian parameters
220// for the current AliTimestamp instance.
221// As such the TTimeStamp limitations do NOT apply to this memberfunction.
222// To set the Julian parameters for the current AliTimestamp instance,
223// please use the corresponding SET() memberfunctions of either AliTimestamp
224// or TTimeStamp.
225
226 if (y<0 || m<1 || m>12 || d<1 || d>31) return -1;
227 if (hh<0 || hh>23 || mm<0 || mm>59 || ss<0 || ss>59 || ns<0 || ns>1e9) return -1;
228
229 // The UT daytime in fractional hours
230 Double_t ut=double(hh)+double(mm)/60.+(double(ss)+double(ns)*1.e-9)/3600.;
231
232 Double_t JD=0;
233
234 JD=367*y-int(7*(y+int((m+9)/12))/4)
235 -int(3*(int((y+(m-9)/7)/100)+1)/4)
236 +int(275*m/9)+d+1721028.5+ut/24.;
237
238 return JD;
239}
240///////////////////////////////////////////////////////////////////////////
241Double_t AliTimestamp::GetMJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const
242{
243// Provide the (fractional) Modified Julian Date corresponding to the UT
244// date and time in the Gregorian calendar as specified by the input arguments.
245//
246// The input arguments represent the following :
247// y : year in UT (e.g. 1952, 2003 etc...)
248// m : month in UT (1=jan 2=feb etc...)
249// d : day in UT (1-31)
250// hh : elapsed hours in UT (0-23)
251// mm : elapsed minutes in UT (0-59)
252// ss : elapsed seconds in UT (0-59)
253// ns : remaining fractional elapsed second of UT in nanosecond
254//
255// This algorithm is valid for all AD dates in the Gregorian calendar
256// following the recipe of R.W. Sinnott Sky & Telescope 82, (aug. 1991) 183.
257// See also http://scienceworld.wolfram.com/astronomy/JulianDate.html
258//
259// In case of invalid input, a value of -1 is returned.
260//
261// Note :
262// ------
263// This memberfunction only provides the MJD corresponding to the
264// UT input arguments. It does NOT set the corresponding Julian parameters
265// for the current AliTimestamp instance.
266// As such the TTimeStamp limitations do NOT apply to this memberfunction.
267// To set the Julian parameters for the current AliTimestamp instance,
268// please use the corresponding SET() memberfunctions of either AliTimestamp
269// or TTimeStamp.
270
271 Double_t JD=GetJD(y,m,d,hh,mm,ss,ns);
272
273 if (JD<0) return JD;
274
275 Double_t MJD=JD-2400000.5;
276
277 return MJD;
278}
279///////////////////////////////////////////////////////////////////////////
280Double_t AliTimestamp::GetTJD(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns) const
281{
282// Provide the (fractional) Truncated Julian Date corresponding to the UT
283// date and time in the Gregorian calendar as specified by the input arguments.
284//
285// The input arguments represent the following :
286// y : year in UT (e.g. 1952, 2003 etc...)
287// m : month in UT (1=jan 2=feb etc...)
288// d : day in UT (1-31)
289// hh : elapsed hours in UT (0-23)
290// mm : elapsed minutes in UT (0-59)
291// ss : elapsed seconds in UT (0-59)
292// ns : remaining fractional elapsed second of UT in nanosecond
293//
294// This algorithm is valid for all AD dates in the Gregorian calendar
295// following the recipe of R.W. Sinnott Sky & Telescope 82, (aug. 1991) 183.
296// See also http://scienceworld.wolfram.com/astronomy/JulianDate.html
297//
298// In case of invalid input, a value of -1 is returned.
299//
300// Note :
301// ------
302// This memberfunction only provides the TJD corresponding to the
303// UT input arguments. It does NOT set the corresponding Julian parameters
304// for the current AliTimestamp instance.
305// As such the TTimeStamp limitations do NOT apply to this memberfunction.
306// To set the Julian parameters for the current AliTimestamp instance,
307// please use the corresponding SET() memberfunctions of either AliTimestamp
308// or TTimeStamp.
309
310 Double_t JD=GetJD(y,m,d,hh,mm,ss,ns);
311
312 if (JD<0) return JD;
313
314 Double_t TJD=JD-2440000.5;
315
316 return TJD;
317}
318///////////////////////////////////////////////////////////////////////////
319Double_t AliTimestamp::GetJE(Double_t date,TString mode) const
320{
321// Provide the Julian Epoch (JE) corresponding to the specified date.
322// The argument "mode" indicates the type of the argument "date".
323//
324// Available modes are :
325// mode = "jd" ==> date represents the Julian Date
326// = "mjd" ==> date represents the Modified Julian Date
327// = "tjd" ==> date represents the Truncated Julian Date
328//
329// The default is mode="jd".
330//
331// In case of invalid input, a value of -99999 is returned.
332//
333// Note :
334// ------
335// This memberfunction only provides the JE corresponding to the
336// input arguments. It does NOT set the corresponding Julian parameters
337// for the current AliTimestamp instance.
338// As such the TTimeStamp limitations do NOT apply to this memberfunction.
339// To set the Julian parameters for the current AliTimestamp instance,
340// please use the corresponding SET() memberfunctions of either AliTimestamp
341// or TTimeStamp.
342
343 if ((mode != "jd") && (mode != "mjd") && (mode != "tjd")) return -99999;
344
345 Double_t jd=date;
346 if (mode=="mjd") jd=date+2400000.5;
347 if (mode=="tjd") jd=date+2440000.5;
348
349 Double_t je=2000.+(jd-2451545.)/365.25;
350
351 return je;
352}
353///////////////////////////////////////////////////////////////////////////
354void AliTimestamp::Convert(Double_t date,Int_t& days,Int_t& secs,Int_t& ns) const
355{
356// Convert date as fractional day count into integer days, secs and ns.
357//
358// Note : Due to computer accuracy the ns value may become inaccurate.
359//
360// The arguments represent the following :
361// date : The input date as fractional day count
362// days : Number of elapsed days
363// secs : Remaining number of elapsed seconds
364// ns : Remaining fractional elapsed second in nanoseconds
365//
366// Note :
367// ------
368// This memberfunction only converts the input date into the corresponding
369// integer parameters. It does NOT set the corresponding Julian parameters
370// for the current AliTimestamp instance.
371// As such the TTimeStamp limitations do NOT apply to this memberfunction.
372// To set the Julian parameters for the current AliTimestamp instance,
373// please use the corresponding SET() memberfunctions of either AliTimestamp
374// or TTimeStamp.
375
376 days=int(date);
377 date=date-double(days);
378 Int_t daysecs=24*3600;
379 date=date*double(daysecs);
380 secs=int(date);
381 date=date-double(secs);
382 ns=int(date*1.e9);
383}
384///////////////////////////////////////////////////////////////////////////
385Double_t AliTimestamp::Convert(Int_t days,Int_t secs,Int_t ns) const
386{
387// Convert date in integer days, secs and ns into fractional day count.
388//
389// Note : Due to computer accuracy the ns precision may be lost.
390//
391// The input arguments represent the following :
392// days : Number of elapsed days
393// secs : Remaining number of elapsed seconds
394// ns : Remaining fractional elapsed second in nanoseconds
395//
396// Note :
397// ------
398// This memberfunction only converts the input integer parameters into the
399// corresponding fractional day count. It does NOT set the corresponding
400// Julian parameters for the current AliTimestamp instance.
401// As such the TTimeStamp limitations do NOT apply to this memberfunction.
402// To set the Julian parameters for the current AliTimestamp instance,
403// please use the corresponding SET() memberfunctions of either AliTimestamp
404// or TTimeStamp.
405
406 Double_t frac=double(secs)+double(ns)*1.e-9;
407 Int_t daysecs=24*3600;
408 frac=frac/double(daysecs);
409 Double_t date=double(days)+frac;
410 return date;
411}
412///////////////////////////////////////////////////////////////////////////
413void AliTimestamp::FillJulian()
414{
415// Calculation and setting of the Julian date/time parameters corresponding
416// to the current TTimeStamp date/time parameters.
417
418 UInt_t y,m,d,hh,mm,ss;
419
420 GetDate(kTRUE,0,&y,&m,&d);
421 GetTime(kTRUE,0,&hh,&mm,&ss);
422 Int_t ns=GetNanoSec();
423
424 Double_t mjd=GetMJD(y,m,d,hh,mm,ss,ns);
425
426 fMJD=int(mjd);
427 fJsec=GetSec()%(24*3600); // Daytime in elapsed seconds
428 fJns=ns; // Remaining fractional elapsed second in nanoseconds
429
430 // Store the TTimeStamp seconds and nanoseconds values
431 // for which this Julian calculation was performed.
432 fCalcs=GetSec();
433 fCalcns=GetNanoSec();
434}
435///////////////////////////////////////////////////////////////////////////
436void AliTimestamp::GetMJD(Int_t& mjd,Int_t& sec, Int_t& ns)
437{
438// Provide the Modified Julian Date (MJD) and time corresponding to the
439// currently stored AliTimestamp date/time parameters.
440//
441// The returned arguments represent the following :
442// mjd : The modified Julian date.
443// sec : The number of seconds elapsed within the MJD.
444// ns : The remaining fractional number of seconds (in ns) elapsed within the MJD.
445
446 if (fCalcs != GetSec() || fCalcns != GetNanoSec()) FillJulian();
447
448 mjd=fMJD;
449 sec=fJsec;
450 ns=fJns;
451}
452///////////////////////////////////////////////////////////////////////////
453Double_t AliTimestamp::GetMJD()
454{
455// Provide the (fractional) Modified Julian Date (MJD) corresponding to the
456// currently stored AliTimestamp date/time parameters.
457//
458// Due to computer accuracy the ns precision may be lost.
459// It is advised to use the (mjd,sec,ns) getter instead.
460
461 Int_t mjd=0;
462 Int_t sec=0;
463 Int_t ns=0;
464 GetMJD(mjd,sec,ns);
465
466 Double_t date=Convert(mjd,sec,ns);
467
468 return date;
469}
470///////////////////////////////////////////////////////////////////////////
471void AliTimestamp::GetTJD(Int_t& tjd,Int_t& sec, Int_t& ns)
472{
473// Provide the Truncated Julian Date (TJD) and time corresponding to the
474// currently stored AliTimestamp date/time parameters.
475//
476// The returned arguments represent the following :
477// tjd : The modified Julian date.
478// sec : The number of seconds elapsed within the MJD.
479// ns : The remaining fractional number of seconds (in ns) elapsed within the MJD.
480
481 Int_t mjd=0;
482 GetMJD(mjd,sec,ns);
483
484 tjd=mjd-40000;
485}
486///////////////////////////////////////////////////////////////////////////
487Double_t AliTimestamp::GetTJD()
488{
489// Provide the (fractional) Truncated Julian Date (TJD) corresponding to the
490// currently stored AliTimestamp date/time parameters.
491//
492// Due to computer accuracy the ns precision may be lost.
493// It is advised to use the (mjd,sec,ns) getter instead.
494
495 Int_t tjd=0;
496 Int_t sec=0;
497 Int_t ns=0;
498 GetTJD(tjd,sec,ns);
499
500 Double_t date=Convert(tjd,sec,ns);
501
502 return date;
503}
504///////////////////////////////////////////////////////////////////////////
505void AliTimestamp::GetJD(Int_t& jd,Int_t& sec, Int_t& ns)
506{
507// Provide the Julian Date (JD) and time corresponding to the currently
508// stored AliTimestamp date/time parameters.
509//
510// The returned arguments represent the following :
511// jd : The Julian date.
512// sec : The number of seconds elapsed within the JD.
513// ns : The remaining fractional number of seconds (in ns) elapsed within the JD.
514
515 Int_t mjd=0;
516 GetMJD(mjd,sec,ns);
517
518 jd=mjd+2400000;
519 sec+=12*3600;
520 if (sec >= 24*3600)
521 {
522 sec-=24*3600;
523 jd+=1;
524 }
525}
526///////////////////////////////////////////////////////////////////////////
527Double_t AliTimestamp::GetJD()
528{
529// Provide the (fractional) Julian Date (JD) corresponding to the currently
530// stored AliTimestamp date/time parameters.
531//
532// Due to computer accuracy the ns precision may be lost.
533// It is advised to use the (jd,sec,ns) getter instead.
534
535 Int_t jd=0;
536 Int_t sec=0;
537 Int_t ns=0;
538 GetJD(jd,sec,ns);
539
540 Double_t date=Convert(jd,sec,ns);
541
542 return date;
543}
544///////////////////////////////////////////////////////////////////////////
545Double_t AliTimestamp::GetJE()
546{
547// Provide the Julian Epoch (JE) corresponding to the currently stored
548// AliTimestamp date/time parameters.
549
550 Double_t jd=GetJD();
551 Double_t je=GetJE(jd);
552 return je;
553}
554///////////////////////////////////////////////////////////////////////////
555void AliTimestamp::SetMJD(Int_t mjd,Int_t sec,Int_t ns)
556{
557// Set the Modified Julian Date (MJD) and time and update the TTimeStamp
558// parameters accordingly (if possible).
559//
560// Note :
561// ------
562// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
563// which corresponds to the start of MJD=40587.
564// Using the corresponding MJD of this EPOCH allows construction of
565// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
566// Obviously this TTimeStamp implementation would prevent usage of MJD values
567// smaller than 40587.
568// However, this AliTimestamp facility provides support for the full range
569// of (M)JD values, but the setting of the corresponding TTimeStamp parameters
570// is restricted to the values allowed by the TTimeStamp implementation.
571// For these earlier MJD values, the standard TTimeStamp parameters will
572// be set corresponding to the start of the TTimeStamp EPOCH.
573// This implies that for these earlier MJD values the TTimeStamp parameters
574// do not match the Julian parameters of AliTimestamp.
575//
576// The input arguments represent the following :
577// mjd : The modified Julian date.
578// sec : The number of seconds elapsed within the MJD.
579// ns : The remaining fractional number of seconds (in ns) elapsed within the MJD.
580
581 if (sec<0 || ns<0)
582 {
583 cout << " *AliTimestamp::SetMJD* Invalid input."
584 << " sec : " << sec << " ns : " << ns << endl;
585 return;
586 }
587
588 fMJD=mjd;
589 fJsec=sec;
590 fJns=ns;
591
592 Int_t epoch=40587;
593
594 if (mjd<epoch)
595 {
596 Set(0,kFALSE,0,kFALSE);
597 }
598 else
599 {
600 // The elapsed time since start of EPOCH
601 Int_t days=mjd-epoch;
602 UInt_t secs=days*24*3600;
603 secs+=sec;
604 Set(secs,kFALSE,0,kFALSE);
605 Int_t date=GetDate();
606 Int_t time=GetTime();
607 Set(date,time,ns,kTRUE,0);
608 }
609
610 // Denote that the Julian and TTimeStamp parameters are synchronised,
611 // even in the case the MJD falls outside the TTimeStamp validity range.
612 // The latter still allows retrieval of Julian parameters for these
613 // earlier times.
614 fCalcs=GetSec();
615 fCalcns=GetNanoSec();
616}
617///////////////////////////////////////////////////////////////////////////
618void AliTimestamp::SetMJD(Double_t mjd)
619{
620// Set the Modified Julian Date (MJD) and time and update the TTimeStamp
621// parameters accordingly (if possible).
622//
623// Note :
624// ------
625// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
626// which corresponds to the start of MJD=40587.
627// Using the corresponding MJD of this EPOCH allows construction of
628// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
629// Obviously this TTimeStamp implementation would prevent usage of MJD values
630// smaller than 40587.
631// However, this AliTimestamp facility provides support for the full range
632// of (M)JD values, but the setting of the corresponding TTimeStamp parameters
633// is restricted to the values allowed by the TTimeStamp implementation.
634// For these earlier MJD values, the standard TTimeStamp parameters will
635// be set corresponding to the start of the TTimeStamp EPOCH.
636// This implies that for these earlier MJD values the TTimeStamp parameters
637// do not match the Julian parameters of AliTimestamp.
638//
639// Due to computer accuracy the ns precision may be lost.
640// It is advised to use the (mjd,sec,ns) setting instead.
641//
642// The input argument represents the following :
643// mjd : The modified Julian date as fractional day count.
644
645 Int_t days=0;
646 Int_t secs=0;
647 Int_t ns=0;
648 Convert(mjd,days,secs,ns);
649 SetMJD(days,secs,ns);
650}
651///////////////////////////////////////////////////////////////////////////
652void AliTimestamp::SetJD(Int_t jd,Int_t sec,Int_t ns)
653{
654// Set the Julian Date (JD) and time and update the TTimeStamp
655// parameters accordingly (if possible).
656//
657// Note :
658// ------
659// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
660// which corresponds to JD=2440587.5 or the start of MJD=40587.
661// Using the corresponding MJD of this EPOCH allows construction of
662// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
663// Obviously this TTimeStamp implementation would prevent usage of values
664// smaller than JD=2440587.5.
665// However, this AliTimestamp facility provides support for the full range
666// of (M)JD values, but the setting of the corresponding TTimeStamp parameters
667// is restricted to the values allowed by the TTimeStamp implementation.
668// For these earlier JD values, the standard TTimeStamp parameters will
669// be set corresponding to the start of the TTimeStamp EPOCH.
670// This implies that for these earlier (M)JD values the TTimeStamp parameters
671// do not match the Julian parameters of AliTimestamp.
672//
673// The input arguments represent the following :
674// jd : The Julian date.
675// sec : The number of seconds elapsed within the JD.
676// ns : The remaining fractional number of seconds (in ns) elapsed within the JD.
677
678 Int_t mjd=jd-2400000;
679 sec-=12*3600;
680 if (sec<0)
681 {
682 sec+=24*3600;
683 mjd-=1;
684 }
685
686 SetMJD(mjd,sec,ns);
687}
688///////////////////////////////////////////////////////////////////////////
689void AliTimestamp::SetJD(Double_t jd)
690{
691// Set the Julian Date (JD) and time and update the TTimeStamp
692// parameters accordingly (if possible).
693//
694// Note :
695// ------
696// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
697// which corresponds to JD=2440587.5 or the start of MJD=40587.
698// Using the corresponding MJD of this EPOCH allows construction of
699// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
700// Obviously this TTimeStamp implementation would prevent usage of values
701// smaller than JD=2440587.5.
702// However, this AliTimestamp facility provides support for the full range
703// of (M)JD values, but the setting of the corresponding TTimeStamp parameters
704// is restricted to the values allowed by the TTimeStamp implementation.
705// For these earlier JD values, the standard TTimeStamp parameters will
706// be set corresponding to the start of the TTimeStamp EPOCH.
707// This implies that for these earlier (M)JD values the TTimeStamp parameters
708// do not match the Julian parameters of AliTimestamp.
709//
710// Due to computer accuracy the ns precision may be lost.
711// It is advised to use the (jd,sec,ns) setting instead.
712//
713// The input argument represents the following :
714// jd : The Julian date as fractional day count.
715
716 Int_t days=0;
717 Int_t secs=0;
718 Int_t ns=0;
719 Convert(jd,days,secs,ns);
720
721 SetJD(days,secs,ns);
722}
723///////////////////////////////////////////////////////////////////////////
724void AliTimestamp::SetTJD(Int_t tjd,Int_t sec,Int_t ns)
725{
726// Set the Truncated Julian Date (TJD) and time and update the TTimeStamp
727// parameters accordingly (if possible).
728//
729// Note :
730// ------
731// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
732// which corresponds to JD=2440587.5 or the start of TJD=587.
733// Using the corresponding MJD of this EPOCH allows construction of
734// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
735// Obviously this TTimeStamp implementation would prevent usage of values
736// smaller than TJD=587.
737// However, this AliTimestamp facility provides support for the full range
738// of (T)JD values, but the setting of the corresponding TTimeStamp parameters
739// is restricted to the values allowed by the TTimeStamp implementation.
740// For these earlier JD values, the standard TTimeStamp parameters will
741// be set corresponding to the start of the TTimeStamp EPOCH.
742// This implies that for these earlier (T)JD values the TTimeStamp parameters
743// do not match the Julian parameters of AliTimestamp.
744//
745// The input arguments represent the following :
746// tjd : The Truncated Julian date.
747// sec : The number of seconds elapsed within the JD.
748// ns : The remaining fractional number of seconds (in ns) elapsed within the JD.
749
750 Int_t mjd=tjd+40000;
751
752 SetMJD(mjd,sec,ns);
753}
754///////////////////////////////////////////////////////////////////////////
755void AliTimestamp::SetTJD(Double_t tjd)
756{
757// Set the Truncated Julian Date (TJD) and time and update the TTimeStamp
758// parameters accordingly (if possible).
759//
760// Note :
761// ------
762// The TTimeStamp EPOCH starts at 01-jan-1970 00:00:00 UTC
763// which corresponds to JD=2440587.5 or the start of TJD=587.
764// Using the corresponding MJD of this EPOCH allows construction of
765// the yy-mm-dd hh:mm:ss:ns TTimeStamp from a given input MJD and time.
766// Obviously this TTimeStamp implementation would prevent usage of values
767// smaller than TJD=587.
768// However, this AliTimestamp facility provides support for the full range
769// of (T)JD values, but the setting of the corresponding TTimeStamp parameters
770// is restricted to the values allowed by the TTimeStamp implementation.
771// For these earlier JD values, the standard TTimeStamp parameters will
772// be set corresponding to the start of the TTimeStamp EPOCH.
773// This implies that for these earlier (T)JD values the TTimeStamp parameters
774// do not match the Julian parameters of AliTimestamp.
775//
776// Due to computer accuracy the ns precision may be lost.
777// It is advised to use the (jd,sec,ns) setting instead.
778//
779// The input argument represents the following :
780// tjd : The Truncated Julian date as fractional day count.
781
782 Int_t days=0;
783 Int_t secs=0;
784 Int_t ns=0;
785 Convert(tjd,days,secs,ns);
786
787 SetTJD(days,secs,ns);
788}
789///////////////////////////////////////////////////////////////////////////