DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
HDF5FileLayout.cpp
Go to the documentation of this file.
1
9
10#include <stdexcept>
11#include <string>
12#include <vector>
13
14namespace dunedaq {
15namespace hdf5libs {
16
17HDF5FileLayout::HDF5FileLayout(HDF5FileLayoutParameters conf,
18 uint32_t version) // NOLINT(build/unsigned)
19 : m_conf_params(conf)
20 , m_version(version)
21{
22 if (m_version < 2)
23 m_conf_params = get_v0_file_layout_params();
24
25 fill_path_params_maps(m_conf_params);
26
27 check_config();
28}
29
30void
31HDF5FileLayout::check_config()
32{
33 // for now, don't do additional config checks for old versions
34 if (m_version < 2)
35 return;
36
37 if (m_conf_params.record_name_prefix.compare("TriggerRecord") == 0) {
38 if (m_conf_params.digits_for_sequence_number == 0) {
39 ers::error(FileLayoutSequenceIDsCannotBeZero(ERS_HERE, 4));
40 m_conf_params.digits_for_sequence_number = 4;
41 }
42 } else if (m_conf_params.record_name_prefix.compare("TimeSlice") == 0) {
43 if (m_conf_params.digits_for_sequence_number != 0) {
44 ers::warning(InvalidSequenceDigits(ERS_HERE, m_conf_params.record_name_prefix, 0));
45 m_conf_params.digits_for_sequence_number = 0;
46 }
47 } else {
48 throw InvalidRecordName(ERS_HERE, m_conf_params.record_name_prefix);
49 }
50}
51
52HDF5PathParameters
53HDF5FileLayout::get_path_params(daqdataformats::SourceID::Subsystem type) const
54{
55 try {
56 return m_path_params_map.at(type);
57 } catch (std::out_of_range&) {
58 throw FileLayoutUnconfiguredSubsystem(ERS_HERE, type, daqdataformats::SourceID::subsystem_to_string(type));
59 }
60}
61
62std::string
63HDF5FileLayout::get_record_number_string(uint64_t record_number, // NOLINT(build/unsigned)
64 daqdataformats::sequence_number_t seq_num) const
65{
66 std::ostringstream record_number_string;
67
68 int width = m_conf_params.digits_for_record_number;
69 record_number_string << m_conf_params.record_name_prefix << std::setw(width) << std::setfill('0') << record_number;
70
71 if (m_conf_params.digits_for_sequence_number > 0) {
72
73 width = m_conf_params.digits_for_sequence_number;
74 record_number_string << "." << std::setw(width) << std::setfill('0') << seq_num;
75 }
76
77 return record_number_string.str();
78}
79
80std::string
81HDF5FileLayout::get_trigger_number_string(daqdataformats::trigger_number_t trig_num,
82 daqdataformats::sequence_number_t seq_num) const
83{
84 return get_record_number_string(trig_num, seq_num);
85}
86
87std::string
88HDF5FileLayout::get_timeslice_number_string(daqdataformats::timeslice_number_t ts_num) const
89{
90 return get_record_number_string(ts_num);
91}
92
96std::vector<std::string>
97HDF5FileLayout::get_path_elements(const daqdataformats::TriggerRecordHeader& trh) const
98{
99
100 std::vector<std::string> path_elements;
101
102 // first the Trigger string
103 path_elements.push_back(get_trigger_number_string(trh.get_trigger_number(), trh.get_sequence_number()));
104
105 // then the RawData group name
106 path_elements.push_back(m_conf_params.raw_data_group_name);
107
108 // then the SourceID plus record header name
109 path_elements.push_back(trh.get_header().element_id.to_string() + "_" +
110 m_conf_params.record_header_dataset_name);
111
112 return path_elements;
113}
114
118std::vector<std::string>
119HDF5FileLayout::get_path_elements(const daqdataformats::TimeSliceHeader& tsh) const
120{
121
122 std::vector<std::string> path_elements;
123
124 // first the Trigger string
125 path_elements.push_back(get_timeslice_number_string(tsh.timeslice_number));
126
127 // then the RawData group name
128 path_elements.push_back(m_conf_params.raw_data_group_name);
129
130 // then the SourceID plus record header name
131 path_elements.push_back(tsh.element_id.to_string() + "_" + m_conf_params.record_header_dataset_name);
132
133 return path_elements;
134}
135
139std::vector<std::string>
140HDF5FileLayout::get_path_elements(const daqdataformats::FragmentHeader& fh) const
141{
142
143 std::vector<std::string> path_elements;
144
145 // first the Trigger string
146 // note, this still works for TimeSlices through enforced proper configuration of layout parameters
147 path_elements.push_back(get_trigger_number_string(fh.trigger_number, fh.sequence_number));
148
149 // then the RawData group name
150 path_elements.push_back(m_conf_params.raw_data_group_name);
151
152 // then the SourceID plus FragmentType
153 path_elements.push_back(
154 fh.element_id.to_string() + "_" +
155 daqdataformats::fragment_type_to_string(static_cast<daqdataformats::FragmentType>(fh.fragment_type)));
156
157 return path_elements;
158}
159
163std::string
164HDF5FileLayout::get_path_string(const daqdataformats::TimeSliceHeader& tsh) const
165{
166 std::ostringstream path_string;
167 path_string << "/" << get_timeslice_number_string(tsh.timeslice_number)
168 << "/" << m_conf_params.raw_data_group_name
169 << "/" << tsh.element_id.to_string() << "_" << m_conf_params.record_header_dataset_name;
170 return path_string.str();
171}
172
176std::string
177HDF5FileLayout::get_record_header_path(uint64_t rec_num, // NOLINT (build/unsigned)
178 daqdataformats::sequence_number_t seq_num) const
179{
180 return get_record_number_string(rec_num, seq_num) + "/" + m_conf_params.record_header_dataset_name;
181}
182
186std::string
187HDF5FileLayout::get_trigger_record_header_path(daqdataformats::trigger_number_t trig_num,
188 daqdataformats::sequence_number_t seq_num) const
189{
190 return get_trigger_number_string(trig_num, seq_num) + "/" + m_conf_params.record_header_dataset_name;
191}
192
196std::string
197HDF5FileLayout::get_timeslice_header_path(daqdataformats::timeslice_number_t ts_num) const
198{
199 return get_timeslice_number_string(ts_num) + "/" + m_conf_params.record_header_dataset_name;
200}
201
205std::string
206HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
207 daqdataformats::sequence_number_t seq_num,
208 daqdataformats::SourceID element_id) const
209{
210
211 auto const& path_params = get_path_params(element_id.subsystem);
212
213 std::ostringstream path_string;
214 path_string << get_trigger_number_string(trig_num, seq_num) << "/" << path_params.detector_group_name << "/"
215 << path_params.element_name_prefix << std::setw(path_params.digits_for_element_number)
216 << std::setfill('0') << element_id.id;
217 return path_string.str();
218}
219
223std::string
224HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
225 daqdataformats::sequence_number_t seq_num,
226 daqdataformats::SourceID::Subsystem type,
227 uint32_t element_id) const // NOLINT(build/unsigned)
228{
229 daqdataformats::SourceID sid{ type, element_id };
230 return get_fragment_path(trig_num, seq_num, sid);
231}
232
236std::string
237HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
238 daqdataformats::sequence_number_t seq_num,
239 const std::string& typestring,
240 uint32_t element_id) const // NOLINT(build/unsigned)
241{
242 daqdataformats::SourceID sid{ daqdataformats::SourceID::string_to_subsystem(typestring), element_id };
243 return get_fragment_path(trig_num, seq_num, sid);
244}
245
249std::string
250HDF5FileLayout::get_fragment_type_path(uint64_t trig_num, // NOLINT(build/unsigned)
251 daqdataformats::sequence_number_t seq_num,
252 daqdataformats::SourceID::Subsystem type) const
253{
254 auto const& path_params = get_path_params(type);
255
256 std::ostringstream path_string;
257 path_string << get_trigger_number_string(trig_num, seq_num) << "/" << path_params.detector_group_name;
258 return path_string.str();
259}
260
264std::string
265HDF5FileLayout::get_fragment_type_path(uint64_t trig_num, // NOLINT(build/unsigned)
266 daqdataformats::sequence_number_t seq_num,
267 std::string typestring) const
268{
269 return get_fragment_type_path(trig_num, seq_num, daqdataformats::SourceID::string_to_subsystem(typestring));
270}
271
272daqdataformats::SourceID
273HDF5FileLayout::get_source_id_from_path_elements(std::vector<std::string> const& path_elements) const
274{
275 // ignore first path element, which is for the record group
276 // second path element is detector name.
277 daqdataformats::SourceID::Subsystem systype = m_detector_group_name_to_type_map.at(path_elements[1]);
278
279 // get back the path parameters for this system type from the file layout
280 auto path_params = get_path_params(systype);
281
282 // fourth path element is element. remove prefix and translate to numbers
283 auto ele_id = std::stoi(path_elements[3].substr(path_params.element_name_prefix.size()));
284
285 return daqdataformats::SourceID(systype, ele_id);
286}
287
288void
289HDF5FileLayout::fill_path_params_maps(HDF5FileLayoutParameters const& flp)
290{
291 for (auto const& path_param : flp.path_params_list) {
292 auto sys_type = daqdataformats::SourceID::string_to_subsystem(path_param.detector_group_type);
293
294 if (sys_type == daqdataformats::SourceID::Subsystem::kUnknown)
295 throw FileLayoutInvalidSubsystem(ERS_HERE, path_param.detector_group_type);
296
297 m_path_params_map[sys_type] = path_param;
298 m_detector_group_name_to_type_map[path_param.detector_group_name] = sys_type;
299 }
300}
301
305HDF5FileLayoutParameters
306HDF5FileLayout::get_v0_file_layout_params()
307{
308 HDF5FileLayoutParameters flp;
309 flp.record_name_prefix = "TriggerRecord";
310 flp.digits_for_record_number = 6;
311 flp.digits_for_sequence_number = 0;
312 flp.record_header_dataset_name = "TriggerRecordHeader";
313
314 HDF5PathParameters pp;
315
316 pp.detector_group_type = "TPC";
317 pp.detector_group_name = "TPC";
318 pp.element_name_prefix = "Link";
319 pp.digits_for_element_number = 2;
320 flp.path_params_list.push_back(pp);
321
322 pp.detector_group_type = "PDS";
323 pp.detector_group_name = "PDS";
324 pp.element_name_prefix = "Element";
325 pp.digits_for_element_number = 2;
326 flp.path_params_list.push_back(pp);
327
328 pp.detector_group_type = "NDLArTPC";
329 pp.detector_group_name = "NDLArTPC";
330 pp.element_name_prefix = "Element";
331 pp.digits_for_element_number = 2;
332 flp.path_params_list.push_back(pp);
333
334 pp.detector_group_type = "NDLArPDS";
335 pp.detector_group_name = "NDLArPDS";
336 pp.element_name_prefix = "Element";
337 pp.digits_for_element_number = 2;
338 flp.path_params_list.push_back(pp);
339
340 pp.detector_group_type = "DataSelection";
341 pp.detector_group_name = "Trigger";
342 pp.element_name_prefix = "Element";
343 pp.digits_for_element_number = 2;
344 flp.path_params_list.push_back(pp);
345
346 return flp;
347}
348
349} // namespace hdf5libs
350} // namespace dunedaq
#define ERS_HERE
Including Qt Headers.
void warning(const Issue &issue)
Definition ers.hpp:115
void error(const Issue &issue)
Definition ers.hpp:81