/******************************************************************************** * 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" * ********************************************************************************/ /** * PndMQTopix4Sampler.cpp * * @since 2014-10-10 * @author A. Rybalchenko */ #include // unique_ptr #include #include #include #include "FairMQLogger.h" #include "mrfdata_8b.h" #include "PndMQStatus.h" using namespace std; PndMQTopix4Sampler::PndMQTopix4Sampler() : fFileName(), fGlobalControl(true) { } void PndMQTopix4Sampler::CustomCleanup(void *data, void *object) { delete (TMrfData_8b*)object; } void PndMQTopix4Sampler::Init() { fTopixDataReader.Init(); } void PndMQTopix4Sampler::Run() { bool stopSampling = false; bool startSampling = false; if ((fGlobalControl == false) || (fChannels.count("control-in") == 0)) startSampling = true; while (CheckCurrentState(RUNNING) && stopSampling == false) { //boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); unique_ptr controlMsg(fTransportFactory->CreateMessage()); if (!startSampling && fChannels.at("control-in").at(0).Receive(controlMsg)){ int status = *(static_cast(controlMsg->GetData())); if (status == 1){ startSampling = true; } LOG(INFO) << "Control message " << status << " received"; } if (startSampling){ TMrfData_8b* data = 0; stopSampling = fTopixDataReader.ReadInDataFromFile(data); unique_ptr header(fTransportFactory->CreateMessage(sizeof(int))); int flag = -1; if (stopSampling == false){ flag = PndMQStatus::RUNNING; FairMQParts parts; memcpy(header->GetData(), &flag, sizeof(int)); parts.AddPart(std::move(header)); parts.AddPart(NewMessage(reinterpret_cast(&data->regdata[0]),data->getNumWords(),CustomCleanup,data)); // unique_ptr msg(fTransportFactory->CreateMessage(reinterpret_cast(&data->regdata[0]),data->getNumWords(),CustomCleanup,data)); // LOG(INFO) << "Sending Words\"" << data->getNumWords() << "\"" << " Bits: " << data->getNumBits(); // fChannels.at("data-out").at(0).SendPart(header); // fChannels.at("data-out").at(0).Send(msg); Send(parts, "data-out"); } else { flag = PndMQStatus::STOP; memcpy(header->GetData(), &flag, sizeof(int)); fChannels.at("data-out").at(0).Send(header); } } } } PndMQTopix4Sampler::~PndMQTopix4Sampler() { } void PndMQTopix4Sampler::SetProperty(const int key, const string& value) { switch (key) { case FileName: fFileName = value; fTopixDataReader.SetFileName(fFileName); break; case GlobalControl: if (value.compare("true")) fGlobalControl = true; else fGlobalControl = false; default: FairMQDevice::SetProperty(key, value); break; } } string PndMQTopix4Sampler::GetProperty(const int key, const string& default_ /*= ""*/) { switch (key) { case FileName: return fFileName; break; case GlobalControl: if (fGlobalControl == true) return "true"; else return "false"; default: return FairMQDevice::GetProperty(key, default_); } } void PndMQTopix4Sampler::SetProperty(const int key, const int value) { switch (key) { default: FairMQDevice::SetProperty(key, value); break; } } int PndMQTopix4Sampler::GetProperty(const int key, const int default_ /*= 0*/) { switch (key) { default: return FairMQDevice::GetProperty(key, default_); } }