def write(self):
     """Write the content inside the archive provide."""
     super(Session, self).write()
     for channel in self.channels:
         channel.write()
     for channel in self.deletedChannels:
         channel.remove()
     self.deletedChannels = []
     if self.event_handler is None:
         self.event_handler = StoredData(self, self.pathname + [self.EventFileName])
     self.event_handler.set(SessionEvent.toJson(self.events), indent=4)
class Session(BaseFile):
    EventFileName = ".event"
    """Represents a session experiment of a subject in the sense of BIF."""

    def __init__(self, metadata={}):
        super(Session, self).__init__(metadata)
        self.subject = None
        self.channels = []
        self.deletedChannels = []
        self.events = []
        self.event_handler = None

    def write(self):
        """Write the content inside the archive provide."""
        super(Session, self).write()
        for channel in self.channels:
            channel.write()
        for channel in self.deletedChannels:
            channel.remove()
        self.deletedChannels = []
        if self.event_handler is None:
            self.event_handler = StoredData(self, self.pathname + [self.EventFileName])
        self.event_handler.set(SessionEvent.toJson(self.events), indent=4)

    def remove(self):
        """Removes the content inside the archive provide."""
        super(Session, self).remove()
        for channel in self.channels + self.deletedChannels:
            channel.remove()
        self.deletedChannels = []
        self.writeMetadata()
        self.events = {}
        self.event_handler.set([])

    def addChannel(self, channel):
        """Add a channel dataset, recognizing it as a child XD."""
        self.channels.append(channel)
        channel.session = self

    def removeChannel(self, channel):
        """Remove a session."""
        self.channels.remove(channel)
        self.deletedChannels.append(channel)

    def addEvent(self, event_data):
        self.events.append(event_data)

    def updateHash(self):
        self.hash_me("-".join(child.objectHash for child in self.channels))

    def defaultMetadataValues(self):
        """Fills the minimum neccesary metadata values."""
        super(Subject, self).defaultMetadataValues()
        self.metadata.setdefault("recording-start-time", [0, 0, 0, 0, 0])
        self.metadata.setdefault("sweep-number", 0)

    @property
    def pathname(self):
        return self.subject.pathname + ["SESSION-" + self.uniqueID]

    @property
    def archiver(self):
        return self.subject.archiver