CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HCAL_HLX::TCPReceiver Class Reference

#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
 

Detailed Description

Definition at line 36 of file TCPReceiver.h.

Constructor & Destructor Documentation

HCAL_HLX::TCPReceiver::TCPReceiver ( )

Definition at line 34 of file TCPReceiver.cc.

References acquireMode, Connected, gather_cfg::cout, servIP, and servPort.

34  {
35 #ifdef DEBUG
36  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
37 #endif
38 
39  acquireMode = 0;
40  servPort = 0;
41  servIP = "127.0.0.1";
42  Connected = false;
43 
44 #ifdef DEBUG
45  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
46 #endif
47  }
unsigned char acquireMode
Definition: TCPReceiver.h:55
std::string servIP
Definition: TCPReceiver.h:59
unsigned short servPort
Definition: TCPReceiver.h:58
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, listHistos::IP, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, query::port, servIP, and servPort.

49  {
50 #ifdef DEBUG
51  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
52 #endif
53  acquireMode = mode;
54  servPort = port;
55  servIP = IP;
56  Connected = false;
57 
58 #ifdef DEBUG
59  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
60 #endif
61  }
unsigned char acquireMode
Definition: TCPReceiver.h:55
port
Definition: query.py:116
std::string servIP
Definition: TCPReceiver.h:59
unsigned short servPort
Definition: TCPReceiver.h:58
HCAL_HLX::TCPReceiver::~TCPReceiver ( )

Definition at line 63 of file TCPReceiver.cc.

References Disconnect().

63  {
64  Disconnect();
65  }

Member Function Documentation

int HCAL_HLX::TCPReceiver::Connect ( )

Definition at line 232 of file TCPReceiver.cc.

References acquireMode, DBConfiguration_cff::connect, Connected, gather_cfg::cout, servAddr, servIP, servPort, and tcpSocket.

Referenced by HLXMonitor::analyze(), and HLXMonitor::connectHLXTCP().

232  {
233 #ifdef DEBUG
234  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
235 #endif
236 
237  int errorCode;
238 
239  if(acquireMode == 0){
240  struct hostent * hostInfo = gethostbyname(servIP.c_str());
241 
242  if(servPort < 1024){
243  errorCode = 101; // Protected ports
244  } else {
245 #ifdef DEBUG
246  std::cout << "Requesting connection" << std::endl;
247 #endif
248  if((tcpSocket = socket(AF_INET, SOCK_STREAM, 0))<0){
249  perror("Socket Error");
250  errorCode = 301; // Socket failed
251  }else{
252  memset(&servAddr, 0, sizeof(servAddr));
253  servAddr.sin_family = hostInfo->h_addrtype;
254  memcpy((char *) &servAddr.sin_addr.s_addr,
255  hostInfo->h_addr_list[0],
256  hostInfo->h_length);
257  // servAddr.sin_addr.s_addr = inet_addr(servIP.c_str());
258  servAddr.sin_port = htons(servPort);
259 #ifdef DEBUG
260  std::cout << "Connecting" << std::endl;
261 #endif
262  if(connect(tcpSocket, (struct sockaddr *) &servAddr, sizeof(servAddr))<0){
263  perror("Connect Error");
264  errorCode = 302; // connect failed
265  close(tcpSocket);
266  } else{
267  Connected = true;
268  errorCode = 1; // Successful connection
269  }
270  }
271  }
272  } else if(acquireMode == 1) {
273  Connected = true;
274  errorCode = 1; // do nothing for fake data
275  } else if(acquireMode == 2) {
276  Connected = true;
277  errorCode = 1; // do nothing for random data
278  } else {
279  errorCode = 201; // Invalid acquire mode
280  }
281 
282 #ifdef DEBUG
283  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
284 #endif
285  return errorCode;
286  }
unsigned char acquireMode
Definition: TCPReceiver.h:55
std::string servIP
Definition: TCPReceiver.h:59
unsigned short servPort
Definition: TCPReceiver.h:58
struct sockaddr_in servAddr
Definition: TCPReceiver.h:61
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::~HLXMonitor(), and ~TCPReceiver().

