Skip to content
Snippets Groups Projects
Commit 3289c59b authored by Felix Weiglhofer's avatar Felix Weiglhofer Committed by Dominik Smith
Browse files

UnpackTof: Make thread-safe.

parent d9b8b7c4
No related branches found
No related tags found
1 merge request!1219algo: Unpack TOF and STS in parallel.
...@@ -18,15 +18,16 @@ namespace cbm::algo ...@@ -18,15 +18,16 @@ namespace cbm::algo
// ---- Algorithm execution --------------------------------------------- // ---- Algorithm execution ---------------------------------------------
UnpackTof::resultType UnpackTof::operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr, UnpackTof::resultType UnpackTof::operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
const uint64_t tTimeslice) const uint64_t tTimeslice) const
{ {
// --- Output data // --- Output data
resultType result = {}; resultType result = {};
TimeSpec time = {};
// --- Current Timeslice start time in epoch units. Note that it is always a multiple of epochs // --- Current Timeslice start time in epoch units. Note that it is always a multiple of epochs
// --- and the epoch is a multiple of ns. // --- 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 // --- Number of messages in microslice
auto msSize = msDescr.size; auto msSize = msDescr.size;
...@@ -72,11 +73,11 @@ namespace cbm::algo ...@@ -72,11 +73,11 @@ namespace cbm::algo
switch (message[messageNr].getMessageType()) { switch (message[messageNr].getMessageType()) {
case critof001::MSG_HIT: { case critof001::MSG_HIT: {
ProcessHitMessage(message[messageNr], result.first, result.second); ProcessHitMessage(message[messageNr], result.first, result.second, time);
break; break;
} }
case critof001::MSG_EPOCH: { case critof001::MSG_EPOCH: {
ProcessEpochMessage(message[messageNr]); ProcessEpochMessage(message[messageNr], time);
break; break;
} }
case critof001::MSG_SLOWC: { case critof001::MSG_SLOWC: {
...@@ -101,7 +102,7 @@ namespace cbm::algo ...@@ -101,7 +102,7 @@ namespace cbm::algo
// ----- Process hit message -------------------------------------------- // ----- Process hit message --------------------------------------------
inline void UnpackTof::ProcessHitMessage(const critof001::Message& message, vector<CbmTofDigi>& digiVec, inline void UnpackTof::ProcessHitMessage(const critof001::Message& message, vector<CbmTofDigi>& digiVec,
UnpackTofMonitorData& monitor) const UnpackTofMonitorData& monitor, TimeSpec& time) const
{ {
// --- Check eLink and get parameters // --- Check eLink and get parameters
const uint32_t elink = message.getGet4Idx(); const uint32_t elink = message.getGet4Idx();
...@@ -114,7 +115,7 @@ namespace cbm::algo ...@@ -114,7 +115,7 @@ namespace cbm::algo
const uint32_t channel = message.getGdpbHitChanId(); const uint32_t channel = message.getGdpbHitChanId();
const uint32_t channelUId = (elinkPar.fChannelUId)[channel]; 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 const double charge = (double) message.getGdpbHit32Tot(); //cast from uint32_t
// --- Create output digi // --- Create output digi
...@@ -124,14 +125,14 @@ namespace cbm::algo ...@@ -124,14 +125,14 @@ namespace cbm::algo
// ----- Process an epoch message --------------------------------------- // ----- Process an epoch message ---------------------------------------
inline void UnpackTof::ProcessEpochMessage(const critof001::Message& message) inline void UnpackTof::ProcessEpochMessage(const critof001::Message& message, TimeSpec& time) const
{ {
const uint64_t epoch = message.getGdpbEpEpochNb(); const uint64_t epoch = message.getGdpbEpEpochNb();
// --- Calculate epoch relative to timeslice start time; correct for epoch cycles // --- 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 { else {
fCurrentEpochInTs = epoch + critof001::kulEpochCycleEp - fCurrentTsTime; time.currentEpochInTs = epoch + critof001::kulEpochCycleEp - time.currentTsTime;
} }
//Problem if MS spans multiple epoch cycles? //Problem if MS spans multiple epoch cycles?
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <vector> #include <vector>
#include "CriGet4Mess001.h" #include "CriGet4Mess001.h"
#include "Prelude.h"
namespace cbm::algo namespace cbm::algo
{ {
...@@ -96,13 +97,19 @@ namespace cbm::algo ...@@ -96,13 +97,19 @@ namespace cbm::algo
** @return STS digi data ** @return STS digi data
**/ **/
resultType operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr, resultType operator()(const uint8_t* msContent, const fles::MicrosliceDescriptor& msDescr,
const uint64_t tTimeslice); const uint64_t tTimeslice) const;
/** @brief Set the parameter container /** @brief Set the parameter container
** @param params Pointer to parameter container ** @param params Pointer to parameter container
**/ **/
void SetParams(std::unique_ptr<UnpackTofPar> params) { fParams = *(std::move(params)); } void SetParams(std::unique_ptr<UnpackTofPar> params) { fParams = *(std::move(params)); }
private: // types
struct TimeSpec {
u64 currentTsTime = 0; ///< Unix time of timeslice in units of epoch length
u32 currentEpochInTs = 0; ///< Current epoch number relative to timeslice start epoch
};
private: // methods private: // methods
/** @brief Process a hit message /** @brief Process a hit message
** @param message SMX message (32-bit word) ** @param message SMX message (32-bit word)
...@@ -110,16 +117,14 @@ namespace cbm::algo ...@@ -110,16 +117,14 @@ namespace cbm::algo
** @param monitor Reference to monitor object ** @param monitor Reference to monitor object
**/ **/
void ProcessHitMessage(const critof001::Message& message, std::vector<CbmTofDigi>& digiVec, void ProcessHitMessage(const critof001::Message& message, std::vector<CbmTofDigi>& digiVec,
UnpackTofMonitorData& monitor) const; UnpackTofMonitorData& monitor, TimeSpec& time) const;
/** @brief Process an epoch message /** @brief Process an epoch message
** @param message SMX message (32-bit word) ** @param message SMX message (32-bit word)
**/ **/
void ProcessEpochMessage(const critof001::Message& message); void ProcessEpochMessage(const critof001::Message& message, TimeSpec& time) const;
private: // members 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
UnpackTofPar fParams = {}; ///< Parameter container UnpackTofPar fParams = {}; ///< Parameter container
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment