Re: Single call of procedure works while recurring call in loop returns error.

From: Stephan Zimmer <zimmerst_at_googlemail.com>
Date: Sat, 27 Feb 2010 18:43:45 +0100


Hi Rene,
that's very unfortunate... so far I've tested the macro on different platforms with different root-versions; all with the same result:

>>>>>>>>>>>>>>>>>>>>

root [0] .X henry.C
initial chi2/Ndf: 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Error: Can't call vector<double,allocator<double> >::vector<double,allocator<dou
ble> >((class vector<double>***&)37128248) in current scope C:\Users\zimmer\Desk
top\ex6\henry.C(15)
Possible candidates are...
public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(void);
public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(vector<double,allocator<double> >::size_type n,co
nst double& value=double());
public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(const vector<double,allocator<double> >& x); public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(vector<double,allocator<double> >::const_iterator
 first,vector<double,allocator<double> >::const_iterator last); public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(void);
public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(vector<double,allocator<double> >::size_type n,co
nst double& value=double());
public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(const vector<double,allocator<double> >& x); public: vector<double,allocator<double> > vector<double,allocator<double> >::vec
tor<double,allocator<double> >(vector<double,allocator<double> >::const_iterator
 first,vector<double,allocator<double> >::const_iterator last); *** Interpreter error recovered ***
>>>>>>>>>>>>>>>>>>>>>>>>>

tested architectures and root versions:
Linux, Ubuntu 9.10: 5.18, 5.26
Linux, SLC 4: 5.22
Linux SLC4 on lxplus: 5.21.04
Windows 7, VC9+: 5.26

Any guess what could cause this behavior? Any help is greatly appreciated.

Cheers, Stephan

On 2/27/2010 5:21 AM, Rene Brun wrote:
> Hi Stephan,
>
> I cannot reproduce the problem. Executing your script, I get:
> root [0] .L henry.C
> root [1] henry()
> initial chi2/Ndf: 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> Chi2/Ndf 528.202
> root [2] .q
>
> I tried too with ACLIC and get the same result. To use it with ACLIC, I
> had to make 2 small changes in the includes, see attachment.
>
> Rene
>
> Stephan Zimmer wrote:

>> Oh sorry for that.
>> The script to call is henry.C and the dat-file henry.dat (see
>> attachment) I just wonder whether I did something stupid in my code.
>> Thank you very much.
>> The same behavior happens under 5.18/5.22/5.26
>> Cheers, Stephan
>>
>> On 2/27/2010 5:01 AM, Rene Brun wrote:
>>  
>>> Could you provide a complete script and the data file to execute it?
>>>
>>> Rene
>>>
>>> Stephan Zimmer wrote:
>>>    
>>>> Hi ROOTers,
>>>> I wonder if someone of you might understand why the following code
>>>> crashes...
>>>>
>>>> double CotTheta(const double x_i, const double alpha[2]){
>>>>   // returns the estimate y(x_i) based on the theoretical distribution
>>>>   return alpha[0]*x_i - alpha[1]*pow(x_i,-1);
>>>> }
>>>>
>>>> double CalculateChi2(const vector<double> x, const vector<double> y,
>>>> const vect\
>>>> or<double> yError, const double alpha[2]){
>>>>   // returns the chi2 value for a given set of parameters
>>>>   double sumchi2=0;
>>>>   for (unsigned int i = 0; i<x.size(); i++){
>>>>    
>>>> sumchi2=sumchi2+(pow(yError[i],-2)*pow(y[i]-CotTheta(x[i],alpha),2));
>>>>   }
>>>>   return sumchi2;
>>>> }
>>>>
>>>> void littleHenry(){
>>>>
>>>>   TVirtualFitter::SetDefaultFitter("Minuit");
>>>>
>>>>   // readout henry.dat
>>>>   vector<double> xVec;
>>>>   vector<double> xEVec;
>>>>   vector<double> yVec;
>>>>   vector<double> yEVec;
>>>>   double x(0),y(0),xE(0), yE(0);
>>>>   double output[3];
>>>>   FILE *data;
>>>>   char datafname[]="henry.dat";
>>>>
>>>>   data = fopen(datafname,"r");
>>>>   while (fscanf(data, "%lf %lf %lf %lf",&x,&xE,&y,&yE) != EOF) {
>>>>     xVec.push_back(x);
>>>>     yVec.push_back(y);
>>>>     xEVec.push_back(xE);
>>>>     yEVec.push_back(yE);
>>>>   }
>>>>   double alpha[2];
>>>>   double chi2;
>>>>   alpha[0]=1e-4;
>>>>   alpha[1]=1e2;
>>>>   CalculateChi2(xVec,yVec,yEVec,alpha);
>>>>   --> that works...
>>>>
>>>>
>>>> However, once I want to execute the routine CalculateChi2 more than
>>>> twice, by putting it inside a loop I get a weird error message:
>>>>   for (int i = 0; i<5; i++){
>>>>     chi2=CalculateChi2(xVec,yVec,yEVec,alpha);
>>>>     cout << "Chi2/Ndf " << chi2/xVec.size() << endl;
>>>>   }
>>>> ----> OUTPUT <-------
>>>> Processing littleHenry.C...
>>>> Chi2/Ndf 528.202
>>>> Chi2/Ndf 528.202
>>>> Error: Can't call vector<double,allocator<double>
>>>>  
>>>>      
>>>>> ::vector<double,allocator<double> >((class
>>>>>             
>>>> vector<double>***&)148530456) in current scope littleHenry.C:34:
>>>> Possible candidates are...
>>>> (in vector<double,allocator<double> >)
>>>> vector.dll       -1:-1   0 public: vector<double,allocator<double> >
>>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>>      
>>>>> (void);
>>>>>         
>>>> vector.dll       -1:-1   0 public: vector<double,allocator<double> >
>>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>>  
>>>>      
>>>>> (vector<double,allocator<double> >::size_type n,const double&
>>>>>             
>>>> value=double());
>>>> vector.dll       -1:-1   0 public: vector<double,allocator<double> >
>>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>>  
>>>>      
>>>>> (const vector<double,allocator<double> >& x);
>>>>>             
>>>> vector.dll       -1:-1   0 public: vector<double,allocator<double> >
>>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>>  
>>>>      
>>>>> (vector<double,allocator<double> >::const_iterator
>>>>>             
>>>> first,vector<double,allocator<double> >::const_iterator last);
>>>> *** Interpreter error recovered ***
>>>>
>>>> I wonder if I somehow run out of the boundaries of the vector but that
>>>> should not happen as they are not touched and treated as constants...
>>>> Any ideas?
>>>>
>>>> Cheers,
>>>> Stephan
>>>>
>>>>         

>
Received on Sat Feb 27 2010 - 18:44:02 CET

This archive was generated by hypermail 2.2.0 : Sun Feb 28 2010 - 17:50:01 CET