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:

{
   gROOT->Reset();
   gSystem->Load("libCintex");
   <......>
   Cintex::Enable();

   TChain chain("Events");
   chain.Add("events.root");
   vector<Short_t> * h = new vector<Short_t>();
   TBranch * branch = chain.GetBranch("A_Short_t_Branch");
   branch->SetAddress(h);
   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.

Change

branch->SetAddress(h); to

branch->SetAddress(&h);
Rene

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

branch->SetAddress(&h);
But the result is the same.
And I defined ‘h’ as a pointer of vector, why I need to use ‘&’ then?

:blush:

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

Hi,

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()

Cheers,
Philippe

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

Chang

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?

Thanks,
Chang

Please send the shortest possible RUNNING setup reproducing your problem.

REne

Hi,

[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.

Philippe.