- 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:
winckler 2015-04-03 16:28:58 +02:00 committed by Florian Uhlig
parent 26a1033e9d
commit 445ef356d1
6 changed files with 296 additions and 58 deletions

View File

@ -127,7 +127,6 @@ Set(FairMQHDRFiles
devices/GenericSampler.tpl devices/GenericSampler.tpl
devices/GenericProcessor.h devices/GenericProcessor.h
devices/GenericFileSink.h devices/GenericFileSink.h
devices/GenericFileSink.tpl
tools/FairMQTools.h tools/FairMQTools.h
) )
install(FILES ${FairMQHDRFiles} DESTINATION include) install(FILES ${FairMQHDRFiles} DESTINATION include)

View File

@ -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 * File: GenericFileSink.h
* Author: winckler * Author: winckler
@ -8,39 +16,109 @@
#ifndef GENERICFILESINK_H #ifndef GENERICFILESINK_H
#define GENERICFILESINK_H #define GENERICFILESINK_H
#include "FairMQDevice.h"
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include "FairMQDevice.h"
#include "FairMQLogger.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> template <typename... Args>
void InitInputPolicyContainer(Args... args) void InitInputContainer(Args... args)
{ {
InputPolicy::InitContainer(std::forward<Args>(args)...); InputPolicy::InitContainer(std::forward<Args>(args)...);
} }
protected:
virtual void SetTransport(FairMQTransportFactory* transport); virtual void Init()
virtual void InitOutputFile(); {
FairMQDevice::Init();
OutputPolicy::InitOutputFile();
}
protected: protected:
virtual void Run(); virtual void Run()
virtual void Init(); {
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 */ #endif /* GENERICFILESINK_H */

View File

@ -0,0 +1,107 @@
/*
* File: GenericMerger.h
* Author: winckler
*
* Created on April 9, 2015, 1:37 PM
*/
#ifndef GENERICMERGER_H
#define GENERICMERGER_H
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include "FairMQDevice.h"
#include "FairMQLogger.h"
#include "FairMQPoller.h"
template < typename MergerPolicy,
typename InputPolicy,
typename OutputPolicy
>
class GenericMerger : public FairMQDevice,
public MergerPolicy,
public InputPolicy,
public OutputPolicy
{
public:
GenericMerger() : fBlockingTime(100)
{}
virtual ~GenericMerger()
{}
void SetTransport(FairMQTransportFactory* transport)
{
FairMQDevice::SetTransport(transport);
}
protected:
int fBlockingTime;
virtual void Run()
{
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
FairMQPoller* poller = fTransportFactory->CreatePoller(*fPayloadInputs);
int received = 0;
while (fState == RUNNING)
{
FairMQMessage* msg = fTransportFactory->CreateMessage();
//MergerPolicy::
poller->Poll(fBlockingTime);
for (int i = 0; i < fNumInputs; i++)
{
if (poller->CheckInput(i))
{
received = fPayloadInputs->at(i)->Receive(msg);
MergerPolicy::Merge(InputPolicy::DeSerializeMsg(msg));
}
OutputPolicy::SetMessage(msg);
if ( received > 0 && MergerPolicy::ReadyToSend() )
{
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(MergerPolicy::GetOutputData()));
received = 0;
}
}
delete msg;
}
delete poller;
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();
}
};
#endif /* GENERICMERGER_H */

View File

