otsdaq  v1_01_04
 All Classes Namespaces Functions
UDPDataStreamerConsumer_processor.cc
1 #include "otsdaq-core/DataProcessorPlugins/UDPDataStreamerConsumer.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/Macros/ProcessorPluginMacros.h"
5 
6 #include <iostream>
7 #include <cassert>
8 #include <unistd.h>
9 
10 using namespace ots;
11 
12 //========================================================================================================================
13 UDPDataStreamerConsumer::UDPDataStreamerConsumer(std::string supervisorApplicationUID, std::string bufferUID, std::string processorUID, const ConfigurationTree& theXDAQContextConfigTree, const std::string& configurationPath)
14 : Socket (theXDAQContextConfigTree.getNode(configurationPath).getNode("HostIPAddress").getValue<std::string>(),
15  theXDAQContextConfigTree.getNode(configurationPath).getNode("HostPort").getValue<unsigned int>())
16 , WorkLoop (processorUID)
18  theXDAQContextConfigTree.getNode(configurationPath).getNode("HostIPAddress").getValue<std::string>(),
19  theXDAQContextConfigTree.getNode(configurationPath).getNode("HostPort").getValue<unsigned int>(),
20  theXDAQContextConfigTree.getNode(configurationPath).getNode("StreamToIPAddress").getValue<std::string>(),
21  theXDAQContextConfigTree.getNode(configurationPath).getNode("StreamToPort").getValue<unsigned int>()
22  )
23 , DataConsumer (supervisorApplicationUID, bufferUID, processorUID, HighConsumerPriority)
24 , Configurable (theXDAQContextConfigTree, configurationPath)
25 //, Socket ("192.168.133.1", 47200)
26 //, DataConsumer ("ARTDAQDataManager", 1, "ARTDAQBuffer", "ARTDAQDataStreamer0", HighConsumerPriority)
27 //, streamToSocket_("192.168.133.1", 50100)
28 {
29  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
30  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
31  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
32  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
33  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
34  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << std::endl;
35  //Socket::initialize(); //dont call this! UDPDataStreamer() calls it
36  std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << "done!" << std::endl;
37 }
38 
39 //========================================================================================================================
40 UDPDataStreamerConsumer::~UDPDataStreamerConsumer(void)
41 {
42 }
43 
44 //========================================================================================================================
45 bool UDPDataStreamerConsumer::workLoopThread(toolbox::task::WorkLoop* workLoop)
46 {
47  fastRead();
48  return WorkLoop::continueWorkLoop_;
49 }
50 
51 //========================================================================================================================
52 void UDPDataStreamerConsumer::fastRead(void)
53 {
54  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " running!" << std::endl;
55  if(DataConsumer::read(dataP_, headerP_) < 0)
56  {
57  usleep(100);
58  return;
59  }
60  //unsigned int reconverted = (((*headerP_)["IPAddress"][0]&0xff)<<24) + (((*headerP_)["IPAddress"][1]&0xff)<<16) + (((*headerP_)["IPAddress"][2]&0xff)<<8) + ((*headerP_)["IPAddress"][3]&0xff);
61  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " -> Got some data. From: " << std::hex << reconverted << std::dec << std::endl;
62 
63  //std::cout << __COUT_HDR_FL__ << dataP_->length() << std::endl;
64  TransmitterSocket::send(streamToSocket_, *dataP_);
65  DataConsumer::setReadSubBuffer<std::string, std::map<std::string, std::string>>();
66 }
67 
68 //========================================================================================================================
69 void UDPDataStreamerConsumer::slowRead(void)
70 {
71  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " running!" << std::endl;
72  //This is making a copy!!!
73  if(DataConsumer::read(data_, header_) < 0)
74  {
75  usleep(1000);
76  return;
77  }
78  //unsigned int reconverted = ((header_["IPAddress"][0]&0xff)<<24) + ((header_["IPAddress"][1]&0xff)<<16) + ((header_["IPAddress"][2]&0xff)<<8) + (header_["IPAddress"][3]&0xff);
79  //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << processorUID_ << " -> Got some data. From: " << std::hex << reconverted << std::dec << std::endl;
80 
81  TransmitterSocket::send(streamToSocket_, data_);
82 }
83 
84 DEFINE_OTS_PROCESSOR(UDPDataStreamerConsumer)