Problem with timestamps

Hello,

  1. I have an ascii file with two columns, one for timestamps (in human readable
    local CET/CEST time) and other for values. From that data, I create a ROOT tree,
    by creating an object of the class TDatime, and converting it to an Int_t using
    the Convert method.
TDatime da(myYear,myMonth,myDay,myHour,myMinute,mySecond);
myInt=da.Convert();

When I use the TreeViewer to display the data, I observe a shift of -1 day for
timestamps between March 1st 2007 to February 29th 2008, and for all the 12 months
before any February 29th. How can I solve this?

  1. I then want to plot the data in a postscript file, and for that I use the
    class TH2F.
TH2F *h = new TH2F("h","Values vs time",100,1210240800,1210291200,100,0,130);
//...
h->GetXaxis()->SetTimeDisplay(1);
h->GetXaxis()->SetTimeOffset(0);

What I observe this time is that:
a) the x-axis has a shift of +3 hours with respect to what was requested;
b) all timestamps appear with a shift of +1 hour.
How can I solve this?

Thank you in advance.

Best regards,
Ana Sofia Nunes

File dummy.txt

dummy_name dummy_alias f 35
07 05 2008 09 55 29 1.797300000000e-02 0
08 05 2008 14 25 10 2.754861500000e+01 0
08 05 2008 14 25 30 5.166239000000e+00 0
08 05 2008 14 25 50 2.462700400000e+01 0
08 05 2008 14 26 10 8.617055000000e+00 0
08 05 2008 14 26 30 3.101141300000e+01 0
08 05 2008 14 26 50 4.666989000000e+00 0
08 05 2008 14 27 10 3.494750000000e-01 0
08 05 2008 16 45 30 1.005489500000e+01 0
08 05 2008 16 45 50 2.463898600000e+01 0
08 05 2008 16 46 10 4.730094200000e+01 0
08 05 2008 16 46 30 6.173326100000e+01 0
08 05 2008 16 46 50 7.664885400000e+01 0
08 05 2008 16 47 10 8.213661000000e+01 0
08 05 2008 16 47 30 9.949054000000e+01 0
08 05 2008 16 47 50 1.110911130000e+02 0
08 05 2008 16 48 10 1.152848130000e+02 0
08 05 2008 16 48 50 1.177650870000e+02 0
08 05 2008 16 49 10 9.726388500000e+01 0
08 05 2008 16 49 30 1.139068830000e+02 0
08 05 2008 16 49 50 1.191050740000e+02 0
08 05 2008 16 50 30 9.713607700000e+01 0
08 05 2008 16 50 50 9.545660000000e+01 0
08 05 2008 16 51 10 1.064540790000e+02 0
08 05 2008 16 51 30 1.153587020000e+02 0
08 05 2008 16 52 30 1.112828250000e+02 0
08 05 2008 16 52 50 9.380508100000e+01 0
08 05 2008 16 53 10 7.958644100000e+01 0
08 05 2008 16 53 30 5.610172100000e+01 0
08 05 2008 16 53 50 4.089256900000e+01 0
08 05 2008 16 54 10 1.733795400000e+01 0
08 05 2008 16 54 30 6.578118000000e+00 0
08 05 2008 16 54 50 2.500244000000e+00 0
08 05 2008 16 55 10 4.073880000000e-01 0
13 05 2008 16 47 50 0.000000000000e+00 0

File dummy_convert.c

#include "Riostream.h"
#include "time.h"
                                                                                
void dummy_convert() {
  struct sensor_t {
    Float_t value;
    Int_t myTime;
  };
  sensor_t sensor;
  TString name;	
  TString alias;	
  TString myValue;	
  Char_t type[1];
  int myYear,myMonth,myDay,myHour,myMinute,mySecond,number;
  int invalid;
  int nlines=0;                                                                 
  ifstream fp1;
  fp1.open("dummy.txt");		
  TFile f("dummy.root","recreate");
  while (!fp1.eof()) {
    if (!fp1.good()) {
      cout << "File not ok!" << endl;
      break;
    }
    fp1 >> name >> alias >> type >> number;
    if (alias=="dummy_alias"){
      if (number != 0) {
	TTree *tree1 = new TTree(alias, alias);
	tree1->Branch("value", &sensor.value, "value/F");
	tree1->Branch("time", &sensor.myTime, "myTime/I");
	while (nlines<number) {              
	  fp1 >> myDay >> myMonth >> myYear >> myHour >> myMinute >> mySecond >> myValue >> invalid;	
	  sensor.value = atof(myValue);	    
          TDatime da(myYear, myMonth, myDay, myHour, myMinute, mySecond);
          sensor.myTime = da.Convert();
	  if (invalid == 0) tree1->Fill();
          nlines++; 
	} //nlines
	number = nlines = 0;
	tree1->Print();
	tree1->Write();
      } //if (number != 0)
    else cout << "number = 0" << endl;
    } //alias
    number = nlines = 0;
  } //while(1)
  fp1.close();
}

File dummy_plot.c:

#include "time.h"
                                                                                
void dummy_plot() {
  TFile f("dummy.root");
  TIter nextkey(f.GetListOfKeys());
  TKey *key;
  Int_t time;
  Float_t value;
  Int_t n=1;
  TCanvas *c1 = new TCanvas("c1","Data",800,600);
  c1->Print("MyPlots.ps[");
  TH2F *h = new TH2F("h","Values vs time",100,1210240800,1210291200,100,0,130);
  while ( key = (TKey*)nextkey()) {
    TTree *t = (TTree*)key->ReadObj();
    Int_t nentries = (Int_t)t->GetEntries();
    t->SetBranchAddress("value",&value);
    t->SetBranchAddress("time",&time);	
    char *myTitle = (char*)t->GetName();
    gStyle->SetStatX(0.7);
    h->GetYaxis()->SetLabelSize(0.025);
    h->GetXaxis()->SetLabelSize(0.025);
    h->GetXaxis()->SetTimeDisplay(1);
    h->GetXaxis()->SetTimeOffset(0);
    h->GetXaxis()->SetTitle(myTitle);
    for (Int_t i=0; i<nentries; i++) {
      t->GetEntry(i);
      h->Fill(time,value);
    }
    h->SetOption("COLZ");
    h->Draw();
    c1->Print("MyPlots.ps");
    n++;
    h->Reset();
  }
  c1->Print("MyPlots.ps]");
}

have you tried the " gmt" option ?

h->GetXaxis()->SetTimeOffset(0,"gmt"); 

Hello,

Thank you for your answer. By using your suggestion,

h->GetXaxis()->SetTimeOffset(0,"gmt"); 

the result changes as follows:
2. a) the x-axis has a shift of -1 hour with respect to what was requested;
b) all timestamps appear with a shift of -1 hour.

Ideas? Thank you in advance.

Regards,
Sofia

I’ll look at it. I’ll let you know.

I tried to run your example but I get a crash. I did:

What should I do exactly to run your code and see the problem ?

Can you email me the files I need at Olivier.Couet@cern.ch ?

Hi,
I also have suffer the same problem recently. Have you solved this problem? If so,would you please tell me how to solve it?
Thanks in advance.
Best regards
Luo

Do you have a small macro reproducing the problem ?

Note: This thread is 12 years old. It is not a good idea to resurrect such old thread. Many things may have changed in between. You better create new thread for new questions even if you found a similar one in the forum history.