Project
Loading...
Searching...
No Matches
DataPointValue.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: DataPointValue.h
14 * Author: John Lång (john.larry.lang@cern.ch)
15 *
16 * Created on 23 September 2016, 12:20
17 */
18#ifndef O2_DCS_DATAPOINT_VALUE
19#define O2_DCS_DATAPOINT_VALUE
20
21#include <cstring>
22#include <cstdint>
23#include <ctime>
24#include <atomic>
25#include <string>
26#include <ostream>
27#include <sstream>
28#include <iostream>
29#include <iomanip>
30#include <memory>
31#include <stdexcept>
32#include "Rtypes.h"
34#include "DetectorsDCS/Clock.h"
36
37namespace o2
38{
39namespace dcs
40{
48struct DataPointValue final {
55 static constexpr uint16_t KEEP_ALIVE_FLAG = 0x0001;
56
62 static constexpr uint16_t END_FLAG = 0x0002;
63
69 static constexpr uint16_t FBI_FLAG = 0x0004;
70
78 static constexpr uint16_t NEW_FLAG = 0x0008;
79
89 static constexpr uint16_t DIRTY_FLAG = 0x0010;
90
97 static constexpr uint64_t TURN_FLAG = 0x0020;
98
104 static constexpr uint16_t WRITE_FLAG = 0x0040;
105
111 static constexpr uint16_t READ_FLAG = 0x0080;
112
120 static constexpr uint16_t OVERWRITE_FLAG = 0x0100;
121
130 static constexpr uint16_t VICTIM_FLAG = 0x0200;
131
139 static constexpr uint16_t DIM_ERROR_FLAG = 0x0400;
140
147 static constexpr uint16_t BAD_DPID_FLAG = 0x0800;
148
155 static constexpr uint16_t BAD_FLAGS_FLAG = 0x1000;
156
163 static constexpr uint16_t BAD_TIMESTAMP_FLAG = 0x2000;
164
170 static constexpr uint16_t BAD_PAYLOAD_FLAG = 0x4000;
171
179 static constexpr uint16_t BAD_FBI_FLAG = 0x8000;
180
189 static constexpr uint16_t SESSION_MASK = 0x0007;
190
202 static constexpr uint16_t CONTROL_MASK = 0x00F8;
203
220 static constexpr uint16_t ERROR_MASK = 0xFF00;
221
242
253
262
267
272
277
282
287
292
297
302 DataPointValue() = default;
303
311
334 [[deprecated]] DataPointValue(
335 const uint16_t flags,
336 const uint16_t milliseconds,
337 const uint32_t seconds,
338 const uint64_t* const payload) noexcept : flags(flags), msec(milliseconds), sec(seconds)
339 {
340 memcpy((void*)&payload_pt1, (void*)payload, 56);
341 }
342
364 const uint16_t flags,
365 const uint16_t milliseconds,
366 const uint32_t seconds,
367 const uint64_t* const payload,
368 const DeliveryType type)
369 : flags(flags), msec(milliseconds), sec(seconds)
370 {
371 set_payload(payload, type);
372 }
373
385 inline void set_payload(
386 const uint64_t* const data,
387 const DeliveryType type)
388 {
389 switch (type) {
390 case RAW_INT:
391 case DPVAL_INT:
392 case RAW_UINT:
393 case DPVAL_UINT:
394 case RAW_FLOAT:
395 case DPVAL_FLOAT:
396 this->payload_pt1 = data[0] & 0x00000000FFFFFFFF;
397 break;
398 case RAW_BOOL:
399 case DPVAL_BOOL:
400 this->payload_pt1 = (data[0] ? 1 : 0);
401 break;
402 case RAW_CHAR:
403 case DPVAL_CHAR:
404 this->payload_pt1 = data[0] & 0x00000000000000FF;
405 break;
406 case RAW_DOUBLE:
407 case DPVAL_DOUBLE:
408 case RAW_TIME:
409 case DPVAL_TIME:
410 this->payload_pt1 = data[0];
411 break;
412 case RAW_STRING:
413 case DPVAL_STRING:
414 std::strncpy((char*)&payload_pt1, (char*)data, 8);
415 std::strncpy((char*)&payload_pt2, (char*)data + 8, 8);
416 std::strncpy((char*)&payload_pt3, (char*)data + 16, 8);
417 std::strncpy((char*)&payload_pt4, (char*)data + 24, 8);
418 std::strncpy((char*)&payload_pt5, (char*)data + 32, 8);
419 std::strncpy((char*)&payload_pt6, (char*)data + 40, 8);
420 std::strncpy((char*)&payload_pt7, (char*)data + 48, 8);
421 break;
422 case RAW_BINARY:
423 case DPVAL_BINARY:
424 memcpy((void*)&payload_pt1, (void*)data, 56);
425 case VOID:
426 break;
427 default:
428 throw std::domain_error("Invalid DeliveryType.");
429 }
430 }
431
437 inline uint16_t get_flags() const noexcept
438 {
439 return flags;
440 }
441
446 inline void update_timestamp() noexcept
447 {
448 const uint64_t current_time(o2::dcs::epoch_time());
449 msec = current_time % 1000;
450 sec = current_time / 1000;
451 }
452
463 inline std::unique_ptr<std::string> get_timestamp() const noexcept
464 {
465#if defined(__linux__) || defined(__APPLE__)
466 // time_t should be uint64_t (compatible) on 64-bit Linux platforms:
467 char buffer[33];
468 std::time_t ts((uint64_t)sec);
469 std::strftime(buffer, 32, "%FT%T", std::gmtime(&ts));
470 std::ostringstream oss;
471 oss << std::string(buffer) << "." << std::setw(3) << std::setfill('0') << std::to_string(msec) << "Z";
472 return std::make_unique<std::string>(
473 std::move(oss.str()));
474#else
475 return std::make_unique<std::string>("Unsupported platform");
476#endif
477 }
478
485 inline uint64_t get_epoch_time() const noexcept
486 {
487 return (((uint64_t)sec) * 1000) + msec;
488 }
489
504
511 inline bool operator==(const DataPointValue& other) const noexcept
512 {
513 return memcmp((void*)this, (void*)&other, sizeof(DataPointValue)) == 0;
514 }
515
522 inline bool operator!=(const DataPointValue& other) const noexcept
523 {
524 return !(*this == other);
525 }
526
543 inline void set(
544 const uint16_t flags,
545 const uint16_t milliseconds,
546 const uint32_t seconds,
547 const uint64_t* const payload,
548 const DeliveryType type)
549 {
550 this->flags = flags;
551 this->msec = milliseconds;
552 this->sec = seconds;
553 set_payload(payload, type);
554 }
555
571 inline void set(
572 const uint16_t milliseconds,
573 const uint32_t seconds,
574 const uint64_t* const payload,
575 const DeliveryType type)
576 {
577 msec = milliseconds;
578 sec = seconds;
579 set_payload(payload, type);
580 }
581
596 inline void set(
597 const uint64_t* const data,
598 const DeliveryType type)
599 {
600 this->flags = data[0];
601 this->msec = data[0] >> 16;
602 this->sec = data[0] >> 32;
603 set_payload(data + 1, type);
604 }
605
612 friend inline std::ostream& operator<<(std::ostream& os,
613 const DataPointValue& dpval) noexcept
614 {
615 return os << ((dpval.flags & KEEP_ALIVE_FLAG) ? "A" : "-")
616 << ((dpval.flags & END_FLAG) ? "Z" : "-")
617 << ((dpval.flags & FBI_FLAG) ? "M" : "-")
618 << ((dpval.flags & NEW_FLAG) ? "N" : "-")
619 << ((dpval.flags & DIRTY_FLAG) ? "D" : "-")
620 << ((dpval.flags & TURN_FLAG) ? "U" : "-")
621 << ((dpval.flags & WRITE_FLAG) ? "W" : "-")
622 << ((dpval.flags & READ_FLAG) ? "R " : "- ")
623 << ((dpval.flags & OVERWRITE_FLAG) ? "O" : "-")
624 << ((dpval.flags & VICTIM_FLAG) ? "V" : "-")
625 << ((dpval.flags & DIM_ERROR_FLAG) ? "E" : "-")
626 << ((dpval.flags & BAD_DPID_FLAG) ? "I" : "-")
627 << ((dpval.flags & BAD_FLAGS_FLAG) ? "F" : "-")
628 << ((dpval.flags & BAD_TIMESTAMP_FLAG) ? "T" : "-")
629 << ((dpval.flags & BAD_PAYLOAD_FLAG) ? "P" : "-")
630 << ((dpval.flags & BAD_FBI_FLAG) ? "B;" : "-;")
631 << *(dpval.get_timestamp());
632 }
633
646 inline void acquire_write_lock()
647 {
648 flags |= WRITE_FLAG;
649 flags |= TURN_FLAG;
650 while (flags & READ_FLAG && flags & TURN_FLAG) {
651 }
652 }
653
665 inline void release_write_lock()
666 {
667 flags &= ~WRITE_FLAG;
668 }
669
682 inline void acquire_read_lock()
683 {
684 flags |= READ_FLAG;
685 flags &= ~TURN_FLAG;
686 while (flags & WRITE_FLAG && !(flags & TURN_FLAG)) {
687 }
688 }
689
701 inline void release_read_lock()
702 {
703 flags &= ~READ_FLAG;
704 }
706};
707} // namespace dcs
708} // namespace o2
709
710#endif /* O2_DCS_DATAPOINT_VALUE_H */
unsigned short int uint16_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
uint64_t epoch_time() noexcept
Definition Clock.h:54
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
DataPointValue(const DataPointValue &other)=default
uint64_t get_epoch_time() const noexcept
void set_payload(const uint64_t *const data, const DeliveryType type)
void set(const uint16_t milliseconds, const uint32_t seconds, const uint64_t *const payload, const DeliveryType type)
static constexpr uint16_t BAD_TIMESTAMP_FLAG
static constexpr uint16_t WRITE_FLAG
static constexpr uint16_t DIRTY_FLAG
static constexpr uint64_t TURN_FLAG
void update_timestamp() noexcept
DataPointValue & operator=(const DataPointValue &other)=default
static constexpr uint16_t FBI_FLAG
static constexpr uint16_t END_FLAG
static constexpr uint16_t BAD_PAYLOAD_FLAG
static constexpr uint16_t ERROR_MASK
uint16_t get_flags() const noexcept
static constexpr uint16_t BAD_DPID_FLAG
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 KEEP_ALIVE_FLAG
bool operator==(const DataPointValue &other) const noexcept
DataPointValue(const uint16_t flags, const uint16_t milliseconds, const uint32_t seconds, const uint64_t *const payload) noexcept
void set(const uint64_t *const data, const DeliveryType type)
static constexpr uint16_t DIM_ERROR_FLAG
static constexpr uint16_t SESSION_MASK
static constexpr uint16_t OVERWRITE_FLAG
friend std::ostream & operator<<(std::ostream &os, const DataPointValue &dpval) noexcept
std::unique_ptr< std::string > get_timestamp() const noexcept
static constexpr uint16_t BAD_FBI_FLAG
static constexpr uint16_t VICTIM_FLAG
static constexpr uint16_t BAD_FLAGS_FLAG
DataPointValue(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
static constexpr uint16_t READ_FLAG
static constexpr uint16_t NEW_FLAG
bool operator!=(const DataPointValue &other) const noexcept
ClassDefNV(DataPointValue, 1)
VectorOfTObjectPtrs other