reboost 0.6.1__py3-none-any.whl → 0.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
reboost/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.6.1'
21
- __version_tuple__ = version_tuple = (0, 6, 1)
20
+ __version__ = version = '0.6.2'
21
+ __version_tuple__ = version_tuple = (0, 6, 2)
reboost/build_hit.py CHANGED
@@ -235,6 +235,7 @@ def build_hit(
235
235
  files = utils.get_file_dict(stp_files=stp_files, glm_files=glm_files, hit_files=hit_files)
236
236
 
237
237
  output_tables = {}
238
+ output_tables_names = set()
238
239
 
239
240
  # iterate over files
240
241
  for file_idx, (stp_file, glm_file) in enumerate(zip(files.stp, files.glm)):
@@ -363,16 +364,12 @@ def build_hit(
363
364
  # now write
364
365
  if files.hit[file_idx] is not None:
365
366
  # get modes to write with
366
- new_hit_file = (file_idx == 0) or (
367
- files.hit[file_idx] != files.hit[file_idx - 1]
368
- )
369
-
370
367
  wo_mode = utils.get_wo_mode(
371
368
  group=group_idx,
372
369
  out_det=out_det_idx,
373
370
  in_det=in_det_idx,
374
371
  chunk=chunk_idx,
375
- new_hit_file=new_hit_file,
372
+ new_hit_file=utils.is_new_hit_file(files, file_idx),
376
373
  overwrite=overwrite,
377
374
  )
378
375
  # write the file
@@ -390,6 +387,8 @@ def build_hit(
390
387
  hit_table, output_tables[out_detector]
391
388
  )
392
389
 
390
+ output_tables_names.add(out_detector)
391
+
393
392
  # forward some data, if requested
394
393
  # possible improvement: iterate over data if it's a lot
395
394
  if "forward" in config and files.hit[file_idx] is not None:
@@ -400,12 +399,16 @@ def build_hit(
400
399
 
401
400
  for obj in obj_list:
402
401
  try:
402
+ wo_mode = utils.get_wo_mode_forwarded(
403
+ output_tables_names, utils.is_new_hit_file(files, file_idx), overwrite
404
+ )
403
405
  lh5.write(
404
406
  lh5.read(obj, stp_file),
405
407
  obj,
406
408
  files.hit[file_idx],
407
- wo_mode="write_safe" if file_idx == 0 else "append",
409
+ wo_mode=wo_mode,
408
410
  )
411
+ output_tables_names.add(obj)
409
412
  except LH5EncodeError as e:
410
413
  msg = f"cannot forward object {obj} as it has been already processed by reboost"
411
414
  raise RuntimeError(msg) from e
reboost/utils.py CHANGED
@@ -51,7 +51,9 @@ def get_wo_mode(
51
51
  chunk
52
52
  the chunk index
53
53
  new_hit_file
54
- a flag of whether we are writing a new hit file
54
+ a flag of whether we are writing a new hit file. This does not indicate whether
55
+ the file already exists on disk, but whether the file name is different from the
56
+ last written chunk for this detector.
55
57
  overwrite
56
58
  a flag of whether to overwrite the old file.
57
59
 
@@ -75,6 +77,49 @@ def get_wo_mode(
75
77
  return "append"
76
78
 
77
79
 
80
+ def get_wo_mode_forwarded(
81
+ written_tables: set[str], new_hit_file: bool, overwrite: bool = False
82
+ ) -> str:
83
+ """Get the mode for lh5 file writing for forwarded tables tahat will be copied without chunking.
84
+
85
+ If we are writing a new output file and no other tables had been written yet, then
86
+ the mode "overwrite_file" is used if the overwrite flag is set, otherwise the mode
87
+ "write_safe" is used.
88
+
89
+ Otherwise "append" is used.
90
+
91
+ Parameters
92
+ ----------
93
+ written_tables
94
+ a set of already written table names, also including other table names of
95
+ non-forwarded (i.e. processed) tables.
96
+ new_hit_file
97
+ a flag of whether we are writing a new hit file. This does not indicate whether
98
+ the file already exists on disk, but whether the file name is different from the
99
+ last written chunk for this forwarded table.
100
+ overwrite
101
+ a flag of whether to overwrite the old file.
102
+
103
+ Returns
104
+ -------
105
+ the mode for IO
106
+ """
107
+ if not new_hit_file:
108
+ return "append"
109
+ if overwrite and len(written_tables) == 0:
110
+ return "overwrite_file"
111
+ return "write_safe"
112
+
113
+
114
+ def is_new_hit_file(files: AttrsDict, file_idx: int) -> bool:
115
+ """Return whether the hit file with the given index is a "new" hit file.
116
+
117
+ A new file is either the first file written, or when the previous file index has a
118
+ different file name.
119
+ """
120
+ return (file_idx == 0) or (files.hit[file_idx] != files.hit[file_idx - 1])
121
+
122
+
78
123
  def get_file_dict(
79
124
  stp_files: list[str] | str,
80
125
  glm_files: list[str] | str | None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reboost
3
- Version: 0.6.1
3
+ Version: 0.6.2
4
4
  Summary: New LEGEND Monte-Carlo simulation post-processing
5
5
  Author-email: Manuel Huber <info@manuelhu.de>, Toby Dixon <toby.dixon.23@ucl.ac.uk>, Luigi Pertoldi <gipert@pm.me>
6
6
  Maintainer: The LEGEND Collaboration
@@ -1,15 +1,15 @@
1
1
  reboost/__init__.py,sha256=VZz9uo7i2jgAx8Zi15SptLZnE_qcnGuNWwqkD3rYHFA,278
2
- reboost/_version.py,sha256=a3_WODLDfpmAw3pMw7qGqmRuXHTCC3STyQd2R1iEOgA,511
2
+ reboost/_version.py,sha256=DhO-RAVJdQTjYPaMf0M6q_WAXdD6jcx2tWl_B9FtuhM,511
3
3
  reboost/build_evt.py,sha256=VXIfK_pfe_Cgym6gI8dESwONZi-v_4fll0Pn09vePQY,3767
4
4
  reboost/build_glm.py,sha256=IerSLQfe51ZO7CQP2kmfPnOIVaDtcfw3byOM02Vaz6o,9472
5
- reboost/build_hit.py,sha256=23JL5B7qThdHZqAK_HWoytqcEOWDhGsk4n5UMtojJ1c,15513
5
+ reboost/build_hit.py,sha256=BwcAzr7hkhLqQpyULYPqM70VEvENaw-j90fvBYKh-68,15649
6
6
  reboost/cli.py,sha256=HZgqUZK0tSmnlGqoXjrbmLitW_i001TzibxvDrRxLLg,6324
7
7
  reboost/core.py,sha256=WGbWe2rcfMDEaehVyw7peqAHoTFWoCu5J6CdWHC5aWA,14974
8
8
  reboost/iterator.py,sha256=fATFDxu2PUc0e48OdJJujZo2kwykfRLH1oBtcB-s5pM,6905
9
9
  reboost/log_utils.py,sha256=VqS_9OC5NeNU3jcowVOBB0NJ6ssYvNWnirEY-JVduEA,766
10
10
  reboost/profile.py,sha256=EOTmjmS8Rm_nYgBWNh6Rntl2XDsxdyed7yEdWtsZEeg,2598
11
11
  reboost/units.py,sha256=3EH8XlpbsObdu5vLgxhm1600L6UNYD5jng4SjJT_1QE,2202
12
- reboost/utils.py,sha256=WT2jlyRT3LEMBEBRJtYIat3KIIZKocv4rHlTViBbhYM,10938
12
+ reboost/utils.py,sha256=dzDiQWwv_snoWoRBDnDNZ27hG0CpCRo8V4jSEG2b82c,12592
13
13
  reboost/hpge/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  reboost/hpge/psd.py,sha256=jAUAoQ_PMz76wyA1NXYHNKtOwoCnRT3My8_LCFrKi-U,13860
15
15
  reboost/hpge/surface.py,sha256=lbWcFnFFWKxtFKs755GyM9US_IfyxaoM6MpOIZgIMM0,7478
@@ -29,9 +29,9 @@ reboost/shape/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  reboost/shape/cluster.py,sha256=RIvBlhHzp88aaUZGofp5SD9bimnoiqIOddhQ84jiwoM,8135
30
30
  reboost/shape/group.py,sha256=gOCYgir2gZqmW1JXtbNRPlQqP0gmUcbe7RVb9CbY1pU,5540
31
31
  reboost/shape/reduction.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
32
- reboost-0.6.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
33
- reboost-0.6.1.dist-info/METADATA,sha256=T1TyULoQ01tNoZcuF1tfWdmG2WsV53DQuKCldpPEHRw,44222
34
- reboost-0.6.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
- reboost-0.6.1.dist-info/entry_points.txt,sha256=DxhD6BidSWNot9BrejHJjQ7RRLmrMaBIl52T75oWTwM,93
36
- reboost-0.6.1.dist-info/top_level.txt,sha256=q-IBsDepaY_AbzbRmQoW8EZrITXRVawVnNrB-_zyXZs,8
37
- reboost-0.6.1.dist-info/RECORD,,
32
+ reboost-0.6.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
33
+ reboost-0.6.2.dist-info/METADATA,sha256=o0DAQXxkMCG68Uf-WHTHeVsIEMKMsj044lWWMJLAx_k,44222
34
+ reboost-0.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ reboost-0.6.2.dist-info/entry_points.txt,sha256=DxhD6BidSWNot9BrejHJjQ7RRLmrMaBIl52T75oWTwM,93
36
+ reboost-0.6.2.dist-info/top_level.txt,sha256=q-IBsDepaY_AbzbRmQoW8EZrITXRVawVnNrB-_zyXZs,8
37
+ reboost-0.6.2.dist-info/RECORD,,