-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclasses.py
More file actions
171 lines (137 loc) · 4.3 KB
/
classes.py
File metadata and controls
171 lines (137 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
from hep.config import Paths
from .genutils import (
check_dir,
)
class Method(object):
"""
Base class for methods.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
Attributes:
input_data: The input data for the method.
output_data: The output data for the method.
max_count: Maximum count (optional, default is None).
count: Current count (initialized to 0).
"""
def __init__(self, *args, **kwargs):
"""
Initialize a Method instance.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
compulsory_kwargs = (
"input_data",
"output_data",
)
self.input_data = kwargs.get("input_data")
self.output_data = kwargs.get("output_data")
self.max_count = None
self.count = 0
class PhysicsMethod(Method):
"""
Base class for physics methods.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
def __init__(self, *args, **kwargs):
"""
Initialize a PhysicsMethod instance.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
super().__init__(args, **kwargs)
def __iter__(self):
"""
Return an iterator for the PhysicsMethod instance.
"""
return self
def __len__(self):
"""
Get the length of the PhysicsMethod instance.
Returns:
int: The length of the PhysicsMethod instance.
"""
assert self.max_count, "Calling uninitialized " + type(self).__name__
return self.max_count
class NetworkMethod(Method):
"""
Base class for network methods.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class Data(object):
"""
Base class for data handling.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
Attributes:
dtypes: Data types.
prefix_path: Prefix path (optional).
reader_method: Reader method.
writer_method: Writer method.
data_ext: Data extension.
file_ext: File extension (initialized to None).
mg_event_path: MadGraph event path.
max_count: Maximum count (initialized to "NA").
"""
def __init__(self, *args, **kwargs):
"""
Initialize a Data instance.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
compulsory_keys = {
"reader_method",
"writer_method",
"run_name",
}
# assert compulsory_keys.issubset(set(kwargs.keys()))
self.dtypes = args
self.prefix_path = kwargs.get("prefix_path")
self.reader_method = kwargs.get("reader_method")
self.writer_method = kwargs.get("writer_method")
self.data_ext = kwargs.get("extension")
self.file_ext = None
self.mg_event_path = os.path.join(
Paths.madgraph_dir,
kwargs["run_name"],
"Events",
)
self.max_count = "NA"
class PhysicsData(Data):
"""
Base class for physics data handling.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
def __init__(self, *args, **kwargs):
"""
Initialize a PhysicsData instance.
Args:
*args: Variable-length positional arguments.
**kwargs: Variable-length keyword arguments.
"""
super().__init__(*args, **kwargs)
def __iter__(self):
"""
Return an iterator for the PhysicsData instance.
"""
return self
def __len__(self):
"""
Get the length of the PhysicsData instance.
Returns:
str: The maximum count of the PhysicsData instance (initialized to "NA").
"""
return self.max_count