Skip to content

Commit 01c2aef

Browse files
committed
Add compatibility layer for FairMQ 1.3
1 parent 9bea58d commit 01c2aef

13 files changed

Lines changed: 70 additions & 12 deletions

File tree

CCDB/src/ConditionsMQClient.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "CCDB/BackendOCDB.h"
2222
#include "CCDB/BackendRiak.h"
2323
#include "CCDB/ConditionsMQClient.h"
24+
#include "O2Device/Compatibility.h"
25+
2426
#include <FairMQLogger.h>
2527
#include <options/FairMQProgOptions.h>
2628

@@ -52,7 +54,7 @@ void ConditionsMQClient::Run()
5254
{
5355
Backend* backend;
5456

55-
while (CheckCurrentState(RUNNING)) {
57+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
5658

5759
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
5860
boost::posix_time::ptime startTime = boost::posix_time::microsec_clock::local_time();

CCDB/src/ConditionsMQServer.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "CCDB/Condition.h"
2222
#include "CCDB/ConditionsMQServer.h"
2323
#include "CCDB/IdPath.h"
24+
#include "O2Device/Compatibility.h"
2425
#include <FairMQLogger.h>
2526
#include <FairMQPoller.h>
2627

@@ -92,7 +93,7 @@ void ConditionsMQServer::Run()
9293
std::unique_ptr<FairMQPoller> poller(
9394
fTransportFactory->CreatePoller(fChannels, { "data-put", "data-get", "broker-get" }));
9495

95-
while (CheckCurrentState(RUNNING)) {
96+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
9697

9798
poller->Poll(-1);
9899

Examples/flp2epn-distributed/src/EPNReceiver.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <options/FairMQProgOptions.h>
2424

2525
#include "FLP2EPNex_distributed/EPNReceiver.h"
26+
#include "O2Device/Compatibility.h"
2627

2728
#include <iomanip>
2829

@@ -110,7 +111,7 @@ void EPNReceiver::Run()
110111

111112
FairMQChannel& ackOutChannel = fChannels.at(mAckChannelName).at(0);
112113

113-
while (CheckCurrentState(RUNNING)) {
114+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
114115
FairMQParts parts;
115116

116117
if (Receive(parts, mInChannelName, 0, 100) > 0) {

Examples/flp2epn-distributed/src/FLPSender.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <options/FairMQProgOptions.h>
2424

2525
#include "FLP2EPNex_distributed/FLPSender.h"
26+
#include "O2Device/Compatibility.h"
2627

2728
using namespace std;
2829
using namespace std::chrono;
@@ -71,7 +72,7 @@ void FLPSender::Run()
7172
// store the channel reference to avoid traversing the map on every loop iteration
7273
FairMQChannel& dataInChannel = fChannels.at(mInChannelName).at(0);
7374

74-
while (CheckCurrentState(RUNNING)) {
75+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
7576
// initialize f2e header
7677
auto* header = new f2eHeader;
7778
if (mTestMode > 0) {

Utilities/DataFlow/src/EPNReceiverDevice.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "DataFlow/EPNReceiverDevice.h"
2020
#include "Headers/DataHeader.h"
2121
#include "Headers/SubframeMetadata.h"
22+
#include "O2Device/Compatibility.h"
2223
#include "TimeFrame/TimeFrame.h"
2324

2425
#include <iomanip>
@@ -91,7 +92,7 @@ void EPNReceiverDevice::Run()
9192
std::multimap<TimeframeId, IndexElement> index;
9293
std::multimap<TimeframeId, FlpId> flpIds;
9394

94-
while (CheckCurrentState(RUNNING)) {
95+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
9596
FairMQParts subtimeframeParts;
9697
if (Receive(subtimeframeParts, mInChannelName, 0, 100) <= 0)
9798
continue;

Utilities/DataFlow/src/FLPSenderDevice.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Headers/DataHeader.h"
1919
#include "Headers/SubframeMetadata.h"
2020
#include "DataFlow/FLPSenderDevice.h"
21+
#include "O2Device/Compatibility.h"
2122

2223
using namespace std;
2324
using namespace std::chrono;
@@ -45,7 +46,7 @@ void FLPSenderDevice::Run()
4546
// store the channel reference to avoid traversing the map on every loop iteration
4647
//FairMQChannel& dataInChannel = fChannels.at(fInChannelName).at(0);
4748

48-
while (CheckCurrentState(RUNNING)) {
49+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
4950
// - Get the SubtimeframeMetadata
5051
// - Add the current FLP id to the SubtimeframeMetadata
5152
// - Forward to the EPN the whole subtimeframe

Utilities/DataFlow/src/TimeframeValidatorDevice.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "TimeFrame/TimeFrame.h"
2121
#include "Headers/SubframeMetadata.h"
2222
#include "Headers/DataHeader.h"
23+
#include "O2Device/Compatibility.h"
2324

2425
#include <options/FairMQProgOptions.h>
2526

@@ -41,7 +42,7 @@ void o2::data_flow::TimeframeValidatorDevice::InitTask()
4142

4243
void o2::data_flow::TimeframeValidatorDevice::Run()
4344
{
44-
while (CheckCurrentState(RUNNING)) {
45+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this)) {
4546
FairMQParts timeframeParts;
4647
if (Receive(timeframeParts, mInChannelName, 0, 100) <= 0)
4748
continue;

Utilities/DataFlow/src/TimeframeWriterDevice.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "TimeFrame/TimeFrame.h"
2222
#include "Headers/SubframeMetadata.h"
2323
#include "Headers/DataHeader.h"
24+
#include "O2Device/Compatibility.h"
25+
2426
#include <options/FairMQProgOptions.h>
2527
#include <boost/filesystem.hpp>
2628

@@ -55,7 +57,7 @@ void TimeframeWriterDevice::Run()
5557
boost::filesystem::path p(mOutFileName);
5658
size_t streamedTimeframes = 0;
5759
bool needsNewFile = true;
58-
while (CheckCurrentState(RUNNING) && mFileCount < mMaxFiles) {
60+
while (compatibility::FairMQ13<FairMQDevice>::IsRunning(this) && mFileCount < mMaxFiles) {
5961
// In case we need to process more than one file,
6062
// the filename is split in basename and extension
6163
// and we call the files `<basename><count>.<extension>`.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
#ifndef ALICEO2_UTILITIES_O2DEVICE_COMPATIBILITY_H_
11+
#define ALICEO2_UTILITIES_O2DEVICE_COMPATIBILITY_H_
12+
13+
#include <type_traits>
14+
15+
namespace o2
16+
{
17+
namespace compatibility
18+
{
19+
20+
template <typename T>
21+
class FairMQ13
22+
{
23+
private:
24+
template <typename C>
25+
static std::true_type test(decltype(&C::NewStatePending));
26+
template <typename C>
27+
static std::false_type test(...);
28+
29+
public:
30+
static bool IsRunning(T* device)
31+
{
32+
if constexpr (std::is_same_v<decltype(test<T>(0)), std::true_type>) {
33+
return device->NewStatePending();
34+
} else if constexpr (std::is_same_v<decltype(test<T>(0)), std::false_type>) {
35+
return device->CheckCurrentState(T::RUNNING);
36+
}
37+
}
38+
};
39+
40+
} // namespace compatibility
41+
} // namespace o2
42+
43+
#endif // ALICEO2_UTILITIES_O2DEVICE_COMPATIBILITY_H_

Utilities/O2MessageMonitor/src/O2MessageMonitor.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
#include <FairMQLogger.h>
3232
#include <options/FairMQProgOptions.h>
3333
#include "O2MessageMonitor/O2MessageMonitor.h"
34+
#include "O2Device/Compatibility.h"
3435

3536
using namespace std;
3637
using namespace o2::header;
3738
using namespace o2::base;
39+
using namespace o2::compatibility;
3840

3941
//__________________________________________________________________________________________________
4042
void O2MessageMonitor::InitTask()
@@ -60,7 +62,7 @@ void O2MessageMonitor::Run()
6062

6163
auto dataResource = o2::pmr::getTransportAllocator(subChannels[0].Transport());
6264

63-
while (CheckCurrentState(RUNNING) && (--mIterations) != 0) {
65+
while (FairMQ13<FairMQDevice>::IsRunning(this) && (--mIterations) != 0) {
6466
this_thread::sleep_for(chrono::milliseconds(mDelay));
6567

6668
O2Message message;

0 commit comments

Comments
 (0)