def write_errors(self, value, errors): """ // Writes Error[] T[] { varint length; T* items; } Error { varint error_label; float error_minus; float error_plus; } """ t = get_current_transaction() t.write(self.fp_records, varint_format(len(errors))) for error in errors: error_label_str = error.get('label', '') if 'asymerror' in error: error_minus = error_to_float(value, error['asymerror']['minus']) error_plus = error_to_float(value, error['asymerror']['plus']) else: error_minus = error_plus = error_to_float(value, error['symerror']) error_label = self.string_dict.id_for_str(error_label_str) t.write(self.fp_records, varint_format(error_label)) t.write(self.fp_records, struct.pack('<ff', error_minus, error_plus))
def add_string(self, string): assert '\n' not in string assert string.strip() != '' t = get_current_transaction() if string not in self.strings: self.strings.add(string) if self.fp.tell() != 0: t.write(self.fp, '\n') t.write(self.fp, string)
def write_group_header(self, metadata, num_records): t = get_current_transaction() t.write(self.fp_records, varint_format(metadata.inspire_record)) t.write(self.fp_records, varint_format(metadata.table_num)) t.write(self.fp_records, struct.pack('<ff', *metadata.cmenergies)) t.write(self.fp_records, string_format(metadata.reaction)) t.write(self.fp_records, string_format(metadata.observables)) t.write(self.fp_records, string_format(metadata.var_y)) t.write(self.fp_records, size_format(num_records))
def add_string(self, string): assert '\n' not in string str_id = self.counter self.dict_id_to_str[str_id] = string self.dict_str_to_id[string] = str_id self.counter += 1 t = get_current_transaction() t.write(self.fp, string + '\n') return str_id
def close(self): t = get_current_transaction() t.close(self.fp)
def write_record(self, record): assert isinstance(record, Record) t = get_current_transaction() t.write(self.fp_records, struct.pack('<fff', record.x_low, record.x_high, record.y)) self.write_errors(record.y, record.errors)
def close(self): assert (not self.closed) t = get_current_transaction() t.close(self.fp_records) self.string_dict.close() self.closed = True