Newbie question

Hi all, I’m new to ROOT and my knowledge of C++ is also fairly limited. It therefore follows that I have become stuck. :frowning:

I am trying to get some data from a .txt file into a .root file. There is only one variable and the timestamp, but many entries per timestamp, and not always the same amount. e.g.

2011-11-11 17:51:33.735 3 1 4 623 234 43 76
2011-11-11 17:51:34.735 6 456 45 6 28 92 345 23 23 1 45

At the moment my program will process the timestamp fine and take the first data point for each, but I can’t work out how to make it take n data points.

This is the relevant bit of code that I am using:

ifstream file1(inputfile.c_str(),ios_base::in); // open file std::string line; while ( !file1.eof() ) { getline(file1,line); std::stringstream s(line); bool ok = (s>>day>>time>>data); daytime = day +" "+ time; // convert date to string datime.Set(daytime.c_str());//give string to TDataobject t = datime.Convert();// convert to integer (unix time) tc2011.Fill(); //fill tree j++; //Increase counter } tc2011.Print(); //print tree in terminal tc2011.Write(); //write tree to file std::cout << j << std::endl; file1.close(); //close file

I want to adapt this so that “data” can be a sort of array of unknown size, but I have no idea how to proceed.

Any help would be greatly appreciated!


You could make the second branch a vector<Int_t> and use something like:t = datime.Convert();// convert to integer (unix time) // And now the data proper. datavec.clear(); davavec.push_back(data): while( s >> data) { datavec.push_back(data); } tc2011.Fill(); //fill tree