Skip to content

Commit 4b52c75

Browse files
aphecetcheshahor02
authored andcommitted
[DCS] Ensure DataPointCompositeObject is trivially copyable and add a getValue free function
1 parent 17cc9cf commit 4b52c75

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Detectors/DCS/include/DetectorsDCS/DataPointCompositeObject.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,29 @@ struct alignas(128) DataPointCompositeObject final {
254254
(char*)&dpcom.data.payload_pt1, 56);
255255
}
256256
}
257+
258+
/**
259+
* The destructor for DataPointCompositeObject so it is not deleted
260+
* and thus DataPointCompositeObject is trivially copyable
261+
*/
262+
~DataPointCompositeObject() noexcept = default;
257263
ClassDefNV(DataPointCompositeObject, 1);
258264
};
265+
266+
/**
267+
* Return the value contained in the DataPointCompositeObject, if possible.
268+
*
269+
* @tparam T the expected type of the value
270+
*
271+
* @param dpcom the DataPointCompositeObject the value is extracted from
272+
*
273+
* @returns the value of the data point
274+
*
275+
* @throws if the DeliveryType of the data point is not compatible with T
276+
*/
277+
template <typename T>
278+
T getValue(const DataPointCompositeObject& dpcom);
279+
259280
} // namespace dcs
260281
} // namespace o2
261282

Detectors/DCS/src/DataPointCompositeObject.cxx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,61 @@
1313
using namespace o2::dcs;
1414

1515
ClassImp(DataPointCompositeObject);
16+
17+
namespace o2::dcs
18+
{
19+
template<typename T, o2::dcs::DeliveryType dt>
20+
T getValueImpl(const DataPointCompositeObject& dpcom) {
21+
union Converter {
22+
uint64_t raw_data;
23+
T t_value;
24+
};
25+
if (dpcom.id.get_type() != dt) {
26+
throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dt));
27+
}
28+
Converter converter;
29+
converter.raw_data = dpcom.data.payload_pt1;
30+
return converter.t_value;
31+
}
32+
33+
// only specialize the getValue function for the types we support :
34+
//
35+
// - double
36+
// - uint32_t
37+
// - int32_t
38+
// - char
39+
// - bool
40+
41+
// template<>
42+
// double getValueImpl<double,DeliveryType::RAW_DOUBLE>(const DataPointCompositeObject&);
43+
//
44+
template<>
45+
double getValue(const DataPointCompositeObject& dpcom)
46+
{
47+
return getValueImpl<double,DeliveryType::RAW_DOUBLE>(dpcom);
48+
}
49+
50+
template <>
51+
uint32_t getValue(const DataPointCompositeObject& dpcom)
52+
{
53+
return getValueImpl<uint32_t,DeliveryType::RAW_UINT>(dpcom);
54+
}
55+
56+
template <>
57+
int32_t getValue(const DataPointCompositeObject& dpcom)
58+
{
59+
return getValueImpl<int32_t,DeliveryType::RAW_INT>(dpcom);
60+
}
61+
62+
template <>
63+
char getValue(const DataPointCompositeObject& dpcom)
64+
{
65+
return getValueImpl<char,DeliveryType::RAW_CHAR>(dpcom);
66+
}
67+
68+
template <>
69+
bool getValue(const DataPointCompositeObject& dpcom)
70+
{
71+
return getValueImpl<bool,DeliveryType::RAW_BOOL>(dpcom);
72+
}
73+
} // namespace o2::dcs

0 commit comments

Comments
 (0)