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>
36 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
45 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
51 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
59 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
68 fd_set& ExceptFDs,
int ListeningSocket = -1,
69 int connectSocket = -1) {
76 if (ListeningSocket != -1) {
77 FD_SET(ListeningSocket, &ReadFDs);
78 FD_SET(ListeningSocket, &ExceptFDs);
81 if (connectSocket != -1) {
82 FD_SET(connectSocket, &ReadFDs);
83 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)){
134 if((bytesRcvd = recv(
tcpSocket, Buffer, Buffer_Size, 0))<=0){
135 perror(
"Recv Error");
138 if((totalBytesRcvd + bytesRcvd)<= bytesToReceive){
139 memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd);
141 std::cout <<
"***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****" << std::endl;
144 totalBytesRcvd += bytesRcvd;
152 memcpy(reinterpret_cast<char *>(&localSection), BigBuffer,
sizeof(localSection));
169 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
177 std::cout <<
"Begin and End " << __PRETTY_FUNCTION__ <<
" " <<
Connected << std::endl;
184 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
197 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
204 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
217 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
224 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
228 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
234 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
240 struct hostent * hostInfo = gethostbyname(
servIP.c_str());
246 std::cout <<
"Requesting connection" << std::endl;
248 if((
tcpSocket = socket(AF_INET, SOCK_STREAM, 0))<0){
249 perror(
"Socket Error");
253 servAddr.sin_family = hostInfo->h_addrtype;
254 memcpy((
char *) &
servAddr.sin_addr.s_addr,
255 hostInfo->h_addr_list[0],
263 perror(
"Connect Error");
283 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
290 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
298 perror(
"Shutdown Error");
311 std::cout <<
"End " << __PRETTY_FUNCTION__ <<
" " << errorCode << std::endl;
318 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
331 gettimeofday(&tvTemp,
NULL);
335 localSection.
lumiSummary.DeadtimeNormalization = 0.7;
355 for(j=0; j < 3564; j++){
371 for(i=0; i<36; i ++){
380 for(j=0; j < 3564; j ++){
382 for(k=0; k < 6; k++){
390 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
397 std::cout <<
"Begin " << __PRETTY_FUNCTION__ << std::endl;
410 localSection.
lumiSummary.DeadtimeNormalization = (float)(
rand() % 100)/100;
430 for(j=0; j < 3564; j++){
446 for(i=0; i<36; i ++){
455 for(j=0; j < 3564; j ++){
457 for(k=0; k < 6; k++){
465 std::cout <<
"End " << __PRETTY_FUNCTION__ << std::endl;
473 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]