10 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh" 24 #include <sys/types.h> 25 #include <sys/socket.h> 26 #include <arpa/inet.h> 27 #include <netinet/in.h> 37 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
46 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
52 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
60 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
69 int ListeningSocket = -1,
70 int connectSocket = -1) {
77 if (ListeningSocket != -1) {
78 FD_SET(ListeningSocket, &ReadFDs);
79 FD_SET(ListeningSocket, &ExceptFDs);
82 if (connectSocket != -1) {
83 FD_SET(connectSocket, &ReadFDs);
84 FD_SET(connectSocket, &ExceptFDs);
90 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
99 unsigned int bytesRcvd, bytesToReceive, totalBytesRcvd;
100 const unsigned int Buffer_Size = 8192;
106 fd_set fdsRead, fdsWrite, fdsExcept;
110 time_t tempTime, curTime;
115 bytesToReceive =
sizeof(localSection);
116 Buffer =
new char[Buffer_Size];
117 BigBuffer =
new char[bytesToReceive];
120 memset(reinterpret_cast<char *>(&localSection), 0, Buffer_Size);
121 memset(Buffer, 0, Buffer_Size);
122 memset(BigBuffer, 0, bytesToReceive);
126 while ((totalBytesRcvd < bytesToReceive) && (errorCode == 0)) {
129 if (
select(
tcpSocket + 1, &fdsRead,
nullptr, &fdsExcept,
nullptr) > 0) {
131 if ((bytesRcvd = recv(
tcpSocket, Buffer, Buffer_Size, 0)) <= 0) {
132 perror(
"Recv Error");
135 if ((totalBytesRcvd + bytesRcvd) <= bytesToReceive) {
136 memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd);
138 std::cout <<
"***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****" 142 totalBytesRcvd += bytesRcvd;
149 if (errorCode == 0) {
150 memcpy(reinterpret_cast<char *>(&localSection), BigBuffer,
sizeof(localSection));
167 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
175 std::cout <<
"Begin and End " << __PRETTY_FUNCTION__ <<
" " <<
Connected << std::endl;
182 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
195 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
202 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
215 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
222 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
226 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
232 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
238 struct hostent *hostInfo = gethostbyname(
servIP.c_str());
244 std::cout <<
"Requesting connection" << std::endl;
246 if ((
tcpSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
247 perror(
"Socket Error");
251 servAddr.sin_family = hostInfo->h_addrtype;
252 memcpy((
char *)&
servAddr.sin_addr.s_addr, hostInfo->h_addr_list[0], hostInfo->h_length);
259 perror(
"Connect Error");
279 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
286 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
293 if (shutdown(
tcpSocket, SHUT_RDWR) < 0) {
294 perror(
"Shutdown Error");
306 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
313 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
326 gettimeofday(&tvTemp,
nullptr);
330 localSection.
lumiSummary.DeadtimeNormalization = 0.7;
350 for (
j = 0;
j < 3564;
j++) {
366 for (
i = 0;
i < 36;
i++) {
375 for (
j = 0;
j < 3564;
j++) {
377 for (
k = 0;
k < 6;
k++) {
385 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
391 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
395 srand(
time(
nullptr));
404 localSection.
lumiSummary.DeadtimeNormalization = (
float)(rand() % 100) / 100;
424 for (
j = 0;
j < 3564;
j++) {
440 for (
i = 0;
i < 36;
i++) {
449 for (
j = 0;
j < 3564;
j++) {
450 localSection.
etSum[
i].
data[
j] = 6 * (rand() % 3564);
451 for (
k = 0;
k < 6;
k++) {
454 localSection.
lhc[
i].
data[
j] = 7 * (rand() % 3564);
459 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
466 return !(memcmp(&
L, &localSection,
sizeof(
L)));
void SetupFDSets(fd_set &ReadFDs, fd_set &WriteFDs, fd_set &ExceptFDs, int ListeningSocket=-1, int connectSocket=-1)
unsigned char acquireMode
float InstantOccLumiErr[2]
int SetPort(unsigned short int)
int16_t InstantETLumiQlty
LUMI_SECTION_SUB_HEADER hdr
void SetIP(std::string IP)
int16_t OccLumiQlty[2][4096]
void GenerateRandomData(HCAL_HLX::LUMI_SECTION &localSection)
float ETBXNormalization[4096]
float OccLumiErr[2][4096]
LUMI_SECTION_SUB_HEADER hdr
OCCUPANCY_SECTION occupancy[36]
void GenerateFakeData(HCAL_HLX::LUMI_SECTION &localSection)
int16_t InstantOccLumiQlty[2]
int ReceiveLumiSection(HCAL_HLX::LUMI_SECTION &localSection)
int SetMode(unsigned char)
LUMI_SECTION_SUB_HEADER hdr
struct sockaddr_in servAddr
float OccBXNormalization[2][4096]
bool VerifyFakeData(HCAL_HLX::LUMI_SECTION &localSection)
float OccNormalization[2]