Problem with size of ROOT.std.vector()

Hello,

I’m getting this error when calling size() method:

[code]>>> import ROOT

vec = ROOT.std.vector(“ROOT::Minuit2::MinuitParameter”)
vec.size()


AttributeError Traceback (most recent call last)

/home/…/ in ()

AttributeError: type object ‘vectorROOT::Minuit2::MinuitParameter’ has no attribute ‘size’

[/code]

The size() method is not known:

[code]

dir(vec)
[‘add’,
bool’,
class’,
delattr’,
dict’,
div’,
doc’,
eq’,
format’,
ge’,
getattribute’,
gt’,
hash’,
init’,
le’,
lt’,
module’,
mul’,
ne’,
new’,
nonzero’,
radd’,
rdiv’,
reduce’,
reduce_ex’,
repr’,
rmul’,
rsub’,
setattr’,
sizeof’,
str’,
sub’,
subclasshook’,
weakref’][/code]

How can I fix it? Or is it a bug?

Note that if I do :

[code]

vec2 = ROOT.std.vector(“double”)
vec2.size()


TypeError Traceback (most recent call last)

/…/ in ()

TypeError: none of the 3 overloaded methods succeeded. Full details:
vector<double,allocator >::size_type vector<double,allocator >::size() =>
unbound method vector<double,allocator >::size must be called with a vector<double,allocator > instance as first argument
vector<double,allocator >::size_type vector<double,allocator >::size() =>
unbound method vector<double,allocator >::size must be called with a vector<double,allocator > instance as first argument
vector<double,allocator >::size_type vector<double,allocator >::size() =>
unbound method vector<double,allocator >::size must be called with a vector<double,allocator > instance as first argument

dir(vec2)
[‘add’,
assign’,
bool’,
class’,
cpp_eq’,
cpp_ne’,
delattr’,
dict’,
div’,
doc’,
eq’,
format’,
ge’,
getattribute’,
getitem’,
gt’,
hash’,
iadd’,
init’,
le’,
len’,
lt’,
module’,
mul’,
ne’,
new’,
nonzero’,
radd’,
rdiv’,
reduce’,
reduce_ex’,
repr’,
rmul’,
rsub’,
setattr’,
setitem’,
sizeof’,
str’,
sub’,
subclasshook’,
weakref’,
’_vector__at’,
‘at’,
‘back’,
‘begin’,
‘capacity’,
‘clear’,
‘empty’,
‘end’,
‘erase’,
‘front’,
‘insert’,
‘max_size’,
‘pop_back’,
‘push_back’,
‘rbegin’,
‘rend’,
‘reserve’,
‘resize’,
‘size’,
‘swap’,
‘vector’][/code]

then the size() method is in the list but it gives also an error.

Many thanks,
Jiri

ROOT: trunk

Jiri,

for the first case, I doubt that the necessary dictionary is available, which would then result in none of the normal vector methods being available. However, for both cases, the ‘vec’ and ‘vec2’ are the class instances, not object instances (i.e. the results of the template instantiation, not of the object instantiation). So, use this instead:[code]>>> vec2 = ROOT.std.vector(“double”)()

vec2[/code]
Cheers,
Wim

Hi Wim,

I see. Actualy I would need to get the size of:

>>> par = ROOT.Minuit2.MnUserParameters()
>>> par.Parameters().size()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/.../<ipython console> in <module>()
AttributeError: 'vector<ROOT::Minuit2::MinuitParameter>' object has no attribute 'size'

I guess that the problem is really related to the missing dictionary (as you have mentioned). Could someone from the ROOT developers please create the dictionary for vectorROOT::Minuit2::MinuitParameter ?

I think that it should be easily fixable by putting this line of code:

#pragma link C++ class vector<ROOT::Minuit2::MinuitParameter>;

probably into the file math/minuit2/inc/LinkDef.h…

Many thanks,
Jiri

Hi Jiri,

[quote]someone from the ROOT developers create the dictionary for vectorROOT::Minuit2::MinuitParameter
[/quote]You can also trivially do it, see root.cern.ch/drupal/faq#n676

Cheers,
Philippe.

Hello,

many thanks for the link. I’ve tried to follow the instructions but If I do:

>>>  ROOT.gInterpreter.AddIncludePath("$ROOTSYS/")
>>> ROOT.gInterpreter.GenerateDictionary("vector<ROOT::Minuit2::MinuitParameter>","math/minuit2/inc/Minuit2/MinuitParameter.h;vector");

then I get an error:

