File indexing completed on 2024-04-06 12:26:39
0001
0002
0003
0004
0005
0006
0007 #include <arpa/inet.h>
0008 #include <csignal>
0009 #include <cstdlib>
0010 #include <cstring>
0011 #include <iostream>
0012 #include <sys/socket.h>
0013 #include <unistd.h>
0014
0015 #include "RecoLuminosity/TCPReceiver/interface/TCPReceiver.h"
0016 #include "RecoLuminosity/TCPReceiver/interface/LumiStructures.hh"
0017
0018 int gContinue = 1;
0019 bool Connected = false;
0020 char *Buffer;
0021
0022 void CtrlC(int aSigNum) {
0023 std::cout << "Ctrl-c detected, stopping run" << std::endl;
0024 gContinue = 0;
0025 delete[] Buffer;
0026 exit(1);
0027 }
0028
0029 int main() {
0030 using std::cout;
0031 using std::endl;
0032
0033 int servSock;
0034 int clntSock = -1;
0035
0036 unsigned int runCount = 1;
0037 unsigned int orbitCount = 0;
0038 unsigned int sectionCount = 0;
0039 unsigned int sizeOfRun = 960;
0040 unsigned int sizeOfSection = 1000;
0041
0042 int er;
0043
0044 HCAL_HLX::LUMI_SECTION lumiSection;
0045 HCAL_HLX::TCPReceiver HT;
0046
0047 struct sockaddr_in servAddr;
0048 struct sockaddr_in clntAddr;
0049 unsigned int clntLen;
0050 unsigned short servPort = 51006;
0051 unsigned int Buffer_Size;
0052
0053 signal(SIGINT, CtrlC);
0054
0055 clntLen = sizeof(clntAddr);
0056 Buffer_Size = sizeof(lumiSection);
0057 Buffer = new char[Buffer_Size];
0058
0059 if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
0060 cout << "*** socket failed **** " << endl;
0061 exit(1);
0062 }
0063
0064 memset(&servAddr, 0, sizeof(servAddr));
0065 servAddr.sin_family = AF_INET;
0066 servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
0067 servAddr.sin_port = htons(servPort);
0068 do {
0069 if ((er = bind(servSock, (struct sockaddr *)&servAddr, sizeof(servAddr))) < 0) {
0070 cout << " *** bind failed *** " << endl;
0071 cout << " Attempting to bind in 30 seconds " << endl;
0072 sleep(30);
0073 }
0074 } while (er < 0 && gContinue);
0075
0076 if (listen(servSock, 5) < 0) {
0077 cout << " *** listen failed *** " << endl;
0078 exit(1);
0079 }
0080 memset(reinterpret_cast<char *>(&lumiSection), 0, Buffer_Size);
0081 memset(Buffer, 0, Buffer_Size);
0082
0083 while (gContinue) {
0084 cout << " ** Generating Lumi Section ** " << endl;
0085 HT.GenerateFakeData(lumiSection);
0086
0087 orbitCount += 4;
0088
0089 if (orbitCount >= sizeOfSection) {
0090 sectionCount++;
0091 orbitCount = 0;
0092 }
0093
0094 if (sectionCount >= sizeOfRun) {
0095 runCount++;
0096 sectionCount = 0;
0097 }
0098
0099 lumiSection.hdr.runNumber = runCount;
0100 lumiSection.hdr.sectionNumber = sectionCount;
0101 lumiSection.hdr.startOrbit = orbitCount - 4;
0102 lumiSection.hdr.numOrbits = 4;
0103 lumiSection.hdr.numBunches = 3546;
0104 lumiSection.hdr.numHLXs = 36;
0105 lumiSection.hdr.bCMSLive = true;
0106
0107 memcpy(Buffer, reinterpret_cast<char *>(&lumiSection), Buffer_Size);
0108
0109 if (Connected == false) {
0110 do {
0111 cout << " **** Waiting *** " << endl;
0112 if ((clntSock = accept(servSock, (struct sockaddr *)&clntAddr, &clntLen)) < 0)
0113 cout << " ** accept() failed ** " << endl;
0114 } while (clntSock < 0 && gContinue);
0115 Connected = true;
0116
0117 } else {
0118 cout << " ** Sending Lumi Section - Run: " << lumiSection.hdr.runNumber
0119 << " Section: " << lumiSection.hdr.sectionNumber << " Orbit: " << lumiSection.hdr.startOrbit << " ** "
0120 << endl;
0121 if (send(clntSock, Buffer, Buffer_Size, 0) != (int)Buffer_Size) {
0122 cout << " ** send failed ** " << endl;
0123 Connected = false;
0124 }
0125 sleep(3);
0126 }
0127 }
0128 }