DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
HDF5FileLayout.cpp
Go to the documentation of this file.
1
7
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() + "_" + m_conf_params.record_header_dataset_name);
110
111 return path_elements;
112}
113
117std::vector<std::string>
118HDF5FileLayout::get_path_elements(const daqdataformats::TimeSliceHeader& tsh) const
119{
120
121 std::vector<std::string> path_elements;
122
123 // first the Trigger string
124 path_elements.push_back(get_timeslice_number_string(tsh.timeslice_number));
125
126 // then the RawData group name
127 path_elements.push_back(m_conf_params.raw_data_group_name);
128
129 // then the SourceID plus record header name
130 path_elements.push_back(tsh.element_id.to_string() + "_" + m_conf_params.record_header_dataset_name);
131
132 return path_elements;
133}
134
138std::vector<std::string>
139HDF5FileLayout::get_path_elements(const daqdataformats::FragmentHeader& fh) const
140{
141
142 std::vector<std::string> path_elements;
143
144 // first the Trigger string
145 // note, this still works for TimeSlices through enforced proper configuration of layout parameters
146 path_elements.push_back(get_trigger_number_string(fh.trigger_number, fh.sequence_number));
147
148 // then the RawData group name
149 path_elements.push_back(m_conf_params.raw_data_group_name);
150
151 // then the SourceID plus FragmentType
152 path_elements.push_back(
153 fh.element_id.to_string() + "_" +
154 daqdataformats::fragment_type_to_string(static_cast<daqdataformats::FragmentType>(fh.fragment_type)));
155
156 return path_elements;
157}
158
162std::string
163HDF5FileLayout::get_path_string(const daqdataformats::TimeSliceHeader& tsh) const
164{
165 std::ostringstream path_string;
166 path_string << "/" << get_timeslice_number_string(tsh.timeslice_number) << "/" << m_conf_params.raw_data_group_name
167 << "/" << tsh.element_id.to_string() << "_" << m_conf_params.record_header_dataset_name;
168 return path_string.str();
169}
170
174std::string
175HDF5FileLayout::get_record_header_path(uint64_t rec_num, // NOLINT (build/unsigned)
176 daqdataformats::sequence_number_t seq_num) const
177{
178 return get_record_number_string(rec_num, seq_num) + "/" + m_conf_params.record_header_dataset_name;
179}
180
184std::string
185HDF5FileLayout::get_trigger_record_header_path(daqdataformats::trigger_number_t trig_num,
186 daqdataformats::sequence_number_t seq_num) const
187{
188 return get_trigger_number_string(trig_num, seq_num) + "/" + m_conf_params.record_header_dataset_name;
189}
190
194std::string
195HDF5FileLayout::get_timeslice_header_path(daqdataformats::timeslice_number_t ts_num) const
196{
197 return get_timeslice_number_string(ts_num) + "/" + m_conf_params.record_header_dataset_name;
198}
199
203std::string
204HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
205 daqdataformats::sequence_number_t seq_num,
206 daqdataformats::SourceID element_id) const
207{
208
209 auto const& path_params = get_path_params(element_id.subsystem);
210
211 std::ostringstream path_string;
212 path_string << get_trigger_number_string(trig_num, seq_num) << "/" << path_params.detector_group_name << "/"
213 << path_params.element_name_prefix << std::setw(path_params.digits_for_element_number)
214 << std::setfill('0') << element_id.id;
215 return path_string.str();
216}
217
221std::string
222HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
223 daqdataformats::sequence_number_t seq_num,
224 daqdataformats::SourceID::Subsystem type,
225 uint32_t element_id) const // NOLINT(build/unsigned)
226{
227 daqdataformats::SourceID sid{ type, element_id };
228 return get_fragment_path(trig_num, seq_num, sid);
229}
230
234std::string
235HDF5FileLayout::get_fragment_path(uint64_t trig_num, // NOLINT(build/unsigned)
236 daqdataformats::sequence_number_t seq_num,
237 const std::string& typestring,
238 uint32_t element_id) const // NOLINT(build/unsigned)
239{
240 daqdataformats::SourceID sid{ daqdataformats::SourceID::string_to_subsystem(typestring), element_id };
241 return get_fragment_path(trig_num, seq_num, sid);
242}
243
247std::string
248HDF5FileLayout::get_fragment_type_path(uint64_t trig_num, // NOLINT(build/unsigned)
249 daqdataformats::sequence_number_t seq_num,
250 daqdataformats::SourceID::Subsystem type) const
251{
252 auto const& path_params = get_path_params(type);
253
254 std::ostringstream path_string;
255 path_string << get_trigger_number_string(trig_num, seq_num) << "/" << path_params.detector_group_name;
256 return path_string.str();
257}
258
262std::string
263HDF5FileLayout::get_fragment_type_path(uint64_t trig_num, // NOLINT(build/unsigned)
264 daqdataformats::sequence_number_t seq_num,
265 std::string typestring) const
266{
267 return get_fragment_type_path(trig_num, seq_num, daqdataformats::SourceID::string_to_subsystem(typestring));
268}
269
270daqdataformats::SourceID
271HDF5FileLayout::get_source_id_from_path_elements(std::vector<std::string> const& path_elements) const
272{
273 // ignore first path element, which is for the record group
274 // second path element is detector name.
275 daqdataformats::SourceID::Subsystem systype = m_detector_group_name_to_type_map.at(path_elements[1]);
276
277 // get back the path parameters for this system type from the file layout
278 auto path_params = get_path_params(systype);
279
280 // fourth path element is element. remove prefix and translate to numbers
281 auto ele_id = std::stoi(path_elements[3].substr(path_params.element_name_prefix.size()));
282
283 return daqdataformats::SourceID(systype, ele_id);
284}
285
286void
287HDF5FileLayout::fill_path_params_maps(HDF5FileLayoutParameters const& flp)
288{
289 for (auto const& path_param : flp.path_params_list) {
290 auto sys_type = daqdataformats::SourceID::string_to_subsystem(path_param.detector_group_type);
291
292 if (sys_type == daqdataformats::SourceID::Subsystem::kUnknown)
293 throw FileLayoutInvalidSubsystem(ERS_HERE, path_param.detector_group_type);
294
295 m_path_params_map[sys_type] = path_param;
296 m_detector_group_name_to_type_map[path_param.detector_group_name] = sys_type;
297 }
298}
299
303HDF5FileLayoutParameters
304HDF5FileLayout::get_v0_file_layout_params()
305{
306 HDF5FileLayoutParameters flp;
307 flp.record_name_prefix = "TriggerRecord";
308 flp.digits_for_record_number = 6;
309 flp.digits_for_sequence_number = 0;
310 flp.record_header_dataset_name = "TriggerRecordHeader";
311
312 HDF5PathParameters pp;
313
314 pp.detector_group_type = "TPC";
315 pp.detector_group_name = "TPC";
316 pp.element_name_prefix = "Link";
317 pp.digits_for_element_number = 2;
318 flp.path_params_list.push_back(pp);
319
320 pp.detector_group_type = "PDS";
321 pp.detector_group_name = "PDS";
322 pp.element_name_prefix = "Element";
323 pp.digits_for_element_number = 2;
324 flp.path_params_list.push_back(pp);
325
326 pp.detector_group_type = "NDLArTPC";
327 pp.detector_group_name = "NDLArTPC";
328 pp.element_name_prefix = "Element";
329 pp.digits_for_element_number = 2;
330 flp.path_params_list.push_back(pp);
331
332 pp.detector_group_type = "NDLArPDS";
333 pp.detector_group_name = "NDLArPDS";
334 pp.element_name_prefix = "Element";
335 pp.digits_for_element_number = 2;
336 flp.path_params_list.push_back(pp);
337
338 pp.detector_group_type = "DataSelection";
339 pp.detector_group_name = "Trigger";
340 pp.element_name_prefix = "Element";
341 pp.digits_for_element_number = 2;
342 flp.path_params_list.push_back(pp);
343
344 return flp;
345}
346
347} // namespace hdf5libs
348} // namespace dunedaq
#define ERS_HERE
The DUNE-DAQ namespace.
void warning(const Issue &issue)
Definition ers.hpp:150
void error(const Issue &issue)
Definition ers.hpp:101