$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/DataProcessorPlugins/UDPDataListenerProducer.h" 00002 #include "otsdaq-core/Macros/CoutMacros.h" 00003 #include "otsdaq-core/Macros/ProcessorPluginMacros.h" 00004 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00005 #include "otsdaq-core/NetworkUtilities/NetworkConverters.h" 00006 00007 #include <string.h> 00008 #include <unistd.h> 00009 #include <cassert> 00010 #include <iostream> 00011 00012 using namespace ots; 00013 00014 //======================================================================================================================== 00015 UDPDataListenerProducer::UDPDataListenerProducer( 00016 std::string supervisorApplicationUID, 00017 std::string bufferUID, 00018 std::string processorUID, 00019 const ConfigurationTree& theXDAQContextConfigTree, 00020 const std::string& configurationPath) 00021 : WorkLoop(processorUID) 00022 , Socket(theXDAQContextConfigTree.getNode(configurationPath) 00023 .getNode("HostIPAddress") 00024 .getValue<std::string>(), 00025 theXDAQContextConfigTree.getNode(configurationPath) 00026 .getNode("HostPort") 00027 .getValue<unsigned int>()) 00028 //, Socket ("192.168.133.100", 40000) 00029 , DataProducer(supervisorApplicationUID, 00030 bufferUID, 00031 processorUID, 00032 theXDAQContextConfigTree.getNode(configurationPath) 00033 .getNode("BufferSize") 00034 .getValue<unsigned int>()) 00035 //, DataProducer (supervisorApplicationUID, bufferUID, processorUID, 100) 00036 , Configurable(theXDAQContextConfigTree, configurationPath) 00037 , dataP_(nullptr) 00038 , headerP_(nullptr) 00039 { 00040 unsigned int socketReceiveBufferSize; 00041 try // if socketReceiveBufferSize is defined in configuration, use it 00042 { 00043 socketReceiveBufferSize = theXDAQContextConfigTree.getNode(configurationPath) 00044 .getNode("SocketReceiveBufferSize") 00045 .getValue<unsigned int>(); 00046 } 00047 catch(...) 00048 { 00049 // for backwards compatibility, ignore 00050 socketReceiveBufferSize = 0x10000000; // default to "large" 00051 } 00052 00053 Socket::initialize(socketReceiveBufferSize); 00054 } 00055 00056 //======================================================================================================================== 00057 UDPDataListenerProducer::~UDPDataListenerProducer(void) {} 00058 00059 //======================================================================================================================== 00060 bool UDPDataListenerProducer::workLoopThread(toolbox::task::WorkLoop* workLoop) 00061 // bool UDPDataListenerProducer::getNextFragment(void) 00062 { 00063 //__CFG_COUT__DataProcessor::processorUID_ << " running, because workloop: " << 00064 // WorkLoop::continueWorkLoop_ << std::endl; 00065 fastWrite(); 00066 return WorkLoop::continueWorkLoop_; 00067 } 00068 00069 //======================================================================================================================== 00070 void UDPDataListenerProducer::slowWrite(void) 00071 { 00072 //__CFG_COUT__name_ << " running!" << std::endl; 00073 00074 if(ReceiverSocket::receive(data_, ipAddress_, port_) != -1) 00075 { 00076 //__CFG_COUT__name_ << " Buffer: " << message << std::endl; 00077 //__CFG_COUT__processorUID_ << " -> Got some data. From: " << std::hex << 00078 // fromIPAddress << " port: " << fromPort << std::dec << std::endl; 00079 header_["IPAddress"] = NetworkConverters::networkToStringIP(ipAddress_); 00080 header_["Port"] = NetworkConverters::networkToStringPort(port_); 00081 // unsigned long long value; 00082 // memcpy((void *)&value, (void *) data_.substr(2).data(),8); //make data 00083 // counter 00084 // __CFG_COUT__std::hex << value << std::dec << std::endl; 00085 00086 while(DataProducer::write(data_, header_) < 0) 00087 { 00088 __CFG_COUT__ << "There are no available buffers! Retrying...after waiting 10 " 00089 "milliseconds!" 00090 << std::endl; 00091 usleep(10000); 00092 return; 00093 } 00094 } 00095 } 00096 00097 //======================================================================================================================== 00098 void UDPDataListenerProducer::fastWrite(void) 00099 { 00100 //__CFG_COUT__ << " running!" << std::endl; 00101 00102 if(DataProducer::attachToEmptySubBuffer(dataP_, headerP_) < 0) 00103 { 00104 __CFG_COUT__ 00105 << "There are no available buffers! Retrying...after waiting 10 milliseconds!" 00106 << std::endl; 00107 usleep(10000); 00108 return; 00109 } 00110 00111 // if(0) // test data buffers 00112 // { 00113 // sleep(1); 00114 // unsigned long long value = 0xA54321; // this is 8-bytes 00115 // std::string& buffer = *dataP_; 00116 // buffer.resize( 00117 // 8); // NOTE: this is inexpensive according to Lorenzo/documentation 00118 // // in C++11 (only increases size once and doesn't decrease size) 00119 // memcpy((void*)&buffer[0] /*dest*/, (void*)&value /*src*/, 8 /*numOfBytes*/); 00120 // 00121 // // size() and length() are equivalent 00122 // __CFG_COUT__ << "Writing to buffer " << buffer.size() << " bytes!" << __E__; 00123 // __CFG_COUT__ << "Writing to buffer length " << buffer.length() << " bytes!" 00124 // << __E__; 00125 // 00126 // __CFG_COUT__ << "Buffer Data: " 00127 // << BinaryStringMacros::binaryTo8ByteHexString(buffer) << __E__; 00128 // 00129 // __CFG_COUTV__(DataProcessor::theCircularBuffer_); 00130 // 00131 // DataProducer::setWrittenSubBuffer<std::string, 00132 // std::map<std::string, std::string> >(); 00133 // return; 00134 // } 00135 00136 if(ReceiverSocket::receive(*dataP_, ipAddress_, port_, 1, 0, true) != -1) 00137 { 00138 DataProducer::setWrittenSubBuffer<std::string, 00139 std::map<std::string, std::string> >(); 00140 } 00141 } 00142 00143 DEFINE_OTS_PROCESSOR(UDPDataListenerProducer)