Re: [ROOT] system time in msec ?

From: Joe Robe (joer00@yahoo.com)
Date: Tue Mar 05 2002 - 22:10:02 MET


Rooters,

after all this discussion, don't you think its a good idea to add msec to
TDatime (and its now() ctor) ?

Joe
----- Original Message -----
From: "Robert Hatcher" <rhatcher@SLAC.Stanford.EDU>
To: "Faine, Valeri" <fine@bnl.gov>
Cc: "'Joe Robe '" <joer00@yahoo.com>; <roottalk@pcroot.cern.ch>
Sent: Tuesday, March 05, 2002 5:37 PM
Subject: RE: [ROOT] system time in msec ?


> On Tue, 5 Mar 2002, Faine, Valeri wrote:
>
> > In theory  (;-)the TStopwatch method is a good ROOT candidate.
> > Have a look at
> >
> >
http://root.cern.ch/root/htmldoc/src/TStopwatch.cxx.html#TStopwatch:GetRealT
> > ime
>
> Actually, no it isn't.  TStopwatch is a good candidate for a stop watch
> object.  Stopwatches are good for measuring elapsed times not absolutes.
> Joe's request was:
>
> >>> [...] Any class who returns current time in msec precision ? [...]
>
> TStopwatch does not give the current time (in the sense of Tue, 5 Mar
> 2002, 2:04 CST), but instead gives (in general) the cpu or *delta*
> wall clock time since the the process began...in clock ticks converted
> to real units.  Before you suggest Double_t TStopwatch::GetRealTime()
> you should look at the code, for unix this is:
>
> #elif defined(R__UNIX)
>    struct tms cpt;
>    Double_t trt =  (Double_t)times(&cpt);
>    return trt / (double)gTicks;
>
> So what does "times()" return?
> $ man -S 2 times
>
>   |  RETURN VALUE
>   |     The function times returns the number of clock ticks  that
>   |     have  elapsed  since  an  arbitrary point in the past. For
>   |     Linux this point is the  moment  the  system  was  booted.
>   |     This  return value may overflow the possible range of type
>   |     clock_t.  On error, (clock_t) -1 is returned, and errno is
>   |     set  appropriately.   The number of clock ticks per second
>   |     can be obtained using
>   |            sysconf(_SC_CLK_TCK);
>   [...]
>
> So TStopwatch::GetRealTime, on Linux, returns the seconds since the
> machine was booted.  I doubt this satisfies Joe's requirements.
>
> Brett Viren pointed me to gettimeofday() which is available on Linux
> (and *probably* most of UNIX as it claims "CONFORMING TO SVr4, BSD 4.3"),
> but I don't know how to asertain how uniformly it is implemented
> on other systems nor do I have enough knowledge to say anything about
> the M$ Windows side.  I'm considering the following change to MINOS's
> VldTimeStamp (from whence TTimeStamp was derived):
>
> up in the beginning:
> #ifndef WIN32
> // timeval, timezone, gettimeofday()
> #include <sys/time.h>
> #endif
>
> in void VldTimeStamp::Set() replace all the code with:
>
> #ifndef WIN32
>    // this should work on UNIX to get microsec precision
>    // we'll stick to a ns hack to ensure calls are unique
>    timeval now;
>    static Int_t fake_ns = 0;
>    //struct timezone tz;
>
>    if (!gettimeofday(&now,0)) {
>       fSec     = now.tv_sec;
>       fNanoSec = now.tv_usec*1000 + (++fake_ns)%1000;
>    }
>    else {
>       time_t now;
>       time(&now);
>       fSec     = now;
>       fNanoSec = ++fake_ns;
>    }
> #else
>    time_t now;
>    time(&now);
>    fSec     = now;
>
>    static Int_t fake_ns = 0;
>    fNanoSec = ++fake_ns;
> #endif
>
>
> -robert
>
>
> > -----Original Message-----
> > From: Robert Hatcher
> >
> > On Tue, 5 Mar 2002, Fons Rademakers wrote:
> >
> > > Check TTimeStamp.
> >
> > Well, I'm not sure that this satisfies Joe's needs (any more than
> > TDatime)
> > in that while it can handle sub-second precison it doesn't know how to
> > "get" that info.  the TTimeStamp() ctor constructs a time based on
> > seconds
> > since "epoch" (1970-01-01 00:00:00). The default ctor calls Set() which
> > has:
> >
> >    // Set Date/Time to current time as reported by the system.
> >    // No accounting for nanoseconds with std ANSI functions,
> >    // ns part faked so that subsequent calls simply add 1 to it
> >    // this ensures that calls within the same second come back
> >    // distinct (and sortable).
> >
> >    time_t now;
> >    time(&now);
> >    fSec = now;
> >
> >    static Int_t fake_ns = 0;
> >    fNanoSec = fake_ns++;
> >
> > If there are standard ways of determining sub-second times I'd be
> > interested.  But I know of no means that is consistently available on
> > all platforms.
> >
> > -robert
> >
> > > On Tue, 2002-03-05 at 15:06, Joe Robe wrote:
> > > > Hi,
> > > >
> > > > TTime seems only to be a storage class, and TDatime does only return
> > current time in sec precision. Any class who returns current time in
> > msec precision ? Since my app must run on Linux AND windoze I do not
> > want to implement it by myself ( no clue about Linux).
> > > >
> > > > Joe
> > > >
> > > --
> > > Org:    CERN, European Laboratory for Particle Physics.
> > > Mail:   1211 Geneve 23, Switzerland
> > > E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
> > > WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480
>
> Robert W. Hatcher   | rhatcher@fnal.gov   630-840-3102
> FNAL CD/CP (MINOS)  | MS 220, PO Box 500, Batavia IL 60510
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:44 MET