now writes number of events to database at the end of the run