11 #pragma GCC diagnostic push
12 #pragma GCC diagnostic ignored "-Wunused-parameter"
13 #include <Event/Event.h>
15 #pragma GCC diagnostic pop
17 #include <Event/EventTypes.h>
18 #include <Event/msg_control.h>
19 #include <Event/msg_profile.h>
20 #include <Event/packet.h>
22 #include <MessageTypes.h>
25 #include <TInetAddress.h>
28 #include <TServerSocket.h>
34 #include <sys/types.h>
50 static void *
server(
void *);
55 static void *
server(
void *);
60 pthread_mutex_t mutex;
71 Onlmonserver->GetMutex(mutex);
73 for (
int i = 0;
i < kMAXSIGNALS;
i++)
75 gSystem->IgnoreSignal((ESignals)
i);
78 pthread_mutex_lock(&mutex);
81 #if defined(SERVER) || defined(ROOTTHREAD)
103 pthread_mutex_unlock(&mutex);
112 static uint64_t savetmpticks = 0x7FFFFFFF;
113 static uint64_t borticks = 0;
114 static uint64_t eorticks = 0;
115 static int eventcnt = 0;
118 uint64_t tmpticks = evt->
getTime();
123 savetmpticks = 0x7FFFFFFF;
127 pthread_mutex_lock(&mutex);
142 pthread_mutex_unlock(&mutex);
148 std::ostringstream
msg;
149 msg << __PRETTY_FUNCTION__ <<
"Discarding event with length "
162 pthread_mutex_lock(&mutex);
183 pthread_mutex_unlock(&mutex);
185 savetmpticks = 0x7FFFFFFF;
191 if (tmpticks < borticks)
194 pthread_mutex_lock(&mutex);
197 if (tmpticks < savetmpticks)
199 savetmpticks = tmpticks;
203 pthread_mutex_unlock(&mutex);
206 if (eorticks < se->CurrentTicks())
212 std::ostringstream
msg;
213 msg << __PRETTY_FUNCTION__ <<
" Event with error code: "
223 pthread_mutex_lock(&mutex);
229 pthread_mutex_unlock(&mutex);
245 pthread_mutex_lock(&mutex);
247 TServerSocket *ss =
nullptr;
255 ss =
new TServerSocket(MoniPort, kTRUE);
260 std::ostringstream
msg;
261 msg <<
"Too many Online Monitors running on this machine, bailing out";
269 printf(
"Ignore ROOT error about socket in use, I try another one\n");
271 }
while (!ss->IsValid());
277 int isock = gROOT->GetListOfSockets()->IndexOf(ss);
278 gROOT->GetListOfSockets()->RemoveAt(isock);
281 pthread_mutex_unlock(&mutex);
284 TSocket *s0 = ss->Accept();
288 <<
" in use, either go to a different node or" << std::endl
289 <<
"change MONIPORT in server/OnlMonDefs.h and recompile" << std::endl
290 <<
"server and client" << std::endl;
298 TInetAddress adr = s0->GetInetAddress();
299 std::cout <<
"got connection from " << std::endl;
304 pthread_mutex_lock(&mutex);
310 pthread_mutex_unlock(&mutex);
335 TSocket *s0 = (TSocket *) arg;
345 TMessage *mess =
nullptr;
346 TMessage outgoing(kMESS_OBJECT);
351 std::cout <<
"Waiting for message" << std::endl;
356 std::cout <<
"Broken Connection, closing socket" << std::endl;
359 if (mess->What() == kMESS_STRING)
368 std::cout <<
"received message: " << str << std::endl;
370 if (str ==
"Finished")
374 else if (str ==
"WriteRootFile")
377 s0->Send(
"Finished");
380 else if (str ==
"Ack")
384 else if (str ==
"HistoList")
388 std::cout <<
"number of histos: " << Onlmonserver->
nHistos() << std::endl;
390 for (
auto monitors = Onlmonserver->
monibegin(); monitors != Onlmonserver->
moniend(); ++monitors)
392 for (
auto &
histos : monitors->second)
397 std::cout <<
"subsystem: " << monitors->first <<
", histo: " <<
histos.first << std::endl;
398 std::cout <<
" sending: \"" << subsyshisto <<
"\"" << std::endl;
400 s0->Send(subsyshisto.c_str());
401 int nbytes = s0->Recv(mess);
406 std::ostringstream
msg;
408 msg <<
"Problem receiving message: return code: " << nbytes;
413 s0->Send(
"Finished");
415 else if (str ==
"ALL")
419 std::cout <<
"number of histos: " << Onlmonserver->
nHistos() << std::endl;
421 for (
unsigned int i = 0;
i < Onlmonserver->
nHistos();
i++)
427 outgoing.WriteObject(histo);
435 s0->Send(
"Finished");
437 else if (str.find(
"ISRUNNING") != std::string::npos)
440 unsigned int pos_space = str.find(
' ');
441 std::string moniname = str.substr(pos_space + 1, str.size());
444 if ((*moniter)->Name() == moniname)
452 std::cout <<
"got " << str <<
", replied " << answer << std::endl;
454 s0->Send(answer.c_str());
456 else if (str ==
"LISTMONITORS")
463 std::cout <<
"sending " << (*moniter)->Name().c_str() << std::endl;
465 s0->Send((*moniter)->Name().c_str());
467 s0->Send(
"Finished");
470 else if (str ==
"LIST")
481 if (mess->What() == kMESS_STRING)
492 unsigned int pos_space = str1.find(
' ');
495 std::cout << __PRETTY_FUNCTION__ <<
" getting subsystem " << str1.substr(0, pos_space) <<
", histo " << str1.substr(pos_space + 1, str1.size()) << std::endl;
497 TH1 *histo = Onlmonserver->
getHisto(str1.substr(0, pos_space), str1.substr(pos_space + 1, str1.size()));
501 outgoing.WriteObject(histo);
507 s0->Send(
"UnknownHisto");
511 s0->Send(
"Finished");
516 unsigned int pos_space = str.find(
' ');
517 TH1 *histo = Onlmonserver->
getHisto(strstr.substr(0, pos_space), strstr.substr(pos_space + 1, str.size()));
522 outgoing.WriteObject(histo);
527 s0->Send(
"Finished");
531 s0->Send(
"UnknownHisto");
535 else if (mess->What() == kMESS_OBJECT)
537 printf(
"got object of class: %s\n", mess->GetClass()->GetName());
542 printf(
"*** Unexpected message ***\n");
558 severity,
"pmonitorInterface");
559 std::cout << *Message << msg << std::endl;