f9columnar 0.2.2__tar.gz → 0.2.4__tar.gz

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.
Files changed (36) hide show
  1. {f9columnar-0.2.2 → f9columnar-0.2.4}/PKG-INFO +69 -59
  2. {f9columnar-0.2.2 → f9columnar-0.2.4}/README.md +67 -56
  3. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/hdf5_dataloader.py +5 -4
  4. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/hdf5_writer.py +34 -14
  5. {f9columnar-0.2.2 → f9columnar-0.2.4}/pyproject.toml +1 -1
  6. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/__init__.py +0 -0
  7. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/analysis/__init__.py +0 -0
  8. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/analysis/triggers.py +0 -0
  9. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/arrays.py +0 -0
  10. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/PMGxsecDB_mc16.txt +0 -0
  11. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/PMGxsecDB_mc21.txt +0 -0
  12. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/campaigns.json +0 -0
  13. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/luminosity.json +0 -0
  14. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/periods.json +0 -0
  15. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/data/truth_classification.json +0 -0
  16. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/dataset_builder.py +0 -0
  17. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/histograms.py +0 -0
  18. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/processors.py +0 -0
  19. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/processors_collection.py +0 -0
  20. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/root_dataloader.py +0 -0
  21. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/run.py +0 -0
  22. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/__init__.py +0 -0
  23. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/act_driver.py +0 -0
  24. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/act_handler.py +0 -0
  25. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/act_merger.py +0 -0
  26. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/act_run.py +0 -0
  27. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/submit/act_run.sh +0 -0
  28. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/__init__.py +0 -0
  29. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/ak_helpers.py +0 -0
  30. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/config_utils.py +0 -0
  31. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/helpers.py +0 -0
  32. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/loggers.py +0 -0
  33. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/regex_helpers.py +0 -0
  34. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/rucio_db.py +0 -0
  35. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/rucio_utils.py +0 -0
  36. {f9columnar-0.2.2 → f9columnar-0.2.4}/f9columnar/utils/xsec_db.py +0 -0
@@ -1,8 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: f9columnar
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Columnar analysis utils.
5
- Home-page: https://gitlab.cern.ch/ijs-f9-ljubljana/f9columnar
6
5
  License: MIT
7
6
  Author: Jan Gavranovic
8
7
  Author-email: jan.gavranovic@cern.ch
@@ -43,82 +42,38 @@ Description-Content-Type: text/markdown
43
42
 
44
43
  # F9 Columnar
45
44
 
46
- ### 🚧 **Work in Progress** ⚠️
45
+ A lightweight Python package for batch processing of ROOT and HDF5 event data.
47
46
 
48
- ## Setup
47
+ ### Project description
48
+
49
+ This package is designed for efficient handling of large datasets. Built on PyTorch, Awkward Array, and Uproot, it utilizes PyTorch's DataLoader with an IterableDataset to enable parallel processing. It implements a columnar event loop, returning batches of events in a format compatible with standard PyTorch training loops over multiple epochs.
50
+
51
+ Optimized for machine learning applications, the package provides `RootDataLoader` and `Hdf5DataLoader` classes for data loading from ROOT and HDF5 files. Additionally, it supports parallel data processing through a modular pipeline of processor classes, allowing users to chain operations for complex computations and histogramming.
49
52
 
50
- ### User install
53
+ ## Setup
51
54
 
52
- #### With PyTorch GPU
55
+ ### Install with PyTorch GPU
53
56
 
54
57
  ```shell
55
58
  pip install f9columnar[torch]
56
59
  ```
57
60
 
58
- #### With PyTorch CPU (recommended)
61
+ ### Install with PyTorch CPU (recommended)
59
62
 
60
63
  ```shell
61
64
  pip install f9columnar
62
65
  pip install torch --index-url https://download.pytorch.org/whl/cpu
63
66
  ```
64
67
 
65
- #### Without PyTorch
68
+ ### Install without PyTorch
66
69
 
