1 #include "otsdaq-core/DataProcessorPlugins/UDPDataListenerProducer.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/NetworkUtilities/NetworkConverters.h"
5 #include "otsdaq-core/Macros/ProcessorPluginMacros.h"
16 UDPDataListenerProducer::UDPDataListenerProducer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID,
const ConfigurationTree& theXDAQContextConfigTree,
const std::string& configurationPath)
20 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostIPAddress").getValue<std::string>(),
21 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"HostPort").getValue<unsigned int>()
26 supervisorApplicationUID,
29 theXDAQContextConfigTree.getNode(configurationPath).getNode(
"BufferSize").getValue<unsigned int>()
32 ,
Configurable (theXDAQContextConfigTree, configurationPath)
36 unsigned int socketReceiveBufferSize;
39 socketReceiveBufferSize = theXDAQContextConfigTree.getNode(configurationPath).getNode(
"SocketReceiveBufferSize").getValue<
unsigned int>();
44 socketReceiveBufferSize = 0x10000000;
47 Socket::initialize(socketReceiveBufferSize);
51 UDPDataListenerProducer::~UDPDataListenerProducer(
void)
55 bool UDPDataListenerProducer::workLoopThread(toolbox::task::WorkLoop* workLoop)
60 return WorkLoop::continueWorkLoop_;
64 void UDPDataListenerProducer::slowWrite(
void)
68 if(ReceiverSocket::receive(data_, ipAddress_, port_) != -1)
72 header_[
"IPAddress"] = NetworkConverters::networkToStringIP (ipAddress_);
73 header_[
"Port"] = NetworkConverters::networkToStringPort(port_);
78 while(DataProducer::write(data_, header_) < 0)
80 __COUT__ <<
"There are no available buffers! Retrying...after waiting 10 milliseconds!" << std::endl;
88 void UDPDataListenerProducer::fastWrite(
void)
92 if(DataProducer::attachToEmptySubBuffer(dataP_, headerP_) < 0)
94 __COUT__ <<
"There are no available buffers! Retrying...after waiting 10 milliseconds!" << std::endl;
99 if(ReceiverSocket::receive(*dataP_, ipAddress_, port_) != -1)
101 (*headerP_)[
"IPAddress"] = NetworkConverters::networkToStringIP (ipAddress_);
102 (*headerP_)[
"Port"] = NetworkConverters::networkToStringPort(port_);
106 (requestedPort_ == 47000 || requestedPort_ == 47001 || requestedPort_ == 47002) &&
107 dataP_->length() > 2)
109 unsigned char seqId = (*dataP_)[1];
110 if(!(lastSeqId_ + 1 == seqId ||
111 (lastSeqId_ == 255 && seqId == 0)))
113 __COUT__ << requestedPort_ <<
114 "?????? NOOOO Missing Packets: " <<
115 (
unsigned int)lastSeqId_ <<
" v " << (
unsigned int)seqId << __E__;
160 DataProducer::setWrittenSubBuffer<std::string,std::map<std::string,std::string>>();