Original Post
I have some very strange behaviour. I have this code: Ok, this is just creating a bunch of objects, with some bells and whistles to give them unique names for when I call the method more than once. This is needed in some cases, but is currently turned off for my debugging effort, so this code runs only once. Now, when I use gdb to step through this code, looking at the variable addresses for each line, everything looks fine until I come to the last 'new' statement. At that point I get this:
void makeLocalResolution (char* pre, RooRealVar& timeVariable, RooRealVar& localBias) {
static int pdfs = 0;
pdfs++;
static char* pdfnames = new char[200];
sprintf(pdfnames, "%s_ssf1_%i", pre, pdfs);
RooRealVar* ssf1 = new RooRealVar(pdfnames, "", 0.9, 0.2, 5);
sprintf(pdfnames, "%s_ssf2_%i", pre, pdfs);
RooRealVar* ssf2 = new RooRealVar(pdfnames, "", 2.8, 0.2, 7);
sprintf(pdfnames, "%s_gauss1_%i", pre, pdfs);
RooGaussModel* gauss1 = new RooGaussModel(pdfnames, "", timeVariable, localBias, *ssf1);
sprintf(pdfnames, "%s_gauss2_%i", pre, pdfs);
RooGaussModel* gauss2 = new RooGaussModel(pdfnames, "", timeVariable, localBias, *ssf2);
sprintf(pdfnames, "%s_frac_%i", pre, pdfs);
RooRealVar* frac1 = new RooRealVar(pdfnames, "", 0.175, 0.02, 1);
(...)
}
(gdb) p ssf1
$8 = (class RooRealVar *) 0xa5fea38
(gdb) p frac1
$9 = (class RooRealVar *) 0xa5fea38
In other words, the 'frac1' object is being created right on top of my 'ssf1' object! Naturally this creates all sorts of problems later in the program. Honestly I'm surprised it runs at all, but it does. My question: Does anyone have any ideas on how this kind of situation can occur? I have no idea how to debug this. Even if I can perhaps avoid this particular problem by moving my code around a bit, I would like to be confident that nothing similar is happening elsewhere in the program. I would really, really welcome suggestions.