CbmRoot
Loading...
Searching...
No Matches
CbmTbDaqBuffer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2013-2020 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese, Norbert Herrmann [committer] */
4
10#include "CbmTbDaqBuffer.h"
11
12#include <Logger.h> // for Logger, LOG
13
14#include <boost/any.hpp>
15
16#include <iomanip> // for setprecision, __iom_t5
17#include <sstream> // for basic_stringstream<>::string_type
18
19#include <stddef.h> // for NULL
20
21// ----- Initialisation of static variables ------------------------------
23// ---------------------------------------------------------------------------
24
25
26// ----- Constructor -----------------------------------------------------
28// ---------------------------------------------------------------------------
29
30
31// ----- Destructor ------------------------------------------------------
33// ---------------------------------------------------------------------------
34
36{
37 if (!GetSize()) return -1.;
38 // Return the key from the first element in the map
39 // The key of the map is the time of digi
40 return fData.begin()->first;
41}
42
44{
45 if (!GetSize()) return -1.;
46 // Return the key from the last element in the map
47 // The key of the map is the time of digi
48 return (--fData.end())->first;
49}
50
51// ----- Access to next data ---------------------------------------------
53{
54
55 // --- Check for empty buffer
56 if (!fData.size()) return std::make_pair(boost::any(), ECbmModuleId::kNotExist);
57
58 // --- Get data from buffer
59 std::multimap<Double_t, std::pair<boost::any, ECbmModuleId>>::iterator it = fData.begin();
60 Double_t digi_time = it->first;
61
62 if (digi_time < time) {
63 boost::any digi = it->second.first;
64 ECbmModuleId sysID = it->second.second;
65 fData.erase(it);
66 return std::make_pair(digi, sysID);
67 }
68 return std::make_pair(boost::any(), ECbmModuleId::kNotExist);
69}
70// ---------------------------------------------------------------------------
71
72// ----- Instance --------------------------------------------------------
78// ---------------------------------------------------------------------------
79
80// ----- Print status ----------------------------------------------------
82{
83 Int_t size = GetSize();
84 std::stringstream ss;
85 ss << "CbmTbDaqBuffer: Status ";
86 if (!size) {
87 LOG(info) << ss.str() << "empty";
88 return;
89 }
90 LOG(info) << ss.str() << GetSize() << " digis from " << std::fixed << std::setprecision(9) << GetTimeFirst() * 1.e-9
91 << " s to " << GetTimeLast() * 1.e-9 << " s";
92}
93// ---------------------------------------------------------------------------
ECbmModuleId
Definition CbmDefs.h:39
@ kNotExist
If not found.
static constexpr size_t size()
Definition KfSimdPseudo.h:2
Singleton buffer class for CBM raw data.
Double_t GetTimeLast() const
Data GetNextData(Double_t time)
std::multimap< Double_t, Data > fData
static CbmTbDaqBuffer * Instance()
Int_t GetSize() const
std::pair< boost::any, ECbmModuleId > Data
void PrintStatus() const
Double_t GetTimeFirst() const
static CbmTbDaqBuffer * fgInstance