Hi,
I would like to read a tree (via TChain) using the Selector code from TChain::MakeSelector(). After geting the generated Selector skeleton I’ve looked into http://root.cern.ch/drupal/content/accessing-ttree-tselector to know a bit more about the functions and how they will called. I start to implement some simple examples and I managed to loop over the entries, but I’m unable to retrive values from a tree.
I’m attaching an example to reproduce the problem.
The main (and simple) modification were …
In the main class (file mytree.h) I add a variable to store the number of events
Int_t fNumberOfEvents;
In the Process function (file mytree.C) I call TBranch::GetEntry() and try to get the branch’s value
[code] b_mom->GetEntry(entry);
printf(“Processing Entry number %ld\n”, entry);
printf(“Mom %d\n”, mom);
//printf(“charge %ld\n”, charge);
++fNumberOfEvents;
[/code]
In the Terminate function (file mytree.C) I print the total number of events
printf("\nTotal Number of Events: %d\n", fNumberOfEvents);
To run this example just type
$ root -l run.cc
You’ll need to set the correct path in the “list_small.txt” file
the output that I get is
root [0]
Processing run.cc...
Info in <TUnixSystem::ACLiC>: creating shared library /u/data/comp/lsilva/analise/HADES/tree/./mytree_C.so
In file included from /u/data/comp/lsilva/analise/HADES/tree/./mytree.C:26:0,
from /u/data/comp/lsilva/analise/HADES/tree/mytree_C_ACLiC_dict.h:34,
from /u/data/comp/lsilva/analise/HADES/tree/mytree_C_ACLiC_dict.cxx:17:
/u/data/comp/lsilva/analise/HADES/tree/./mytree.h:76:4: warning: unused parameter ‘tree’ [-Wunused-parameter]
In file included from /u/data/comp/lsilva/analise/HADES/tree/mytree_C_ACLiC_dict.h:34:0,
from /u/data/comp/lsilva/analise/HADES/tree/mytree_C_ACLiC_dict.cxx:17:
/u/data/comp/lsilva/analise/HADES/tree/./mytree.C:31:6: warning: unused parameter ‘tree’ [-Wunused-parameter]
/u/data/comp/lsilva/analise/HADES/tree/./mytree.C:42:6: warning: unused parameter ‘tree’ [-Wunused-parameter]
/u/data/comp/lsilva/analise/HADES/tree/./mytree.C: In member function ‘virtual Bool_t mytree::Process(Long64_t)’:
/u/data/comp/lsilva/analise/HADES/tree/./mytree.C:86:48: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 2 has type ‘Long64_t {aka long long int}’ [-Wformat]
/u/data/comp/lsilva/analise/HADES/tree/./mytree.C:88:25: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat]
Processing Entry number 0
Mom 26
Processing Entry number 1
Mom 26
Processing Entry number 2
Mom 26
Processing Entry number 3
Mom 26
Total Number of Events: 4
While the momenta values for these 4 tracks are
root [1] tree->Scan("mom")
************************
* Row * mom *
************************
* 0 * 805.04699 *
* 1 * 625.64422 *
* 2 * 790.17584 *
* 3 * 546.20159 *
************************
(Long64_t)4
I have the feeling that I’m maybe doing some mistake, because this looks very trivial. What is wrong in my simple implementation?
Thanks in advance.
Regards,
Luis.
P.S. - This problem is linked to my previous post, [url]Error in <TPacketizerAdaptive::ValidateFiles>: cannot get en after I’ve posed that post I realised that in the example I’ve quote there were some intrinsic problems (e.g. the tree was empty )
tree_120_12.root (8.27 KB)
mytree.h (5.14 KB)
mytree.C (3.57 KB)
list_small.txt (56 Bytes)
run.cc (479 Bytes)