@ -1,3 +1,10 @@
/********************************************************************************
* 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: GenericProcessor.h * File: GenericProcessor.h
* Author: winckler * Author: winckler
@ -10,7 +17,34 @@
#include "FairMQDevice.h" #include "FairMQDevice.h"
template <typename InputPolicy, typename OutputPolicy, typename TaskPolicy>
/*********************************************************************
* -------------- 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)
* InputPolicy::InitContainer(...) // if GenericProcessor::InitInputContainer(...) is used
*
*
* -------- OUTPUT POLICY --------
* OutputPolicy::SerializeMsg(CONTAINER_TYPE)
* OutputPolicy::SetMessage(FairMQMessage* msg)
* OutputPolicy::InitContainer(...) // if GenericProcessor::InitOutputContainer(...) is used
*
* -------- TASK POLICY --------
* CONTAINER_TYPE TaskPolicy::GetOutputData()
* TaskPolicy::ExecuteTask(CONTAINER_TYPE container)
* TaskPolicy::InitTask(...) // if GenericProcessor::InitTask(...) is used
*
**********************************************************************/
template < typename InputPolicy,
typename OutputPolicy,
typename TaskPolicy>
class GenericProcessor: public FairMQDevice, class GenericProcessor: public FairMQDevice,
public InputPolicy, public InputPolicy,
public OutputPolicy, public OutputPolicy,
@ -23,11 +57,12 @@ class GenericProcessor: public FairMQDevice,
virtual ~GenericProcessor() virtual ~GenericProcessor()
{} {}
// the four following methods ensure
// that the correct policy method is called
void SetTransport(FairMQTransportFactory* transport) void SetTransport(FairMQTransportFactory* transport)
{ {
FairMQDevice::SetTransport(transport); FairMQDevice::SetTransport(transport);
//InputPolicy::SetTransport(transport);
//OutputPolicy::SetTransport(transport);
} }
template <typename... Args> template <typename... Args>
@ -48,16 +83,20 @@ class GenericProcessor: public FairMQDevice,
OutputPolicy::InitContainer(std::forward<Args>(args)...); OutputPolicy::InitContainer(std::forward<Args>(args)...);
} }
//void SendPart();
//bool ReceivePart();
/*
*
// *********************** TODO: implement multipart features
void SendPart() void SendPart()
{ {
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(TaskPolicy::GetData()), "snd-more"); fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(TaskPolicy::GetData()), "snd-more");
OutputPolicy::CloseMessage(); OutputPolicy::CloseMessage();
} }
/* //void SendPart();
//bool ReceivePart();
bool ReceivePart() bool ReceivePart()
{ {
int64_t more = 0; int64_t more = 0;
@ -81,7 +120,7 @@ class GenericProcessor: public FairMQDevice,
virtual void Init() virtual void Init()
{ {
FairMQDevice::Init(); FairMQDevice::Init();
// TODO: implement the code below with the new design // TODO: implement multipart features
//fProcessorTask->InitTask(); //fProcessorTask->InitTask();
//fProcessorTask->SetSendPart(boost::bind(&FairMQProcessor::SendPart, this)); //fProcessorTask->SetSendPart(boost::bind(&FairMQProcessor::SendPart, this));
//fProcessorTask->SetReceivePart(boost::bind(&FairMQProcessor::ReceivePart, this)); //fProcessorTask->SetReceivePart(boost::bind(&FairMQProcessor::ReceivePart, this));
@ -121,7 +160,6 @@ class GenericProcessor: public FairMQDevice,
if(msg) if(msg)
msg->CloseMessage(); msg->CloseMessage();
//OutputPolicy::CloseMessage();
} }
MQLOG(INFO) << "Received " << receivedMsgs << " and sent " << sentMsgs << " messages!"; MQLOG(INFO) << "Received " << receivedMsgs << " and sent " << sentMsgs << " messages!";
@ -145,8 +183,5 @@ class GenericProcessor: public FairMQDevice,
}; };
//#include "GenericSampler.tpl"
#endif /* GENERICPROCESSOR_H */ #endif /* GENERICPROCESSOR_H */

View File

