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 35 of file TCPReceiver.h.

Constructor & Destructor Documentation

◆ TCPReceiver() [1/2]

HCAL_HLX::TCPReceiver::TCPReceiver ( )

Definition at line 35 of file TCPReceiver.cc.

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

35  {
36 #ifdef DEBUG
37  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
38 #endif
39 
40  acquireMode = 0;
41  servPort = 0;
42  servIP = "127.0.0.1";
43  Connected = false;
44 
45 #ifdef DEBUG
46  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
47 #endif
48  }
unsigned char acquireMode
Definition: TCPReceiver.h:53
std::string servIP
Definition: TCPReceiver.h:57
unsigned short servPort
Definition: TCPReceiver.h:56

◆ TCPReceiver() [2/2]

HCAL_HLX::TCPReceiver::TCPReceiver ( unsigned short int  port,
std::string  IP,
unsigned char  mode = 0 
)

Definition at line 50 of file TCPReceiver.cc.

References acquireMode, Connected, gather_cfg::cout, listHistos::IP, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, query::port, servIP, and servPort.

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

◆ ~TCPReceiver()

HCAL_HLX::TCPReceiver::~TCPReceiver ( )

Definition at line 64 of file TCPReceiver.cc.

References Disconnect().

64 { Disconnect(); }

Member Function Documentation

◆ Connect()

int HCAL_HLX::TCPReceiver::Connect ( )

Definition at line 230 of file TCPReceiver.cc.

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

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

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

◆ Disconnect()

int HCAL_HLX::TCPReceiver::Disconnect ( )

Definition at line 284 of file TCPReceiver.cc.

References acquireMode, Connected, gather_cfg::cout, and tcpSocket.

Referenced by HLXMonitor::analyze(), HLXMonitor::~HLXMonitor(), and ~TCPReceiver().

284  {
285 #ifdef DEBUG
286  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
287 #endif
288 
289  int errorCode = 0;
290 
291  if (Connected) {
292  if (acquireMode == 0) {
293  if (shutdown(tcpSocket, SHUT_RDWR) < 0) {
294  perror("Shutdown Error");
295  errorCode = 601; // Disconnect Failed
296  } else {
297  errorCode = 1; // Successful Disconnect
298  }
299  }
300  Connected = false;
301  } else {
302  errorCode = 401; // Not Connected
303  }
304 
305 #ifdef DEBUG
306  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
307 #endif
308  return errorCode;
309  }
unsigned char acquireMode
Definition: TCPReceiver.h:53

◆ GenerateFakeData()

void HCAL_HLX::TCPReceiver::GenerateFakeData ( HCAL_HLX::LUMI_SECTION localSection)

Definition at line 311 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, dqmiolumiharvest::j, isotrackApplyRegressor::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().

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

◆ GenerateRandomData()

void HCAL_HLX::TCPReceiver::GenerateRandomData ( HCAL_HLX::LUMI_SECTION localSection)

Definition at line 389 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, ALCARECOEcalPhiSym_cff::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, dqmiolumiharvest::j, isotrackApplyRegressor::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, and hcalRecHitTable_cff::time.

Referenced by ReceiveLumiSection().

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

◆ IsConnected()

bool HCAL_HLX::TCPReceiver::IsConnected ( )

Definition at line 173 of file TCPReceiver.cc.

References Connected, and gather_cfg::cout.

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

173  {
174 #ifdef DEBUG
175  std::cout << "Begin and End " << __PRETTY_FUNCTION__ << " " << Connected << std::endl;
176 #endif
177  return Connected;
178  }

◆ ReceiveLumiSection()

int HCAL_HLX::TCPReceiver::ReceiveLumiSection ( HCAL_HLX::LUMI_SECTION localSection)

Definition at line 88 of file TCPReceiver.cc.

References acquireMode, cms::cuda::assert(), Connected, gather_cfg::cout, GenerateFakeData(), GenerateRandomData(), singleTopDQM_cfi::select, HCAL_HLX::SetupFDSets(), tcpSocket, and hcalRecHitTable_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  assert(tcpSocket >= 0);
126  while ((totalBytesRcvd < bytesToReceive) && (errorCode == 0)) {
127  SetupFDSets(fdsRead, fdsWrite, fdsExcept, -1, tcpSocket);
128 
129  if (select(tcpSocket + 1, &fdsRead, nullptr, &fdsExcept, nullptr) > 0) {
130  if (FD_ISSET(tcpSocket, &fdsRead)) {
131  if ((bytesRcvd = recv(tcpSocket, Buffer, Buffer_Size, 0)) <= 0) {
132  perror("Recv Error");
133  errorCode = 501;
134  } else {
135  if ((totalBytesRcvd + bytesRcvd) <= bytesToReceive) {
136  memcpy(&BigBuffer[totalBytesRcvd], Buffer, bytesRcvd);
137  } else {
138  std::cout << "***** MEM OVER FLOW: Did someone forget to update LumiStructures.hh? *****"
139  << std::endl;
140  errorCode = 502;
141  }
142  totalBytesRcvd += bytesRcvd;
143  time(&tempTime);
144  }
145  }
146  }
147  }
148 
149  if (errorCode == 0) {
150  memcpy(reinterpret_cast<char *>(&localSection), BigBuffer, sizeof(localSection));
151  errorCode = 1; // success
152  }
153  delete[] Buffer;
154  delete[] BigBuffer;
155  }
156  } else if (acquireMode == 1) { // fill with fake data. Should be unique.
157  GenerateFakeData(localSection);
158  errorCode = 1;
159  } else if (acquireMode == 2) { // fill with random fake data.
160  GenerateRandomData(localSection);
161  errorCode = 1;
162  } else {
163  errorCode = 201;
164  }
165 
166 #ifdef DEBUG
167  std::cout << "End " << __PRETTY_FUNCTION__ << " " << errorCode << std::endl;
168 #endif
169 
170  return errorCode;
171  }
void SetupFDSets(fd_set &ReadFDs, fd_set &WriteFDs, fd_set &ExceptFDs, int ListeningSocket=-1, int connectSocket=-1)
Definition: TCPReceiver.cc:66
unsigned char acquireMode
Definition: TCPReceiver.h:53
assert(be >=bs)
void GenerateRandomData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:389
void GenerateFakeData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:311

◆ SetIP()

void HCAL_HLX::TCPReceiver::SetIP ( std::string  IP)

Definition at line 220 of file TCPReceiver.cc.

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

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

220  {
221 #ifdef DEBUG
222  std::cout << "Begin " << __PRETTY_FUNCTION__ << std::endl;
223 #endif
224  servIP = IP;
225 #ifdef DEBUG
226  std::cout << "End " << __PRETTY_FUNCTION__ << std::endl;
227 #endif
228  }
std::string servIP
Definition: TCPReceiver.h:57

◆ SetMode()

int HCAL_HLX::TCPReceiver::SetMode ( unsigned char  mode)

Definition at line 200 of file TCPReceiver.cc.

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

Referenced by HLXMonitor::connectHLXTCP().

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

◆ SetPort()

int HCAL_HLX::TCPReceiver::SetPort ( unsigned short int  port)

Definition at line 180 of file TCPReceiver.cc.

References gather_cfg::cout, query::port, and servPort.

Referenced by HLXMonitor::connectHLXTCP().

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

◆ VerifyFakeData()

bool HCAL_HLX::TCPReceiver::VerifyFakeData ( HCAL_HLX::LUMI_SECTION localSection)

Definition at line 463 of file TCPReceiver.cc.

References GenerateFakeData(), and dttmaxenums::L.

463  {
466  return !(memcmp(&L, &localSection, sizeof(L)));
467  }
void GenerateFakeData(HCAL_HLX::LUMI_SECTION &localSection)
Definition: TCPReceiver.cc:311

Member Data Documentation

◆ acquireMode

unsigned char HCAL_HLX::TCPReceiver::acquireMode
private

Definition at line 53 of file TCPReceiver.h.

Referenced by Connect(), Disconnect(), ReceiveLumiSection(), SetMode(), and TCPReceiver().

◆ Connected

bool HCAL_HLX::TCPReceiver::Connected
private

Definition at line 54 of file TCPReceiver.h.

Referenced by Connect(), Disconnect(), IsConnected(), ReceiveLumiSection(), and TCPReceiver().

◆ servAddr

struct sockaddr_in HCAL_HLX::TCPReceiver::servAddr
private

Definition at line 59 of file TCPReceiver.h.

Referenced by Connect().

◆ servIP

std::string HCAL_HLX::TCPReceiver::servIP
private

Definition at line 57 of file TCPReceiver.h.

Referenced by Connect(), SetIP(), and TCPReceiver().

◆ servPort

unsigned short HCAL_HLX::TCPReceiver::servPort
private

Definition at line 56 of file TCPReceiver.h.

Referenced by Connect(), SetPort(), and TCPReceiver().

◆ tcpSocket

int HCAL_HLX::TCPReceiver::tcpSocket
private

Definition at line 58 of file TCPReceiver.h.

Referenced by Connect(), Disconnect(), and ReceiveLumiSection().