vector<RooPlot*> push_back error

Can anyone tell me why,

vector<RooPlot*> MassframeVector;
RooPlot* Massframe1 = new RooPlot(-limit, limit);

RooPlot* m2 = Massframe1->Clone();
MassframeVector.push_back(m2);

Works fine, but,

vector<RooPlot*> MassframeVector;
RooPlot* Massframe1 = new RooPlot(-limit, limit);

MassframeVector.push_back(Massframe1->Clone());

crashes with,
‘Can’t call vector<RooPlot*>::push_back(Massframe1->Clone()) in current scope
possible candidates are…
public: void vector<RooPlot*>::push_back(RooPlot* const& x);’

Thanks,
-Julian

Hi,

Use:MassframeVector.push_back(dynamic_cast<RooPlot*>(Massframe1->Clone()));

Cheers,
Philippe.

Thanks, for my own reference, for what reason do I have to cast it?

Also, my code still crashes (with seg fault this time) when I try to Draw() from the vector, am I doing something silly?

vector<RooPlot*> MassframeVector;
RooPlot* Massframe1 = new RooPlot(-limit, limit);

for(int it = 1; i < n; i++) {
   Fit(hist, Massframe1)  
   MassframeVector.push_back(dynamic_cast<RooPlot*>(Massframe1->Clone()));
}
MassframeVector[0]->Draw();

Where Fit.C is

void Fit(TH1F HistName, RooPlot*& Massframe)
{....
Massframe = Mass.frame();
....}

Thanks,
-Julian

Hi Julian,

Clone returns a TObject* that must be explicitly cast to be used in function calls. (It works without it in the case of the assignment due to CINT magic (if compiled the code should fails to compile).

[quote]Also, my code still crashes (with seg fault this time) when I try to Draw() from the vector, am I doing something silly?[/quote]Is MassframeVector.size() > 0 and MassframeVector[0]!=0 ?

Philippe.

Hi Philippe, sorry for delay on my part.

Yes, if I check those values in my current setup MassframeVector.size() is 13 and and MassframeVector[0] != 0.

-Julian

Hi,

Then I am not sure. The easiest is probably to use valgrind to decipher where the segfault comes from (i.e. start ROOT with: valgrind root.exe ).

Philippe.

I can’t say I’m familiar with valgrind, it is not even installed on my local machine.

If I try to run my setup on lxplus I get the message, “valgrind: failed to start tool ‘memcheck’ for platform ‘x86-linux’: No such file or directory”. Simple fix?

Thanks,
-Julian

hi Julian,

From what I understand ATLAS and CMS do have a working version of valgrind stashed somewhere on afs (but no clue where). Alternatively you can easily download and build the valgrind (from valgrind.org), just making to configure with --prefix=/somewhere/you/own.

Cheers,
Philippe.

Hi Philippe,

I installed and ran with ‘valgrind --leak-check=full --show-reachable=yes -v root’

My macro runs, seg faults, dumps stack trace, prints ‘busy flag cleared’ and returns to the root prompt. If i then quit root, valgrind gives me the printout:

–31547-- REDIR: 0x4cdc1a0 (operator delete(void*)) redirected to 0x4a06e19 (operator delete(void*))
==31547==
==31547== HEAP SUMMARY:
==31547== in use at exit: 93 bytes in 1 blocks
==31547== total heap usage: 671 allocs, 670 frees, 739,384 bytes allocated
==31547==
==31547== Searching for pointers to 1 not-freed blocks
==31547== Checked 248,448 bytes
==31547==
==31547== 93 bytes in 1 blocks are still reachable in loss record 1 of 1
==31547== at 0x4A08262: operator new[](unsigned long) (vg_replace_malloc.c:363)
==31547== by 0x4026FF: main (in /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.01-x86_64-slc5-gcc4.3/bin/root)
==31547==
==31547== LEAK SUMMARY:
==31547== definitely lost: 0 bytes in 0 blocks
==31547== indirectly lost: 0 bytes in 0 blocks
==31547== possibly lost: 0 bytes in 0 blocks
==31547== still reachable: 93 bytes in 1 blocks
==31547== suppressed: 0 bytes in 0 blocks
==31547==
==31547== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
–31547–
–31547-- used_suppression: 4 dl-hack3
==31547==
==31547== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

I’m not sure what exactly this means, the memory check seems OK?

Cheers,
Philippe.

I see what you mean, I ran it on root.exe and the result was much different! Although it made not a lot of sense to me! I can include the log if you wish…

However I have found if instead of generating the copies in the loop, if I first generate them beforehand and fill the vector, it works fine:

vector<RooPlot*> MassframeVector;
RooPlot* Massframe1 = new RooPlot(-limit, limit);

for(int k = 0; i < n; i++) {
   MassframeVector.push_back(dynamic_cast<RooPlot*>(Massframe1->Clone()));
}

for(int i = 1; i < n; i++) {
   Fit(hist, MassframeVector[i-1]); 
}
MassframeVector[0]->Draw();

Where as I was previously doing this (from previous post for convenience):

vector<RooPlot*> MassframeVector;
RooPlot* Massframe1 = new RooPlot(-limit, limit);

for(int it = 1; i < n; i++) {
   Fit(hist, Massframe1) 
   MassframeVector.push_back(dynamic_cast<RooPlot*>(Massframe1->Clone()));
}
MassframeVector[0]->Draw();

Any idea why this new method works when the old fails?

-Julian

Hi,

No, I do not really see. What did valgrind say?

Philippe