Skip to content
Snippets Groups Projects
Commit b4ed6340 authored by Felix Weiglhofer's avatar Felix Weiglhofer
Browse files

Unpack: Make BMON Unpacker thread-safe.

parent 6579588d
Branches
Tags
1 merge request!1242algo::Unpack: Unpack BMON and MUCH in parallel.
......@@ -19,15 +19,16 @@ namespace cbm::algo
// ---- Algorithm execution ---------------------------------------------
UnpackBmon::resultType UnpackBmon::operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
const uint64_t tTimeslice)
const uint64_t tTimeslice) const
{
// --- Output data
resultType result = {};
TimeSpec time;
// --- Current Timeslice start time in epoch units. Note that it is always a multiple of epochs
// --- and the epoch is a multiple of ns.
fCurrentTsTime = static_cast<uint64_t>(tTimeslice / critof001::kuEpochInNs) % critof001::kulEpochCycleEp;
time.currentTsTime = static_cast<uint64_t>(tTimeslice / critof001::kuEpochInNs) % critof001::kulEpochCycleEp;
// --- Number of messages in microslice
auto msSize = msDescr.size;
......@@ -76,11 +77,11 @@ namespace cbm::algo
switch (message[messageNr].getMessageType()) {
case critof001::MSG_HIT: {
ProcessHitMessage(message[messageNr], result.first, result.second);
ProcessHitMessage(message[messageNr], time, result.first, result.second);
break;
}
case critof001::MSG_EPOCH: {
ProcessEpochMessage(message[messageNr]);
ProcessEpochMessage(message[messageNr], time);
break;
}
case critof001::MSG_SLOWC: {
......@@ -104,8 +105,8 @@ namespace cbm::algo
// ----- Process hit message --------------------------------------------
inline void UnpackBmon::ProcessHitMessage(const critof001::Message& message, vector<CbmBmonDigi>& digiVec,
UnpackBmonMonitorData& monitor) const
inline void UnpackBmon::ProcessHitMessage(const critof001::Message& message, const TimeSpec& time,
vector<CbmBmonDigi>& digiVec, UnpackBmonMonitorData& monitor) const
{
// IGNORES:
// - Duplicate messages
......@@ -126,7 +127,7 @@ namespace cbm::algo
const uint32_t channel = message.getGdpbHitChanId();
const uint32_t channelUId = (elinkPar.fChannelUId)[channel];
double messageTime = message.getMsgFullTimeD(fCurrentEpochInTs) - elinkPar.fTimeOffset;
double messageTime = message.getMsgFullTimeD(time.currentEpochInTs) - elinkPar.fTimeOffset;
const double charge = (double) message.getGdpbHit32Tot(); //cast from uint32_t
// --- Create output digi
......@@ -136,14 +137,14 @@ namespace cbm::algo
// ----- Process an epoch message ---------------------------------------
inline void UnpackBmon::ProcessEpochMessage(const critof001::Message& message)
inline void UnpackBmon::ProcessEpochMessage(const critof001::Message& message, TimeSpec& time) const
{
const uint64_t epoch = message.getGdpbEpEpochNb();
// --- Calculate epoch relative to timeslice start time; correct for epoch cycles
if (fCurrentTsTime <= epoch) { fCurrentEpochInTs = epoch - fCurrentTsTime; }
if (time.currentTsTime <= epoch) { time.currentEpochInTs = epoch - time.currentTsTime; }
else {
fCurrentEpochInTs = epoch + critof001::kulEpochCycleEp - fCurrentTsTime;
time.currentEpochInTs = epoch + critof001::kulEpochCycleEp - time.currentTsTime;
}
//Problem if MS spans multiple epoch cycles?
}
......
......@@ -104,13 +104,18 @@ namespace cbm::algo
** @return STS digi data
**/
resultType operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
const uint64_t tTimeslice);
const uint64_t tTimeslice) const;
/** @brief Set the parameter container
** @param params Pointer to parameter container
**/
void SetParams(std::unique_ptr<UnpackBmonPar> params) { fParams = *(std::move(params)); }
private: // datatypes
struct TimeSpec {
uint64_t currentTsTime; ///< Unix time of timeslice in units of epoch length
uint32_t currentEpochInTs; ///< Current epoch number relative to timeslice start epoch
};
private: // methods
/** @brief Process a hit message
......@@ -118,18 +123,16 @@ namespace cbm::algo
** @param digiVec Vector to append the created digi to
** @param monitor Reference to monitor object
**/
void ProcessHitMessage(const critof001::Message& message, std::vector<CbmBmonDigi>& digiVec,
void ProcessHitMessage(const critof001::Message& message, const TimeSpec& time, std::vector<CbmBmonDigi>& digiVec,
UnpackBmonMonitorData& monitor) const;
/** @brief Process an epoch message (TS_MSB)
** @param message SMX message (32-bit word)
**/
void ProcessEpochMessage(const critof001::Message& message);
void ProcessEpochMessage(const critof001::Message& message, TimeSpec& time) const;
private: // members
uint64_t fCurrentTsTime = 0; ///< Unix time of timeslice in units of epoch length
uint32_t fCurrentEpochInTs = 0; ///< Current epoch number relative to timeslice start epoch
UnpackBmonPar fParams = {}; ///< Parameter container
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment