Newer
Older
/* Copyright (C) 2013-2020 PI-UHd, GSI
SPDX-License-Identifier: GPL-3.0-only
Authors: Volker Friese, Norbert Herrmann [committer] */
/** @file CbmTbDaqBuffer.cxx
** @author Volker Friese <v.friese@gsi.de>
** @date 13 December 2013
**/
#include "CbmTbDaqBuffer.h"
#include <iomanip> // for setprecision, __iom_t5
#include <sstream> // for basic_stringstream<>::string_type
// ----- Initialisation of static variables ------------------------------
CbmTbDaqBuffer* CbmTbDaqBuffer::fgInstance = nullptr;
// ---------------------------------------------------------------------------
// ----- Constructor -----------------------------------------------------
// ---------------------------------------------------------------------------
// ----- Destructor ------------------------------------------------------
// ---------------------------------------------------------------------------
Double_t CbmTbDaqBuffer::GetTimeFirst() const
{
// Return the key from the first element in the map
// The key of the map is the time of digi
return fData.begin()->first;
}
Double_t CbmTbDaqBuffer::GetTimeLast() const
{
// Return the key from the last element in the map
// The key of the map is the time of digi
return (--fData.end())->first;
}
// ----- Access to next data ---------------------------------------------
CbmTbDaqBuffer::Data CbmTbDaqBuffer::GetNextData(Double_t time)
{
// --- Check for empty buffer
if (!fData.size()) return std::make_pair(boost::any(), ECbmModuleId::kNotExist);
std::multimap<Double_t, std::pair<boost::any, ECbmModuleId>>::iterator it = fData.begin();
Double_t digi_time = it->first;
if (digi_time < time) {
boost::any digi = it->second.first;
ECbmModuleId sysID = it->second.second;
fData.erase(it);
return std::make_pair(digi, sysID);
}
return std::make_pair(boost::any(), ECbmModuleId::kNotExist);
}
// ---------------------------------------------------------------------------
// ----- Instance --------------------------------------------------------
CbmTbDaqBuffer* CbmTbDaqBuffer::Instance()
{
return fgInstance;
}
// ---------------------------------------------------------------------------
// ----- Print status ----------------------------------------------------
void CbmTbDaqBuffer::PrintStatus() const
{
Int_t size = GetSize();
std::stringstream ss;
ss << "CbmTbDaqBuffer: Status ";
LOG(info) << ss.str() << "empty";
return;
}
LOG(info) << ss.str() << GetSize() << " digis from " << std::fixed << std::setprecision(9) << GetTimeFirst() * 1.e-9
<< " s to " << GetTimeLast() * 1.e-9 << " s";
}
// ---------------------------------------------------------------------------