70 def writeH5File(fileName, globalTags, excludeRecords, includeRecords, tagReader, compressorName):
73 keyListRecords = set([
"ExDwarfListRcd",
"DTKeyedConfigListRcd",
"DTKeyedConfigContainerRcd"])
75 default_compressor_name = compressorName
76 print(default_compressor_name)
77 default_compressor =
None 78 if default_compressor_name ==
"zlib":
79 default_compressor = zlib
80 elif default_compressor_name ==
"lzma":
81 default_compressor = lzma
82 with h5py.File(fileName,
'w')
as h5file:
83 h5file.attrs[
"file_format"] = 1
84 h5file.attrs[
"default_payload_compressor"] = default_compressor_name.encode(
"ascii")
85 recordsGroup = h5file.create_group(
"Records")
86 globalTagsGroup = h5file.create_group(
"GlobalTags")
87 null_dataset = h5file.create_dataset(
"null_payload", data=np.array([], dtype=
'b') )
90 for name
in globalTags:
94 if rcd
in keyListRecords:
96 if rcd
in excludeRecords:
98 if includeRecords
and (
not rcd
in includeRecords):
102 payloadToRefs = {
None: null_dataset.ref}
104 recordGroup = recordsGroup.create_group(rcd)
105 tagsGroup = recordGroup.create_group(
"Tags")
106 dataProductsGroup = recordGroup.create_group(
"DataProducts")
107 print(
"record: %s"%rcd)
109 for dataProduct
in tag.dataProducts():
110 productNames.append(dataProduct.name())
111 dataProductGroup = dataProductsGroup.create_group(dataProduct.name())
112 dataProductGroup.attrs[
"type"] = dataProduct.objtype().
encode(
"ascii")
113 payloadsGroup = dataProductGroup.create_group(
"Payloads")
114 print(
" product: %s"%dataProduct.name())
115 for p_index, payload
in enumerate(dataProduct.payloads()):
116 print(
" %i payload: %s size: %i"%(p_index,payload.name(),len(payload.data())))
117 recordDataSize +=len(payload.data())
118 if default_compressor:
119 b = default_compressor.compress(payload.data())
120 if len(b) >= len(payload.data()):
125 pl = payloadsGroup.create_dataset(payload.name(), data=np.frombuffer(b,dtype=
'b'))
126 pl.attrs[
"memsize"] = len(payload.data())
127 pl.attrs[
"type"] = payload.actualType()
128 payloadToRefs[payload.name()] = pl.ref
130 tagGroupRefs.append(
writeTag(tagsGroup, tag.time_type(), tag.iovsNPayloadNames(), payloadToRefs, tag.originalTagNames(), rcd, productNames))
131 print(
" total size:",recordDataSize)
134 globalTagGroup = globalTagsGroup.create_group(name)
135 globalTagGroup.create_dataset(
"Tags", data=tagGroupRefs, dtype=h5py.ref_dtype)
136 def writeH5File(fileName, globalTags, excludeRecords, includeRecords, tagReader, compressorName)
def writeTag(tagsGroup, time_type, IOV_payloads, payloadToRefs, originalTagNames, recName, productNames)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)