Re: No cooperation between dictionaries from Cint and Reflex

From: Roel Aaij <Roel.Aaij_at_cern.ch>
Date: Tue, 31 Jan 2012 16:08:45 +0100


Hi Sebastien,

> On Tue, 31 Jan 2012 15:45:01 +0100, Roel Aaij <Roel.Aaij_at_cern.ch> wrote:

>> Hi,
>>
>> The LHCb software framework uses Reflex dictionaries to provide python
>> bindings for most of its C++ classes. To be able to interact with one
>> of the C++ classes from python, I need to be able to create a
>> std::map<std::string, double>. A dictionary for this type exists, but
>> it does not allow me to do the following:
>>
>>>>> import ROOT
>>>>> m = ROOT.std.map('string', 'double')()
>>>>> p = ROOT.std.pair('string', 'double')('one', 1.)
>>>>> m.insert(p)

I should have been clearer here, the first two steps of these work in plain ROOT with and without Cintex and the last one does not work, with or without Cintex.

>> The full error message is included at the bottom. It seems that a
>> dictionary is not being picked up for the return type of the insert
>> method, while I believe I have created it as a Reflex dictionary (log
>> of genreflex is attached).
>>
>> For a similar type, std::map<unsigned long, bool>, generating
>> appropriate dictionaries for the map, pair<const unsigned long, bool>,
>> iterators and the return type of map.insert allows me to perform the
>> same operation. Since the map<string, double> dictionary seems to be a
>> Cint dictionary, I suspect that cooperation between Cint dictionaries
>> and Reflex dictionaries has a problem here. Perhaps the types are
>> slightly differently defined?

For the std::map<unsigned long, bool> type, similar steps as outlined above work when Cintex is enabled (this is automatically done by GaudiPython, which is used by the LHCb framework).

>> Any ideas on what is going wrong?

> 
> for reflex dictionaries to be available from CINT and PyROOT, one needs
> to enable Cintex:
> 
> import PyCintex
> PyCintex.Cintex.Enable()
> 
> *before* opening any ROOT file (as this might load up and/or generate
> CINT dictionaries as side-effects)

This I didn't know. I don't think GuadiPython opens any files, but I'll check with a minimal setup.

Thanks, Roel

> I have the following helper function:
> 
> def import_root(batch=True):
>     """a helper method to wrap the 'import ROOT' statement to prevent ROOT
>     from messing up the display or loading graphics libraries when in batch
>     mode (which is the default.)
> 
>     e.g.
>     >>> ROOT = import_root(batch=True)
>     >>> f = ROOT.TFile.Open(...)
>     """
>     import ROOT
>     ROOT.gROOT.SetBatch(batch)
>     if batch:
>         ROOT.PyConfig.IgnoreCommandLineOptions = True
>     import PyCintex
>     PyCintex.Cintex.Enable()
>     return ROOT
> 
> hth,
> -s
> 


-- 
Roel Aaij
Cern, office 13-1-20        Tel: +41 (0)22 76 76284
CH-1211 Genève              Mob: +41 (0)79 9272 882


Received on Tue Jan 31 2012 - 16:11:21 CET

This archive was generated by hypermail 2.2.0 : Tue Jan 31 2012 - 17:50:01 CET