TString in a TTree

Hey guys,

I have really some problems with Trees and strings.

I’m defining a struct, which will be filled in a branch, whereas a char array is part of it.


struct MOCK_SAMPLE {
      double a;
      double b;
      double c;
      char name [256];
      double d;
      double e;
}

MOCK_SAMPLE sample;

tree->Branch("sample", &sample, "a/D:b/D:c/D:name/C[256]:d/D:e/D");

Afterwards I read from a file the first line, each column corresponds to one variable in the struct (the file has the same order as in the definition of the struct). Then I fill my tree. Everything looks fine so far.

But when I open my tree, only those variables are ok, which are before the char array. The two afterwards are corrupted.

And the funny thing is, using cout before I fill the tree, the output is ok for each variable.

Has anybody an idea, what I should change? Otherwise I can give more information on the program.

Thanks a lot,
Stephan

To make it more clear, I attach the input file, the macro and the tree.

There you can see what I described above.
test.txt (112 Bytes)
mock_tree.root (5.21 KB)
Mock_File_Parser_Test.C (1.32 KB)

Hi,

The problem is in the leaflist description where the arraytree->Branch("sample", &sample, "a/D:b/D:c/D:name[256]/C:d/D:e/D");

Note that inherently we can not check the validity of the leaf list string. Hence we strongly recommend that instead of using the leaflist, you ought to use the branch creation technique that uses C++ object (i.e. compile the struct and generate a dictionary for it, for example via ACLiC) which will auto-determine the location of the members.

Cheers,
Philippe.

Well, luckily a colleague found an easy way to do it.

The macro has just to be modified a little bit and it works. See the attachment!
Mock_File_Parser_Test.C (1.41 KB)

Hi,

Cheers,
Philippe.

Oh… ok… thanks!