#include <TCPReceiver.h>
Public Member Functions | |
int | Connect () |
int | Disconnect () |
void | GenerateFakeData (HCAL_HLX::LUMI_SECTION &localSection) |
void | GenerateRandomData (HCAL_HLX::LUMI_SECTION &localSection) |
bool | IsConnected () |
int | ReceiveLumiSection (HCAL_HLX::LUMI_SECTION &localSection) |
void | SetIP (std::string IP) |
int | SetMode (unsigned char) |
int | SetPort (unsigned short int) |
TCPReceiver () | |
TCPReceiver (unsigned short int, std::string, unsigned char) | |
bool | VerifyFakeData (HCAL_HLX::LUMI_SECTION &localSection) |
~TCPReceiver () | |
Private Attributes | |
unsigned char | acquireMode |
bool | Connected |
struct sockaddr_in | servAddr |
std::string | servIP |
unsigned short | servPort |
int | tcpSocket |
Definition at line 36 of file TCPReceiver.h.
HCAL_HLX::TCPReceiver::TCPReceiver | ( | ) |
Definition at line 34 of file TCPReceiver.cc.
References acquireMode, Connected, gather_cfg::cout, servIP, and servPort.
HCAL_HLX::TCPReceiver::TCPReceiver | ( | unsigned short int | port, |
std::string | IP, | ||
unsigned char | mode = 0 |
||
) |
Definition at line 49 of file TCPReceiver.cc.
References acquireMode, Connected, gather_cfg::cout, mode, query::port, servIP, and servPort.
HCAL_HLX::TCPReceiver::~TCPReceiver | ( | ) |
int HCAL_HLX::TCPReceiver::Connect | ( | ) |
Definition at line 232 of file TCPReceiver.cc.
References acquireMode, align_tpl::connect, Connected, gather_cfg::cout, servAddr, servIP, servPort, and tcpSocket.
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int errorCode; if(acquireMode == 0){ struct hostent * hostInfo = gethostbyname(servIP.c_str()); if(servPort < 1024){ errorCode = 101; // Protected ports } else { #ifdef DEBUG std::cout << "Requesting connection" << std::endl; #endif if((tcpSocket = socket(AF_INET, SOCK_STREAM, 0))<0){ perror("Socket Error"); errorCode = 301; // Socket failed }else{ memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = hostInfo->h_addrtype; memcpy((char *) &servAddr.sin_addr.s_addr, hostInfo->h_addr_list[0], hostInfo->h_length); // servAddr.sin_addr.s_addr = inet_addr(servIP.c_str()); servAddr.sin_port = htons(servPort); #ifdef DEBUG std::cout << "Connecting" << std::endl; #endif if(connect(tcpSocket, (struct sockaddr *) &servAddr, sizeof(servAddr))<0){ perror("Connect Error"); errorCode = 302; // connect failed close(tcpSocket); } else{ Connected = true; errorCode = 1; // Successful connection } } } } else if(acquireMode == 1) { Connected = true; errorCode = 1; // do nothing for fake data } else if(acquireMode == 2) { Connected = true; errorCode = 1; // do nothing for random data } else { errorCode = 201; // Invalid acquire mode } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; #endif return errorCode; }
int HCAL_HLX::TCPReceiver::Disconnect | ( | ) |
Definition at line 288 of file TCPReceiver.cc.
References acquireMode, Connected, gather_cfg::cout, and tcpSocket.
Referenced by HLXMonitor::analyze(), HLXMonitor::endJob(), HLXMonitor::~HLXMonitor(), and ~TCPReceiver().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int errorCode = 0; if(Connected){ if( acquireMode == 0 ){ if(shutdown(tcpSocket,SHUT_RDWR)<0){ perror("Shutdown Error"); errorCode = 601; // Disconnect Failed } else { errorCode = 1; // Successful Disconnect } } Connected = false; } else { errorCode = 401; // Not Connected } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; #endif return errorCode; }
void HCAL_HLX::TCPReceiver::GenerateFakeData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 316 of file TCPReceiver.cc.
References HCAL_HLX::LUMI_SECTION_HEADER::bCMSLive, HCAL_HLX::LUMI_SECTION_SUB_HEADER::bIsComplete, gather_cfg::cout, HCAL_HLX::ET_SUM_SECTION::data, HCAL_HLX::LHC_SECTION::data, HCAL_HLX::OCCUPANCY_SECTION::data, HCAL_HLX::LUMI_DETAIL::ETBXNormalization, HCAL_HLX::LUMI_DETAIL::ETLumi, HCAL_HLX::LUMI_DETAIL::ETLumiErr, HCAL_HLX::LUMI_DETAIL::ETLumiQlty, HCAL_HLX::LUMI_SUMMARY::ETNormalization, HCAL_HLX::LUMI_SECTION::etSum, HCAL_HLX::LHC_SECTION::hdr, HCAL_HLX::ET_SUM_SECTION::hdr, HCAL_HLX::LUMI_SECTION::hdr, HCAL_HLX::OCCUPANCY_SECTION::hdr, i, HCAL_HLX::LUMI_SUMMARY::InstantETLumi, HCAL_HLX::LUMI_SUMMARY::InstantETLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantETLumiQlty, HCAL_HLX::LUMI_SUMMARY::InstantLumi, HCAL_HLX::LUMI_SUMMARY::InstantLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantLumiQlty, HCAL_HLX::LUMI_SUMMARY::InstantOccLumi, HCAL_HLX::LUMI_SUMMARY::InstantOccLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantOccLumiQlty, j, gen::k, HCAL_HLX::LUMI_SECTION::lhc, HCAL_HLX::LUMI_DETAIL::LHCLumi, HCAL_HLX::LUMI_SUMMARY::LHCNormalization, HCAL_HLX::LUMI_SECTION::lumiDetail, HCAL_HLX::LUMI_SUMMARY::lumiNoise, HCAL_HLX::LUMI_SECTION::lumiSummary, NULL, HCAL_HLX::LUMI_SECTION_HEADER::numBunches, HCAL_HLX::LUMI_SECTION_HEADER::numHLXs, HCAL_HLX::LUMI_SECTION_SUB_HEADER::numNibbles, HCAL_HLX::LUMI_SECTION_HEADER::numOrbits, HCAL_HLX::LUMI_DETAIL::OccBXNormalization, HCAL_HLX::LUMI_DETAIL::OccLumi, HCAL_HLX::LUMI_DETAIL::OccLumiErr, HCAL_HLX::LUMI_DETAIL::OccLumiQlty, HCAL_HLX::LUMI_SUMMARY::OccNormalization, HCAL_HLX::LUMI_SECTION::occupancy, HCAL_HLX::LUMI_SECTION_HEADER::runNumber, HCAL_HLX::LUMI_SECTION_HEADER::sectionNumber, HCAL_HLX::LUMI_SECTION_HEADER::startOrbit, HCAL_HLX::LUMI_SECTION_HEADER::timestamp, and HCAL_HLX::LUMI_SECTION_HEADER::timestamp_micros.
Referenced by ReceiveLumiSection(), and VerifyFakeData().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int i, j, k; localSection.hdr.runNumber = 1; localSection.hdr.startOrbit = 2; localSection.hdr.numOrbits = 3; localSection.hdr.numBunches = 4; localSection.hdr.numHLXs = 5; localSection.hdr.bCMSLive = true; localSection.hdr.sectionNumber = 120; timeval tvTemp; gettimeofday(&tvTemp, NULL); localSection.hdr.timestamp = tvTemp.tv_sec; localSection.hdr.timestamp_micros = tvTemp.tv_usec; localSection.lumiSummary.DeadtimeNormalization = 0.7; localSection.lumiSummary.LHCNormalization = 0.75; localSection.lumiSummary.OccNormalization[0] = 0.8; localSection.lumiSummary.OccNormalization[1] = 0.85; localSection.lumiSummary.ETNormalization = 0.8; localSection.lumiSummary.InstantLumi = 0.9; localSection.lumiSummary.InstantLumiErr = 0.10; localSection.lumiSummary.InstantLumiQlty = 11; localSection.lumiSummary.InstantETLumi = 0.12; localSection.lumiSummary.InstantETLumiErr = 0.13; localSection.lumiSummary.InstantETLumiQlty = 14; localSection.lumiSummary.InstantOccLumi[0] = 0.15; localSection.lumiSummary.InstantOccLumiErr[0] = 0.16; localSection.lumiSummary.InstantOccLumiQlty[0] = 17; localSection.lumiSummary.lumiNoise[0] = 0.18; localSection.lumiSummary.InstantOccLumi[1] = 0.19; localSection.lumiSummary.InstantOccLumiErr[1] = 0.20; localSection.lumiSummary.InstantOccLumiQlty[1] = 21; localSection.lumiSummary.lumiNoise[1] = 0.22; for(j=0; j < 3564; j++){ localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0; localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0; localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0; localSection.lumiDetail.LHCLumi[j] = 1*j/35640.0; localSection.lumiDetail.ETLumi[j] = 2*j/35640.0; localSection.lumiDetail.ETLumiErr[j] = 3*j/35640.0; localSection.lumiDetail.ETLumiQlty[j] = 4*j; localSection.lumiDetail.OccLumi[0][j] = 5*j/35640.0; localSection.lumiDetail.OccLumiErr[0][j] = 6*j/35640.0; localSection.lumiDetail.OccLumiQlty[0][j] = 7*j; localSection.lumiDetail.OccLumi[1][j] = 8*j/35640.0; localSection.lumiDetail.OccLumiErr[1][j] = 9*j/35640.0; localSection.lumiDetail.OccLumiQlty[1][j] = 10*j; } for(i=0; i<36; i ++){ localSection.etSum[i].hdr.numNibbles = 7; localSection.occupancy[i].hdr.numNibbles = 8; localSection.lhc[i].hdr.numNibbles = 9; localSection.etSum[i].hdr.bIsComplete = true; localSection.occupancy[i].hdr.bIsComplete = true; localSection.lhc[i].hdr.bIsComplete = true; for(j=0; j < 3564; j ++){ localSection.etSum[i].data[j] = 6*j+ 10*i; for(k=0; k < 6; k++){ localSection.occupancy[i].data[k][j] = k*j + 11*i; } localSection.lhc[i].data[j] = 7*j + 12*i; } } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; #endif }
void HCAL_HLX::TCPReceiver::GenerateRandomData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 395 of file TCPReceiver.cc.
References HCAL_HLX::LUMI_SECTION_HEADER::bCMSLive, HCAL_HLX::LUMI_SECTION_SUB_HEADER::bIsComplete, gather_cfg::cout, HCAL_HLX::ET_SUM_SECTION::data, HCAL_HLX::LHC_SECTION::data, HCAL_HLX::OCCUPANCY_SECTION::data, HCAL_HLX::LUMI_DETAIL::ETBXNormalization, HCAL_HLX::LUMI_DETAIL::ETLumi, HCAL_HLX::LUMI_DETAIL::ETLumiErr, HCAL_HLX::LUMI_DETAIL::ETLumiQlty, HCAL_HLX::LUMI_SUMMARY::ETNormalization, HCAL_HLX::LUMI_SECTION::etSum, HCAL_HLX::LHC_SECTION::hdr, HCAL_HLX::ET_SUM_SECTION::hdr, HCAL_HLX::LUMI_SECTION::hdr, HCAL_HLX::OCCUPANCY_SECTION::hdr, i, HCAL_HLX::LUMI_SUMMARY::InstantETLumi, HCAL_HLX::LUMI_SUMMARY::InstantETLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantETLumiQlty, HCAL_HLX::LUMI_SUMMARY::InstantLumi, HCAL_HLX::LUMI_SUMMARY::InstantLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantLumiQlty, HCAL_HLX::LUMI_SUMMARY::InstantOccLumi, HCAL_HLX::LUMI_SUMMARY::InstantOccLumiErr, HCAL_HLX::LUMI_SUMMARY::InstantOccLumiQlty, j, gen::k, HCAL_HLX::LUMI_SECTION::lhc, HCAL_HLX::LUMI_DETAIL::LHCLumi, HCAL_HLX::LUMI_SUMMARY::LHCNormalization, HCAL_HLX::LUMI_SECTION::lumiDetail, HCAL_HLX::LUMI_SUMMARY::lumiNoise, HCAL_HLX::LUMI_SECTION::lumiSummary, NULL, HCAL_HLX::LUMI_SECTION_HEADER::numBunches, HCAL_HLX::LUMI_SECTION_HEADER::numHLXs, HCAL_HLX::LUMI_SECTION_SUB_HEADER::numNibbles, HCAL_HLX::LUMI_SECTION_HEADER::numOrbits, HCAL_HLX::LUMI_DETAIL::OccBXNormalization, HCAL_HLX::LUMI_DETAIL::OccLumi, HCAL_HLX::LUMI_DETAIL::OccLumiErr, HCAL_HLX::LUMI_DETAIL::OccLumiQlty, HCAL_HLX::LUMI_SUMMARY::OccNormalization, HCAL_HLX::LUMI_SECTION::occupancy, HCAL_HLX::LUMI_SECTION_HEADER::runNumber, HCAL_HLX::LUMI_SECTION_HEADER::sectionNumber, HCAL_HLX::LUMI_SECTION_HEADER::startOrbit, and cond::rpcobgas::time.
Referenced by ReceiveLumiSection().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int i, j, k; srand(time(NULL)); localSection.hdr.runNumber = 55; //(rand() % 100); localSection.hdr.startOrbit = (rand() % 100); localSection.hdr.numOrbits = (rand() % 100); localSection.hdr.numBunches = (rand() % 100); localSection.hdr.numHLXs = (rand() % 100); localSection.hdr.bCMSLive = true; localSection.hdr.sectionNumber = (rand() %100); localSection.lumiSummary.DeadtimeNormalization = (float)(rand() % 100)/100; localSection.lumiSummary.LHCNormalization = (float)(rand() % 100)/100; localSection.lumiSummary.OccNormalization[0] = (float)(rand() % 100)/100; localSection.lumiSummary.OccNormalization[1] = (float)(rand() % 100)/100; localSection.lumiSummary.ETNormalization = (float)(rand() % 100)/100; localSection.lumiSummary.InstantLumi = (float)(rand() % 100)/100; localSection.lumiSummary.InstantLumiErr = (float)(rand() % 100)/100; localSection.lumiSummary.InstantLumiQlty = (rand() % 100); localSection.lumiSummary.InstantETLumi = (float)(rand() % 100)/100; localSection.lumiSummary.InstantETLumiErr = (float)(rand() % 100)/100; localSection.lumiSummary.InstantETLumiQlty = (rand() % 100); localSection.lumiSummary.InstantOccLumi[0] = (float)(rand() % 100)/100; localSection.lumiSummary.InstantOccLumiErr[0] = (float)(rand() % 100)/100; localSection.lumiSummary.InstantOccLumiQlty[0] = (rand() % 100); localSection.lumiSummary.lumiNoise[0] = (float)(rand() % 100)/100; localSection.lumiSummary.InstantOccLumi[1] = (float)(rand() % 100)/100; localSection.lumiSummary.InstantOccLumiErr[1] = (float)(rand() % 100)/100; localSection.lumiSummary.InstantOccLumiQlty[1] = (rand() % 100); localSection.lumiSummary.lumiNoise[1] = (float)(rand() % 100)/100; for(j=0; j < 3564; j++){ localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0; localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0; localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0; localSection.lumiDetail.LHCLumi[j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.ETLumi[j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.ETLumiErr[j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.ETLumiQlty[j] = (rand() % 100); localSection.lumiDetail.OccLumi[0][j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.OccLumiErr[0][j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.OccLumiQlty[0][j] = (rand() % 100); localSection.lumiDetail.OccLumi[1][j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.OccLumiErr[1][j] = (float)(rand() % 100)/100.0; localSection.lumiDetail.OccLumiQlty[1][j] = (rand() % 100); } for(i=0; i<36; i ++){ localSection.etSum[i].hdr.numNibbles = (rand() % 100); localSection.occupancy[i].hdr.numNibbles = 8*(rand() % 100); localSection.lhc[i].hdr.numNibbles = 9*(rand() % 100); localSection.etSum[i].hdr.bIsComplete = true; localSection.occupancy[i].hdr.bIsComplete = true; localSection.lhc[i].hdr.bIsComplete = true; for(j=0; j < 3564; j ++){ localSection.etSum[i].data[j] = 6*(rand() % 3564); for(k=0; k < 6; k++){ localSection.occupancy[i].data[k][j] = k*(rand() % 3564); } localSection.lhc[i].data[j] = 7*(rand() % 3564); } } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; #endif }
bool HCAL_HLX::TCPReceiver::IsConnected | ( | ) |
Definition at line 175 of file TCPReceiver.cc.
References Connected, and gather_cfg::cout.
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
int HCAL_HLX::TCPReceiver::ReceiveLumiSection | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 88 of file TCPReceiver.cc.
References acquireMode, Connected, gather_cfg::cout, GenerateFakeData(), GenerateRandomData(), benchmark_cfg::select, HCAL_HLX::SetupFDSets(), tcpSocket, and cond::rpcobgas::time.
Referenced by HLXMonitor::analyze().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int errorCode = 0; if(acquireMode == 0){ // real data if(Connected == false){ errorCode = 701; // not connected } else { unsigned int bytesRcvd, bytesToReceive, totalBytesRcvd; const unsigned int Buffer_Size = 8192; char *Buffer; char *BigBuffer; // From John's code fd_set fdsRead, fdsWrite, fdsExcept; // int outputcode; //int z = 0, localCount = 0; time_t tempTime, curTime; //int ret; time(&curTime); bytesToReceive = sizeof(localSection); Buffer = new char[Buffer_Size]; BigBuffer = new char[bytesToReceive]; totalBytesRcvd = 0; memset(reinterpret_cast<char *>(&localSection), 0, Buffer_Size); memset(Buffer, 0, Buffer_Size); memset(BigBuffer, 0, bytesToReceive); usleep(10000); while((totalBytesRcvd < bytesToReceive) && (errorCode == 0)){ SetupFDSets(fdsRead, fdsWrite, fdsExcept, -1, tcpSocket); if(select(tcpSocket+1, &fdsRead, 0, &fdsExcept, 0)> 0){ if (FD_ISSET(tcpSocket, &fdsRead)) { if((bytesRcvd = recv(tcpSocket, Buffer, Buffer_Size, 0))<=0){ perror("Recv Error"); errorCode = 501; }else{ if((totalBytesRcvd + bytesRcvd)<= bytesToReceive){ memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd); }else{ std::cout << "***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****" << std::endl; errorCode = 502; } totalBytesRcvd += bytesRcvd; time(&tempTime); } } } } if(errorCode == 0){ memcpy(reinterpret_cast<char *>(&localSection), BigBuffer, sizeof(localSection)); errorCode = 1; // success } delete [] Buffer; delete [] BigBuffer; } } else if(acquireMode == 1){ // fill with fake data. Should be unique. GenerateFakeData(localSection); errorCode = 1; } else if(acquireMode == 2){ // fill with random fake data. GenerateRandomData(localSection); errorCode = 1; } else { errorCode = 201; } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; #endif return errorCode; }
void HCAL_HLX::TCPReceiver::SetIP | ( | std::string | IP | ) |
Definition at line 222 of file TCPReceiver.cc.
References gather_cfg::cout, and servIP.
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
int HCAL_HLX::TCPReceiver::SetMode | ( | unsigned char | mode | ) |
Definition at line 202 of file TCPReceiver.cc.
References acquireMode, gather_cfg::cout, and mode.
Referenced by HLXMonitor::beginJob().
{ #ifdef DEBUG std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; #endif int errorCode; if(mode > 2){ errorCode = 201; } else { acquireMode = mode; errorCode = 1; } #ifdef DEBUG std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; #endif return errorCode; }
int HCAL_HLX::TCPReceiver::SetPort | ( | unsigned short int | port | ) |
Definition at line 182 of file TCPReceiver.cc.
References gather_cfg::cout, query::port, and servPort.
Referenced by HLXMonitor::beginJob().
bool HCAL_HLX::TCPReceiver::VerifyFakeData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 469 of file TCPReceiver.cc.
References GenerateFakeData(), and dttmaxenums::L.
{ HCAL_HLX::LUMI_SECTION L; GenerateFakeData(L); return !(memcmp(&L, &localSection, sizeof(L))); }
unsigned char HCAL_HLX::TCPReceiver::acquireMode [private] |
Definition at line 55 of file TCPReceiver.h.
Referenced by Connect(), Disconnect(), ReceiveLumiSection(), SetMode(), and TCPReceiver().
bool HCAL_HLX::TCPReceiver::Connected [private] |
Definition at line 56 of file TCPReceiver.h.
Referenced by Connect(), Disconnect(), IsConnected(), ReceiveLumiSection(), and TCPReceiver().
struct sockaddr_in HCAL_HLX::TCPReceiver::servAddr [private] |
Definition at line 61 of file TCPReceiver.h.
Referenced by Connect().
std::string HCAL_HLX::TCPReceiver::servIP [private] |
Definition at line 59 of file TCPReceiver.h.
Referenced by Connect(), SetIP(), and TCPReceiver().
unsigned short HCAL_HLX::TCPReceiver::servPort [private] |
Definition at line 58 of file TCPReceiver.h.
Referenced by Connect(), SetPort(), and TCPReceiver().
int HCAL_HLX::TCPReceiver::tcpSocket [private] |
Definition at line 60 of file TCPReceiver.h.
Referenced by Connect(), Disconnect(), and ReceiveLumiSection().