Problem reading branches of structs

From: Andrea Bocci <>
Date: Tue, 26 Apr 2005 19:04:41 +0200

after quite some debugging of oure code, we've discovered a problem in reading a struct back from a branch.

The structure definition is:

struct bTagInfo {
  bTagInfo (void) {
    std::memset (this, 0, sizeof(bTagInfo));

  // MonteCarlo truth (or a good approximation...)   unsigned int jet_flavour;
  // Reconstructed informations
  double jet_E;
  double jet_ET;

  double mu_p;
  double mu_pT;
  double mu_pTrel;
  double mu_pTrelexcl;
  double mu_sip3d;
  double mu_deltaR;


A branch of these struct is crated like this:

tree->Branch ("bTagInfo", &data, "jet_flavour/i:jet_E/D:jet_ET:mu_p:mu_pT:mu_pTrel:mu_pTrelexcl:mu_sip3d:mu_deltaR");

and it is read back like this:

  bTagInfo info;
  if (tree->GetBranch ("bTagInfo")) {
    tree->SetBranchAddress ("bTagInfo", &info);

Now, when I read back the root file in a compiled executable, everythin works as expected, ie. the struct gets filled back correctly. Howeer, if I try to read back the struct in an interactive ROOT session, this doesn't work, and only the first field is correct.

After some debugging, I've found out that this is due to root/cint alligning the fields in the sruct to 8-bytes boundary, while the version in the root file is obviously packed.

The only workaround I've found is to read back the branch to a buffer, and the copying the memory from it into the struct as needed to proprly re-allign it.

The most confusing thing has been the different behaviour between the compiled version (which runs fine, as gcc keeps the struct fields alligned to 4 bytes boundaries) and the interpreted version!

So, what is wrong here?
Is this the expected behaviour, and I'm reading and writing the rootfile in a wrong way, or is this a bug?

.Andrea. Received on Tue Apr 26 2005 - 19:04:49 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET