TTimeStamp and system clock

dear rooters,
I am trying to read timestamp as a class from a root file.
Instead of getting the time saved in the file I am getting the time
automatically set from my system ( the day of today).

TTimeStamp *timstmp = 0;
Tree->SetBranchAddress(“timestamp”, &timstmp);
for(int i=0;i<10;i++){
Tree->GetEntry(i);
cout <AsString(“C”)<< endl;
}

Any ideas…
Cheers,

Hi,

on master, I tried this and I got the expected output.
What version are you using? Could you share the complete example?

Cheers,
Danilo


void write(){
   cout << "Write\n";
   TFile f("ofile.root","RECREATE");
   auto t=new TTimeStamp();
   TTree tree("tree","stamp tree");
   tree.Branch("stamp",&t);
   for (int i=0;i<10;++i){
      sleep(.3*i);
      t->Set();
      t->Print();
      tree.Fill();
   }
   tree.Write();
   f.Close();
}

void read(){
   cout << "Read. Waiting 5s\n";
   sleep(5);
   TFile f("ofile.root");
   TTreeReader rdr("tree",&f);
   TTreeReaderValue<TTimeStamp> stamp(rdr, "stamp");
   while (rdr.Next()) {
      stamp->Print();
   }
}


void example2(){
   write();
   read();
}

/*
 * Output:
Processing example2.C...
Write
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +252859000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253187000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253205000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253214000 nsec
Date/Time = Tue, 12 May 2015 06:33:30 +0000 (GMT) +253288000 nsec
Date/Time = Tue, 12 May 2015 06:33:31 +0000 (GMT) +253403000 nsec
Date/Time = Tue, 12 May 2015 06:33:32 +0000 (GMT) +253531000 nsec
Date/Time = Tue, 12 May 2015 06:33:34 +0000 (GMT) +253659000 nsec
Date/Time = Tue, 12 May 2015 06:33:36 +0000 (GMT) +253783000 nsec
Date/Time = Tue, 12 May 2015 06:33:38 +0000 (GMT) +253908000 nsec
Read. Waiting 5s
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +252859000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253187000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253205000 nsec
Date/Time = Tue, 12 May 2015 06:33:29 +0000 (GMT) +253214000 nsec
Date/Time = Tue, 12 May 2015 06:33:30 +0000 (GMT) +253288000 nsec
Date/Time = Tue, 12 May 2015 06:33:31 +0000 (GMT) +253403000 nsec
Date/Time = Tue, 12 May 2015 06:33:32 +0000 (GMT) +253531000 nsec
Date/Time = Tue, 12 May 2015 06:33:34 +0000 (GMT) +253659000 nsec
Date/Time = Tue, 12 May 2015 06:33:36 +0000 (GMT) +253783000 nsec
Date/Time = Tue, 12 May 2015 06:33:38 +0000 (GMT) +253908000 nsec
 * */

Thanks for the suggestion.
I still end up reading the time from my system instead of the rootfile.
Here is the code.
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TTimeStamp.h>
#include <TObject.h>

void test(){
TFile *file = new TFile(“FILENAME.root”);
TTree tree = (TTree) file->Get(“TREENAME”);
TTimeStamp *timstmp = 0;
tree->SetMakeClass(1);
//reading time branch from rootfile
tree->SetBranchAddress(“timestamp”, &timstmp);

//reading time leaf from rootfile
Int_t fSec;
TBranch *b_timestamp_fSec; //!
tree->SetBranchAddress(“fSec”, &fSec, &b_timestamp_fSec);

for(int i=0;i<10;i++){
tree->GetEntry(i);
cout <<fSec << " " << timstmp->AsString(“C”)<< endl;
//Print Should match but timstmp grabs the time of system.
}
file->Close();

}

As a workaround, you can save your timestamp as a TObjString in your ROOT file. This is unclean, but safe.