288  {
289 #ifdef DEBUG
290  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
291 #endif
292 
293  int errorCode = 0;
294 
295  if(Connected){
296  if( acquireMode == 0 ){
297  if(shutdown(tcpSocket,SHUT_RDWR)<0){
298  perror("Shutdown Error");
299  errorCode = 601; // Disconnect Failed
300  } else {
301 
302  errorCode = 1; // Successful Disconnect
303  }
304  }
305  Connected = false;
306  } else {
307  errorCode = 401; // Not Connected
308  }
309 
310 #ifdef DEBUG
311  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
312 #endif
313  return errorCode;
314  }
unsigned char acquireMode
Definition: TCPReceiver.h:55
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::OCCUPANCY_SECTION::data, HCAL_HLX::LHC_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::ET_SUM_SECTION::hdr, HCAL_HLX::OCCUPANCY_SECTION::hdr, HCAL_HLX::LHC_SECTION::hdr, HCAL_HLX::LUMI_SECTION::hdr, mps_fire::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, 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, 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().

316  {
317 #ifdef DEBUG
318  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
319 #endif
320  int i, j, k;
321 
322  localSection.hdr.runNumber = 1;
323  localSection.hdr.startOrbit = 2;
324  localSection.hdr.numOrbits = 3;
325  localSection.hdr.numBunches = 4;
326  localSection.hdr.numHLXs = 5;
327  localSection.hdr.bCMSLive = true;
328  localSection.hdr.sectionNumber = 120;
329 
330  timeval tvTemp;
331  gettimeofday(&tvTemp, nullptr);
332  localSection.hdr.timestamp = tvTemp.tv_sec;
333  localSection.hdr.timestamp_micros = tvTemp.tv_usec;
334 
335  localSection.lumiSummary.DeadtimeNormalization = 0.7;
336  localSection.lumiSummary.LHCNormalization = 0.75;
337  localSection.lumiSummary.OccNormalization[0] = 0.8;
338  localSection.lumiSummary.OccNormalization[1] = 0.85;
339  localSection.lumiSummary.ETNormalization = 0.8;
340  localSection.lumiSummary.InstantLumi = 0.9;
341  localSection.lumiSummary.InstantLumiErr = 0.10;
342  localSection.lumiSummary.InstantLumiQlty = 11;
343  localSection.lumiSummary.InstantETLumi = 0.12;
344  localSection.lumiSummary.InstantETLumiErr = 0.13;
345  localSection.lumiSummary.InstantETLumiQlty = 14;
346  localSection.lumiSummary.InstantOccLumi[0] = 0.15;
347  localSection.lumiSummary.InstantOccLumiErr[0] = 0.16;
348  localSection.lumiSummary.InstantOccLumiQlty[0] = 17;
349  localSection.lumiSummary.lumiNoise[0] = 0.18;
350  localSection.lumiSummary.InstantOccLumi[1] = 0.19;
351  localSection.lumiSummary.InstantOccLumiErr[1] = 0.20;
352  localSection.lumiSummary.InstantOccLumiQlty[1] = 21;
353  localSection.lumiSummary.lumiNoise[1] = 0.22;
354 
355  for(j=0; j < 3564; j++){
356  localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0;
357  localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0;
358  localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0;
359  localSection.lumiDetail.LHCLumi[j] = 1*j/35640.0;
360  localSection.lumiDetail.ETLumi[j] = 2*j/35640.0;
361  localSection.lumiDetail.ETLumiErr[j] = 3*j/35640.0;
362  localSection.lumiDetail.ETLumiQlty[j] = 4*j;
363  localSection.lumiDetail.OccLumi[0][j] = 5*j/35640.0;
364  localSection.lumiDetail.OccLumiErr[0][j] = 6*j/35640.0;
365  localSection.lumiDetail.OccLumiQlty[0][j] = 7*j;
366  localSection.lumiDetail.OccLumi[1][j] = 8*j/35640.0;
367  localSection.lumiDetail.OccLumiErr[1][j] = 9*j/35640.0;
368  localSection.lumiDetail.OccLumiQlty[1][j] = 10*j;
369  }
370 
371  for(i=0; i<36; i ++){
372  localSection.etSum[i].hdr.numNibbles = 7;
373  localSection.occupancy[i].hdr.numNibbles = 8;
374  localSection.lhc[i].hdr.numNibbles = 9;
375 
376  localSection.etSum[i].hdr.bIsComplete = true;
377  localSection.occupancy[i].hdr.bIsComplete = true;
378  localSection.lhc[i].hdr.bIsComplete = true;
379 
380  for(j=0; j < 3564; j ++){
381  localSection.etSum[i].data[j] = 6*j+ 10*i;
382  for(k=0; k < 6; k++){
383  localSection.occupancy[i].data[k][j] = k*j + 11*i;
384  }
385  localSection.lhc[i].data[j] = 7*j + 12*i;
386  }
387  }
388 
389 #ifdef DEBUG
390  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
391 #endif
392 
393  }
LUMI_SECTION_SUB_HEADER hdr
OCCUPANCY_SECTION occupancy[36]
int k[5][pyjets_maxn]
LUMI_SECTION_SUB_HEADER hdr
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::OCCUPANCY_SECTION::data, HCAL_HLX::LHC_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, objects.autophobj::float, HCAL_HLX::ET_SUM_SECTION::hdr, HCAL_HLX::OCCUPANCY_SECTION::hdr, HCAL_HLX::LHC_SECTION::hdr, HCAL_HLX::LUMI_SECTION::hdr, mps_fire::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, 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, 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, rand(), HCAL_HLX::LUMI_SECTION_HEADER::runNumber, HCAL_HLX::LUMI_SECTION_HEADER::sectionNumber, HCAL_HLX::LUMI_SECTION_HEADER::startOrbit, and protons_cff::time.

