1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // This is the class for perfoming the monitoring process. //
21 // It checks if a raw data file exists, loops over the events in the raw //
22 // data file, reconstructs TPC and ITS clusters and tracks, fills the //
23 // monitor histograms and sends the updated histograms to the clients. //
24 // Then the raw data file is deleted and it waits for a new file. //
26 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliMonitorProcess.h"
30 #include "AliMonitorTPC.h"
31 #include "AliMonitorITS.h"
32 #include "AliMonitorV0s.h"
33 #include "AliMonitorHLT.h"
34 #include "AliMonitorHLTHough.h"
35 #include "AliRawReaderRoot.h"
36 #include "AliLoader.h"
39 #include "AliTPCclustererMI.h"
40 #include "AliTPCtrackerMI.h"
42 #include "AliITSclustererV2.h"
43 #include "AliITStrackerV2.h"
44 #include "AliITSLoader.h"
45 #include "AliV0vertexer.h"
48 #include <TServerSocket.h>
50 #include <TGridResult.h>
53 #include <AliLevel3.h>
54 #include <AliL3Transform.h>
55 #include <AliL3Track.h>
56 #include <AliL3TrackArray.h>
57 #include <AliL3StandardIncludes.h>
58 #include <AliL3HoughMaxFinder.h>
59 #include <AliL3HoughBaseTransformer.h>
60 #include <AliL3Hough.h>
61 #include <AliL3ClusterFitter.h>
62 #include <AliL3Vertex.h>
63 #include <AliL3Fitter.h>
66 ClassImp(AliMonitorProcess)
69 const Int_t AliMonitorProcess::fgkPort = 9327;
72 //_____________________________________________________________________________
73 AliMonitorProcess::AliMonitorProcess(const char* alienDir,
74 const char* fileNameGalice)
76 // initialize the monitoring process and the monitor histograms
78 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
79 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
81 Fatal("AliMonitorProcess", "could not connect to alien");
84 fLogicalFileName = "";
87 fRunLoader = AliRunLoader::Open(fileNameGalice);
88 if (!fRunLoader) Fatal("AliMonitorProcess",
89 "could not get run loader from file %s",
92 fRunLoader->CdGAFile();
93 fTPCParam = AliTPC::LoadTPCParam(gFile);
94 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
96 fRunLoader->LoadgAlice();
97 gAlice = fRunLoader->GetAliRun();
98 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
99 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
100 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
101 fITSgeom = its->GetITSgeom();
102 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
105 // Init TPC parameters for HLT
106 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
108 cerr << "Could not create transform settings, please check log for error messages!" << endl;
117 fWriteHistoList = kFALSE;
119 fTopFolder = new TFolder("Monitor", "monitor histograms");
120 fTopFolder->SetOwner(kTRUE);
122 fMonitors.Add(new AliMonitorTPC(fTPCParam));
123 fMonitors.Add(new AliMonitorITS(fITSgeom));
124 fMonitors.Add(new AliMonitorV0s);
126 fMonitors.Add(new AliMonitorHLT(fTPCParam));
127 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
130 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
131 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
134 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
135 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
138 fFile = TFile::Open("monitor_tree.root", "RECREATE");
139 if (!fFile || !fFile->IsOpen()) {
140 Fatal("AliMonitorProcess", "could not open file for tree");
142 fTree = new TTree("MonitorTree", "tree for monitoring");
143 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
144 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
148 fServerSocket = new TServerSocket(fgkPort, kTRUE);
149 fServerSocket->SetOption(kNoBlock, 1);
150 fDisplaySocket = NULL;
151 CheckForConnections();
160 //_____________________________________________________________________________
161 AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
164 Fatal("AliMonitorProcess", "copy constructor not implemented");
167 //_____________________________________________________________________________
168 AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
171 Fatal("operator =", "assignment operator not implemented");
175 //_____________________________________________________________________________
176 AliMonitorProcess::~AliMonitorProcess()
184 delete fServerSocket;
186 delete fDisplaySocket;
193 gSystem->Unlink("monitor_tree.root");
202 //_____________________________________________________________________________
203 const char* AliMonitorProcess::GetRevision()
209 //_____________________________________________________________________________
210 void AliMonitorProcess::SetStatus(EStatus status)
212 // set the current status and process system events
215 gSystem->ProcessEvents();
219 //_____________________________________________________________________________
220 void AliMonitorProcess::Run()
222 // run the monitor process:
223 // check for a raw data file, process the raw data file and delete it
229 while (!CheckForNewFile()) {
230 CheckForConnections();
232 if (fStopping) break;
235 if (fStopping) break;
247 //_____________________________________________________________________________
248 void AliMonitorProcess::Stop()
250 // set the fStopping flag to terminate the monitor process after the current
251 // event was processed
253 if (GetStatus() != kStopped) fStopping = kTRUE;
257 //_____________________________________________________________________________
258 void AliMonitorProcess::ProcessFile(const char* fileName)
260 // create a file with monitor histograms for a single file
262 if (GetStatus() != kStopped) {
263 Error("ProcessFile", "ProcessFile can not be called"
264 " while the monitor process is running");
268 fFileName = fileName;
269 Int_t nEventMin = fNEventsMin;
273 fNEventsMin = nEventMin;
278 //_____________________________________________________________________________
279 Bool_t AliMonitorProcess::CheckForNewFile()
281 // check whether a new file was registered in alien
283 TGridResult* result = fGrid->Ls();
288 while (const char* entry = result->Next()) {
289 // entry = host_date_time.root
290 TString entryCopy(entry);
291 char* p = const_cast<char*>(entryCopy.Data());
292 if (!strtok(p, "_") || !p) continue; // host name
293 char* dateStr = strtok(NULL, "_");
294 if (!dateStr || !p) continue;
295 char* timeStr = strtok(NULL, ".");
296 if (!timeStr || !p) continue;
297 Long_t date = atoi(dateStr);
298 Long_t time = atoi(timeStr);
300 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
307 if (maxDate < 0) return kFALSE; // no files found
308 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
310 fLogicalFileName = fileName;
311 TGridResult* result2 = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
312 fFileName = result2->Next();
317 //_____________________________________________________________________________
318 Bool_t AliMonitorProcess::ProcessFile()
320 // loop over all events in the raw data file, run the reconstruction
321 // and fill the monitor histograms
323 Int_t nEvents = GetNumberOfEvents(fFileName);
324 if (nEvents <= 0) return kFALSE;
325 Info("ProcessFile", "found %d event(s) in file %s",
326 nEvents, fFileName.Data());
328 CreateHLT(fFileName);
329 CreateHLTHough(fFileName);
332 // loop over the events
333 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
335 fRunLoader->SetEventNumber(0);
336 AliRawReaderRoot rawReader(fFileName, iEvent);
337 if (fStopping) break;
338 if (rawReader.GetRunNumber() != fRunNumber) {
341 fRunNumber = rawReader.GetRunNumber();
342 fEventNumber[0] = rawReader.GetEventId()[0];
343 fEventNumber[1] = rawReader.GetEventId()[1];
345 if (fStopping) break;
348 if (!ReconstructTPC(&rawReader)) return kFALSE;
349 if (fStopping) break;
350 if (!ReconstructITS(&rawReader)) return kFALSE;
351 if (fStopping) break;
352 if (!ReconstructV0s()) return kFALSE;
353 if (fStopping) break;
354 if (!ReconstructHLT(iEvent)) return kFALSE;
355 if (fStopping) break;
356 if (!ReconstructHLTHough(iEvent)) return kFALSE;
357 if (fStopping) break;
359 if (fDisplaySocket) fDisplaySocket->Send("new event");
361 Info("ProcessFile", "filling histograms...");
363 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
364 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
365 if (fStopping) break;
367 if (fStopping) break;
369 Info("ProcessFile", "updating histograms...");
370 SetStatus(kUpdating);
371 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
372 while (TFolder* folder = (TFolder*) iFolder->Next()) {
373 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
374 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
380 if (fStopping) break;
382 Info("ProcessFile", "filling the tree...");
385 Info("ProcessFile", "broadcasting histograms...");
386 CheckForConnections();
390 if (fStopping) break;
401 //_____________________________________________________________________________
402 void AliMonitorProcess::Reset()
404 // write the current histograms to a file and reset them
406 if (fSubRunNumber == 0) fSubRunNumber++;
413 //_____________________________________________________________________________
414 UInt_t AliMonitorProcess::GetEventPeriodNumber() const
416 // get the period number from the event id
418 return (fEventNumber[1] >> 4);
421 //_____________________________________________________________________________
422 UInt_t AliMonitorProcess::GetEventOrbitNumber() const
424 // get the orbit number from the event id
426 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
429 //_____________________________________________________________________________
430 UInt_t AliMonitorProcess::GetEventBunchNumber() const
432 // get the bunch number from the event id
434 return (fEventNumber[0] % 0x0FFF);
437 //_____________________________________________________________________________
438 Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
440 // determine the number of events in the given raw data file
444 TFile* file = TFile::Open(fileName);
445 if (!file || !file->IsOpen()) {
446 Error("GetNumberOfEvents", "could not open file %s", fileName);
447 if (file) delete file;
451 TTree* tree = (TTree*) file->Get("RAW");
453 Error("GetNumberOfEvents", "could not find tree with raw data");
455 nEvents = (Int_t) tree->GetEntries();
463 //_____________________________________________________________________________
464 Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
466 // find TPC clusters and tracks
470 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
472 Error("ReconstructTPC", "no TPC loader found");
475 gSystem->Unlink("TPC.RecPoints.root");
476 gSystem->Unlink("TPC.Tracks.root");
479 Info("ReconstructTPC", "reconstructing clusters...");
480 tpcLoader->LoadRecPoints("recreate");
481 AliTPCclustererMI clusterer(fTPCParam);
482 tpcLoader->MakeRecPointsContainer();
483 clusterer.SetOutput(tpcLoader->TreeR());
484 clusterer.Digits2Clusters(rawReader);
485 tpcLoader->WriteRecPoints("OVERWRITE");
488 Info("ReconstructTPC", "reconstructing tracks...");
489 tpcLoader->LoadTracks("recreate");
491 AliTPCtrackerMI tracker(fTPCParam);
492 tracker.Clusters2Tracks();
495 tpcLoader->UnloadRecPoints();
496 tpcLoader->UnloadTracks();
500 //_____________________________________________________________________________
501 Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
503 // find ITS clusters and tracks
507 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
509 Error("ReconstructITS", "no ITS loader found");
512 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
514 Error("ReconstructITS", "no TPC loader found");
517 gSystem->Unlink("ITS.RecPoints.root");
518 gSystem->Unlink("ITS.Tracks.root");
521 Info("ReconstructITS", "reconstructing clusters...");
522 itsLoader->LoadRecPoints("recreate");
523 AliITSclustererV2 clusterer(fITSgeom);
524 itsLoader->MakeRecPointsContainer();
525 clusterer.Digits2Clusters(rawReader);
528 Info("ReconstructITS", "reconstructing tracks...");
529 itsLoader->LoadTracks("recreate");
530 itsLoader->MakeTracksContainer();
531 tpcLoader->LoadTracks();
532 AliITStrackerV2 tracker(fITSgeom);
533 tracker.LoadClusters(itsLoader->TreeR());
534 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
535 tracker.UnloadClusters();
536 itsLoader->WriteTracks("OVERWRITE");
538 itsLoader->UnloadRecPoints();
539 itsLoader->UnloadTracks();
540 tpcLoader->UnloadTracks();
544 //_____________________________________________________________________________
545 Bool_t AliMonitorProcess::ReconstructV0s()
551 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
553 Error("ReconstructV0", "no ITS loader found");
556 gSystem->Unlink("ITS.V0s.root");
559 Info("ReconstructV0s", "reconstructing V0s...");
560 itsLoader->LoadTracks("read");
561 itsLoader->LoadV0s("recreate");
562 AliV0vertexer vertexer;
563 TTree* tracks = itsLoader->TreeT();
565 Error("ReconstructV0s", "no ITS tracks tree found");
568 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
569 TTree* v0s = itsLoader->TreeV0();
570 vertexer.Tracks2V0vertices(tracks, v0s);
571 itsLoader->WriteV0s("OVERWRITE");
573 itsLoader->UnloadTracks();
574 itsLoader->UnloadV0s();
578 //_____________________________________________________________________________
580 void AliMonitorProcess::CreateHLT(const char* fileName)
583 // create the HLT (Level3) object
585 if (fHLT) delete fHLT;
588 strcpy(name, fileName);
589 fHLT = new AliLevel3(name);
590 fHLT->Init("./", AliLevel3::kRaw, 1);
592 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
594 Int_t phiSegments = 50;
595 Int_t etaSegments = 100;
596 Int_t trackletlength = 3;
597 Int_t tracklength = 20;//40 or 5
598 Int_t rowscopetracklet = 2;
599 Int_t rowscopetrack = 10;
600 Double_t minPtFit = 0;
601 Double_t maxangle = 0.1745;
602 Double_t goodDist = 5;
603 Double_t maxphi = 0.1;
604 Double_t maxeta = 0.1;
605 Double_t hitChi2Cut = 15;//100 or 15
606 Double_t goodHitChi2 = 5;//20 or 5
607 Double_t trackChi2Cut = 10;//50 or 10
608 fHLT->SetTrackerParam(phiSegments, etaSegments,
609 trackletlength, tracklength,
610 rowscopetracklet, rowscopetrack,
611 minPtFit, maxangle, goodDist, hitChi2Cut,
612 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
614 fHLT->WriteFiles("./hlt/");
617 //_____________________________________________________________________________
618 void AliMonitorProcess::CreateHLTHough(const char* fileName)
621 // create the HLT Hough transform (L3Hough) object
623 if (fHLTHough) delete fHLTHough;
626 strcpy(name, fileName);
628 fHLTHough = new AliL3Hough();
629 fHLTHough->SetThreshold(4);
630 fHLTHough->SetTransformerParams(140,150,0.2,-1);
631 fHLTHough->SetPeakThreshold(6000,-1);
632 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
633 fHLTHough->SetAddHistograms();
634 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
639 //_____________________________________________________________________________
640 Bool_t AliMonitorProcess::ReconstructHLT(
648 // run the HLT cluster and track finder
653 Warning("ReconstructHLT", "the code was compiled without HLT support");
657 gSystem->Exec("rm -rf hlt");
658 gSystem->MakeDirectory("hlt");
659 if (!fHLT) return kFALSE;
661 fHLT->ProcessEvent(0, 35, iEvent);
663 // remove the event number from the file names
665 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
666 gSystem->Exec(command);
667 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
668 gSystem->Exec(command);
669 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
670 gSystem->Exec(command);
671 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
672 gSystem->Exec(command);
677 //_____________________________________________________________________________
678 Bool_t AliMonitorProcess::ReconstructHLTHough(
686 // run the HLT Hough transformer
691 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
695 gSystem->Exec("rm -rf hlt/hough");
696 gSystem->MakeDirectory("hlt/hough");
697 gSystem->Exec("rm -rf hlt/fitter");
698 gSystem->MakeDirectory("hlt/fitter");
699 if (!fHLTHough) return kFALSE;
701 // fHLTHough->Process(0, 35);
702 // Loop over TPC sectors and process the data
703 for(Int_t i=0; i<=35; i++)
705 fHLTHough->ReadData(i,iEvent);
706 fHLTHough->Transform();
707 // if(fHLTHough->fAddHistograms)
708 fHLTHough->AddAllHistograms();
709 fHLTHough->FindTrackCandidates();
710 fHLTHough->AddTracks();
712 fHLTHough->WriteTracks("./hlt/hough");
714 // Run cluster fitter
715 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
717 // Set debug flag for the cluster fitter
720 // Setting fitter parameters
721 fitter->SetInnerWidthFactor(1,1.5);
722 fitter->SetOuterWidthFactor(1,1.5);
723 fitter->SetNmaxOverlaps(5);
725 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
726 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
728 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
730 // Takes input from global hough tracks produced by HT
731 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
733 for(Int_t islice = 0; islice <= 35; islice++)
735 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
737 fitter->Init(islice,ipatch);
740 AliL3DigitRowData *digits = fHLTHough->GetTransformer(ipatch)->GetDataPointer();
741 fitter->SetInputData(digits);
742 fitter->FindClusters();
743 fitter->WriteClusters();
747 // Refit of the clusters
749 //The seeds are the input tracks from circle HT
750 AliL3TrackArray *tracks = fitter->GetSeeds();
751 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
753 // Temporary solution !
754 // sprintf(command, "rename _5.raw _-1.raw hlt/fitter/points*.raw", iEvent);
755 // gSystem->Exec(command);
757 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
758 for(Int_t i=0; i<tracks->GetNTracks(); i++)
760 AliL3Track *track = tracks->GetCheckedTrack(i);
762 if(track->GetNHits() < 40) continue;
763 ft->SortTrackClusters(track);
765 ft->UpdateTrack(track);
769 //Write the final tracks
770 fitter->WriteTracks(5);
774 // remove the event number from the file names
776 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
777 gSystem->Exec(command);
778 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
779 gSystem->Exec(command);
780 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
781 gSystem->Exec(command);
786 //_____________________________________________________________________________
787 Bool_t AliMonitorProcess::WriteHistos()
789 // write the monitor tree and the monitor histograms to the file
790 // "monitor_<run number>[_<sub_run_number>].root"
791 // if at least fNEventsMin events were monitored
795 // rename tree file and create a new one
802 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
803 if (fSubRunNumber > 0) {
804 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
806 if (fNEvents < fNEventsMin) {
807 gSystem->Unlink("monitor_tree.root");
809 gSystem->Rename("monitor_tree.root", fileName);
812 fFile = TFile::Open("monitor_tree.root", "RECREATE");
813 if (!fFile || !fFile->IsOpen()) {
814 Fatal("WriteHistos", "could not open file for tree");
816 fTree = new TTree("MonitorTree", "tree for monitoring");
817 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
818 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
822 // write the histograms
823 if (fNEvents < fNEventsMin) return kTRUE;
825 if (!fWriteHistoList) {
826 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
827 while (TFolder* folder = (TFolder*) iFolder->Next()) {
828 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
829 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
837 Bool_t result = kTRUE;
838 sprintf(fileName, "monitor_%d.root", fRunNumber);
839 if (fSubRunNumber > 0) {
840 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
842 TFile* file = TFile::Open(fileName, "recreate");
843 if (!file || !file->IsOpen()) {
844 Error("WriteHistos", "could not open file %s", fileName);
850 if (file) delete file;
855 //_____________________________________________________________________________
856 void AliMonitorProcess::StartNewRun()
858 // reset the histograms for a new run
860 SetStatus(kResetting);
861 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
862 while (TFolder* folder = (TFolder*) iFolder->Next()) {
863 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
864 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
875 //_____________________________________________________________________________
876 void AliMonitorProcess::CheckForConnections()
878 // check if new clients want to connect and add them to the list of sockets
880 TMessage message(kMESS_OBJECT);
881 message.WriteObject(fTopFolder);
882 SetStatus(kConnecting);
885 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
886 socket->SetOption(kNoBlock, 1);
887 char socketType[256];
888 if (!socket->Recv(socketType, 255)) continue;
889 if (strcmp(socketType, "client") == 0) {
890 if ((fNEvents == 0) || (socket->Send(message) >= 0)) {
891 fSockets.Add(socket);
892 TInetAddress adr = socket->GetInetAddress();
893 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
894 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
896 } else if (strcmp(socketType, "display") == 0) {
897 if (fDisplaySocket) {
898 fDisplaySocket->Close();
899 delete fDisplaySocket;
901 fDisplaySocket = socket;
902 fDisplaySocket->SetOption(kNoBlock, 1);
903 TInetAddress adr = socket->GetInetAddress();
904 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
905 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
909 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
910 socket = (TSocket*) fSockets[iSocket];
911 if (!socket) continue;
912 // remove finished client
914 if (socket->Recv(str, 255)) {
915 TString socketMessage(str);
916 if(socketMessage.CompareTo("Finished") == 0) {
917 TInetAddress adr = socket->GetInetAddress();
918 Info("CheckForConnections",
919 "disconnect finished client:\n %s (%s), port %d\n",
920 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
921 delete fSockets.RemoveAt(iSocket);
925 if (!socket->IsValid()) {
926 // remove invalid sockets from the list
927 TInetAddress adr = socket->GetInetAddress();
928 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
929 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
930 delete fSockets.RemoveAt(iSocket);
936 //_____________________________________________________________________________
937 void AliMonitorProcess::BroadcastHistos()
939 // send the monitor histograms to the clients
941 SetStatus(kBroadcasting);
942 TMessage message(kMESS_OBJECT);
943 message.WriteObject(fTopFolder);
945 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
946 TSocket* socket = (TSocket*) fSockets[iSocket];
947 if (!socket) continue;
948 socket->SetOption(kNoBlock, 0);
949 if (!socket->IsValid() || (socket->Send(message) < 0)) {
950 // remove the socket from the list if there was an error
951 TInetAddress adr = socket->GetInetAddress();
952 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
953 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
954 delete fSockets.RemoveAt(iSocket);
956 socket->SetOption(kNoBlock, 1);