import ROOT # When iterating over an EventFile, the Evt object is actually # the same one. It just gets filled by root each time... # But root does not fill/clear the __dict__, so we intercept it # and do it from python try : orgnext = ROOT.EventFile.iterator.next except AttributeError : # happens in py3 orgnext = ROOT.EventFile.iterator.__next__ def newnext( it ) : obj = orgnext(it) #print "Next!", id(obj) # it's reall the same objectproxy each time obj.__dict__.clear() return obj ROOT.EventFile.iterator.next = newnext # allow list of strings as argument to translate to vector def to_vector( lst ) : r = ROOT.vector( ROOT.string ) () for item in lst : r.push_back( item ) return r # constructors are the __call__ function of the type (/meta-class). # their first arugment (args[0]) is allways the type. xx__oldcall__ = type(ROOT.EventFile).__call__ def new_eventfile_call ( *args ) : if len(args) == 2 and type( args[1] ) == list : print ( "---> args = ", args ) v = to_vector( args[1] ) return xx__oldcall__( args[0], v ) # fallback to whatever was done before return xx__oldcall__ ( *args ) #install the new constructor type(ROOT.EventFile).__call__ = new_eventfile_call