c-style arrays used in setbranch for std::vector branches

From: Erkcan Ozcan <eo_at_hep.ucl.ac.uk>
Date: Mon, 17 Jan 2011 00:59:25 +0200


Dear ROOT experts,

We have an ntuple that contains std::vectors of floats and ints. When we do MakeClass() we get branches like this:

  vector<float> *pvx;

We also have an old piece of code written before the ntuple format was modified and it used to use c-style arrays. The same branch used to be:

  float pvx[10];

And we were doing the following setbranch step:

 anltree->SetBranchAddress("pvx" , &pvx);

We have found out that the code seems to work on the new ntuples without any modifications, ie. we still define c-style arrays and setbranch to a branch which is really a pointer to an std::vector.

Is this safe to do? I know normally it is not ok to cast an std::vector to a c-style array, but given that in this scenario we will only be reading from a ROOT file, perhaps what we do is completely fine. Could some expert confirm please?

Thanks a lot,
e.

PS: I have had some problems when I sent this email the first time. Apologies to all the mailing list members if we end up getting it twice. PS2: We are using ROOT 5.26/00b.

-- 

In case they are not written explicitly, please be aware that my greetings and farewell are inherently implied in this email.

V. Erkcan Ozcan
Research Fellow
University College London
Dept. of Physics & Astronomy
Received on Sun Jan 16 2011 - 23:59:42 CET

This archive was generated by hypermail 2.2.0 : Mon Jan 17 2011 - 23:50:01 CET