Useless warnings when using fstream via PyROOT

Hi,

I’m testing some C++ code in python via PyROOT, which I use from iPython.
The C++ contains some classes which use streams to serialize a-la the standard C++ technique isocpp.org/wiki/faq/serializatio … it-no-ptrs
These are usable form pyroot by defining a “pickle” method to write and a suitable constructor for reading.
To test this, I need to control the fstream via PyROOT, which works fine both from a functional interface and as a managed context.

Working simplified examples of all these are in the attached files. Just run the python file (e.g. from iPython run -i example)

Everything works well, except for one annoying snag: the first time I run this combination I get a lot of warnings (which are apparently irrelevant). Any ideas how to avoid them or suppress them?

The warnings:Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for basic_fstream<char,char_traits<char> >! Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for basic_iostream<char,char_traits<char> >! Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for basic_istream<char,char_traits<char> >! Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for basic_ios<char,char_traits<char> >! Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for ios_base! Error in <TClass::BuildRealData>: Cannot find any ShowMembers function for basic_ostream<char,char_traits<char> >! TStreamerInfo::Build::0: RuntimeWarning: basic_ios<char,char_traits<char> >: base class ios_base has no streamer or dictionary it will not be saved TStreamerInfo::Build::0: RuntimeWarning: basic_istream<char,char_traits<char> >: base class basic_ios<char,char_traits<char> > has no streamer or dictionary it will not be saved TStreamerInfo::Build::0: RuntimeWarning: basic_iostream<char,char_traits<char> >: base class basic_istream<char,char_traits<char> > has no streamer or dictionary it will not be saved TStreamerInfo::Build::0: RuntimeWarning: basic_ostream<char,char_traits<char> >: base class basic_ios<char,char_traits<char> > has no streamer or dictionary it will not be saved TStreamerInfo::Build::0: RuntimeWarning: basic_iostream<char,char_traits<char> >: base class basic_ostream<char,char_traits<char> > has no streamer or dictionary it will not be saved TStreamerInfo::Build::0: RuntimeWarning: basic_fstream<char,char_traits<char> >: base class basic_iostream<char,char_traits<char> > has no streamer or dictionary it will not be saved

many thanks,
Amnon Harel
example.py (515 Bytes)
example.h (694 Bytes)
example.c (852 Bytes)

Amnon,

which version of ROOT are you using? (I know about trouble with ios_base, which is why it is filtered in PyROOT; didn’t do so for the others)

(Aside, all ROOT-bound objects can be pickled.)

Cheers,
Wim

Hi Wim,

Sorry for the late reply. Somehow I missed your follow up question.

I’m using ROOT 5.34/14 and python version
2.7.9 (default, Feb 13 2015, 23:16:47)
[GCC 4.8.3]

(And continuing the “aside” sub-thread, these C++ objects are meant to also be used outside the ROOT universe, so they are not ROOT-bound. Hence the independent pickling/unpickling code which I test via PyROOT.)

Can I filter these warnings in user code, or must PyROOT itself be changed for this?

many thanks,
Amnon

Hi,

the actual warnings (“RuntimeWarning”) you can filter in full detail, as PyROOT maps them onto Python warnings. See the documentation of module warnings.

But these messages that are marked as “Error” can not be filtered the same way. You’ll need to set ROOT.gErrorIgnoreLevel to some high value. I recommend looking at [url]Decorator for Quiet Functions & Methods

Since none of these messages originate with PyROOT, changes there can not help this.

Cheers,
Wim

Thanks Wim,

That was exactly the information I needed.
So I have a similar context manager for the python warnings:

import contextlib, warnings
@contextlib.contextmanager
def suppressed_warnings( message_re, category = RuntimeWarning ):
    '''Suppress warnings from a particular category, whose message matches the given regular expression'''
    warnings.filterwarnings( action='ignore', category=category, message=message_re )
    try:
        yield
    finally:
        warnings.filterwarnings( action='default', category=category, message=message_re )

and I added the ROOT-error-suppression context manager you linked to (“Quiet”), and then I have in the calling code (which happens to be in yet another context manager):

import contextlib
@contextlib.contextmanager
def open_fstream( path, mode ):
    '''Open a C++ std::fstream that can be passed through pyroot.
    A pythonic wrapper around make_fstream and close_fstream.'''
    with suppressed_warnings('.*base class.*has no streamer or dictionary.*'), Quiet(R.kError+1):
        stream = R.make_fstream( path, mode )
    try:
        yield stream
    finally:
        R.close_fstream( stream )

Works perfectly.

thanks again,
Amnon