Project
Loading...
Searching...
No Matches
DataPointIdentifier.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: DataPointIdentifier.h
14 * Author: John Lång (john.larry.lang@cern.ch)
15 *
16 * Created on 23 September 2016, 12:00
17 */
18#ifndef O2_DCS_DATAPOINT_IDENTIFIER_H
19#define O2_DCS_DATAPOINT_IDENTIFIER_H
20
21#include <cstring>
22#include <string>
23#include <cstdint>
24#include <iostream>
25#include <iomanip>
26#include <functional>
27#include <unordered_map>
28
29#include "Rtypes.h"
33
34namespace o2
35{
36namespace dcs
37{
43{
44 const uint64_t pt1;
45 const uint64_t pt2;
46 const uint64_t pt3;
47 const uint64_t pt4;
48 const uint64_t pt5;
49 const uint64_t pt6;
50 const uint64_t pt7;
51 const uint64_t pt8; // Contains the last 6 chars of alias and the type.
52
54 const uint64_t pt1, const uint64_t pt2, const uint64_t pt3,
55 const uint64_t pt4, const uint64_t pt5, const uint64_t pt6,
56 const uint64_t pt7, const uint64_t pt8) noexcept : pt1(pt1), pt2(pt2), pt3(pt3), pt4(pt4), pt5(pt5), pt6(pt6), pt7(pt7), pt8(pt8) {}
57
58 public:
66 DataPointIdentifier() noexcept : pt1(0), pt2(0), pt3(0), pt4(0), pt5(0), pt6(0), pt7(0), pt8(0)
67 {
68 }
69
79 DataPointIdentifier(const std::string& alias, const DeliveryType type) noexcept : DataPointIdentifier()
80 {
81 strncpy((char*)this, alias.c_str(), 62);
82 ((char*)&pt8)[7] = type;
83 }
84
88 DataPointIdentifier(const DataPointIdentifier& src) noexcept : DataPointIdentifier(src.pt1, src.pt2, src.pt3, src.pt4, src.pt5, src.pt6, src.pt7, src.pt8) {}
89
91 {
92 if (&src != this) {
93 memcpy(this, &src, sizeof(DataPointIdentifier));
94 }
95 return *this;
96 }
97
107 static inline void FILL(
108 const DataPointIdentifier& dpid,
109 const std::string& alias,
110 const DeliveryType type) noexcept
111 {
112 strncpy((char*)&dpid, alias.c_str(), 62);
113 ((char*)&dpid.pt8)[7] = type;
114 }
115
123 static inline void FILL(
124 const DataPointIdentifier& dpid,
125 const uint64_t* const data) noexcept
126 {
127 std::strncpy((char*)&dpid, (char*)data, 62);
128 ((char*)&dpid)[63] = ((data[7] & 0xFF00000000000000) >> 56);
129 }
130
138 inline bool operator==(const DataPointIdentifier& other) const
139 {
140 constexpr char mask = 0x7F;
141
142 return (memcmp((char*)this, (char*)&other, 63) == 0) &&
143 (((DeliveryType)this->get_type() & mask) == ((DeliveryType)other.get_type() & mask));
144 }
145
152 inline bool operator!=(const DataPointIdentifier& other) const
153 {
154 return !(*this == other);
155 }
156
161 friend inline std::ostream& operator<<(std::ostream& os,
162 const DataPointIdentifier& dpid) noexcept
163 {
164 return os << std::string((char*)&dpid) << ";" << o2::dcs::show((DeliveryType)((dpid.pt8 & 0xFF00000000000000) >> 56));
165 }
166
173 inline const char* const get_alias() const noexcept
174 {
175 return (char*)&pt1;
176 }
177
183 inline DeliveryType get_type() const noexcept
184 {
185 return (DeliveryType)((pt8 & 0xFF00000000000000) >> 56);
186 }
187
195 inline size_t hash_code() const noexcept
196 {
197 return o2::dcs::hash_code(std::string((char*)&pt1));
198 }
199
203 ~DataPointIdentifier() noexcept = default;
205};
206
215struct DPIDHash {
217 const
218 {
219 return dpid.hash_code();
220 }
221};
222} // namespace dcs
223
225namespace framework
226{
227template <typename T>
228struct is_messageable;
229template <>
230struct is_messageable<o2::dcs::DataPointIdentifier> : std::true_type {
231};
232} // namespace framework
233
234} // namespace o2
235
236// specailized std::hash
237namespace std
238{
239template <>
240struct hash<o2::dcs::DataPointIdentifier> {
241 std::size_t operator()(const o2::dcs::DataPointIdentifier& dpid) const
242 {
243 return std::hash<uint64_t>{}(dpid.hash_code());
244 }
245};
246
247template <>
248struct is_trivially_copyable<o2::dcs::DataPointIdentifier> : std::true_type {
249};
250
251} // namespace std
252
253#endif /* O2_DCS_DATAPOINT_IDENTIFIER_H */
ClassDefNV(DataPointIdentifier, 1)
DataPointIdentifier(const std::string &alias, const DeliveryType type) noexcept
friend std::ostream & operator<<(std::ostream &os, const DataPointIdentifier &dpid) noexcept
DeliveryType get_type() const noexcept
bool operator==(const DataPointIdentifier &other) const
static void FILL(const DataPointIdentifier &dpid, const std::string &alias, const DeliveryType type) noexcept
DataPointIdentifier(const DataPointIdentifier &src) noexcept
static void FILL(const DataPointIdentifier &dpid, const uint64_t *const data) noexcept
bool operator!=(const DataPointIdentifier &other) const
size_t hash_code() const noexcept
~DataPointIdentifier() noexcept=default
const char *const get_alias() const noexcept
DataPointIdentifier & operator=(const DataPointIdentifier &src) noexcept
GLenum src
Definition glcorearb.h:1767
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
GLboolean * data
Definition glcorearb.h:298
GLint GLuint mask
Definition glcorearb.h:291
uint64_t hash_code(const std::string &input) noexcept
std::string show(const DeliveryType type)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
uint64_t operator()(const o2::dcs::DataPointIdentifier &dpid) const
std::size_t operator()(const o2::dcs::DataPointIdentifier &dpid) const
VectorOfTObjectPtrs other