Referenced by ReceiveLumiSection().

395  {
396 #ifdef DEBUG
397  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
398 #endif
399  int i, j, k;
400 
401  srand(time(nullptr));
402  localSection.hdr.runNumber = 55; //(rand() % 100);
403  localSection.hdr.startOrbit = (rand() % 100);
404  localSection.hdr.numOrbits = (rand() % 100);
405  localSection.hdr.numBunches = (rand() % 100);
406  localSection.hdr.numHLXs = (rand() % 100);
407  localSection.hdr.bCMSLive = true;
408  localSection.hdr.sectionNumber = (rand() %100);
409 
410  localSection.lumiSummary.DeadtimeNormalization = (float)(rand() % 100)/100;
411  localSection.lumiSummary.LHCNormalization = (float)(rand() % 100)/100;
412  localSection.lumiSummary.OccNormalization[0] = (float)(rand() % 100)/100;
413  localSection.lumiSummary.OccNormalization[1] = (float)(rand() % 100)/100;
414  localSection.lumiSummary.ETNormalization = (float)(rand() % 100)/100;
415  localSection.lumiSummary.InstantLumi = (float)(rand() % 100)/100;
416  localSection.lumiSummary.InstantLumiErr = (float)(rand() % 100)/100;
417  localSection.lumiSummary.InstantLumiQlty = (rand() % 100);
418  localSection.lumiSummary.InstantETLumi = (float)(rand() % 100)/100;
419  localSection.lumiSummary.InstantETLumiErr = (float)(rand() % 100)/100;
420  localSection.lumiSummary.InstantETLumiQlty = (rand() % 100);
421  localSection.lumiSummary.InstantOccLumi[0] = (float)(rand() % 100)/100;
422  localSection.lumiSummary.InstantOccLumiErr[0] = (float)(rand() % 100)/100;
423  localSection.lumiSummary.InstantOccLumiQlty[0] = (rand() % 100);
424  localSection.lumiSummary.lumiNoise[0] = (float)(rand() % 100)/100;
425  localSection.lumiSummary.InstantOccLumi[1] = (float)(rand() % 100)/100;
426  localSection.lumiSummary.InstantOccLumiErr[1] = (float)(rand() % 100)/100;
427  localSection.lumiSummary.InstantOccLumiQlty[1] = (rand() % 100);
428  localSection.lumiSummary.lumiNoise[1] = (float)(rand() % 100)/100;
429 
430  for(j=0; j < 3564; j++){
431  localSection.lumiDetail.ETBXNormalization[j] = 0.25*j/35640.0;
432  localSection.lumiDetail.OccBXNormalization[0][j] = 0.5*j/35640.0;
433  localSection.lumiDetail.OccBXNormalization[1][j] = 0.75*j/35640.0;
434  localSection.lumiDetail.LHCLumi[j] = (float)(rand() % 100)/100.0;
435  localSection.lumiDetail.ETLumi[j] = (float)(rand() % 100)/100.0;
436  localSection.lumiDetail.ETLumiErr[j] = (float)(rand() % 100)/100.0;
437  localSection.lumiDetail.ETLumiQlty[j] = (rand() % 100);
438  localSection.lumiDetail.OccLumi[0][j] = (float)(rand() % 100)/100.0;
439  localSection.lumiDetail.OccLumiErr[0][j] = (float)(rand() % 100)/100.0;
440  localSection.lumiDetail.OccLumiQlty[0][j] = (rand() % 100);
441  localSection.lumiDetail.OccLumi[1][j] = (float)(rand() % 100)/100.0;
442  localSection.lumiDetail.OccLumiErr[1][j] = (float)(rand() % 100)/100.0;
443  localSection.lumiDetail.OccLumiQlty[1][j] = (rand() % 100);
444  }
445 
446  for(i=0; i<36; i ++){
447  localSection.etSum[i].hdr.numNibbles = (rand() % 100);
448  localSection.occupancy[i].hdr.numNibbles = 8*(rand() % 100);
449  localSection.lhc[i].hdr.numNibbles = 9*(rand() % 100);
450 
451  localSection.etSum[i].hdr.bIsComplete = true;
452  localSection.occupancy[i].hdr.bIsComplete = true;
453  localSection.lhc[i].hdr.bIsComplete = true;
454 
455  for(j=0; j < 3564; j ++){
456  localSection.etSum[i].data[j] = 6*(rand() % 3564);
457  for(k=0; k < 6; k++){
458  localSection.occupancy[i].data[k][j] = k*(rand() % 3564);
459  }
460  localSection.lhc[i].data[j] = 7*(rand() % 3564);
461  }
462  }
463 
464 #ifdef DEBUG
465  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
466 #endif
467  }
LUMI_SECTION_SUB_HEADER hdr
OCCUPANCY_SECTION occupancy[36]
int k[5][pyjets_maxn]
LUMI_SECTION_SUB_HEADER hdr
Signal rand(Signal arg)
Definition: vlib.cc:442
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::connectHLXTCP().

