Home | News | Documentation | Download

Import a Date and Time from txt file into a Tree

Dear all,

I would like to ask your help to read a txt file into a Tree if I have date and time.
my txt file is like

27	60	8.82E+04	0.016	2021-1-18 12:00:00
55	137	8.07E+03	0.028	2021-1-18 12:00:00

and I’m able to read all the other values except the date and time. this is how I’m trying right now

TDatime Date;
TTree *tCalib = new TTree("tCalib", "tCalib");
tCalib->Branch("AA",&AA,"AA/I");
tCalib->Branch("ZZ",&ZZ,"ZZ/I"); /
tCalib->Branch("A0",&A0,"A0[2]/D");

while (true){
	fCalib >> AA >> ZZ >> A0[0] >> A0[1] >> Date;
	Date_s = Date.Convert();
	if (fCalib.eof()) break;
	tCalib->Fill();}	

Thanks for any help


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


You could read in the day and time in two strings and then combine them, like this:

std::string day;
std::string time;
fCalib >> AA >> ZZ >> A0[0] >> A0[1] >> day >> time;
Date = TDatime((day + " " + time).c_str());
std::string Date_s = Date.AsString();