mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 01:51:45 +00:00
- Rename some function members of Generic MQ Devices and propagate the modifications accordingly.
- Add a generic merger. add SYSTEM_INCLUDE_DIRECTORIES in project_template CMakeLists.txt so that boost include dirs are found.
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
/*
|
||||
* File: GenericFileSink.h
|
||||
* Author: winckler
|
||||
@@ -8,39 +16,109 @@
|
||||
#ifndef GENERICFILESINK_H
|
||||
#define GENERICFILESINK_H
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
template <typename InputPolicy, typename OutputPolicy>
|
||||
class GenericFileSink : public FairMQDevice, public InputPolicy, public OutputPolicy
|
||||
{
|
||||
//using InputPolicy::message;
|
||||
//using OutputPolicy::InitOutFile;
|
||||
//using OutputPolicy::AddToFile;
|
||||
|
||||
public:
|
||||
GenericFileSink();
|
||||
virtual ~GenericFileSink();
|
||||
|
||||
/*********************************************************************
|
||||
* -------------- NOTES -----------------------
|
||||
* All policies must have a default constructor
|
||||
* Function to define in (parent) policy classes :
|
||||
*
|
||||
* -------- INPUT POLICY --------
|
||||
* InputPolicy::InitContainer(...)
|
||||
* CONTAINER_TYPE InputPolicy::DeSerializeMsg(FairMQMessage* msg)
|
||||
*
|
||||
*
|
||||
* -------- OUTPUT POLICY --------
|
||||
* OutputPolicy::AddToFile(CONTAINER_TYPE);
|
||||
* OutputPolicy::InitOutputFile()
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
template < typename InputPolicy,
|
||||
typename OutputPolicy>
|
||||
class GenericFileSink : public FairMQDevice,
|
||||
public InputPolicy,
|
||||
public OutputPolicy
|
||||
{
|
||||
public:
|
||||
GenericFileSink():
|
||||
InputPolicy(),
|
||||
OutputPolicy()
|
||||
{}
|
||||
|
||||
virtual ~GenericFileSink()
|
||||
{}
|
||||
|
||||
|
||||
void SetTransport(FairMQTransportFactory* transport)
|
||||
{
|
||||
FairMQDevice::SetTransport(transport);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void InitInputPolicyContainer(Args... args)
|
||||
void InitInputContainer(Args... args)
|
||||
{
|
||||
InputPolicy::InitContainer(std::forward<Args>(args)...);
|
||||
}
|
||||
protected:
|
||||
|
||||
virtual void SetTransport(FairMQTransportFactory* transport);
|
||||
virtual void InitOutputFile();
|
||||
virtual void Init()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
OutputPolicy::InitOutputFile();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void Run();
|
||||
virtual void Init();
|
||||
virtual void Run()
|
||||
{
|
||||
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
int receivedMsg = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
if(received>0)
|
||||
{
|
||||
OutputPolicy::AddToFile(InputPolicy::DeSerializeMsg(msg));
|
||||
receivedMsg++;
|
||||
}
|
||||
delete msg;
|
||||
}
|
||||
|
||||
MQLOG(INFO) << "Received " << receivedMsg << " messages!";
|
||||
try
|
||||
{
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#include "GenericFileSink.tpl"
|
||||
|
||||
#endif /* GENERICFILESINK_H */
|
||||
|
||||
|
Reference in New Issue
Block a user