Crash when trying to use vector <pair <int,double>

Hi,

I am reading a Tree with an interpreted C code I obtained using MakeClass on the given Tree. So far, the code has been working without problems, until I tried to use a vector of pairs. Since then, it’s been crashing whenever I am pushing back values in the vector.

Here’s the code I am using to test this (not including the part which reads the Tree):

#include "Jpsi.h"
#include <pair.h>
#include <vector.h>

void Jpsi::Loop()
{
using namespace std;
vector< pair<int,double> > true_elec_index;
int testint=1;
double testdouble=1.2325646548;

true_elec_index.push_back( make_pair( testint, testdouble ) );

}

When executing this, I get the following output:

root [1] Jpsi t; t.Loop();
*** glibc detected *** double free or corruption (!prev): 0x08eebda8 ***
%@>

And then Root exits. I know this code works in compiled c++ (i.e. not using Root libraries). Does anybody know why it doesn’t in interpreted Root?

Thanks in advance,

Andrée

When using STL collections in your code, you must use ACLIC to compile it.
do

root > .L Jpsi.C+ root > Jpsi t;

The coming version of CINT will provide a correct support for STL.

Rene

Thanks for the hint! But I still have some problems using this…

ACLIC tells me that the compilation failed, even with code that is normally working and I am not sure to quite get what the problems are…

Using this simple code (removing the Jpsi part):

#include <pair.h>
#include <vector.h>

void test()
{
using namespace std;
   vector< pair<int,double> > true_elec_index;
   int testint=1;
   double testdouble=1.2325646548;

   true_elec_index.push_back( make_pair( testint, testdouble ) );

}

Root tells me the following:

root [0] .L test.C+ 
Info in <TUnixSystem::ACLiC>: creating shared library /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./test_C.so
In file included from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/pair.h:59,
                 from /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./test.C:1,
                 from /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./fileuJCylO.h:32,
                 from /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./fileuJCylO.cxx:16:
/usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
In file included from /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./fileuJCylO.cxx:16:
/atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./fileuJCylO.h:33:23: algorithm.h: No such file or directory
g++: /atlas/data1/userdata/arobic/Egamma/14.2.10/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run/./fileuJCylO.o: No such file or directory
Error in <ACLiC>: Compilation failed!

I don’t quite grasp what is the error here… it seems to come from those ./filennnnn.cxx but what are they? Otherwise, I only see warnings listed there.

For the record, I use version 5.18.00d

Thanks!

Andrée

You are including the wrong (obsolete headers). Do:

[code]#include

void test() {
using namespace std;
vector< pair<int,double> > true_elec_index;
int testint=1;
double testdouble=1.2325646548;

true_elec_index.push_back( make_pair( testint, testdouble ) );

}
[/code]
Rene

Brilliant, now it works like a charm!

Thanks a million!

Andrée