Branch get 0 size vector

Hi rooters,
I don’t know where did I missed when using Branch to get a vector but resulted in nothing. I followed tutorials that all I can find step by step :cry:


   TChain chain("Events");
   vector<Short_t> * h = new vector<Short_t>();
   TBranch * branch = chain.GetBranch("A_Short_t_Branch");
   Int_t nentries = 0;
   nentries = Int_t(chain.GetEntries());
   Int_t nentry = 0;
   for (int k = 0; k < nentries; ++k ) {
      nentry += chain.GetEntry(k);
      Long64_t localEntry = chain.LoadTree(k);
      Int_t o1 = branch->GetEntry(localEntry);
      cout <<(*h).size() << endl;

It print out 0s in a row. :confused:
There’s no problem with the branch in root file (checked by TBrowser) and I’m using root. 5.08/00b.
What can be the reason:?: Thanks.


branch->SetAddress(h); to


Thank you. Really appreciate your help.
I tried to use

But the result is the same.
And I defined ‘h’ as a pointer of vector, why I need to use ‘&’ then?


I used the similar code to another root file, which works fine. :open_mouth:

Now I’m wondering where I may made mistake…

The A_Short_t_Branch in

is not a real branch. Indeed it’s a leaf on a branch. So I can’t pass the address outside via a method of TBranch.

The only way is to read out the whole branch, and then read the leaf from the vector of branch.

Is what I understand correct?

Rene, Thank you for your help anyway


I strongly recommend that you do NOT manipulate the TBranch objects directly. They come and go during the life of the TChain.

Do NOT usebranch->SetAddress(...); but USE

chain.SetBranchAddress(name,&h);This will properly propagate the information during the life of the TChain AND will provide checking of the address type being passed (aka if you make an error it should warn you).

[quote]The only way is to read out the whole branch, and then read the leaf from the vector of branch. [/quote]I am not sure what you mean. Could you send the result of chain.Print()


Thanks a lot, I tried both way and I think the problem is not at this point.
please check email, thanks.


Hi rooters,

I was using the same code, but it now ruturns error for defining

edm::Wrapper<vector> * psh = 0;

The error message:

Limitation: Can’t instantiate precompiled template
edm::Wrapper<vector > analysis.C:39:

*** Break *** segmentation violation
Generating stack trace…

Did I missed anything?


Please send the shortest possible RUNNING setup reproducing your problem.



[quote]Limitation: Can’t instantiate precompiled template
edm::Wrapper<vector > analysis.C:39:[/quote]This indicates that the dictionary for edm::Wrapper<vector > was NOT loaded. Please check with your local CMS build system guru to see why this is not properly loaded.