175  {
176 #ifdef DEBUG
177  std::cout << "Begin and End " << __PRETTY_FUNCTION__ << " " << Connected << std::endl;
178 #endif
179  return Connected;
180  }
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(), TauGenJetsDecayModeSelectorAllHadrons_cfi::select, HCAL_HLX::SetupFDSets(), tcpSocket, and protons_cff::time.

Referenced by HLXMonitor::analyze().

88  {
89 #ifdef DEBUG
90  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
91 #endif
92 
93  int errorCode = 0;
94 
95  if(acquireMode == 0){ // real data
96  if(Connected == false){
97  errorCode = 701; // not connected
98  } else {
99  unsigned int bytesRcvd, bytesToReceive, totalBytesRcvd;
100  const unsigned int Buffer_Size = 8192;
101  char *Buffer;
102  char *BigBuffer;
103 
104  // From John's code
105 
106  fd_set fdsRead, fdsWrite, fdsExcept;
107 
108  // int outputcode;
109  //int z = 0, localCount = 0;
110  time_t tempTime, curTime;
111  //int ret;
112 
113  time(&curTime);
114 
115  bytesToReceive = sizeof(localSection);
116  Buffer = new char[Buffer_Size];
117  BigBuffer = new char[bytesToReceive];
118  totalBytesRcvd = 0;
119 
120  memset(reinterpret_cast<char *>(&localSection), 0, Buffer_Size);
121  memset(Buffer, 0, Buffer_Size);
122  memset(BigBuffer, 0, bytesToReceive);
123 
124  usleep(10000);
125 
126  while((totalBytesRcvd < bytesToReceive) && (errorCode == 0)){
127 
128  SetupFDSets(fdsRead, fdsWrite, fdsExcept, -1, tcpSocket);
129 
130  if(select(tcpSocket+1, &fdsRead, nullptr, &fdsExcept, nullptr)> 0){
131 
132  if (FD_ISSET(tcpSocket, &fdsRead)) {
133 
134  if((bytesRcvd = recv(tcpSocket, Buffer, Buffer_Size, 0))<=0){
135  perror("Recv Error");
136  errorCode = 501;
137  }else{
138  if((totalBytesRcvd + bytesRcvd)<= bytesToReceive){
139  memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd);
140  }else{
141  std::cout << "***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****" << std::endl;
142  errorCode = 502;
143  }
144  totalBytesRcvd += bytesRcvd;
145  time(&tempTime);
146  }
147  }
148  }
149  }
150 
151  if(errorCode == 0){
152  memcpy(reinterpret_cast<char *>(&localSection), BigBuffer, sizeof(localSection));
153  errorCode = 1; // success
154  }
155  delete [] Buffer;
156  delete [] BigBuffer;
157  }
158  } else if(acquireMode == 1){ // fill with fake data. Should be unique.
159  GenerateFakeData(localSection);
160  errorCode = 1;
161  } else if(acquireMode == 2){ // fill with random fake data.
162  GenerateRandomData(localSection);
163  errorCode = 1;
164  } else {
165  errorCode = 201;
166  }
167 
168 #ifdef DEBUG
169  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
170 #endif
171 
172  return errorCode;
173  }
void SetupFDSets(fd_set &ReadFDs, fd_set &WriteFDs, fd_set &ExceptFDs, int ListeningSocket=-1, int connectSocket=-1)
Definition: TCPReceiver.cc:67
unsigned char acquireMode
Definition: TCPReceiver.h:55
void GenerateRandomData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:395
void GenerateFakeData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:316
void HCAL_HLX::TCPReceiver::SetIP ( std::string  IP)

