def read_powers_all(header, nsec, npkgs): ric.init_event_list(3) pkgpwr_pos = ric.get_lpos("pkgpwr") drmpwr_pos = ric.get_lpos("drmpwr") secfiles = ric.get_sec_file_list(header) pkgpwr = [[0.0 for i in range(nsec)] for j in range(npkgs)] drmpwr = [[0.0 for i in range(nsec)] for j in range(npkgs)] for secfile in secfiles: with open(secfile) as f: for line in f: if line.startswith("##C "): pkg_id = machine.get_pkg_id(line) break f.seek(0) (lnsec, lnev, lpwr) = read_average(f, nsec) for isec in range(nsec): pkgpwr[pkg_id][isec] = lpwr[isec][pkgpwr_pos] drmpwr[pkg_id][isec] = lpwr[isec][drmpwr_pos] f.close() # return (pkgpwr, drmpwr)
def read_average(fin, nsec): (ev_pos, ev_name, ev_frac, ev_type) = ric.get_event_list() nev = len(ev_pos) sec_pos = ric.get_pos("sec") etm_pos = ric.get_pos("etime") VALUES = [[[0.0 for i in range(nev)] for j in range(nsec)] for k in range(MAX_NITERA)] ntmp = 0 itera = -1 for line in fin: if line.startswith("##T "): toks = line.split() secname = toks[sec_pos] etime = float(toks[etm_pos]) isec = ric.get_sec_id(secname) for iev in range(nev): ipos = ev_pos[iev] val = float(toks[ipos]) if ev_type[iev] == 1: val *= etime VALUES[itera][isec][iev] += val ntmp += 1 elif line.startswith("##C "): if itera == -1 or ntmp > 0: ntmp = 0 itera += 1 # if ntmp > 0: itera += 1 nitera = itera secnames = ric.get_sec_names() etm_pos = ric.get_lpos("etime") for itera in range(nitera): for isec in range(nsec): etime = VALUES[itera][isec][etm_pos] for iev in range(nev): if ev_type[iev] == 1: VALUES[itera][isec][iev] /= etime aves = [[0.0 for i in range(nev)] for j in range(nsec)] for itera in range(nitera): for isec in range(nsec): for iev in range(nev): aves[isec][iev] += VALUES[itera][isec][iev] for isec in range(nsec): for iev in range(nev): aves[isec][iev] /= nitera return (nsec, nev, aves)