Project
Loading...
Searching...
No Matches
DataPointCompositeObject.h
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
12/*
13 * File: DataPointCompositeObject.h
14 * Author: John Lång (john.larry.lang@cern.ch)
15 *
16 * Created on 23 September 2016, 11:28
17 */
18#ifndef O2_DCS_DATAPOINT_COMPOSITE_OBJECT_H
19#define O2_DCS_DATAPOINT_COMPOSITE_OBJECT_H
20
21#include <cstdint>
22#include <stdexcept>
23#include <ostream>
24#include <string>
25#include "Rtypes.h"
30
31namespace o2
32{
33namespace dcs
34{
51
61
70 DataPointCompositeObject() noexcept : id(), data() {}
71
80 const DataPointIdentifier& id,
81 const DataPointValue& data) noexcept : id(id), data(data) {}
82
87
89 {
90 if (&src != this) {
91 memcpy(this, &src, sizeof(DataPointCompositeObject));
92 }
93 return *this;
94 }
95
102 inline bool operator==(const DataPointCompositeObject& other) const
103 noexcept
104 {
105 return id == other.id && data == other.data;
106 }
107
114 inline bool operator!=(const DataPointCompositeObject& other) const
115 noexcept
116 {
117 return id != other.id || data != other.data;
118 }
119
127 inline void set(const DataPointIdentifier& id, DataPointValue& data) noexcept
128 {
129 DataPointIdentifier::FILL(this->id, (uint64_t*)&id);
130 this->data = data;
131 }
132
141 inline void set(const uint64_t* const data) noexcept
142 {
143 DataPointIdentifier::FILL(this->id, data);
144 this->data.set(data + 8, id.get_type());
145 }
146
158 inline void update(const DataPointValue& dpval) noexcept
159 {
160 data.set(
161 dpval.flags & ~DataPointValue::CONTROL_MASK,
162 dpval.msec,
163 dpval.sec,
164 (uint64_t*)&dpval.payload_pt1,
165 id.get_type());
166 }
167
179 inline void* dim_buffer() const
180 {
181 switch (id.get_type()) {
182 case RAW_INT:
183 case RAW_UINT:
184 case RAW_BOOL:
185 case RAW_CHAR:
186 case RAW_DOUBLE:
187 case RAW_TIME:
188 case RAW_STRING:
189 case RAW_BINARY:
190 case RAW_FLOAT:
191 return (void*)&data.payload_pt1;
192 case DPVAL_INT:
193 case DPVAL_UINT:
194 case DPVAL_BOOL:
195 case DPVAL_CHAR:
196 case DPVAL_DOUBLE:
197 case DPVAL_TIME:
198 case DPVAL_STRING:
199 case DPVAL_BINARY:
200 case DPVAL_FLOAT:
201 return (void*)&data;
202 default:
203 case VOID:
204 throw std::domain_error("Illegal DeliveryType.");
205 }
206 }
207
217 inline friend std::ostream& operator<<(std::ostream& os,
218 const DataPointCompositeObject& dpcom) noexcept
219 {
220 std::string payload;
221 os << dpcom.id << ";" << dpcom.data << ";";
222 union Converter {
223 uint64_t raw_data;
224 float float_value;
225 double double_value;
226 uint32_t uint_value;
227 int32_t int_value;
228 char char_value;
229 bool bool_value;
230 } converter;
231 converter.raw_data = dpcom.data.payload_pt1;
232 switch (dpcom.id.get_type()) {
233 case VOID:
234 return os;
235 case RAW_INT:
236 case DPVAL_INT:
237 return os << converter.int_value;
238 case RAW_UINT:
239 case DPVAL_UINT:
240 return os << converter.uint_value;
241 case RAW_BOOL:
242 case DPVAL_BOOL:
243 return os << (converter.bool_value ? "True" : "False");
244 case RAW_CHAR:
245 case DPVAL_CHAR:
246 return os << converter.char_value;
247 case RAW_FLOAT:
248 case DPVAL_FLOAT:
249 return os << converter.float_value;
250 case RAW_DOUBLE:
251 case DPVAL_DOUBLE:
252 return os << converter.double_value;
253 case RAW_STRING:
254 case DPVAL_STRING:
255 return os << std::string((char*)&dpcom.data.payload_pt1);
256 case RAW_TIME:
257 case DPVAL_TIME: {
258 // I have no idea how to properly test the time_t backend.
259 // It's probably even hardware/os/kernel specific...
260#ifdef __linux__
261 char buffer[17];
262 std::time_t ts((dpcom.data.payload_pt1) >> 32);
263 std::strftime(buffer, 32, "%FT%T", std::gmtime(&ts));
264 return os << std::string(buffer) << "." << std::setw(3) << std::setfill('0') << std::to_string((dpcom.data.payload_pt1 & 0x00000000FFFF0000) >> 16)
265 << "Z";
266#else
267 return os << "[Timestamps not supported on this platform.]";
268#endif
269 }
270 case RAW_BINARY:
271 case DPVAL_BINARY:
272 default:
274 (char*)&dpcom.data.payload_pt1, 56);
275 }
276 }
277
282 ~DataPointCompositeObject() noexcept = default;
284};
285
297template <typename T>
299
300} // namespace dcs
301
303namespace framework
304{
305template <typename T>
306struct is_messageable;
307template <>
309};
310} // namespace framework
311
312} // namespace o2
313
315namespace std
316{
317template <>
318struct is_trivially_copyable<o2::dcs::DataPointCompositeObject> : std::true_type {
319};
320} // namespace std
321
322#endif /* O2_DCS_DATAPOINT_COMPOSITE_OBJECT_H */
static void FILL(const DataPointIdentifier &dpid, const std::string &alias, const DeliveryType type) noexcept
GLenum src
Definition glcorearb.h:1767
GLuint buffer
Definition glcorearb.h:655
GLboolean * data
Definition glcorearb.h:298
std::string to_hex_little_endian(const char *const start, size_t length) noexcept
T getValue(const DataPointCompositeObject &dpcom)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
~DataPointCompositeObject() noexcept=default
void set(const uint64_t *const data) noexcept
DataPointCompositeObject & operator=(const DataPointCompositeObject &src) noexcept
DataPointCompositeObject(const DataPointCompositeObject &src) noexcept
DataPointCompositeObject(const DataPointIdentifier &id, const DataPointValue &data) noexcept
ClassDefNV(DataPointCompositeObject, 1)
bool operator==(const DataPointCompositeObject &other) const noexcept
friend std::ostream & operator<<(std::ostream &os, const DataPointCompositeObject &dpcom) noexcept
void set(const DataPointIdentifier &id, DataPointValue &data) noexcept
bool operator!=(const DataPointCompositeObject &other) const noexcept
void update(const DataPointValue &dpval) noexcept
void set(const uint16_t flags, const uint16_t milliseconds, const uint32_t seconds, const uint64_t *const payload, const DeliveryType type)
static constexpr uint16_t CONTROL_MASK
VectorOfTObjectPtrs other