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::dcs
32{
49
59
68 DataPointCompositeObject() noexcept : id(), data() {}
69
78 const DataPointIdentifier& id,
79 const DataPointValue& data) noexcept : id(id), data(data) {}
80
85
87
94 inline bool operator==(const DataPointCompositeObject& other) const
95 noexcept
96 {
97 return id == other.id && data == other.data;
98 }
99
106 inline bool operator!=(const DataPointCompositeObject& other) const
107 noexcept
108 {
109 return id != other.id || data != other.data;
110 }
111
119 inline void set(const DataPointIdentifier& id, DataPointValue& data) noexcept
120 {
121 DataPointIdentifier::FILL(this->id, (uint64_t*)&id);
122 this->data = data;
123 }
124
133 inline void set(const uint64_t* const data) noexcept
134 {
135 DataPointIdentifier::FILL(this->id, data);
136 this->data.set(data + 8, id.get_type());
137 }
138
150 inline void update(const DataPointValue& dpval) noexcept
151 {
152 data.set(
153 dpval.flags & ~DataPointValue::CONTROL_MASK,
154 dpval.msec,
155 dpval.sec,
156 (uint64_t*)&dpval.payload_pt1,
157 id.get_type());
158 }
159
171 inline void* dim_buffer() const
172 {
173 switch (id.get_type()) {
174 case RAW_INT:
175 case RAW_UINT:
176 case RAW_BOOL:
177 case RAW_CHAR:
178 case RAW_DOUBLE:
179 case RAW_TIME:
180 case RAW_STRING:
181 case RAW_BINARY:
182 case RAW_FLOAT:
183 return (void*)&data.payload_pt1;
184 case DPVAL_INT:
185 case DPVAL_UINT:
186 case DPVAL_BOOL:
187 case DPVAL_CHAR:
188 case DPVAL_DOUBLE:
189 case DPVAL_TIME:
190 case DPVAL_STRING:
191 case DPVAL_BINARY:
192 case DPVAL_FLOAT:
193 return (void*)&data;
194 default:
195 case VOID:
196 throw std::domain_error("Illegal DeliveryType.");
197 }
198 }
199
209 inline friend std::ostream& operator<<(std::ostream& os,
210 const DataPointCompositeObject& dpcom) noexcept
211 {
212 std::string payload;
213 os << dpcom.id << ";" << dpcom.data << ";";
214 union Converter {
215 uint64_t raw_data;
216 float float_value;
217 double double_value;
218 uint32_t uint_value;
219 int32_t int_value;
220 char char_value;
221 bool bool_value;
222 } converter;
223 converter.raw_data = dpcom.data.payload_pt1;
224 switch (dpcom.id.get_type()) {
225 case VOID:
226 return os;
227 case RAW_INT:
228 case DPVAL_INT:
229 return os << converter.int_value;
230 case RAW_UINT:
231 case DPVAL_UINT:
232 return os << converter.uint_value;
233 case RAW_BOOL:
234 case DPVAL_BOOL:
235 return os << (converter.bool_value ? "True" : "False");
236 case RAW_CHAR:
237 case DPVAL_CHAR:
238 return os << converter.char_value;
239 case RAW_FLOAT:
240 case DPVAL_FLOAT:
241 return os << converter.float_value;
242 case RAW_DOUBLE:
243 case DPVAL_DOUBLE:
244 return os << converter.double_value;
245 case RAW_STRING:
246 case DPVAL_STRING:
247 return os << std::string((char*)&dpcom.data.payload_pt1);
248 case RAW_TIME:
249 case DPVAL_TIME: {
250 // I have no idea how to properly test the time_t backend.
251 // It's probably even hardware/os/kernel specific...
252#ifdef __linux__
253 char buffer[17];
254 std::time_t ts((dpcom.data.payload_pt1) >> 32);
255 std::strftime(buffer, 32, "%FT%T", std::gmtime(&ts));
256 return os << std::string(buffer) << "." << std::setw(3) << std::setfill('0') << std::to_string((dpcom.data.payload_pt1 & 0x00000000FFFF0000) >> 16)
257 << "Z";
258#else
259 return os << "[Timestamps not supported on this platform.]";
260#endif
261 }
262 case RAW_BINARY:
263 case DPVAL_BINARY:
264 default:
266 (char*)&dpcom.data.payload_pt1, 56);
267 }
268 }
269
274 ~DataPointCompositeObject() noexcept = default;
276};
277
289template <typename T>
291
292} // namespace o2::dcs
293
294#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)
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(const DataPointCompositeObject &src) noexcept=default
DataPointCompositeObject & operator=(const DataPointCompositeObject &src) noexcept=default
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