Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(SRCS
src/DriverControl.cxx
src/DriverInfo.cxx
src/FairOptionsRetriever.cxx
src/FairMQDeviceProxy.cxx
src/GraphvizHelpers.cxx
src/InputRecord.cxx
src/LocalRootFileService.cxx
Expand Down
27 changes: 15 additions & 12 deletions Framework/Core/include/Framework/DataAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@
#ifndef FRAMEWORK_DATAALLOCATOR_H
#define FRAMEWORK_DATAALLOCATOR_H

#include <fairmq/FairMQDevice.h>
#include "Headers/DataHeader.h"
#include "Framework/Output.h"
#include "Framework/OutputRef.h"
#include "Framework/OutputRoute.h"
#include "Framework/DataChunk.h"
#include "Framework/FairMQDeviceProxy.h"
#include "Framework/MessageContext.h"
#include "Framework/RootObjectContext.h"
#include "Framework/TMessageSerializer.h"
#include "Framework/TypeTraits.h"
#include "Framework/SerializationMethods.h"

#include "fairmq/FairMQMessage.h"

#include <vector>
#include <map>
#include <string>
Expand All @@ -34,6 +32,10 @@

#include <TClass.h>

// Do not change this for a full inclusion of FairMQDevice.
class FairMQDevice;
class FairMQMessage;

namespace o2 {
namespace framework {

Expand All @@ -50,7 +52,7 @@ class DataAllocator
using DataDescription = o2::header::DataDescription;
using SubSpecificationType = o2::header::DataHeader::SubSpecificationType;

DataAllocator(FairMQDevice *device,
DataAllocator(FairMQDeviceProxy device,
MessageContext *context,
RootObjectContext *rootContext,
const AllowedOutputRoutes &routes);
Expand Down Expand Up @@ -162,9 +164,9 @@ class DataAllocator
typename std::enable_if<has_root_dictionary<T>::value == true && is_messageable<T>::value == false, void>::type
snapshot(const Output& spec, T& object)
{
FairMQMessagePtr payloadMessage(mDevice->NewMessage());
FairMQMessagePtr payloadMessage(mProxy.createMessage());
auto* cl = TClass::GetClass(typeid(T));
mDevice->Serialize<TMessageSerializer>(*payloadMessage, &object, cl);
TMessageSerializer().Serialize(*payloadMessage, &object, cl);

addPartToContext(std::move(payloadMessage), spec, o2::header::gSerializationMethodROOT);
}
Expand All @@ -186,7 +188,7 @@ class DataAllocator
std::is_void<typename W::hint_type>::value, //
"class hint must be of type TClass or const char");

FairMQMessagePtr payloadMessage(mDevice->NewMessage());
FairMQMessagePtr payloadMessage(mProxy.createMessage());
const TClass* cl = nullptr;
if (wrapper.getHint() == nullptr) {
// get TClass info by wrapped type
Expand All @@ -207,7 +209,7 @@ class DataAllocator
}
throw std::runtime_error(msg);
}
mDevice->Serialize<TMessageSerializer>(*payloadMessage, &wrapper(), cl);
TMessageSerializer().Serialize(*payloadMessage, &wrapper(), cl);
addPartToContext(std::move(payloadMessage), spec, o2::header::gSerializationMethodROOT);
}

Expand All @@ -221,7 +223,7 @@ class DataAllocator
typename std::enable_if<is_messageable<T>::value == true, void>::type
snapshot(const Output& spec, T const& object)
{
FairMQMessagePtr payloadMessage(mDevice->NewMessage(sizeof(T)));
FairMQMessagePtr payloadMessage(mProxy.createMessage(sizeof(T)));
memcpy(payloadMessage->GetData(), &object, sizeof(T));

addPartToContext(std::move(payloadMessage), spec, o2::header::gSerializationMethodNone);
Expand All @@ -238,7 +240,7 @@ class DataAllocator
snapshot(const Output& spec, C const& v)
{
auto sizeInBytes = sizeof(typename C::value_type) * v.size();
FairMQMessagePtr payloadMessage(mDevice->NewMessage(sizeInBytes));
FairMQMessagePtr payloadMessage(mProxy.createMessage(sizeInBytes));

typename C::value_type *tmp = const_cast<typename C::value_type*>(v.data());
memcpy(payloadMessage->GetData(), reinterpret_cast<void*>(tmp), sizeInBytes);
Expand All @@ -260,7 +262,7 @@ class DataAllocator
using ElementType = typename std::remove_pointer<typename C::value_type>::type;
constexpr auto elementSizeInBytes = sizeof(ElementType);
auto sizeInBytes = elementSizeInBytes * v.size();
FairMQMessagePtr payloadMessage(mDevice->NewMessage(sizeInBytes));
FairMQMessagePtr payloadMessage(mProxy.createMessage(sizeInBytes));

auto target = reinterpret_cast<unsigned char*>(payloadMessage->GetData());
for (auto const & pointer : v) {
Expand Down Expand Up @@ -332,7 +334,8 @@ class DataAllocator
}

private:
FairMQDevice* mDevice;
FairMQDeviceProxy mProxy;
FairMQDevice *mDevice;
AllowedOutputRoutes mAllowedOutputRoutes;
MessageContext* mContext;
RootObjectContext* mRootContext;
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/include/Framework/DataRelayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#ifndef FRAMEWORK_DATARELAYER_H
#define FRAMEWORK_DATARELAYER_H

#include <fairmq/FairMQMessage.h>
#include "Framework/InputRoute.h"
#include "Framework/ForwardRoute.h"
#include <cstddef>
#include <vector>

class FairMQMessage;

namespace o2 {
namespace framework {

Expand Down
50 changes: 50 additions & 0 deletions Framework/Core/include/Framework/FairMQDeviceProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef FRAMEWORK_FAIRMQDEVICEPROXY_H
#define FRAMEWORK_FAIRMQDEVICEPROXY_H

#include <memory>

class FairMQDevice;
class FairMQMessage;
class FairMQTransportFactory;

namespace o2
{
namespace framework
{
/// Helper class to hide FairMQDevice headers in the DataAllocator header.
/// This is done because FairMQDevice brings in a bunch of boost.mpl /
/// boost.fusion stuff, slowing down compilation times enourmously.
class FairMQDeviceProxy
{
public:
FairMQDeviceProxy(FairMQDevice *device)
: mDevice{device}
{}

/// To be used in DataAllocator.cxx to avoid reimplenting any device
/// API.
FairMQDevice *getDevice() {
return mDevice;
}

/// Looks like what we really need in the headers is just the transport.
const FairMQTransportFactory* getTransport();
std::unique_ptr<FairMQMessage> createMessage() const;
std::unique_ptr<FairMQMessage> createMessage(const size_t size) const;
private:
FairMQDevice* mDevice;
};

} // namespace framework
} // namespace o2

#endif // FRAMEWORK_FAIRMQDEVICEPROXY_H
5 changes: 2 additions & 3 deletions Framework/Core/include/Framework/InputRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include "Framework/InputRoute.h"
#include "Framework/TypeTraits.h"

#include <fairmq/FairMQMessage.h>
#include <Framework/TMessageSerializer.h>

#include <TClass.h>

#include <iterator>
Expand All @@ -29,6 +26,8 @@
#include <memory>
#include <type_traits>

class FairMQMessage;

namespace o2
{
namespace framework
Expand Down
11 changes: 6 additions & 5 deletions Framework/Core/include/Framework/RootObjectContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,28 @@
#ifndef FRAMEWORK_ROOTOBJETCONTEXT_H
#define FRAMEWORK_ROOTOBJETCONTEXT_H

#include <fairmq/FairMQMessage.h>
#include <TObject.h>

#include <vector>
#include <cassert>
#include <string>
#include <memory>

class TObject;
class FairMQMessage;

namespace o2 {
namespace framework {

class RootObjectContext {
public:
struct MessageRef {
FairMQMessagePtr header;
std::unique_ptr<FairMQMessage> header;
std::unique_ptr<TObject> payload;
std::string channel;
};

using Messages = std::vector<MessageRef>;

void addObject(FairMQMessagePtr header,
void addObject(std::unique_ptr<FairMQMessage> header,
std::unique_ptr<TObject> obj,
const std::string &channel)
{
Expand Down
9 changes: 7 additions & 2 deletions Framework/Core/src/DataAllocator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@
#include "Framework/RootObjectContext.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/DataProcessingHeader.h"

#include <fairmq/FairMQDevice.h>

#include <TClonesArray.h>


namespace o2 {
namespace framework {

using DataHeader = o2::header::DataHeader;
using DataDescription = o2::header::DataDescription;
using DataProcessingHeader = o2::framework::DataProcessingHeader;

DataAllocator::DataAllocator(FairMQDevice *device,
DataAllocator::DataAllocator(FairMQDeviceProxy proxy,
MessageContext *context,
RootObjectContext *rootContext,
const AllowedOutputRoutes &routes)
: mDevice{device},
: mProxy{proxy},
mDevice{proxy.getDevice()},
mAllowedOutputRoutes{routes},
mContext{context},
mRootContext{rootContext}
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Framework/DataProcessor.h"
#include "Framework/DataSpecUtils.h"
#include "Framework/FairOptionsRetriever.h"
#include "Framework/FairMQDeviceProxy.h"
#include "Framework/MetricsService.h"
#include "Framework/CallbackService.h"
#include "Framework/TMessageSerializer.h"
Expand All @@ -39,7 +40,7 @@ DataProcessingDevice::DataProcessingDevice(const DeviceSpec &spec,
mStatelessProcess{spec.algorithm.onProcess},
mError{spec.algorithm.onError},
mConfigRegistry{nullptr},
mAllocator{this, &mContext, &mRootContext, spec.outputs},
mAllocator{FairMQDeviceProxy{this}, &mContext, &mRootContext, spec.outputs},
mRelayer{spec.inputs, spec.forwards, registry.get<MetricsService>()},
mInputChannels{spec.inputChannels},
mOutputChannels{spec.outputChannels},
Expand Down
3 changes: 2 additions & 1 deletion Framework/Core/src/DataSourceDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Framework/TMessageSerializer.h"
#include "Framework/DataProcessor.h"
#include "Framework/FairOptionsRetriever.h"
#include "Framework/FairMQDeviceProxy.h"
#include "Framework/DataProcessingHeader.h"
#include "Framework/CallbackService.h"
#include <cassert>
Expand All @@ -30,7 +31,7 @@ DataSourceDevice::DataSourceDevice(const DeviceSpec &spec, ServiceRegistry &regi
mStatelessProcess{spec.algorithm.onProcess},
mError{spec.algorithm.onError},
mConfigRegistry{nullptr},
mAllocator{this,&mContext, &mRootContext, spec.outputs},
mAllocator{FairMQDeviceProxy{this},&mContext, &mRootContext, spec.outputs},
mServiceRegistry{registry},
mCurrentTimeslice{0},
mRate{0.},
Expand Down
1 change: 1 addition & 0 deletions Framework/Core/src/ExternalFairMQDeviceProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "Headers/DataHeader.h"
#include "Framework/DataProcessingHeader.h"
#include <fairmq/FairMQParts.h>
#include <fairmq/FairMQDevice.h>
#include <cstring>
#include <cassert>
#include <memory>
Expand Down
35 changes: 35 additions & 0 deletions Framework/Core/src/FairMQDeviceProxy.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

#include "Framework/FairMQDeviceProxy.h"

#include <fairmq/FairMQDevice.h>
#include <fairmq/FairMQMessage.h>

namespace o2
{
namespace framework
{
const FairMQTransportFactory *FairMQDeviceProxy::getTransport() {
return mDevice->Transport();
}

std::unique_ptr<FairMQMessage> FairMQDeviceProxy::createMessage() const
{
return mDevice->Transport()->CreateMessage();
}

std::unique_ptr<FairMQMessage> FairMQDeviceProxy::createMessage(const size_t size) const
{
return mDevice->Transport()->CreateMessage(size);
}

} // namespace framework
} // namespace o2