/******************************************************************************** * 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 * * Created on October 7, 2014, 6:06 PM */ #ifndef GENERICFILESINK_H #define GENERICFILESINK_H #include "FairMQDevice.h" #include #include #include "FairMQLogger.h" /********************************************************************* * -------------- NOTES ----------------------- * All policies must have a default constructor * Function to define in (parent) policy classes : * * -------- INPUT POLICY -------- * deserialization_type::InitContainer(...) * CONTAINER_TYPE deserialization_type::DeserializeMsg(FairMQMessage* msg) * * * -------- OUTPUT POLICY -------- * sink_type::AddToFile(CONTAINER_TYPE); * sink_type::InitOutputFile() **********************************************************************/ #include "FairMQDevice.h" template class GenericFileSink : public FairMQDevice, public T, public U { public: typedef T input_policy; typedef U sink_type; GenericFileSink() : FairMQDevice(), input_policy(), sink_type() {} virtual ~GenericFileSink() {} template void InitInputData(Args&&... args) { input_policy::Create(std::forward(args)...); } protected: using input_policy::fInput; virtual void InitTask() { sink_type::InitOutputFile(); } typedef typename input_policy::deserialization_type deserializer_type; virtual void Run() { int receivedMsg = 0; while (CheckCurrentState(RUNNING)) { std::unique_ptr msg(NewMessage()); if (Receive(msg,"data-in") > 0) { Deserialize(*msg,fInput); U::Serialize(fInput);// add fInput to file receivedMsg++; } } LOG(INFO) << "Received " << receivedMsg << " messages!"; } }; #endif /* GENERICFILESINK_H */