PyLamarr
Pythonizations for the ultra-fast simulation option for the LHCb experiment
 
Loading...
Searching...
No Matches
EventBatch.py
1from dataclasses import dataclass
2from typing import Callable, Optional
3
4@dataclass
6 n_events: Optional[int] = None
7 batch_id: Optional[int] = None
8 n_batches: Optional[int] = None
9 description: Optional[str] = None
10
11 def __len__(self):
12 return self.n_events or 0
13
14 def load(self):
15 raise NotImplementedError
16
17 def __str__(self):
18 ret = []
19 if self.batch_id is not None:
20 ret.append(f"{self.__class__.__name__} #{self.batch_id}")
21 if self.n_batches is not None:
22 ret.append(f"/ {self.n_batches}")
23 else:
24 ret.append(f"a batch of type {self.__class__.__name__}")
25
26 if self.n_events is not None:
27 ret.append(f"containing {self.n_events} events")
28
29 if self.description is not None:
30 ret.append(f"({self.description})")
31
32 return " ".join(ret)
33
34if __name__ == '__main__':
35 print (EventBatch())
36
37
38 print (EventBatch(n_events=100))
39
40
41 print (EventBatch(n_events=100, description="my super important batch"))
42
43
44 print (EventBatch(n_batches=5, n_events=100))
45
46
47 print (EventBatch(batch_id=3, n_events=100, description="Third batch"))
48
49
50 print (EventBatch(batch_id=3, n_events=100, description="Third batch"))
51
52
53 print (EventBatch(batch_id=3, n_batches=5, n_events=100, description="Third batch"))
54