Dear ROOTers.
I am trying to declare a vector of pointers to histograms, adding histograms inside the loop, and accessing the histograms after the loop is done. However, I am not able to do it, and I cannot figure out why. Here's the relevant code:
#include <iostream>
#include <vector>
#include "TFile"
#include "TH1"
int test() {
using namespace std;
vector <TH1I*> vechist;
do {
cout << "in the loop..." << endl;
TFile* f = new TFile("rootfile.root");
TH1I* temphist = (TH1I*) f->Get("histogram");
vechist.push_back(temphist);
cout << "off the loop..." << endl;
} while(0);
cout << vechist[0]->GetEntries() << endl;
f->Close();
return 0;
}
It crashes just before the third cout. I thought it was a scope problem, but removing the do and the while(0), while still keeping the curly braces (thus defining a scope inside) makes the problem disappear. What am I doing wrong? What can I do to solve my problem?
I am using ROOT 5.17/04, in an Ubuntu 7.10 machine.
The output from bt command from the debugger:
#0 0x53e58955 in ?? ()
#1 0xb68bcd1d in ?? () from /usr/lib/root/5.17/libHist.so
#2 0xb72d54e7 in Cint::G__ExceptionWrapper ()
from /usr/lib/root/libCint.so.5.17
#3 0xb73be6e0 in G__call_cppfunc () from /usr/lib/root/libCint.so.5.17
#4 0xb7397ba5 in G__interpret_func () from /usr/lib/root/libCint.so.5.17
#5 0xb7386651 in G__getfunction () from /usr/lib/root/libCint.so.5.17
#6 0xb74569b8 in G__getstructmem () from /usr/lib/root/libCint.so.5.17
#7 0xb744d802 in G__getvariable () from /usr/lib/root/libCint.so.5.17
#8 0xb735ad11 in G__getitem () from /usr/lib/root/libCint.so.5.17
#9 0xb736a79f in G__getexpr () from /usr/lib/root/libCint.so.5.17
#10 0xb73e2151 in G__exec_statement () from /usr/lib/root/libCint.so.5.17
#11 0xb7398f1b in G__interpret_func () from /usr/lib/root/libCint.so.5.17
#12 0xb73866b7 in G__getfunction () from /usr/lib/root/libCint.so.5.17
#13 0xb735adf2 in G__getitem () from /usr/lib/root/libCint.so.5.17
#14 0xb7361865 in G__getexpr () from /usr/lib/root/libCint.so.5.17
#15 0xb736d17a in G__calc_internal () from /usr/lib/root/libCint.so.5.17
#16 0xb73f6441 in G__process_cmd () from /usr/lib/root/libCint.so.5.17
#17 0xb7a1f275 in TCint::ProcessLine () from /usr/lib/root/libCore.so.5.17
#18 0xb7a19086 in TCint::ProcessLineSynch () from /usr/lib/root/libCore.so.5.17
#19 0xb798147b in TApplication::ExecuteFile ()
from /usr/lib/root/libCore.so.5.17
#20 0xb79817b4 in TApplication::ProcessFile ()
from /usr/lib/root/libCore.so.5.17
#21 0xb797eddb in TApplication::ProcessLine ()
from /usr/lib/root/libCore.so.5.17
#22 0xb726ea89 in TRint::HandleTermInput () from /usr/lib/root/libRint.so.5.17
#23 0xb726cf75 in TTermInputHandler::Notify ()
from /usr/lib/root/libRint.so.5.17
#24 0xb726f3e4 in TTermInputHandler::ReadNotify ()
from /usr/lib/root/libRint.so.5.17
#25 0xb7a4b59b in TUnixSystem::CheckDescriptors ()
from /usr/lib/root/libCore.so.5.17
#26 0xb7a4b98e in TUnixSystem::DispatchOneEvent ()
from /usr/lib/root/libCore.so.5.17
#27 0xb79d6ce1 in TSystem::InnerLoop () from /usr/lib/root/libCore.so.5.17
#28 0xb79d8631 in TSystem::Run () from /usr/lib/root/libCore.so.5.17
#29 0xb797d858 in TApplication::Run () from /usr/lib/root/libCore.so.5.17
#30 0xb726f01e in TRint::Run () from /usr/lib/root/libRint.so.5.17
#31 0x08048ea3 in main ()
Best regards,
Thiago Tomei
-- Thiago R. F. P Tomei - http://cern.ch/Thiago.Tomei SPRACE - São Paulo Regional Analysis Center CERN - European Organization for Nuclear ResearchReceived on Thu Nov 08 2007 - 20:45:45 CET
This archive was generated by hypermail 2.2.0 : Thu Nov 08 2007 - 23:50:01 CET