Beispiel #1
0
class StoreToH5(DataHandler):
    default_autotbl = None

    def __init__(self, destination=None):
        """ 
        Store data to the specified .h5 destination.

        *destination* may be either a file name or an existing AutoTable object
        """
        self.destination = destination

        if comm.rank == 0:
            if isinstance(destination, AutoTable):
                self.autotbl = destination
            elif isinstance(destination, str):
                self.autotbl = AutoTable(destination)
            elif destination is None:
                if StoreToH5.default_autotbl is None:
                    self.autotbl = AutoTable()
                else:
                    self.autotbl = StoreToH5.default_autotbl
            else:
                raise TypeError(
                    "Expects an AutoTable instance or a string as argument")

            if StoreToH5.default_autotbl is None:
                StoreToH5.default_autotbl = self.autotbl

    def __repr__(self):
        return "StoreToH5 into file %s" % self.destination

    def append(self, tblname, value):
        self.autotbl.append(tblname, value)

    def append_all(self, valdict):
        self.autotbl.append_all(valdict)

    def read(self, tblname, row):
        pass

    def close(self):
        #if comm.rank != 0:
        #return
        self.autotbl.close()
Beispiel #2
0
class StoreToH5(DataHandler):
    default_autotbl = None

    def __init__(self, destination=None):
        """ 
        Store data to the specified .h5 destination.

        *destination* may be either a file name or an existing AutoTable object
        """
        self.destination = destination
        
        if comm.rank == 0:
            if isinstance(destination, AutoTable):
                self.autotbl = destination
            elif isinstance(destination, str):
                self.autotbl = AutoTable(destination)
            elif destination is None:
                if StoreToH5.default_autotbl is None:
                    self.autotbl = AutoTable()
                else:
                    self.autotbl = StoreToH5.default_autotbl
            else:
                raise TypeError("Expects an AutoTable instance or a string as argument")

            if StoreToH5.default_autotbl is None:
                StoreToH5.default_autotbl = self.autotbl
    def __repr__(self):
        return "StoreToH5 into file %s" % self.destination   
     
    def append(self, tblname, value):
        self.autotbl.append(tblname, value)
    
    def append_all(self, valdict):
        self.autotbl.append_all(valdict)

    def read(self, tblname, row):
        pass

    def close(self):
        #if comm.rank != 0:
            #return
        self.autotbl.close()