Project
Loading...
Searching...
No Matches
DataPointCompositeObject.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15using namespace o2::dcs;
16
18
19namespace o2::dcs
20{
21template <typename T, o2::dcs::DeliveryType dt>
23{
24 union Converter {
25 uint64_t raw_data;
26 T t_value;
27 };
28 if (dpcom.id.get_type() != dt) {
29 throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dpcom.id.get_type()) + " instead of the requested " + o2::dcs::show(dt));
30 }
31 Converter converter;
32 converter.raw_data = dpcom.data.payload_pt1;
33 return converter.t_value;
34}
35
36// only specialize the getValue function for the types we support :
37//
38// - double
39// - float
40// - uint32_t
41// - int32_t
42// - char
43// - bool
44//
45// - string
46
47template <>
49{
50 return getValueImpl<double, DeliveryType::DPVAL_DOUBLE>(dpcom);
51}
52
53template <>
55{
56 return getValueImpl<float, DeliveryType::DPVAL_FLOAT>(dpcom);
57}
58
59template <>
60uint32_t getValue(const DataPointCompositeObject& dpcom)
61{
62 return getValueImpl<uint32_t, DeliveryType::DPVAL_UINT>(dpcom);
63}
64
65template <>
67{
68 return getValueImpl<int32_t, DeliveryType::DPVAL_INT>(dpcom);
69}
70
71template <>
73{
74 return getValueImpl<char, DeliveryType::DPVAL_CHAR>(dpcom);
75}
76
77template <>
79{
80 return getValueImpl<bool, DeliveryType::DPVAL_BOOL>(dpcom);
81}
82
83template <>
84std::string getValue(const DataPointCompositeObject& dpcom)
85{
86 if (dpcom.id.get_type() != o2::dcs::DeliveryType::DPVAL_STRING) {
87 throw std::runtime_error("DPCOM is of unexpected type " + o2::dcs::show(dpcom.id.get_type()));
88 }
89 return std::string((char*)&dpcom.data.payload_pt1);
90}
91
92} // namespace o2::dcs
ClassImp(DataPointCompositeObject)
DeliveryType get_type() const noexcept
T getValue(const DataPointCompositeObject &dpcom)
std::string show(const DeliveryType type)
T getValueImpl(const DataPointCompositeObject &dpcom)