Accessing array elements with MakeProxy

I am trying to figure out how MakeProxy works. I want to access the individual array elements from the branch, but can’t make it work. My tree, proxy.h and proxyTry.C files are here https://drive.google.com/open?id=0Bxa5bvqmnbLZUWtkY0ZSYlJBVkk

Thanks,
Andrea

Hi,

How does it fail for you?

Cheers,
Philippe.

Hi Philippe,

I want to access individual array elements of StrSimHits.m_Edep and fill a histogram, but I can’t find a way to iterate over them. I remember last time StrSimHits was the one containing the size of the arrays, but now I can’t use it as the condition in the for loop, it returns

error: invalid operands to binary expression ('int' and 'proxy::TClaPx_Belle2__StrSimHit') for (int i; i < StrSimHits; i++) { ~ ^ ~~~~~~~~~~

Thanks,

Andrea

for (int i; i < StrSimHits.GetEntries(); i++) {should work.

Cheers,
Philippe.

Yes, that works, but the filled histogram has 1.24e07 entries, but should have 63287 (from TBrowser). Also, if I cout StrSimHits.GetEntries(), I get the error:

Hi,

ThisError in <TClonesArray::At>: index -2097903834 out of bounds (size: 1000, this: 0x7fec833a2340)is likely because ‘i’ is not initialized in the for loop:for (int i; i < StrSimHits.GetEntries(); i++) {(Sorry for missing this earlier).

[quote]
Yes, that works, but the filled histogram has 1.24e07 entries, but should have 63287 (from TBrowser). [/quote]This is because what you see is the histogram of the return value of the ‘process’ function (named proxyTry) in your case. There is indeed one value (always zero) for each entries. To skip this histogram, use the ‘nohist’ option when generating the proxy:

tree->MakeProxy("proxy","proxyTry.C","nohist")Also rather than modifying the resulting file, add the thing you need to be added in the global space (for example the #include “TCanvas.h”) in a header file for your script (so name ‘proxyTry.h’) in your case.

Note that in the example you upload, the actual histogram are not display because the _Terminate routine is misnamed. It should be:void proxyTry_Terminate()

Cheers,
Philippe.

It works, thanks for your patience!

New problem I have is when I transfer everything from my laptop to my desktop. They are bot running version 6.06/02.

root [1] selectedTree->Process("proxy.h+") Info in <TUnixSystem::ACLiC>: creating shared library /raid/hypnos/afodor/2016/testSkim/largeCrystals/./proxy_h.so In file included from input_line_12:9: In file included from /raid/hypnos/afodor/2016/testSkim/largeCrystals/./proxy.h:23: /usr/local/include/root/TBranchProxyTemplate.h:35:17: error: unknown type name 'TBranchProxyDirector' TObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {}; ^ /usr/local/include/root/TBranchProxyTemplate.h:36:17: error: unknown type name 'TBranchProxyDirector' TObjProxy(TBranchProxyDirector *director, const char *top, const char *name) : ^ /usr/local/include/root/TBranchProxyTemplate.h:38:17: error: unknown type name 'TBranchProxyDirector' TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) : ^ /usr/local/include/root/TBranchProxyTemplate.h:40:17: error: unknown type name 'TBranchProxyDirector' TObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : ^ /usr/local/include/root/TBranchProxyTemplate.h:68:7: error: unknown type name 'TClaProxy' TClaProxy obj; ^ /usr/local/include/root/TBranchProxyTemplate.h:79:20: error: unknown type name 'TBranchProxyDirector' TClaObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {}; ^ /usr/local/include/root/TBranchProxyTemplate.h:80:20: error: unknown type name 'TBranchProxyDirector' TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name) : ^ /usr/local/include/root/TBranchProxyTemplate.h:82:20: error: unknown type name 'TBranchProxyDirector' TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) : ^ /usr/local/include/root/TBranchProxyTemplate.h:84:20: error: unknown type name 'TBranchProxyDirector' TClaObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : ^ /usr/local/include/root/TBranchProxyTemplate.h:109:7: error: unknown type name 'TStlProxy' TStlProxy obj; ^ /usr/local/include/root/TBranchProxyTemplate.h:121:20: error: unknown type name 'TBranchProxyDirector' TStlObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {}; ^ /usr/local/include/root/TBranchProxyTemplate.h:122:20: error: unknown type name 'TBranchProxyDirector' TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name) : ^ /usr/local/include/root/TBranchProxyTemplate.h:124:20: error: unknown type name 'TBranchProxyDirector' TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) : ^ /usr/local/include/root/TBranchProxyTemplate.h:126:20: error: unknown type name 'TBranchProxyDirector' TStlObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : ^ /usr/local/include/root/TBranchProxyTemplate.h:161:23: error: unknown type name 'TBranchProxyDirector' TStlSimpleProxy(TBranchProxyDirector *director, const char *name) : ROOT::TObjProxy<T>(director,name),fCollection(0) {}; ^ /usr/local/include/root/TBranchProxyTemplate.h:162:23: error: unknown type name 'TBranchProxyDirector' TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name) : ^ /usr/local/include/root/TBranchProxyTemplate.h:164:23: error: unknown type name 'TBranchProxyDirector' TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) : ^ /usr/local/include/root/TBranchProxyTemplate.h:166:23: error: unknown type name 'TBranchProxyDirector' TStlSimpleProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mi... ^ In file included from input_line_12:9: /raid/hypnos/afodor/2016/testSkim/largeCrystals/./proxy.h:83:7: error: unknown type name 'TClaObjProxy' TClaObjProxy<TObject > obj; ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] Error in <ACLiC>: Dictionary generation failed! Error in <TSelector::GetSelector>: The file proxy.h+ does not define a class named proxy. (Long64_t) -1

I tried doing everything from scratch, but I get the same error. Even if I do

I get the similar error message.

Warning in <TTreePlayer::DrawScript>: TTreeProxy does not work in interpreted mode yet. The script will be compiled.
Info in <TTreePlayer::DrawScript>: Will process tree/chain using generatedSel.h+
Info in <TUnixSystem::ACLiC>: creating shared library /raid/hypnos/afodor/2016/testSkim/largeCrystals/./generatedSel_h.so
In file included from input_line_12:9:
In file included from /raid/hypnos/afodor/2016/testSkim/largeCrystals/./generatedSel.h:23:
/usr/local/include/root/TBranchProxyTemplate.h:35:17: error: unknown type name 'TBranchProxyDirector'
      TObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
                ^
/usr/local/include/root/TBranchProxyTemplate.h:36:17: error: unknown type name 'TBranchProxyDirector'
      TObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
                ^
/usr/local/include/root/TBranchProxyTemplate.h:38:17: error: unknown type name 'TBranchProxyDirector'
      TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
                ^
/usr/local/include/root/TBranchProxyTemplate.h:40:17: error: unknown type name 'TBranchProxyDirector'
      TObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : 
                ^
/usr/local/include/root/TBranchProxyTemplate.h:68:7: error: unknown type name 'TClaProxy'
      TClaProxy obj;
      ^
/usr/local/include/root/TBranchProxyTemplate.h:79:20: error: unknown type name 'TBranchProxyDirector'
      TClaObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:80:20: error: unknown type name 'TBranchProxyDirector'
      TClaObjProxy(TBranchProxyDirector *director,  const char *top, const char *name) :
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:82:20: error: unknown type name 'TBranchProxyDirector'
      TClaObjProxy(TBranchProxyDirector *director,  const char *top, const char *name, const char *data) :
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:84:20: error: unknown type name 'TBranchProxyDirector'
      TClaObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : 
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:109:7: error: unknown type name 'TStlProxy'
      TStlProxy obj;
      ^
/usr/local/include/root/TBranchProxyTemplate.h:121:20: error: unknown type name 'TBranchProxyDirector'
      TStlObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:122:20: error: unknown type name 'TBranchProxyDirector'
      TStlObjProxy(TBranchProxyDirector *director,  const char *top, const char *name) :
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:124:20: error: unknown type name 'TBranchProxyDirector'
      TStlObjProxy(TBranchProxyDirector *director,  const char *top, const char *name, const char *data) :
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:126:20: error: unknown type name 'TBranchProxyDirector'
      TStlObjProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : 
                   ^
/usr/local/include/root/TBranchProxyTemplate.h:161:23: error: unknown type name 'TBranchProxyDirector'
      TStlSimpleProxy(TBranchProxyDirector *director, const char *name) : ROOT::TObjProxy<T>(director,name),fCollection(0) {};
                      ^
/usr/local/include/root/TBranchProxyTemplate.h:162:23: error: unknown type name 'TBranchProxyDirector'
      TStlSimpleProxy(TBranchProxyDirector *director,  const char *top, const char *name) :
                      ^
/usr/local/include/root/TBranchProxyTemplate.h:164:23: error: unknown type name 'TBranchProxyDirector'
      TStlSimpleProxy(TBranchProxyDirector *director,  const char *top, const char *name, const char *data) :
                      ^
/usr/local/include/root/TBranchProxyTemplate.h:166:23: error: unknown type name 'TBranchProxyDirector'
      TStlSimpleProxy(TBranchProxyDirector *director, TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) : 
                      ^
In file included from input_line_12:9:
/raid/hypnos/afodor/2016/testSkim/largeCrystals/./generatedSel.h:83:7: error: unknown type name 'TClaObjProxy'
      TClaObjProxy<TObject > obj;
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Error in <ACLiC>: Dictionary generation failed!
Error in <TSelector::GetSelector>: The file generatedSel.h+ does not define a class named generatedSel.

Any ideas?

Hi,

/usr/local/include/root/TBranchProxyTemplate.h:35:17: error: unknown type name 'TBranchProxyDirector'

It looks like you might have a mix-up of ROOT version. In v6-06-02 the line 35 of TBranchProxyTemplate.h is supposed to be class TObjProxy {

So I assuming the version in /usr/local is not the one you expect.

Cheers,
Philippe.