#include <RecoLuminosity/TCPReceiver/interface/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 (unsigned short int, std::string, unsigned char) | |
TCPReceiver () | |
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 46 of file TCPReceiver.h.
HCAL_HLX::TCPReceiver::TCPReceiver | ( | ) |
Definition at line 14 of file TCPReceiver.cc.
References acquireMode, Connected, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), servIP, and servPort.
00014 { 00015 #ifdef DEBUG 00016 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00017 #endif 00018 acquireMode = 0; 00019 servPort = 0; 00020 servIP = "127.0.0.1"; 00021 Connected = false; 00022 #ifdef DEBUG 00023 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00024 #endif 00025 }
HCAL_HLX::TCPReceiver::TCPReceiver | ( | unsigned short int | port, | |
std::string | IP, | |||
unsigned char | mode = 0 | |||
) |
Definition at line 27 of file TCPReceiver.cc.
References acquireMode, Connected, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), mode, servIP, and servPort.
00027 { 00028 #ifdef DEBUG 00029 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00030 #endif 00031 acquireMode = mode; 00032 servPort = port; 00033 servIP = IP; 00034 Connected = false; 00035 00036 #ifdef DEBUG 00037 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00038 #endif 00039 }
HCAL_HLX::TCPReceiver::~TCPReceiver | ( | ) |
Definition at line 41 of file TCPReceiver.cc.
References Disconnect().
00041 { 00042 Disconnect(); 00043 }
int HCAL_HLX::TCPReceiver::Connect | ( | ) |
Definition at line 214 of file TCPReceiver.cc.
References acquireMode, HLT_VtxMuL3::connect, Connected, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), servAddr, servIP, servPort, socket, and tcpSocket.
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
00214 { 00215 #ifdef DEBUG 00216 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00217 #endif 00218 00219 int errorCode; 00220 00221 if(acquireMode == 0){ 00222 struct hostent * hostInfo = gethostbyname(servIP.c_str()); 00223 00224 if(servPort < 1024){ 00225 errorCode = 101; // Protected ports 00226 } else { 00227 #ifdef DEBUG 00228 std::cout << "Requesting connection" << std::endl; 00229 #endif 00230 if((tcpSocket = socket(AF_INET, SOCK_STREAM, 0))<0){ 00231 perror("Socket Error"); 00232 errorCode = 301; // Socket failed 00233 }else{ 00234 memset(&servAddr, 0, sizeof(servAddr)); 00235 servAddr.sin_family = hostInfo->h_addrtype; 00236 memcpy((char *) &servAddr.sin_addr.s_addr, 00237 hostInfo->h_addr_list[0], 00238 hostInfo->h_length); 00239 // servAddr.sin_addr.s_addr = inet_addr(servIP.c_str()); 00240 servAddr.sin_port = htons(servPort); 00241 #ifdef DEBUG 00242 std::cout << "Connecting" << std::endl; 00243 #endif 00244 if(connect(tcpSocket, (struct sockaddr *) &servAddr, sizeof(servAddr))<0){ 00245 perror("Connect Error"); 00246 errorCode = 302; // connect failed 00247 close(tcpSocket); 00248 } else{ 00249 Connected = true; 00250 errorCode = 1; // Successful connection 00251 } 00252 } 00253 } 00254 } else if(acquireMode == 1) { 00255 Connected = true; 00256 errorCode = 1; // do nothing for fake data 00257 } else if(acquireMode == 2) { 00258 Connected = true; 00259 errorCode = 1; // do nothing for random data 00260 } else { 00261 errorCode = 201; // Invalid aquire mode 00262 } 00263 00264 #ifdef DEBUG 00265 std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; 00266 #endif 00267 return errorCode; 00268 }
int HCAL_HLX::TCPReceiver::Disconnect | ( | ) |
Definition at line 270 of file TCPReceiver.cc.
References Connected, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and tcpSocket.
Referenced by HLXMonitor::analyze(), HLXMonitor::endJob(), HLXMonitor::~HLXMonitor(), and ~TCPReceiver().
00270 { 00271 #ifdef DEBUG 00272 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00273 #endif 00274 00275 int errorCode; 00276 00277 if(Connected){ 00278 if(shutdown(tcpSocket,SHUT_RDWR)<0){ 00279 perror("Shutdown Error"); 00280 errorCode = 601; // Disconnect Failed 00281 Connected = false; 00282 } else { 00283 Connected = false; 00284 errorCode = 1; // Successful Disconnect 00285 } 00286 } else { 00287 errorCode = 401; // Not Connected 00288 } 00289 00290 #ifdef DEBUG 00291 std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; 00292 #endif 00293 return errorCode; 00294 }
void HCAL_HLX::TCPReceiver::GenerateFakeData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 296 of file TCPReceiver.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, j, and k.
Referenced by ReceiveLumiSection(), and VerifyFakeData().
00296 { 00297 #ifdef DEBUG 00298 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00299 #endif 00300 int i, j, k; 00301 00302 localSection.hdr.runNumber = 1; 00303 localSection.hdr.startOrbit = 2; 00304 localSection.hdr.numOrbits = 3; 00305 localSection.hdr.numBunches = 4; 00306 localSection.hdr.numHLXs = 5; 00307 localSection.hdr.bCMSLive = true; 00308 localSection.hdr.sectionNumber = 120; 00309 00310 localSection.lumiSummary.DeadtimeNormalization = 0.7; 00311 localSection.lumiSummary.LHCNormalization = 0.75; 00312 localSection.lumiSummary.OccNormalization[0] = 0.8; 00313 localSection.lumiSummary.OccNormalization[1] = 0.85; 00314 localSection.lumiSummary.ETNormalization = 0.8; 00315 localSection.lumiSummary.InstantLumi = 0.9; 00316 localSection.lumiSummary.InstantLumiErr = 0.10; 00317 localSection.lumiSummary.InstantLumiQlty = 11; 00318 localSection.lumiSummary.InstantETLumi = 0.12; 00319 localSection.lumiSummary.InstantETLumiErr = 0.13; 00320 localSection.lumiSummary.InstantETLumiQlty = 14; 00321 localSection.lumiSummary.InstantOccLumi[0] = 0.15; 00322 localSection.lumiSummary.InstantOccLumiErr[0] = 0.16; 00323 localSection.lumiSummary.InstantOccLumiQlty[0] = 17; 00324 localSection.lumiSummary.lumiNoise[0] = 0.18; 00325 localSection.lumiSummary.InstantOccLumi[1] = 0.19; 00326 localSection.lumiSummary.InstantOccLumiErr[1] = 0.20; 00327 localSection.lumiSummary.InstantOccLumiQlty[1] = 21; 00328 localSection.lumiSummary.lumiNoise[1] = 0.22; 00329 00330 for(j=0; j < 3564; j++){ 00331 localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0; 00332 localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0; 00333 localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0; 00334 localSection.lumiDetail.LHCLumi[j] = 1*j/35640.0; 00335 localSection.lumiDetail.ETLumi[j] = 2*j/35640.0; 00336 localSection.lumiDetail.ETLumiErr[j] = 3*j/35640.0; 00337 localSection.lumiDetail.ETLumiQlty[j] = 4*j; 00338 localSection.lumiDetail.OccLumi[0][j] = 5*j/35640.0; 00339 localSection.lumiDetail.OccLumiErr[0][j] = 6*j/35640.0; 00340 localSection.lumiDetail.OccLumiQlty[0][j] = 7*j; 00341 localSection.lumiDetail.OccLumi[1][j] = 8*j/35640.0; 00342 localSection.lumiDetail.OccLumiErr[1][j] = 9*j/35640.0; 00343 localSection.lumiDetail.OccLumiQlty[1][j] = 10*j; 00344 } 00345 00346 for(i=0; i<36; i ++){ 00347 localSection.etSum[i].hdr.numNibbles = 7; 00348 localSection.occupancy[i].hdr.numNibbles = 8; 00349 localSection.lhc[i].hdr.numNibbles = 9; 00350 00351 localSection.etSum[i].hdr.bIsComplete = true; 00352 localSection.occupancy[i].hdr.bIsComplete = true; 00353 localSection.lhc[i].hdr.bIsComplete = true; 00354 00355 for(j=0; j < 3564; j ++){ 00356 localSection.etSum[i].data[j] = 6*j+ 10*i; 00357 for(k=0; k < 6; k++){ 00358 localSection.occupancy[i].data[k][j] = k*j + 11*i; 00359 } 00360 localSection.lhc[i].data[j] = 7*j + 12*i; 00361 } 00362 } 00363 00364 #ifdef DEBUG 00365 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00366 #endif 00367 00368 }
void HCAL_HLX::TCPReceiver::GenerateRandomData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 370 of file TCPReceiver.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), i, j, k, and NULL.
Referenced by ReceiveLumiSection().
00370 { 00371 #ifdef DEBUG 00372 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00373 #endif 00374 int i, j, k; 00375 00376 srand(time(NULL)); 00377 localSection.hdr.runNumber = 55; //(rand() % 100); 00378 localSection.hdr.startOrbit = (rand() % 100); 00379 localSection.hdr.numOrbits = (rand() % 100); 00380 localSection.hdr.numBunches = (rand() % 100); 00381 localSection.hdr.numHLXs = (rand() % 100); 00382 localSection.hdr.bCMSLive = true; 00383 localSection.hdr.sectionNumber = (rand() %100); 00384 00385 localSection.lumiSummary.DeadtimeNormalization = (float)(rand() % 100)/100; 00386 localSection.lumiSummary.LHCNormalization = (float)(rand() % 100)/100; 00387 localSection.lumiSummary.OccNormalization[0] = (float)(rand() % 100)/100; 00388 localSection.lumiSummary.OccNormalization[1] = (float)(rand() % 100)/100; 00389 localSection.lumiSummary.ETNormalization = (float)(rand() % 100)/100; 00390 localSection.lumiSummary.InstantLumi = (float)(rand() % 100)/100; 00391 localSection.lumiSummary.InstantLumiErr = (float)(rand() % 100)/100; 00392 localSection.lumiSummary.InstantLumiQlty = (rand() % 100); 00393 localSection.lumiSummary.InstantETLumi = (float)(rand() % 100)/100; 00394 localSection.lumiSummary.InstantETLumiErr = (float)(rand() % 100)/100; 00395 localSection.lumiSummary.InstantETLumiQlty = (rand() % 100); 00396 localSection.lumiSummary.InstantOccLumi[0] = (float)(rand() % 100)/100; 00397 localSection.lumiSummary.InstantOccLumiErr[0] = (float)(rand() % 100)/100; 00398 localSection.lumiSummary.InstantOccLumiQlty[0] = (rand() % 100); 00399 localSection.lumiSummary.lumiNoise[0] = (float)(rand() % 100)/100; 00400 localSection.lumiSummary.InstantOccLumi[1] = (float)(rand() % 100)/100; 00401 localSection.lumiSummary.InstantOccLumiErr[1] = (float)(rand() % 100)/100; 00402 localSection.lumiSummary.InstantOccLumiQlty[1] = (rand() % 100); 00403 localSection.lumiSummary.lumiNoise[1] = (float)(rand() % 100)/100; 00404 00405 for(j=0; j < 3564; j++){ 00406 localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0; 00407 localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0; 00408 localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0; 00409 localSection.lumiDetail.LHCLumi[j] = (float)(rand() % 100)/100.0; 00410 localSection.lumiDetail.ETLumi[j] = (float)(rand() % 100)/100.0; 00411 localSection.lumiDetail.ETLumiErr[j] = (float)(rand() % 100)/100.0; 00412 localSection.lumiDetail.ETLumiQlty[j] = (rand() % 100); 00413 localSection.lumiDetail.OccLumi[0][j] = (float)(rand() % 100)/100.0; 00414 localSection.lumiDetail.OccLumiErr[0][j] = (float)(rand() % 100)/100.0; 00415 localSection.lumiDetail.OccLumiQlty[0][j] = (rand() % 100); 00416 localSection.lumiDetail.OccLumi[1][j] = (float)(rand() % 100)/100.0; 00417 localSection.lumiDetail.OccLumiErr[1][j] = (float)(rand() % 100)/100.0; 00418 localSection.lumiDetail.OccLumiQlty[1][j] = (rand() % 100); 00419 } 00420 00421 for(i=0; i<36; i ++){ 00422 localSection.etSum[i].hdr.numNibbles = (rand() % 100); 00423 localSection.occupancy[i].hdr.numNibbles = 8*(rand() % 100); 00424 localSection.lhc[i].hdr.numNibbles = 9*(rand() % 100); 00425 00426 localSection.etSum[i].hdr.bIsComplete = true; 00427 localSection.occupancy[i].hdr.bIsComplete = true; 00428 localSection.lhc[i].hdr.bIsComplete = true; 00429 00430 for(j=0; j < 3564; j ++){ 00431 localSection.etSum[i].data[j] = 6*(rand() % 3564); 00432 for(k=0; k < 6; k++){ 00433 localSection.occupancy[i].data[k][j] = k*(rand() % 3564); 00434 } 00435 localSection.lhc[i].data[j] = 7*(rand() % 3564); 00436 } 00437 } 00438 00439 #ifdef DEBUG 00440 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00441 #endif 00442 }
bool HCAL_HLX::TCPReceiver::IsConnected | ( | ) |
Definition at line 157 of file TCPReceiver.cc.
References Connected, GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
00157 { 00158 #ifdef DEBUG 00159 std::cout << "Begin and End " << __PRETTY_FUNCTION__ << " " << Connected << std::endl; 00160 #endif 00161 return Connected; 00162 }
int HCAL_HLX::TCPReceiver::ReceiveLumiSection | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 66 of file TCPReceiver.cc.
References acquireMode, Connected, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), GenerateFakeData(), GenerateRandomData(), dummy::select(), HCAL_HLX::SetupFDSets(), and tcpSocket.
Referenced by HLXMonitor::analyze().
00066 { 00067 #ifdef DEBUG 00068 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00069 #endif 00070 00071 int errorCode = 0; 00072 00073 if(acquireMode == 0){ // real data 00074 if(Connected == false){ 00075 errorCode = 701; // not connected 00076 } else { 00077 unsigned int bytesRcvd, bytesToReceive, totalBytesRcvd; 00078 const unsigned int Buffer_Size = 8192; 00079 char *Buffer; 00080 char *BigBuffer; 00081 00082 // From John's code 00083 00084 fd_set fdsRead, fdsWrite, fdsExcept; 00085 struct timeval tv; 00086 00087 tv.tv_sec = 1; 00088 tv.tv_usec = 0; 00089 00090 // int outputcode; 00091 //int z = 0, localCount = 0; 00092 time_t tempTime, curTime; 00093 //int ret; 00094 00095 time(&curTime); 00096 00097 bytesToReceive = sizeof(localSection); 00098 Buffer = new char[Buffer_Size]; 00099 BigBuffer = new char[bytesToReceive]; 00100 totalBytesRcvd = 0; 00101 00102 memset(reinterpret_cast<char *>(&localSection), 0, Buffer_Size); 00103 memset(Buffer, 0, Buffer_Size); 00104 memset(BigBuffer, 0, bytesToReceive); 00105 00106 usleep(10000); 00107 00108 while((totalBytesRcvd < bytesToReceive) && (errorCode == 0)){ 00109 00110 SetupFDSets(fdsRead, fdsWrite, fdsExcept, -1, tcpSocket); 00111 00112 if(select(tcpSocket+1, &fdsRead, 0, &fdsExcept, 0)> 0){ 00113 00114 if (FD_ISSET(tcpSocket, &fdsRead)) { 00115 00116 if((bytesRcvd = recv(tcpSocket, Buffer, Buffer_Size, 0))<=0){ 00117 perror("Recv Error"); 00118 errorCode = 501; 00119 }else{ 00120 if((totalBytesRcvd + bytesRcvd)<= bytesToReceive){ 00121 memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd); 00122 }else{ 00123 std::cout << "***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****" << std::endl; 00124 errorCode = 502; 00125 } 00126 totalBytesRcvd += bytesRcvd; 00127 time(&tempTime); 00128 } 00129 } 00130 } 00131 } 00132 00133 if(errorCode == 0){ 00134 memcpy(reinterpret_cast<char *>(&localSection), BigBuffer, sizeof(localSection)); 00135 errorCode = 1; // success 00136 } 00137 delete [] Buffer; 00138 delete [] BigBuffer; 00139 } 00140 } else if(acquireMode == 1){ // fill with fake data. Should be unique. 00141 GenerateFakeData(localSection); 00142 errorCode = 1; 00143 } else if(acquireMode == 2){ // fill with random fake data. 00144 GenerateRandomData(localSection); 00145 errorCode = 1; 00146 } else { 00147 errorCode = 201; 00148 } 00149 00150 #ifdef DEBUG 00151 std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; 00152 #endif 00153 00154 return errorCode; 00155 }
void HCAL_HLX::TCPReceiver::SetIP | ( | std::string | IP | ) |
Definition at line 204 of file TCPReceiver.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and servIP.
Referenced by HLXMonitor::analyze(), and HLXMonitor::beginJob().
00204 { 00205 #ifdef DEBUG 00206 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00207 #endif 00208 servIP = IP; 00209 #ifdef DEBUG 00210 std::cout << "End " << __PRETTY_FUNCTION__ << std::endl; 00211 #endif 00212 }
int HCAL_HLX::TCPReceiver::SetMode | ( | unsigned char | mode | ) |
Definition at line 184 of file TCPReceiver.cc.
References acquireMode, GenMuonPlsPt100GeV_cfg::cout, and lat::endl().
Referenced by HLXMonitor::beginJob().
00184 { 00185 #ifdef DEBUG 00186 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00187 #endif 00188 00189 int errorCode; 00190 00191 if(mode > 2){ 00192 errorCode = 201; 00193 } else { 00194 acquireMode = mode; 00195 errorCode = 1; 00196 } 00197 00198 #ifdef DEBUG 00199 std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; 00200 #endif 00201 return errorCode; 00202 }
Definition at line 164 of file TCPReceiver.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), and servPort.
Referenced by HLXMonitor::beginJob().
00164 { 00165 #ifdef DEBUG 00166 std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl; 00167 #endif 00168 00169 int errorCode; 00170 00171 if(port < 1024){ 00172 errorCode = 101; 00173 }else{ 00174 servPort = port; 00175 errorCode = 1; 00176 } 00177 00178 #ifdef DEBUG 00179 std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl; 00180 #endif 00181 return errorCode; 00182 }
bool HCAL_HLX::TCPReceiver::VerifyFakeData | ( | HCAL_HLX::LUMI_SECTION & | localSection | ) |
Definition at line 444 of file TCPReceiver.cc.
References GenerateFakeData(), L, and HLT_VtxMuL3::result.
00444 { 00445 00446 HCAL_HLX::LUMI_SECTION L; 00447 GenerateFakeData(L); 00448 int result; 00449 00450 result = memcmp(&L, &localSection, sizeof(L)); 00451 00452 if(result = 0){ 00453 return true; 00454 }else{ 00455 return false; 00456 } 00457 }
unsigned char HCAL_HLX::TCPReceiver::acquireMode [private] |
Definition at line 65 of file TCPReceiver.h.
Referenced by Connect(), ReceiveLumiSection(), SetMode(), and TCPReceiver().
bool HCAL_HLX::TCPReceiver::Connected [private] |
Definition at line 66 of file TCPReceiver.h.
Referenced by Connect(), Disconnect(), IsConnected(), ReceiveLumiSection(), and TCPReceiver().
struct sockaddr_in HCAL_HLX::TCPReceiver::servAddr [read, private] |
std::string HCAL_HLX::TCPReceiver::servIP [private] |
unsigned short HCAL_HLX::TCPReceiver::servPort [private] |
int HCAL_HLX::TCPReceiver::tcpSocket [private] |
Definition at line 70 of file TCPReceiver.h.
Referenced by Connect(), Disconnect(), and ReceiveLumiSection().