/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx: In member function ‘void std::vector<_Tp, _Alloc>::resize(std::vector::size_type, value_type) [with _Tp = ROOT::Minuit2::MinuitParameter, _Alloc = std::allocator<ROOT::Minuit2::MinuitParameter>, std::vector::size_type = long unsigned int, value_type = ROOT::Minuit2::MinuitParameter]’:
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:264:239: error: no matching function for call to ‘ROOT::Minuit2::MinuitParameter::MinuitParameter()’
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:67:4: note: candidates are: ROOT::Minuit2::MinuitParameter::MinuitParameter(const ROOT::Minuit2::MinuitParameter&)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:52:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:45:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:38:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double)
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx: In constructor ‘std::vector<_Tp, _Alloc>::vector(std::vector::size_type, const value_type&, const allocator_type&) [with _Tp = ROOT::Minuit2::MinuitParameter, _Alloc = std::allocator<ROOT::Minuit2::MinuitParameter>, std::vector::size_type = long unsigned int, value_type = ROOT::Minuit2::MinuitParameter, allocator_type = std::allocator<ROOT::Minuit2::MinuitParameter>]’:
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:338:214: error: no matching function for call to ‘ROOT::Minuit2::MinuitParameter::MinuitParameter()’
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:67:4: note: candidates are: ROOT::Minuit2::MinuitParameter::MinuitParameter(const ROOT::Minuit2::MinuitParameter&)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:52:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:45:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:38:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double)
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:340:227: error: no matching function for call to ‘ROOT::Minuit2::MinuitParameter::MinuitParameter()’
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:67:4: note: candidates are: ROOT::Minuit2::MinuitParameter::MinuitParameter(const ROOT::Minuit2::MinuitParameter&)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:52:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:45:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:38:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double)
In file included from /home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:19:0:
/opt/root/include/TCollectionProxyInfo.h: In member function ‘void std::vector<_Tp, _Alloc>::resize(std::vector::size_type, value_type) [with _Tp = ROOT::Minuit2::MinuitParameter, _Alloc = std::allocator<ROOT::Minuit2::MinuitParameter>, std::vector::size_type = long unsigned int, value_type = ROOT::Minuit2::MinuitParameter]’:
/opt/root/include/TCollectionProxyInfo.h:202:10:   instantiated from ‘static void ROOT::TCollectionProxyInfo::Pushback<T>::resize(void*, size_t) [with T = std::vector<ROOT::Minuit2::MinuitParameter, std::allocator<ROOT::Minuit2::MinuitParameter> >, size_t = long unsigned int]’
/opt/root/include/TCollectionProxyInfo.h:369:64:   instantiated from ‘static ROOT::TCollectionProxyInfo* ROOT::TCollectionProxyInfo::Generate(const T&) [with T = ROOT::TCollectionProxyInfo::Pushback<std::vector<ROOT::Minuit2::MinuitParameter, std::allocator<ROOT::Minuit2::MinuitParameter> > >]’
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:125:146:   instantiated from here
/opt/root/include/TCollectionProxyInfo.h:202:10: error: no matching function for call to ‘ROOT::Minuit2::MinuitParameter::MinuitParameter()’
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:67:4: note: candidates are: ROOT::Minuit2::MinuitParameter::MinuitParameter(const ROOT::Minuit2::MinuitParameter&)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:52:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:45:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:38:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double)
/opt/root/include/TCollectionProxyInfo.h: In static member function ‘static void* ROOT::TCollectionProxyInfo::Type<T>::construct(void*, size_t) [with T = std::vector<ROOT::Minuit2::MinuitParameter, std::allocator<ROOT::Minuit2::MinuitParameter> >, size_t = long unsigned int]’:
/opt/root/include/TCollectionProxyInfo.h:369:64:   instantiated from ‘static ROOT::TCollectionProxyInfo* ROOT::TCollectionProxyInfo::Generate(const T&) [with T = ROOT::TCollectionProxyInfo::Pushback<std::vector<ROOT::Minuit2::MinuitParameter, std::allocator<ROOT::Minuit2::MinuitParameter> > >]’
/home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.cxx:125:146:   instantiated from here
/opt/root/include/TCollectionProxyInfo.h:165:13: error: no matching function for call to ‘ROOT::Minuit2::MinuitParameter::MinuitParameter()’
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:67:4: note: candidates are: ROOT::Minuit2::MinuitParameter::MinuitParameter(const ROOT::Minuit2::MinuitParameter&)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:52:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:45:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double, double)
/opt/root/math/minuit2/inc/Minuit2/MinuitParameter.h:38:4: note:                 ROOT::Minuit2::MinuitParameter::MinuitParameter(unsigned int, const std::string&, double)
g++: /home/jiri/Desktop/rootProblem/test10/AutoDict_vector_ROOT__Minuit2__MinuitParameter__cxx_ACLiC_dict.o: No such file or directory
Error in <ACLiC>: Compilation failed!

So it looks like there is a problem. What am I doing wrong?

Cheers,
Jiri

Hi,

[quote]So it looks like there is a problem. What am I doing wrong?[/quote]Currently MinuitParameter does not provide a default constructor and thus you can not generate a dictionary for an std::vector of MinuitParameter.

Philippe.

Hello,

I filled therefore a feature request for creation of the missing dictionary for std::vectorROOT::Minuit2::MinuitParameter (savannah.cern.ch/bugs/?77252). However, for accesing the number of parameters for accesing the number of parameters one may do (thanks to Lorenzo):

[code]>>> par = ROOT.Minuit2.MnUserParameters()

npar = par.Params().size()
variable_npar = par.VariableParameters() [/code]

instead of

[code]>>> par = ROOT.Minuit2.MnUserParameters()

par.Parameters().size()[/code]

One may access the MinuitParameters like (if full access is needed):

[code]

par.Parameter(i) [/code]

So the dictionary is not needed.

Many thanks you all for help,
Jiri