Definition at line 222 of file TCPReceiver.cc.

References gather_cfg::cout, listHistos::IP, and servIP.

Referenced by HLXMonitor::analyze(), and HLXMonitor::connectHLXTCP().

222  {
223 #ifdef DEBUG
224  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
225 #endif
226  servIP = IP;
227 #ifdef DEBUG
228  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
229 #endif
230  }
std::string servIP
Definition: TCPReceiver.h:59
int HCAL_HLX::TCPReceiver::SetMode ( unsigned char  mode)

Definition at line 202 of file TCPReceiver.cc.

References acquireMode, gather_cfg::cout, and ALCARECOPromptCalibProdSiPixelAli0T_cff::mode.

Referenced by HLXMonitor::connectHLXTCP().

202  {
203 #ifdef DEBUG
204  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
205 #endif
206 
207  int errorCode;
208 
209  if(mode > 2){
210  errorCode = 201;
211  } else {
212  acquireMode = mode;
213  errorCode = 1;
214  }
215 
216 #ifdef DEBUG
217  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
218 #endif
219  return errorCode;
220  }
unsigned char acquireMode
Definition: TCPReceiver.h:55
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::connectHLXTCP().

182  {
183 #ifdef DEBUG
184  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
185 #endif
186 
187  int errorCode;
188 
189  if(port < 1024){
190  errorCode = 101;
191  }else{
192  servPort = port;
193  errorCode = 1;
194  }
195 
196 #ifdef DEBUG
197  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
198 #endif
199  return errorCode;
200  }
port
Definition: query.py:116
unsigned short servPort
Definition: TCPReceiver.h:58
bool HCAL_HLX::TCPReceiver::VerifyFakeData ( HCAL_HLX::LUMI_SECTION localSection)

Definition at line 469 of file TCPReceiver.cc.

References GenerateFakeData(), and dttmaxenums::L.

469  {
470 
472  GenerateFakeData(L);
473  return !(memcmp(&L, &localSection, sizeof(L)));
474  }
void GenerateFakeData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:316

Member Data Documentation

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().