Reading a comma separated file into TTree

Hi,

Is there already a  way to read into a TTree a comma separated (or in general delimited by a user specified delimiter) data file, containing, among other things, character variables with spaces within them ?

 TTree.ReadFile() seems to be able to read only white-space delimited files, and string variable values can't have spaces in them.

 I thought I would check to see if there may be a method available in ROOT already for doing this.

Many thanks.

-Arun

Hi,

Indeed, the only ‘canned’ ascii reading requires a space separated file.
You can either transfer you file (for example using sed) or one could
tweak TTree::ReadFile. If you do the later, we will be more than happy to incorporate it into the ROOT code.

Cheers,
Philippe

I usally use this function to read a line.

               vector<TString> Tokens(TString aline,TString aDelim)
		{
			Int_t i;
			TObjArray* InObjArray;
			TObjString* os;
			TString s;
			vector<TString> OutStringVec;
			OutStringVec.clear();

			InObjArray=aline.Tokenize(aDelim);
			for ( i=0; i<InObjArray->GetEntriesFast(); i++ )
			{
				os=(TObjString*)InObjArray->At(i);
				s=os->GetString();
				OutStringVec.push_back(s);
			}
			return OutStringVec;
		}

This looks like a good start :slight_smile:
Can you try to incorporate it into TTree::ReadFile?

Thanks,
Philippe.