@ -1,3 +1,10 @@
/********************************************************************************
* 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: GenericSampler.h * File: GenericSampler.h
* Author: winckler * Author: winckler
@ -5,11 +12,13 @@
* Created on November 24, 2014, 3:30 PM * Created on November 24, 2014, 3:30 PM
*/ */
#ifndef GENERICSAMPLER_H #ifndef GENERICSAMPLER_H
#define GENERICSAMPLER_H #define GENERICSAMPLER_H
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include <stdint.h>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
@ -18,31 +27,40 @@
#include "FairMQDevice.h" #include "FairMQDevice.h"
#include "FairMQLogger.h" #include "FairMQLogger.h"
/** /* GENERIC SAMPLER (data source) MQ-DEVICE */
* Reads simulated digis from a root file and samples the digi as a time-series UDP stream. /*********************************************************************
* Must be initialized with the filename to the root file and the name of the sub-detector * -------------- NOTES -----------------------
* branch, whose digis should be streamed. * All policies must have a default constructor
* Function to define in (parent) policy classes :
* *
* The purpose of this class is to provide a data source of digis very similar to the * -------- INPUT POLICY (SAMPLER POLICY) --------
* future detector output at the point where the detector is connected to the online * SamplerPolicy::InitSampler()
* computing farm. For the development of online analysis algorithms, it is very important * int64_t SamplerPolicy::GetNumberOfEvent()
* to simulate the future detector output as realistic as possible to evaluate the * CONTAINER_TYPE SamplerPolicy::GetDataBranch(int64_t eventNr)
* feasibility and quality of the various possible online analysis features. * SamplerPolicy::SetFileProperties(Args&... args)
*/ *
* -------- OUTPUT POLICY --------
* OutputPolicy::SerializeMsg(CONTAINER_TYPE)
* OutputPolicy::SetMessage(FairMQMessage* msg)
*
**********************************************************************/
template <typename SamplerPolicy, typename OutputPolicy> template <typename SamplerPolicy,
class GenericSampler: public FairMQDevice, public SamplerPolicy, public OutputPolicy typename OutputPolicy>
class GenericSampler: public FairMQDevice,
public SamplerPolicy,
public OutputPolicy
{ {
//using SamplerPolicy::GetDataBranch; // get data from file
//using OutputPolicy::message; // serialize method
public: public:
enum {
InputFile = FairMQDevice::Last, enum
Branch, {
ParFile, InputFile = FairMQDevice::Last,
EventRate Branch,
ParFile,
EventRate
}; };
GenericSampler(); GenericSampler();
virtual ~GenericSampler(); virtual ~GenericSampler();
virtual void SetTransport(FairMQTransportFactory* factory); virtual void SetTransport(FairMQTransportFactory* factory);
@ -66,7 +84,8 @@ class GenericSampler: public FairMQDevice, public SamplerPolicy, public OutputPo
* This method can be given as a callback to the SamplerTask. * This method can be given as a callback to the SamplerTask.
* The final message part must be sent with normal Send method. * The final message part must be sent with normal Send method.
*/ */
void SendPart(); // temporary disabled
//void SendPart();
void SetContinuous(bool flag) { fContinuous = flag; } void SetContinuous(bool flag) { fContinuous = flag; }
@ -78,7 +97,7 @@ protected:
std::string fInputFile; // Filename of a root file containing the simulated digis. std::string fInputFile; // Filename of a root file containing the simulated digis.
std::string fParFile; std::string fParFile;
std::string fBranch; // The name of the sub-detector branch to stream the digis from. std::string fBranch; // The name of the sub-detector branch to stream the digis from.
int fNumEvents; int64_t fNumEvents;
int fEventRate; int fEventRate;
int fEventCounter; int fEventCounter;
bool fContinuous; bool fContinuous;

View File

@ -31,7 +31,7 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::Init()
{ {
FairMQDevice::Init(); FairMQDevice::Init();
SamplerPolicy::InitSampler(); SamplerPolicy::InitSampler();
fNumEvents=SamplerPolicy::GetDataBunchNumber(); fNumEvents=SamplerPolicy::GetNumberOfEvent();
} }
template <typename SamplerPolicy, typename OutputPolicy> template <typename SamplerPolicy, typename OutputPolicy>
@ -53,7 +53,7 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::Run()
do do
{ {
for ( unsigned long eventNr = 0 ; eventNr < fNumEvents; ++eventNr ) for ( int64_t eventNr = 0 ; eventNr < fNumEvents; ++eventNr )
{ {
//fSamplerTask->SetEventIndex(eventNr); //fSamplerTask->SetEventIndex(eventNr);
FairMQMessage* msg = fTransportFactory->CreateMessage(); FairMQMessage* msg = fTransportFactory->CreateMessage();