I get those strange numbers in the array instead of what I expected (root[3]t1->Scan)…
I think the problems lies in the form of the branch data (vector*) but i cannot figure out how to change my commands to make it work…
thank you for your time…
Do i have to use the SetMakeClass command before the SetBranchAddress or replace it? I’m sorry, but I can’t find out what this command does…
Could you please show me an example of the syntax for the second sollution cause i’m not so familiar with C commands. Should i create 2 vectors?
The SetMakeClass call, must be issued before calling SetBranchAddres ; it tells the TTree that you intend to access the data content directly using ints and floats and do not plan to use the original object hierarchy.
As far as using objects, you simply would do #include <vector>
...
vector<int> * mod1layer0_ptr = 0;
t1->SetBranchAddress("BATStripIdMod1layer0",& mod1layer0_ptr);
Following your instructions i end up with a pointer to a vector (mod1layer0_ptr). However the values in the vector cells are not the values that are held in the branch.
I suppose I have to associate this new ponter to a new vector in some way to get the real values…???
root [4] mod1layer0_ptr
(vector<int>*)0x3ca3f88
root [5] mod1layer0_ptr[0] I think you meant to use:root [4] mod1layer0_ptr
(vector<int>*)0x3ca3f88
root [5] mod1layer0_ptr->at(0); // the variable is a _pointer_ to a vector!
Although the previous instructions really work , while trying to use them in a loop root throws an exception error.
Cheking it step by step i found out that the exception is thrown when the vector cell the pointer points to is null…
root [3] strip_ptr->at(0)
(int)305
root [4] strip_ptr->at(13)
(int)318
root [5] strip_ptr->at(14)
Exception: invalid vector subscript
Error: Symbol G__exception is not defined in current scope (tmpfile)(1)
Error: type G__exception not defined FILE:(tmpfile) LINE:1
(int)0
*** Interpreter error recovered ***
In this case the 14th cell of the vector is null as I’m reading only the first event
root [3] t1->Scan(“BATStripIdMod1layer0”)
Row * Instance * BATStripI *
0 * 0 * 305 *
0 * 1 * 306 *
0 * 2 * 307 *
0 * 3 * 308 *
0 * 4 * 309 *
0 * 5 * 310 *
0 * 6 * 311 *
0 * 7 * 312 *
0 * 8 * 313 *
0 * 9 * 314 *
0 * 10 * 315 *
0 * 11 * 316 *
0 * 12 * 317 *
0 * 13 * 318 * //end of the first event
1 * 0 * 240 *
1 * 1 * 241 *
1 * 2 * 242 *
1 * 3 * 243 *
1 * 4 * 244 *
2 * 0 * 307 *
2 * 1 * 308 *
2 * 2 * 309 *
2 * 3 * 310 *
2 * 4 * 311 *
3 * 0 * 283 *
Type to continue or q to quit ==>
Is there any way i can manage this exception in my script?
[quote]In this case the 14th cell of the vector is null as I’m reading only the first event [/quote]Actually it is not null, it does not exist! Use:root [5] if (strip_ptr->size() > 14) strip_ptr->at(14);(You may want to re-read your favorite primer/textbook on how to use stl containers).