1 #include "otsdaq-demo/Generators/STIBReceiver.hh"
2 #include "otsdaq/Macros/CoutMacros.h"
5 #include "artdaq-core/Utilities/SimpleLookupPolicy.h"
6 #include "artdaq/Application/GeneratorMacros.hh"
7 #include "cetlib/exception.h"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "otsdaq-demo/Overlays/FragmentType.hh"
10 #include "otsdaq-demo/Overlays/STIBFragmentWriter.hh"
18 ots::STIBReceiver::STIBReceiver(fhicl::ParameterSet
const& ps) : UDPReceiver(ps) {}
20 void ots::STIBReceiver::ProcessData_(artdaq::FragmentPtrs& frags)
23 metadata.port = dataport_;
24 metadata.address = si_data_.sin_addr.s_addr;
27 uint64_t bunch_counter = 0;
28 uint64_t triggerCounter = 0;
29 uint8_t triggerInput0 = 0;
30 uint8_t triggerInput1 = 0;
31 std::vector<uint32_t> data;
36 std::string outputPath =
37 rawPath_ +
"/STIBReceiver-" + ip_ +
":" + std::to_string(dataport_) +
".bin";
38 output.open(outputPath, std::ios::out | std::ios::app | std::ios::binary);
41 std::cout << __COUT_HDR_FL__ <<
"Starting STIBReceiver Packet Processing Loop"
43 for(
auto packet = packetBuffers_.begin(); packet != packetBuffers_.end(); ++packet)
45 for(
size_t word = 0; word < (*packet)->size(); word += 4)
47 uint8_t byte3 = (*packet)->at(word);
48 uint8_t byte2 = (*packet)->at(word + 1);
49 uint8_t byte1 = (*packet)->at(word + 2);
50 uint8_t byte0 = (*packet)->at(word + 3);
54 output.write((
char*)&(byte3),
sizeof(uint32_t));
57 if((byte0 & 0x8) == 0)
61 std::size_t initial_payload_size = 0;
64 artdaq::Fragment::FragmentBytes(initial_payload_size,
67 ots::detail::FragmentType::STIB,
72 thisFrag.resize(4 * data.size());
73 thisFrag.set_hdr_bunch_counter(bunch_counter);
74 thisFrag.set_hdr_trigger_counter(triggerCounter);
75 thisFrag.set_hdr_trigger_input0(triggerInput0);
76 thisFrag.set_hdr_trigger_input1(triggerInput1);
82 for(
size_t ii = 0; ii < data.size(); ++ii)
84 *(thisFrag.dataBegin() + ii) = data[ii];
89 if((byte0 & 0x10) == 0x10)
91 bunch_counter = (bunch_counter & 0xFFFFFF000000) + byte1 +
92 (byte2 << 8) + (byte3 << 16);
94 else if((byte0 & 0x20) == 0x20)
96 bunch_counter = (bunch_counter & 0xFFFFFF) + ((uint64_t)byte1 << 24) +
97 ((uint64_t)byte2 << 32) + ((uint64_t)byte3 << 40);
99 else if((byte0 & 0xb0) == 0xb0)
101 triggerCounter = (triggerCounter & 0xFFFF) + ((uint64_t)byte1 << 16) +
102 ((uint64_t)byte2 << 24) + ((uint64_t)byte3 << 32);
104 else if((byte0 & 0xa0) == 0xa0)
106 bunch_counter = (bunch_counter & 0xFFFFFFFFFF00) + byte1;
108 (triggerCounter & 0xFFFFFF0000) + byte2 + (byte3 << 8);
110 else if(((byte0 & 0xc0) == 0xc0) ||
111 ((byte0 & 0xd0) == 0xd0) ||
112 ((byte0 & 0xe0) == 0xe0) || ((byte0 & 0xf0) == 0xf0))
114 bunch_counter = (bunch_counter & 0xFFFFFFFFFF00) + byte1;
115 triggerInput0 = byte2;
116 triggerInput1 = byte3;
119 else if((byte0 & 1) == 1)
122 data.push_back((uint32_t)byte0 + ((uint32_t)byte1 << 8) +
123 ((uint64_t)byte2 << 16) + ((uint64_t)byte3 << 24));