epic-drich-beam-test-analysis
ePIC dRICH beam test analysis framework
Loading...
Searching...
No Matches
alcor_spilldata.h
1#pragma once
2
3#include <vector>
4#include <iostream>
5#include <cstdint>
6#include <unordered_map>
7#include <map>
8
9#include "alcor_lightdata.h"
10#include "TH1.h"
11#include "TTree.h"
12#include "triggers.h"
13
14// ============================================================================
15// Data structures
16// ============================================================================
17
25{
26 uint8_t device;
27 uint32_t mask;
28};
29
46{
47 // --- Special members ------------------------------------------------
48 alcor_spilldata_struct() noexcept = default;
49
51 alcor_spilldata_struct &operator=(alcor_spilldata_struct &&) noexcept = default;
52
54 alcor_spilldata_struct &operator=(const alcor_spilldata_struct &) = default;
55
56 // --- Working maps (random-access processing) ------------------------
57 std::map<uint8_t, uint32_t> dead_mask;
58 std::map<uint8_t, uint32_t> participants_mask;
59 std::map<uint32_t, alcor_lightdata_struct> frame_and_lightdata;
60
61 // --- Flat vectors (ROOT TTree serialisation) -------------------------
62 std::vector<data_mask_struct> dead_mask_list;
63 std::vector<data_mask_struct> participants_mask_list;
64 std::vector<uint32_t> frame_reference;
65 std::vector<alcor_lightdata_struct> lightdata_list_in_frame;
66
67 // --- Branch-address pointers (ROOT internal use) --------------------
68 // @warning These are intentionally NOT initialised here. Taking the address
69 // of a sibling member in a default member initialiser is UB, and
70 // after any copy/move the pointers would dangle into the source
71 // object. They are set correctly by clear() and prepare_tree_fill().
72 std::vector<data_mask_struct> *dead_mask_list_ptr;
73 std::vector<data_mask_struct> *participants_mask_list_ptr;
74 std::vector<uint32_t> *frame_reference_ptr;
75 std::vector<alcor_lightdata_struct> *lightdata_list_in_frame_ptr;
76
81 void clear();
82};
83
84// ============================================================================
85// alcor_spilldata class
86// ============================================================================
87
99{
100public:
101 // -----------------------------------------------------------------------
102 // Constructors
103 // -----------------------------------------------------------------------
104
106 alcor_spilldata() { spilldata.clear(); }
107
112 explicit alcor_spilldata(const alcor_spilldata_struct &v) : spilldata(v) {}
113
114 // -----------------------------------------------------------------------
115 // Getters — by value (deep copy)
116 // -----------------------------------------------------------------------
117
119 alcor_spilldata_struct get_spilldata() const { return spilldata; }
120
122 std::map<uint32_t, alcor_lightdata_struct> get_frame() const { return spilldata.frame_and_lightdata; }
123
125 std::map<uint8_t, uint32_t> get_participants_mask() const { return spilldata.participants_mask; }
126
128 std::map<uint8_t, uint32_t> get_dead_mask() const { return spilldata.dead_mask; }
129
131 std::vector<alcor_lightdata_struct> get_frame_list() const { return spilldata.lightdata_list_in_frame; }
132
134 std::vector<uint32_t> get_frame_reference_list() const { return spilldata.frame_reference; }
135
136 // -----------------------------------------------------------------------
137 // Getters — by reference (zero-copy, caller must not outlive this object)
138 // -----------------------------------------------------------------------
139
142
144 std::map<uint32_t, alcor_lightdata_struct> &get_frame_link() { return spilldata.frame_and_lightdata; }
145
147 std::map<uint8_t, uint32_t> &get_participants_mask_link() { return spilldata.participants_mask; }
148
150 std::map<uint8_t, uint32_t> &get_dead_mask_link() { return spilldata.dead_mask; }
151
153 std::vector<alcor_lightdata_struct> &get_frame_list_link() { return spilldata.lightdata_list_in_frame; }
154
156 std::vector<uint32_t> &get_frame_reference_list_link() { return spilldata.frame_reference; }
157
158 // -----------------------------------------------------------------------
159 // Per-frame hit-vector getters
160 // -----------------------------------------------------------------------
161
166 std::vector<trigger_event> &get_frame_trigger_hits(uint32_t index_of_frame) { return spilldata.frame_and_lightdata[index_of_frame].trigger_hits; }
167
172 std::vector<alcor_finedata_struct> &get_frame_timing_hits(uint32_t index_of_frame) { return spilldata.frame_and_lightdata[index_of_frame].timing_hits; }
173
178 std::vector<alcor_finedata_struct> &get_frame_tracking_hits(uint32_t index_of_frame) { return spilldata.frame_and_lightdata[index_of_frame].tracking_hits; }
179
184 std::vector<alcor_finedata_struct> &get_frame_cherenkov_hits(uint32_t index_of_frame) { return spilldata.frame_and_lightdata[index_of_frame].cherenkov_hits; }
185
186 // -----------------------------------------------------------------------
187 // Setters — by value (deep copy)
188 // -----------------------------------------------------------------------
189
191 void set_spilldata(alcor_spilldata_struct v) { spilldata = v; }
192
194 void set_frame(std::map<uint32_t, alcor_lightdata_struct> v) { spilldata.frame_and_lightdata = v; }
195
197 void set_participants_mask(std::map<uint8_t, uint32_t> v) { spilldata.participants_mask = v; }
198
200 void set_dead_mask(std::map<uint8_t, uint32_t> v) { spilldata.dead_mask = v; }
201
202 // -----------------------------------------------------------------------
203 // Setters — by reference (moves/aliases the source)
204 // -----------------------------------------------------------------------
205
207 void set_spilldata_link(alcor_spilldata_struct &v) { spilldata = v; }
208
210 void set_frame_link(std::map<uint32_t, alcor_lightdata_struct> &v) { spilldata.frame_and_lightdata = v; }
211
213 void set_participants_mask_link(std::map<uint8_t, uint32_t> &v) { spilldata.participants_mask = v; }
214
216 void set_dead_mask_link(std::map<uint8_t, uint32_t> &v) { spilldata.dead_mask = v; }
217
218 // -----------------------------------------------------------------------
219 // Utility methods
220 // -----------------------------------------------------------------------
221
225 void clear()
226 {
227 spilldata.clear();
228 frame_reference_for_deletion.clear();
229 }
230
235 bool has_trigger(uint32_t index_of_frame) { return !spilldata.frame_and_lightdata[index_of_frame].trigger_hits.empty(); }
236
242 void add_trigger_to_frame(uint32_t index_of_frame, trigger_event trg) { spilldata.frame_and_lightdata[index_of_frame].trigger_hits.push_back(trg); }
243
252 void do_not_write_frame(uint32_t index_of_frame) { frame_reference_for_deletion[index_of_frame] = true; }
253
266 std::map<uint32_t, std::vector<uint8_t>> get_not_dead_participants();
267
274 bool has_data() { return !spilldata.participants_mask.empty() || !spilldata.participants_mask_list.empty(); }
275
276 // -----------------------------------------------------------------------
277 // ROOT TTree I/O
278 // -----------------------------------------------------------------------
279
289 void link_to_tree(TTree *input_tree);
290
300 void write_to_tree(TTree *output_tree);
301
315 void prepare_tree_fill();
316
323 void get_entry() {}
324
325private:
326 alcor_spilldata_struct spilldata;
327 std::unordered_map<uint32_t, bool> frame_reference_for_deletion;
328};
329
330// ============================================================================
331// Free-function merge / reduce utilities
332// ============================================================================
333
341void merge_lightdata(alcor_lightdata_struct &lhs, alcor_lightdata_struct &&rhs);
342
353void merge(alcor_spilldata_struct &lhs, alcor_spilldata_struct &&rhs);
354
360void merge(alcor_spilldata &lhs, alcor_spilldata &&rhs);
361
368
374alcor_spilldata operator+(alcor_spilldata lhs, const alcor_spilldata &rhs);
Class wrapping lightdata hits with convenient accessors and utilities.
Definition alcor_lightdata.h:38
High-level accessor class for one beam-spill worth of ALCOR data.
Definition alcor_spilldata.h:99
void clear()
Resets the spill to an empty state, also clearing the deletion registry.
Definition alcor_spilldata.h:225
void set_dead_mask(std::map< uint8_t, uint32_t > v)
Replaces the dead-mask map (copied).
Definition alcor_spilldata.h:200
std::map< uint32_t, alcor_lightdata_struct > get_frame() const
Returns a copy of the frame → light-data map.
Definition alcor_spilldata.h:122
void prepare_tree_fill()
Converts the working maps into flat vectors ready for TTree::Fill.
Definition alcor_spilldata.cxx:101
std::vector< alcor_finedata_struct > & get_frame_cherenkov_hits(uint32_t index_of_frame)
Returns a mutable reference to the Cherenkov-hit list for a given frame.
Definition alcor_spilldata.h:184
alcor_spilldata()
Default constructor — initialises to an empty spill.
Definition alcor_spilldata.h:106
std::vector< alcor_lightdata_struct > get_frame_list() const
Returns a copy of the flat light-data vector (TTree representation).
Definition alcor_spilldata.h:131
std::vector< trigger_event > & get_frame_trigger_hits(uint32_t index_of_frame)
Returns a mutable reference to the trigger-hit list for a given frame.
Definition alcor_spilldata.h:166
void set_spilldata_link(alcor_spilldata_struct &v)
Replaces the internal spill-data struct (move-assigned from reference).
Definition alcor_spilldata.h:207
std::map< uint8_t, uint32_t > get_participants_mask() const
Returns a copy of the device → participants-mask map.
Definition alcor_spilldata.h:125
std::map< uint32_t, alcor_lightdata_struct > & get_frame_link()
Returns a mutable reference to the frame → light-data map.
Definition alcor_spilldata.h:144
void get_entry()
Placeholder called after TTree::GetEntry — currently a no-op.
Definition alcor_spilldata.h:323
void link_to_tree(TTree *input_tree)
Binds the flat-vector members to branches of an existing input TTree.
Definition alcor_spilldata.cxx:79
std::vector< alcor_finedata_struct > & get_frame_tracking_hits(uint32_t index_of_frame)
Returns a mutable reference to the tracking-hit list for a given frame.
Definition alcor_spilldata.h:178
void set_participants_mask(std::map< uint8_t, uint32_t > v)
Replaces the participants-mask map (copied).
Definition alcor_spilldata.h:197
std::vector< alcor_finedata_struct > & get_frame_timing_hits(uint32_t index_of_frame)
Returns a mutable reference to the timing-hit list for a given frame.
Definition alcor_spilldata.h:172
std::vector< uint32_t > get_frame_reference_list() const
Returns a copy of the flat frame-reference vector (TTree representation).
Definition alcor_spilldata.h:134
void set_frame(std::map< uint32_t, alcor_lightdata_struct > v)
Replaces the frame → light-data map (copied).
Definition alcor_spilldata.h:194
void write_to_tree(TTree *output_tree)
Creates branches on an output TTree and binds them to the flat vectors.
Definition alcor_spilldata.cxx:90
std::vector< uint32_t > & get_frame_reference_list_link()
Returns a mutable reference to the flat frame-reference vector.
Definition alcor_spilldata.h:156
void set_dead_mask_link(std::map< uint8_t, uint32_t > &v)
Replaces the dead-mask map (move-assigned from reference).
Definition alcor_spilldata.h:216
alcor_spilldata_struct & get_spilldata_link()
Returns a mutable reference to the internal spill-data struct.
Definition alcor_spilldata.h:141
void add_trigger_to_frame(uint32_t index_of_frame, trigger_event trg)
Appends a trigger event to the hit list of the specified frame.
Definition alcor_spilldata.h:242
std::map< uint8_t, uint32_t > get_dead_mask() const
Returns a copy of the device → dead-mask map.
Definition alcor_spilldata.h:128
void set_spilldata(alcor_spilldata_struct v)
Replaces the internal spill-data struct (copied).
Definition alcor_spilldata.h:191
std::vector< alcor_lightdata_struct > & get_frame_list_link()
Returns a mutable reference to the flat light-data vector.
Definition alcor_spilldata.h:153
std::map< uint32_t, std::vector< uint8_t > > get_not_dead_participants()
Returns, per device, the list of channels that are participating but not marked as dead.
Definition alcor_spilldata.cxx:41
alcor_spilldata(const alcor_spilldata_struct &v)
Construct from an existing spill-data struct (copied).
Definition alcor_spilldata.h:112
void do_not_write_frame(uint32_t index_of_frame)
Marks a frame to be excluded from the next TTree fill.
Definition alcor_spilldata.h:252
bool has_trigger(uint32_t index_of_frame)
Returns true if the given frame contains at least one trigger hit.
Definition alcor_spilldata.h:235
bool has_data()
Returns true if this object contains any spill data.
Definition alcor_spilldata.h:274
std::map< uint8_t, uint32_t > & get_dead_mask_link()
Returns a mutable reference to the dead-mask map.
Definition alcor_spilldata.h:150
std::map< uint8_t, uint32_t > & get_participants_mask_link()
Returns a mutable reference to the participants-mask map.
Definition alcor_spilldata.h:147
alcor_spilldata_struct get_spilldata() const
Returns a full copy of the internal spill-data struct.
Definition alcor_spilldata.h:119
void set_participants_mask_link(std::map< uint8_t, uint32_t > &v)
Replaces the participants-mask map (move-assigned from reference).
Definition alcor_spilldata.h:213
void set_frame_link(std::map< uint32_t, alcor_lightdata_struct > &v)
Replaces the frame map (move-assigned from reference).
Definition alcor_spilldata.h:210
Structure holding all types of light detector hits for a spill.
Definition alcor_lightdata.h:17
Plain-old-data aggregate that owns all spill information for one beam spill.
Definition alcor_spilldata.h:46
void clear()
Resets all members to an empty state and re-synchronises the branch-address pointers with their respe...
Definition alcor_spilldata.cxx:7
std::vector< alcor_lightdata_struct > * lightdata_list_in_frame_ptr
Stable pointer for ROOT branch address.
Definition alcor_spilldata.h:75
std::map< uint32_t, alcor_lightdata_struct > frame_and_lightdata
frame_id → light-data payload.
Definition alcor_spilldata.h:59
std::vector< data_mask_struct > participants_mask_list
Flat copy of participants_mask for TTree output.
Definition alcor_spilldata.h:63
std::map< uint8_t, uint32_t > dead_mask
device → dead-channel bitmask.
Definition alcor_spilldata.h:57
std::vector< data_mask_struct > * participants_mask_list_ptr
Stable pointer for ROOT branch address.
Definition alcor_spilldata.h:73
std::vector< data_mask_struct > * dead_mask_list_ptr
Stable pointer for ROOT branch address.
Definition alcor_spilldata.h:72
std::vector< uint32_t > * frame_reference_ptr
Stable pointer for ROOT branch address.
Definition alcor_spilldata.h:74
std::vector< alcor_lightdata_struct > lightdata_list_in_frame
Light-data entries parallel to frame_reference.
Definition alcor_spilldata.h:65
std::vector< data_mask_struct > dead_mask_list
Flat copy of dead_mask for TTree output.
Definition alcor_spilldata.h:62
std::map< uint8_t, uint32_t > participants_mask
device → participating-channel bitmask.
Definition alcor_spilldata.h:58
std::vector< uint32_t > frame_reference
Ordered list of frame IDs written to the TTree.
Definition alcor_spilldata.h:64
Pairs a device ID with a bitmask (used for dead and participant masks).
Definition alcor_spilldata.h:25
uint32_t mask
Bitmask encoding channel states (e.g. alive/dead).
Definition alcor_spilldata.h:27
uint8_t device
Device (ALCOR chip) identifier.
Definition alcor_spilldata.h:26
Per-event trigger data attached to a decoded data frame.
Definition triggers.h:114
Header-only trigger definitions, registry, and TOML-based configuration reader.