67
70
  ```shell
68
71
  pip install f9columnar
69
72
  ```
70
73
 
71
- ### Development install
72
-
73
- Use [poetry](https://python-poetry.org/) to install the required packages:
74
-
75
- ```shell
76
- poetry config cache-dir $PWD
77
- poetry config virtualenvs.in-project true
78
- poetry install -E torch
79
- ```
80
-
81
- This environment is duplicated for batch processing on dCache.
82
-
83
- ## aCT
84
-
85
- [ARC](https://doc.vega.izum.si/arc) Control Tower (aCT) is a system for submitting and managing payloads on ARC (and other) Computing Elements. It is used to submit jobs on sites in Slovenia.
86
-
87
- ### Installation
88
-
89
- Install aCT client from the repository with the following command to the virtual environment (or with poetry):
90
-
91
- ```shell
92
- pip install "git+https://github.com/ARCControlTower/aCT.git@test#subdirectory=src/act/client/aCT-client"
93
- ```
94
-
95
- The command `act` is available in `PATH` as the virtual environment is activated. See the scripts in the [`submit`](f9columnar/submit/) directory for further details.
96
-
97
- ### Voms proxy setup
98
-
99
- Note that it is recommended to be in `/atlas/si` group and make the proxy with it. Active it using (in a separate terminal):
100
-
101
- ```shell
102
- setupATLAS
103
- lsetup emi
104
- voms-proxy-init --valid 96:0 --voms atlas:/atlas/si
105
- ```
106
-
107
- To propagate the proxy to the system use
108
-
109
- ```shell
110
- act proxy
111
- ```
112
-
113
- At this point you are ready to use aCT.
114
-
115
74
  ## Getting started example
116
75
 
117
- The code is written in a way that it can be used standalone or as a part of an analysis containing data and MC samples. The following example shows the standalone usage.
118
-
119
- ### Basic example
120
-
121
- The main idea is to have a columnar event loop that returns arrays of events. The code and usage is the same as in a standard torch training loop over epochs, but instead of having epochs we iterate over batches of events.
76
+ The following example demonstrates how to load data from multiple ROOT files, apply a simple filter to select two branches, define variables, apply a cut, and create a histogram.
122
77
 
123
78
  ```python
124
79
  from f9columnar.root_dataloader import get_root_dataloader
@@ -144,7 +99,9 @@ for events in root_dataloader:
144
99
  # ... do something with the arrays
145
100
  ```
146
101
 
147
- Doing calculations on arrays inside of workers can be done using a `Processor`. Many processors can be chained together into a `ProcessorsGraph` (DAG) to perform more complex calculations. Processors are applied to the arrays in the order given by the topological sort of the DAG. Note that each worker runs the same processor graph on batches of array events and returns the result to the event loop when done. So in the above example there would be 12 (`num_workers`) processor graphs running in parallel on small batches of events. An example of calculating tau visible mass and then applying a cut on this variable is shown below.
102
+ Calculations on arrays within worker processes can be performed using a `Processor`. Multiple processors can be linked together in a `ProcessorsGraph`, forming a directed acyclic graph (DAG). These processors are applied to arrays in the sequence determined by the DAG’s topological order.
103
+
104
+ Each worker executes the same processor graph on batches of event data and returns the results to the event loop once processing is complete. In the example above, 12 (`num_workers`) processor graphs would be running in parallel, each handling small batches of events. Below is an example demonstrating how to calculate the tau visible mass and apply a cut to this variable.
148
105
 
149
106
  ```python
150
107
  from f9columnar.processors import ProcessorsGraph, CheckpointProcessor
@@ -228,8 +185,61 @@ for processed_graph in dataloader:
228
185
  # ... do something with the histograms and arrays
229
186
  ```
230
187
 
188
+ A higher level of abstraction is also possible using the [`ColumnarEventLoop`](f9columnar/run.py) class. See benchmark [examples](benchmark/f9columnar_benchmark.py) for some more details.
189
+
190
+ ## aCT
191
+
192
+ Basic job submitting to Slovenian grid is also possible using aCT. Currently it only supports Ntuple analysis data format from rucio (for [R21](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/MultiLeptonAnalysis) and [R25](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/EnhancedCPToolkit)).
193
+
194
+ ### Installation
195
+
196
+ [ARC](https://doc.vega.izum.si/arc) Control Tower (aCT) is a system for submitting and managing payloads on ARC (and other) Computing Elements. It is used to submit jobs on sites in Slovenia. Install aCT client from the repository with the following command to the virtual environment (or with poetry):
197
+
198
+ ```shell
199
+ pip install "git+https://github.com/ARCControlTower/aCT.git@test#subdirectory=src/act/client/aCT-client"
200
+ ```
201
+
202
+ The command `act` is available in `PATH` as the virtual environment is activated. See the scripts in the [`submit`](f9columnar/submit/) directory for further details.
203
+
204
+ ### Voms proxy setup
205
+
206
+ Note that it is recommended to be in `/atlas/si` group and make the proxy with it. Active it using (in a separate terminal):
207
+
208
+ ```shell
209
+ setupATLAS
210
+ lsetup emi
211
+ voms-proxy-init --valid 96:0 --voms atlas:/atlas/si
212
+ ```
213
+
214
+ To propagate the proxy to the system use
215
+
216
+ ```shell
217
+ act proxy
218
+ ```
219
+
220
+ At this point you are ready to use aCT.
221
+
222
+ ## Examples
223
+
224
+ - [Mini-analysis](https://gitlab.cern.ch/jgavrano/columnar-seesaw)
225
+ - [Converting ROOT to HDF5](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/hdf5_converter.py?ref_type=heads)
226
+ - [HDF5 Dataloader for ML](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/hdf5_dataloader.py?ref_type=heads)
227
+ - [Histogramming](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/el_fake_hists.py?ref_type=heads)
228
+
231
229
  ## Development
232
230
 
231
+ ### Development install
232
+
233
+ Use [poetry](https://python-poetry.org/) to install the required packages:
234
+
235
+ ```shell
236
+ poetry config cache-dir $PWD
237
+ poetry config virtualenvs.in-project true
238
+ poetry install -E torch
239
+ ```
240
+
241
+ Note: this environment should be duplicated for batch processing on dCache.
242
+
233
243
  ### Making a portable venv with conda
234
244
 
235
245
  Make sure you have [Miniconda](https://docs.anaconda.com/miniconda/) installed:
@@ -1,81 +1,37 @@
1
1
  # F9 Columnar
2
2
 
3
- ### 🚧 **Work in Progress** ⚠️
3
+ A lightweight Python package for batch processing of ROOT and HDF5 event data.
4
4
 
5
- ## Setup
5
+ ### Project description
6
+
7
+ This package is designed for efficient handling of large datasets. Built on PyTorch, Awkward Array, and Uproot, it utilizes PyTorch's DataLoader with an IterableDataset to enable parallel processing. It implements a columnar event loop, returning batches of events in a format compatible with standard PyTorch training loops over multiple epochs.
8
+
9
+ Optimized for machine learning applications, the package provides `RootDataLoader` and `Hdf5DataLoader` classes for data loading from ROOT and HDF5 files. Additionally, it supports parallel data processing through a modular pipeline of processor classes, allowing users to chain operations for complex computations and histogramming.
6
10
 
7
- ### User install
11
+ ## Setup
8
12
 
9
- #### With PyTorch GPU
13
+ ### Install with PyTorch GPU
10
14
 
11
15
  ```shell
12
16
  pip install f9columnar[torch]
13
17
  ```
14
18
 
15
- #### With PyTorch CPU (recommended)
19
+ ### Install with PyTorch CPU (recommended)
16
20
 
17
21
  ```shell
18
22
  pip install f9columnar
19
23
  pip install torch --index-url https://download.pytorch.org/whl/cpu
20
24
  ```
21
25
 
22
- #### Without PyTorch
26
+ ### Install without PyTorch
23
27
 
24
28
  ```shell
25
29
  pip install f9columnar
26
30
  ```
27
31
 
28
- ### Development install
29
-
30
- Use [poetry](https://python-poetry.org/) to install the required packages:
31
-
32
- ```shell
33
- poetry config cache-dir $PWD
34
- poetry config virtualenvs.in-project true
35
- poetry install -E torch
36
- ```
37
-
38
- This environment is duplicated for batch processing on dCache.
39
-
40
- ## aCT
41
-
42
- [ARC](https://doc.vega.izum.si/arc) Control Tower (aCT) is a system for submitting and managing payloads on ARC (and other) Computing Elements. It is used to submit jobs on sites in Slovenia.
43
-
44
- ### Installation
45
-
46
- Install aCT client from the repository with the following command to the virtual environment (or with poetry):
47
-
48
- ```shell
49
- pip install "git+https://github.com/ARCControlTower/aCT.git@test#subdirectory=src/act/client/aCT-client"
50
- ```
51
-
52
- The command `act` is available in `PATH` as the virtual environment is activated. See the scripts in the [`submit`](f9columnar/submit/) directory for further details.
53
-
54
- ### Voms proxy setup
55
-
56
- Note that it is recommended to be in `/atlas/si` group and make the proxy with it. Active it using (in a separate terminal):
57
-
58
- ```shell
59
- setupATLAS
60
- lsetup emi
61
- voms-proxy-init --valid 96:0 --voms atlas:/atlas/si
62
- ```
63
-
64
- To propagate the proxy to the system use
65
-
66
- ```shell
67
- act proxy
68
- ```
69
-
70
- At this point you are ready to use aCT.
71
-
72
32
  ## Getting started example
73
33
 
74
- The code is written in a way that it can be used standalone or as a part of an analysis containing data and MC samples. The following example shows the standalone usage.
75
-
76
- ### Basic example
77
-
78
- The main idea is to have a columnar event loop that returns arrays of events. The code and usage is the same as in a standard torch training loop over epochs, but instead of having epochs we iterate over batches of events.
34
+ The following example demonstrates how to load data from multiple ROOT files, apply a simple filter to select two branches, define variables, apply a cut, and create a histogram.
79
35
 
80
36
  ```python
81
37
  from f9columnar.root_dataloader import get_root_dataloader
@@ -101,7 +57,9 @@ for events in root_dataloader:
101
57
  # ... do something with the arrays
102
58
  ```
103
59
 
104
- Doing calculations on arrays inside of workers can be done using a `Processor`. Many processors can be chained together into a `ProcessorsGraph` (DAG) to perform more complex calculations. Processors are applied to the arrays in the order given by the topological sort of the DAG. Note that each worker runs the same processor graph on batches of array events and returns the result to the event loop when done. So in the above example there would be 12 (`num_workers`) processor graphs running in parallel on small batches of events. An example of calculating tau visible mass and then applying a cut on this variable is shown below.
60
+ Calculations on arrays within worker processes can be performed using a `Processor`. Multiple processors can be linked together in a `ProcessorsGraph`, forming a directed acyclic graph (DAG). These processors are applied to arrays in the sequence determined by the DAG’s topological order.
61
+
62
+ Each worker executes the same processor graph on batches of event data and returns the results to the event loop once processing is complete. In the example above, 12 (`num_workers`) processor graphs would be running in parallel, each handling small batches of events. Below is an example demonstrating how to calculate the tau visible mass and apply a cut to this variable.
105
63
 
106
64
  ```python
107
65
  from f9columnar.processors import ProcessorsGraph, CheckpointProcessor
@@ -185,8 +143,61 @@ for processed_graph in dataloader:
185
143
  # ... do something with the histograms and arrays
186
144
  ```
187
145
 
146
+ A higher level of abstraction is also possible using the [`ColumnarEventLoop`](f9columnar/run.py) class. See benchmark [examples](benchmark/f9columnar_benchmark.py) for some more details.
147
+
148
+ ## aCT
149
+
150
+ Basic job submitting to Slovenian grid is also possible using aCT. Currently it only supports Ntuple analysis data format from rucio (for [R21](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/MultiLeptonAnalysis) and [R25](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/EnhancedCPToolkit)).
151
+
152
+ ### Installation
153
+
154
+ [ARC](https://doc.vega.izum.si/arc) Control Tower (aCT) is a system for submitting and managing payloads on ARC (and other) Computing Elements. It is used to submit jobs on sites in Slovenia. Install aCT client from the repository with the following command to the virtual environment (or with poetry):
155
+
156
+ ```shell
157
+ pip install "git+https://github.com/ARCControlTower/aCT.git@test#subdirectory=src/act/client/aCT-client"
158
+ ```
159
+
160
+ The command `act` is available in `PATH` as the virtual environment is activated. See the scripts in the [`submit`](f9columnar/submit/) directory for further details.
161
+
162
+ ### Voms proxy setup
163
+
164
+ Note that it is recommended to be in `/atlas/si` group and make the proxy with it. Active it using (in a separate terminal):
165
+
166
+ ```shell
167
+ setupATLAS
168
+ lsetup emi
169
+ voms-proxy-init --valid 96:0 --voms atlas:/atlas/si
170
+ ```
171
+
172
+ To propagate the proxy to the system use
173
+
174
+ ```shell
175
+ act proxy
176
+ ```
177
+
178
+ At this point you are ready to use aCT.
179
+
180
+ ## Examples
181
+
182
+ - [Mini-analysis](https://gitlab.cern.ch/jgavrano/columnar-seesaw)
183
+ - [Converting ROOT to HDF5](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/hdf5_converter.py?ref_type=heads)
184
+ - [HDF5 Dataloader for ML](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/hdf5_dataloader.py?ref_type=heads)
185
+ - [Histogramming](https://gitlab.cern.ch/atlas-dch-seesaw-analyses/SeeSawML/-/blob/main/seesaw/fakes/el_fake_hists.py?ref_type=heads)
186
+
188
187
  ## Development
189
188
 
189
+ ### Development install
190
+
191
+ Use [poetry](https://python-poetry.org/) to install the required packages:
192
+
193
+ ```shell
194
+ poetry config cache-dir $PWD
195
+ poetry config virtualenvs.in-project true
196
+ poetry install -E torch
197
+ ```
198
+
199
+ Note: this environment should be duplicated for batch processing on dCache.
200
+
190
201
  ### Making a portable venv with conda
191
202
 
192
203
  Make sure you have [Miniconda](https://docs.anaconda.com/miniconda/) installed:
@@ -229,7 +229,7 @@ class Hdf5LoaderIterator:
229
229
  name: str,
230
230
  iterators_df: pd.DataFrame,
231
231
  worker_id: int,
232
- processors: list[Callable[[ArrayLike, dict], tuple[ArrayLike, dict]]] | ProcessorsGraph | None,
232
+ processors: list[Callable[[ArrayLike, dict], tuple[ArrayLike, dict]]] | ProcessorsGraph | None = None,
233
233
  hdf5_files_desc_dct: dict[str, dict[str, Any]] | None = None,
234
234
  ) -> None:
235
235
  self.name = name
@@ -372,13 +372,14 @@ class Hdf5IterableDataset(IterableDataset):
372
372
  logging.warning(f"Dataset {dataset_name} not found in {file}. Skipping!")
373
373
  continue
374
374
 
375
- piles_metadata[file] = {"piles_lst": None, "piles_shapes": None}
375
+ if file not in piles_metadata:
376
+ piles_metadata[file] = {"piles_lst": [], "piles_shapes": []}
376
377
 
377
378
  piles_lst = self._get_piles_metadata(file)["piles"][dataset_name]
378
- piles_metadata[file]["piles_lst"] = piles_lst
379
+ piles_metadata[file]["piles_lst"] += piles_lst
379
380
 
380
381
  piles_shapes = self._get_piles_shape(file, piles_lst)
381
- piles_metadata[file]["piles_shapes"] = piles_shapes
382
+ piles_metadata[file]["piles_shapes"] += piles_shapes
382
383
 
383
384
  for file, metadata in piles_metadata.items():
384
385
  for pile, shape in zip(metadata["piles_lst"], metadata["piles_shapes"]):
@@ -443,9 +443,17 @@ class NtupleHdf5Writer(ArraysHdf5Writer):
443
443
  write_mc: bool = True,
444
444
  write_data: bool = True,
445
445
  name: str = "datasetHDF5Writer",
446
+ dataset_names: list[str] | None = None,
446
447
  **hdf5_kwargs: Any,
447
448
  ) -> None:
448
- super().__init__(file_path, dataset_names=None, name=name)
449
+
450
+ if dataset_names is None:
451
+ dataset_names = ["mc", "data"]
452
+
453
+ if len(dataset_names) != 2:
454
+ raise ValueError("Dataset names must be a list of two strings!")
455
+
456
+ super().__init__(file_path, dataset_names=dataset_names, name=name)
449
457
  self.save_node = save_node
450
458
  self.chunk_shape = chunk_shape
451
459
 
@@ -463,25 +471,26 @@ class NtupleHdf5Writer(ArraysHdf5Writer):
463
471
  self.data_column_names = data_column_names
464
472
 
465
473
  metadata = {}
474
+ mc_group, data_group = self.dataset_names[0], self.dataset_names[1]
466
475
 
467
476
  if write_mc:
468
477
  self.create_datasets(
469
- dataset_names=["mc"],
478
+ dataset_names=[mc_group],
470
479
  shape=(self.chunk_shape, len(self.mc_column_names)),
471
480
  maxshape=(None, len(self.mc_column_names)),
472
481
  **hdf5_kwargs,
473
482
  )
474
- metadata["mc_columns"] = self.mc_column_names
483
+ metadata[f"{mc_group}_columns"] = self.mc_column_names
475
484
 
476
485
  if write_data:
477
486
  self.create_datasets(
478
487
  mode="a" if self.write_mc else "w",
479
- dataset_names=["data"],
488
+ dataset_names=[data_group],
480
489
  shape=(self.chunk_shape, len(self.data_column_names)),
481
490
  maxshape=(None, len(self.data_column_names)),
482
491
  **hdf5_kwargs,
483
492
  )
484
- metadata["data_columns"] = self.data_column_names
493
+ metadata[f"{data_group}_columns"] = self.data_column_names
485
494
 
486
495
  self.add_metadata(metadata)
487
496
 
@@ -498,12 +507,12 @@ class NtupleHdf5Writer(ArraysHdf5Writer):
498
507
 
499
508
  if self.is_data and self.write_data:
500
509
  self._current_idx, self._current_shape = self._current_mc_idx, self._current_mc_shape
501
- self.write_arrays(arrays, "data", self.data_column_names, self.chunk_shape)
510
+ self.write_arrays(arrays, self.dataset_names[1], self.data_column_names, self.chunk_shape)
502
511
  self._current_mc_idx, self._current_mc_shape = self._current_idx, self._current_shape
503
512
 
504
513
  if not self.is_data and self.write_mc:
505
514
  self._current_idx, self._current_shape = self._current_data_idx, self._current_data_shape
506
- self.write_arrays(arrays, "mc", self.mc_column_names, self.chunk_shape)
515
+ self.write_arrays(arrays, self.dataset_names[0], self.mc_column_names, self.chunk_shape)
507
516
  self._current_data_idx, self._current_data_shape = self._current_idx, self._current_shape
508
517
 
509
518
  return {"processors": processors}
@@ -522,9 +531,19 @@ class NtupleHdf5PileWriter(ArraysHdf5PileWriter):
522
531
  write_mc: bool = True,
523
532
  write_data: bool = True,
524
533
  name: str = "datasetHDF5Writer",
534
+ dataset_names_map: dict[str, str] | None = None,
525
535
  **hdf5_kwargs: Any,
526
536
  ) -> None:
527
- super().__init__(file_path, n_piles, pile_assignment, dataset_names=["mc", "data"], name=name)
537
+
538
+ if dataset_names_map is None:
539
+ dataset_names = ["mc", "data"]
540
+ else:
541
+ dataset_names = [dataset_names_map["mc"], dataset_names_map["data"]]
542
+
543
+ if len(dataset_names) != 2:
544
+ raise ValueError("Dataset names must be a list of two strings!")
545
+
546
+ super().__init__(file_path, n_piles, pile_assignment, dataset_names=dataset_names, name=name)
528
547
  self.save_node = save_node
529
548
  self.chunk_shape = chunk_shape
530
549
 
@@ -542,25 +561,26 @@ class NtupleHdf5PileWriter(ArraysHdf5PileWriter):
542
561
  self.data_column_names = data_column_names
543
562
 
544
563
  metadata: dict[str, Any] = {}
564
+ mc_group, data_group = self.dataset_names[0], self.dataset_names[1]
545
565
 
546
566
  if write_mc:
547
567
  self.create_datasets(
548
- dataset_names=self.pile_datasets_dct["mc"],
568
+ dataset_names=self.pile_datasets_dct[mc_group],
549
569
  shape=(self.chunk_shape, len(self.mc_column_names)),
550
570
  maxshape=(None, len(self.mc_column_names)),
551
571
  **hdf5_kwargs,
552
572
  )
553
- metadata["mc_columns"] = self.mc_column_names
573
+ metadata[f"{mc_group}_columns"] = self.mc_column_names
554
574
 
555
575
  if write_data:
556
576
  self.create_datasets(
557
577
  mode="a" if self.write_mc else "w",
558
- dataset_names=self.pile_datasets_dct["data"],
578
+ dataset_names=self.pile_datasets_dct[data_group],
559
579
  shape=(self.chunk_shape, len(self.data_column_names)),
560
580
  maxshape=(None, len(self.data_column_names)),
561
581
  **hdf5_kwargs,
562
582
  )
563
- metadata["data_columns"] = self.data_column_names
583
+ metadata[f"{data_group}_columns"] = self.data_column_names
564
584
 
565
585
  metadata["piles"] = self.pile_datasets_dct
566
586
 
@@ -575,10 +595,10 @@ class NtupleHdf5PileWriter(ArraysHdf5PileWriter):
575
595
  raise AttributeError("Arrays attribute not found in the processor!")
576
596
 
577
597
  if self.is_data and self.write_data:
578
- self.write_arrays(arrays, "data", self.data_column_names, self.chunk_shape)
598
+ self.write_arrays(arrays, self.dataset_names[1], self.data_column_names, self.chunk_shape)
579
599
 
580
600
  if not self.is_data and self.write_mc:
581
- self.write_arrays(arrays, "mc", self.mc_column_names, self.chunk_shape)
601
+ self.write_arrays(arrays, self.dataset_names[0], self.mc_column_names, self.chunk_shape)
582
602
 
583
603
  return {"processors": processors}
584
604
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "f9columnar"
3
- version = "0.2.2"
3
+ version = "0.2.4"
4
4
  description = "Columnar analysis utils."
5
5
  authors = ["Jan Gavranovic <jan.gavranovic@cern.ch>"]
6
6
  readme = "README.md"
File without changes