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>
64 #include <AliL3DDLDataFileHandler.h>
67 ClassImp(AliMonitorProcess)
70 const Int_t AliMonitorProcess::fgkPort = 9327;
73 //_____________________________________________________________________________
74 AliMonitorProcess::AliMonitorProcess(
75 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
76 const char* /*alienHost*/,
78 const char* alienHost,
81 const char* fileNameGalice)
83 // initialize the monitoring process and the monitor histograms
85 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
86 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
88 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
90 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
92 Fatal("AliMonitorProcess", "could not connect to alien");
94 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
99 fLogicalFileName = "";
102 fRunLoader = AliRunLoader::Open(fileNameGalice);
103 if (!fRunLoader) Fatal("AliMonitorProcess",
104 "could not get run loader from file %s",
107 fRunLoader->CdGAFile();
108 fTPCParam = AliTPC::LoadTPCParam(gFile);
109 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
111 fRunLoader->LoadgAlice();
112 gAlice = fRunLoader->GetAliRun();
113 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
114 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
115 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
116 fITSgeom = its->GetITSgeom();
117 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
120 // Init TPC parameters for HLT
121 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
123 cerr << "Could not create transform settings, please check log for error messages!" << endl;
132 fWriteHistoList = kFALSE;
134 fTopFolder = new TFolder("Monitor", "monitor histograms");
135 fTopFolder->SetOwner(kTRUE);
137 fMonitors.Add(new AliMonitorTPC(fTPCParam));
138 fMonitors.Add(new AliMonitorITS(fITSgeom));
139 fMonitors.Add(new AliMonitorV0s);
141 fMonitors.Add(new AliMonitorHLT(fTPCParam));
142 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
145 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
146 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
149 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
150 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
153 fFile = TFile::Open("monitor_tree.root", "RECREATE");
154 if (!fFile || !fFile->IsOpen()) {
155 Fatal("AliMonitorProcess", "could not open file for tree");
157 fTree = new TTree("MonitorTree", "tree for monitoring");
158 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
159 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
163 fServerSocket = new TServerSocket(fgkPort, kTRUE);
164 fServerSocket->SetOption(kNoBlock, 1);
165 fDisplaySocket = NULL;
166 CheckForConnections();
174 fInterruptHandler = new AliMonitorInterruptHandler(this);
175 gSystem->AddSignalHandler(fInterruptHandler);
178 //_____________________________________________________________________________
179 AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
182 Fatal("AliMonitorProcess", "copy constructor not implemented");
185 //_____________________________________________________________________________
186 AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
189 Fatal("operator =", "assignment operator not implemented");
193 //_____________________________________________________________________________
194 AliMonitorProcess::~AliMonitorProcess()
202 delete fServerSocket;
204 delete fDisplaySocket;
206 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
213 gSystem->Unlink("monitor_tree.root");
220 gSystem->RemoveSignalHandler(fInterruptHandler);
221 delete fInterruptHandler;
225 //_____________________________________________________________________________
226 const char* AliMonitorProcess::GetRevision()
232 //_____________________________________________________________________________
233 void AliMonitorProcess::SetStatus(EStatus status)
235 // set the current status and process system events
238 gSystem->ProcessEvents();
242 //_____________________________________________________________________________
243 void AliMonitorProcess::Run()
245 // run the monitor process:
246 // check for a raw data file, process the raw data file and delete it
252 while (!CheckForNewFile()) {
253 CheckForConnections();
255 if (fStopping) break;
258 if (fStopping) break;
270 //_____________________________________________________________________________
271 void AliMonitorProcess::Stop()
273 // set the fStopping flag to terminate the monitor process after the current
274 // event was processed
276 if (GetStatus() != kStopped) fStopping = kTRUE;
280 //_____________________________________________________________________________
281 void AliMonitorProcess::ProcessFile(const char* fileName)
283 // create a file with monitor histograms for a single file
285 if (GetStatus() != kStopped) {
286 Error("ProcessFile", "ProcessFile can not be called"
287 " while the monitor process is running");
291 fFileName = fileName;
292 Int_t nEventMin = fNEventsMin;
296 fNEventsMin = nEventMin;
301 //_____________________________________________________________________________
302 Bool_t AliMonitorProcess::CheckForNewFile()
304 // check whether a new file was registered in alien
306 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
307 TGridResult* result = fGrid->Ls();
311 sprintf(dirName, "%s/adc-%d", fAlienDir.Data(), datime.GetDate());
313 sprintf(findName, "*.root");
314 Grid_ResultHandle_t handle = fGrid->Find(dirName, findName);
316 Error("CheckForNewFile", "could not open alien directory %s",
320 TGridResult* result = fGrid->CreateGridResult(handle);
326 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
327 while (const char* entry = result->Next()) {
329 while (Grid_Result_t* resultEntry = result->Next()) {
330 const char* entry = resultEntry->name.c_str();
332 if (strrchr(entry, '/')) entry = strrchr(entry, '/')+1;
333 // entry = host_date_time.root
334 TString entryCopy(entry);
335 char* p = const_cast<char*>(entryCopy.Data());
336 if (!strtok(p, "_") || !p) continue; // host name
337 char* dateStr = strtok(NULL, "_");
338 if (!dateStr || !p) continue;
339 char* timeStr = strtok(NULL, ".");
340 if (!timeStr || !p) continue;
341 Long_t date = atoi(dateStr);
342 Long_t time = atoi(timeStr);
344 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
352 if (maxDate < 0) return kFALSE; // no files found
353 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
355 fLogicalFileName = fileName;
356 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
357 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
358 fFileName = result->Next();
360 fileName = dirName + ("/" + fLogicalFileName);
361 handle = fGrid->GetPhysicalFileNames(fileName.Data());
363 Error("CheckForNewFile", "could not get physical file names for %s",
367 result = fGrid->CreateGridResult(handle);
369 Grid_Result_t* resultEntry = result->Next();
371 Error("CheckForNewFile", "could not get physical file names for %s",
375 fFileName = resultEntry->name2.c_str();
376 fFileName.ReplaceAll("castor:/", "rfio:/");
383 //_____________________________________________________________________________
384 Bool_t AliMonitorProcess::ProcessFile()
386 // loop over all events in the raw data file, run the reconstruction
387 // and fill the monitor histograms
389 Int_t nEvents = GetNumberOfEvents(fFileName);
390 if (nEvents <= 0) return kFALSE;
391 Info("ProcessFile", "found %d event(s) in file %s",
392 nEvents, fFileName.Data());
394 CreateHLT(fFileName);
395 CreateHLTHough(fFileName);
398 // loop over the events
399 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
400 CheckForConnections();
402 fRunLoader->SetEventNumber(0);
403 AliRawReaderRoot rawReader(fFileName, iEvent);
404 if (fStopping) break;
405 if (rawReader.GetRunNumber() != fRunNumber) {
408 fRunNumber = rawReader.GetRunNumber();
409 fEventNumber[0] = rawReader.GetEventId()[0];
410 fEventNumber[1] = rawReader.GetEventId()[1];
412 if (fStopping) break;
415 // monitor only central physics events
416 if (rawReader.GetType() != 7) continue;
417 if ((rawReader.GetAttributes()[0] & 0x02) == 0) continue;
418 Info("ProcessFile", "run: %d event: %d %d\n", rawReader.GetRunNumber(),
419 rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
421 CheckForConnections();
422 if (!ReconstructTPC(&rawReader)) return kFALSE;
423 if (fStopping) break;
424 CheckForConnections();
425 if (!ReconstructITS(&rawReader)) return kFALSE;
426 if (fStopping) break;
427 CheckForConnections();
428 if (!ReconstructV0s()) return kFALSE;
429 if (fStopping) break;
430 CheckForConnections();
431 if (!ReconstructHLT(iEvent)) return kFALSE;
432 if (fStopping) break;
433 CheckForConnections();
434 if (!ReconstructHLTHough(iEvent)) return kFALSE;
435 if (fStopping) break;
437 if (fDisplaySocket) fDisplaySocket->Send("new event");
439 Info("ProcessFile", "filling histograms...");
440 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
441 CheckForConnections();
443 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
444 if (fStopping) break;
446 if (fStopping) break;
448 Info("ProcessFile", "updating histograms...");
449 CheckForConnections();
450 SetStatus(kUpdating);
451 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
452 while (TFolder* folder = (TFolder*) iFolder->Next()) {
453 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
454 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
460 if (fStopping) break;
462 Info("ProcessFile", "filling the tree...");
465 Info("ProcessFile", "broadcasting histograms...");
466 CheckForConnections();
470 if (fStopping) break;
481 //_____________________________________________________________________________
482 void AliMonitorProcess::Reset()
484 // write the current histograms to a file and reset them
486 if (fSubRunNumber == 0) fSubRunNumber++;
493 //_____________________________________________________________________________
494 UInt_t AliMonitorProcess::GetEventPeriodNumber() const
496 // get the period number from the event id
498 return (fEventNumber[1] >> 4);
501 //_____________________________________________________________________________
502 UInt_t AliMonitorProcess::GetEventOrbitNumber() const
504 // get the orbit number from the event id
506 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
509 //_____________________________________________________________________________
510 UInt_t AliMonitorProcess::GetEventBunchNumber() const
512 // get the bunch number from the event id
514 return (fEventNumber[0] % 0x0FFF);
517 //_____________________________________________________________________________
518 Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
520 // determine the number of events in the given raw data file
524 TFile* file = TFile::Open(fileName);
525 if (!file || !file->IsOpen()) {
526 Error("GetNumberOfEvents", "could not open file %s", fileName);
527 if (file) delete file;
531 TTree* tree = (TTree*) file->Get("RAW");
533 Error("GetNumberOfEvents", "could not find tree with raw data");
535 nEvents = (Int_t) tree->GetEntries();
543 //_____________________________________________________________________________
544 Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
546 // find TPC clusters and tracks
550 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
552 Error("ReconstructTPC", "no TPC loader found");
555 gSystem->Unlink("TPC.RecPoints.root");
556 gSystem->Unlink("TPC.Tracks.root");
559 Info("ReconstructTPC", "reconstructing clusters...");
560 tpcLoader->LoadRecPoints("recreate");
561 AliTPCclustererMI clusterer(fTPCParam);
562 tpcLoader->MakeRecPointsContainer();
563 clusterer.SetOutput(tpcLoader->TreeR());
564 clusterer.Digits2Clusters(rawReader);
565 tpcLoader->WriteRecPoints("OVERWRITE");
568 Info("ReconstructTPC", "reconstructing tracks...");
569 tpcLoader->LoadTracks("recreate");
571 AliTPCtrackerMI tracker(fTPCParam);
573 tracker.LoadClusters();
574 tracker.Clusters2Tracks();
575 tracker.WriteTracks();
576 tracker.UnloadClusters();
577 tpcLoader->WriteTracks("OVERWRITE");
580 tpcLoader->UnloadRecPoints();
581 tpcLoader->UnloadTracks();
585 //_____________________________________________________________________________
586 Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
588 // find ITS clusters and tracks
592 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
594 Error("ReconstructITS", "no ITS loader found");
597 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
599 Error("ReconstructITS", "no TPC loader found");
602 gSystem->Unlink("ITS.RecPoints.root");
603 gSystem->Unlink("ITS.Tracks.root");
606 Info("ReconstructITS", "reconstructing clusters...");
607 itsLoader->LoadRecPoints("recreate");
608 AliITSclustererV2 clusterer(fITSgeom);
609 itsLoader->MakeRecPointsContainer();
610 clusterer.Digits2Clusters(rawReader);
613 Info("ReconstructITS", "reconstructing tracks...");
614 itsLoader->LoadTracks("recreate");
615 itsLoader->MakeTracksContainer();
616 tpcLoader->LoadTracks();
617 AliITStrackerV2 tracker(fITSgeom);
618 tracker.LoadClusters(itsLoader->TreeR());
619 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
620 tracker.UnloadClusters();
621 itsLoader->WriteTracks("OVERWRITE");
623 itsLoader->UnloadRecPoints();
624 itsLoader->UnloadTracks();
625 tpcLoader->UnloadTracks();
629 //_____________________________________________________________________________
630 Bool_t AliMonitorProcess::ReconstructV0s()
636 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
638 Error("ReconstructV0", "no ITS loader found");
641 gSystem->Unlink("ITS.V0s.root");
644 Info("ReconstructV0s", "reconstructing V0s...");
645 itsLoader->LoadTracks("read");
646 itsLoader->LoadV0s("recreate");
647 AliV0vertexer vertexer;
648 TTree* tracks = itsLoader->TreeT();
650 Error("ReconstructV0s", "no ITS tracks tree found");
653 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
654 TTree* v0s = itsLoader->TreeV0();
655 vertexer.Tracks2V0vertices(tracks, v0s);
656 itsLoader->WriteV0s("OVERWRITE");
658 itsLoader->UnloadTracks();
659 itsLoader->UnloadV0s();
663 //_____________________________________________________________________________
665 void AliMonitorProcess::CreateHLT(const char* fileName)
668 // create the HLT (Level3) object
670 if (fHLT) delete fHLT;
673 strcpy(name, fileName);
674 fHLT = new AliLevel3(name);
675 fHLT->Init("./", AliLevel3::kRaw, 1);
677 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
679 Int_t phiSegments = 50;
680 Int_t etaSegments = 100;
681 Int_t trackletlength = 3;
682 Int_t tracklength = 20;//40 or 5
683 Int_t rowscopetracklet = 2;
684 Int_t rowscopetrack = 10;
685 Double_t minPtFit = 0;
686 Double_t maxangle = 0.1745;
687 Double_t goodDist = 5;
688 Double_t maxphi = 0.1;
689 Double_t maxeta = 0.1;
690 Double_t hitChi2Cut = 15;//100 or 15
691 Double_t goodHitChi2 = 5;//20 or 5
692 Double_t trackChi2Cut = 10;//50 or 10
693 fHLT->SetTrackerParam(phiSegments, etaSegments,
694 trackletlength, tracklength,
695 rowscopetracklet, rowscopetrack,
696 minPtFit, maxangle, goodDist, hitChi2Cut,
697 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
699 fHLT->WriteFiles("./hlt/");
702 //_____________________________________________________________________________
703 void AliMonitorProcess::CreateHLTHough(const char* fileName)
706 // create the HLT Hough transform (L3Hough) object
708 if (fHLTHough) delete fHLTHough;
711 strcpy(name, fileName);
713 fHLTHough = new AliL3Hough();
714 fHLTHough->SetThreshold(4);
715 fHLTHough->SetTransformerParams(140,150,0.5,-1);
716 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
717 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
718 fHLTHough->SetAddHistograms();
719 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
724 //_____________________________________________________________________________
725 Bool_t AliMonitorProcess::ReconstructHLT(
733 // run the HLT cluster and track finder
738 Warning("ReconstructHLT", "the code was compiled without HLT support");
742 gSystem->Exec("rm -rf hlt");
743 gSystem->MakeDirectory("hlt");
744 if (!fHLT) return kFALSE;
746 fHLT->ProcessEvent(0, 35, iEvent);
748 // remove the event number from the file names
750 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
751 gSystem->Exec(command);
752 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
753 gSystem->Exec(command);
754 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
755 gSystem->Exec(command);
756 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
757 gSystem->Exec(command);
762 //_____________________________________________________________________________
763 Bool_t AliMonitorProcess::ReconstructHLTHough(
771 // run the HLT Hough transformer
776 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
780 gSystem->Exec("rm -rf hlt/hough");
781 gSystem->MakeDirectory("hlt/hough");
782 gSystem->Exec("rm -rf hlt/fitter");
783 gSystem->MakeDirectory("hlt/fitter");
784 if (!fHLTHough) return kFALSE;
786 // fHLTHough->Process(0, 35);
787 // Loop over TPC sectors and process the data
788 for(Int_t i=0; i<=35; i++)
790 fHLTHough->ReadData(i,iEvent);
791 fHLTHough->Transform();
792 // if(fHLTHough->fAddHistograms)
793 fHLTHough->AddAllHistograms();
794 fHLTHough->FindTrackCandidates();
795 fHLTHough->AddTracks();
797 fHLTHough->WriteTracks("./hlt/hough");
799 // Run cluster fitter
800 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
802 // Set debug flag for the cluster fitter
805 // Setting fitter parameters
806 fitter->SetInnerWidthFactor(1,1.5);
807 fitter->SetOuterWidthFactor(1,1.5);
808 fitter->SetNmaxOverlaps(5);
810 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
811 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
813 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
815 // Takes input from global hough tracks produced by HT
816 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
820 for(Int_t islice = 0; islice <= 35; islice++)
822 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
825 fHLTHough->GetMemHandler(ipatch)->Free();
826 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
827 AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
829 fitter->Init(islice,ipatch);
830 fitter->SetInputData(digits);
831 fitter->FindClusters();
832 fitter->WriteClusters();
836 // Refit of the clusters
838 //The seeds are the input tracks from circle HT
839 AliL3TrackArray *tracks = fitter->GetSeeds();
840 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
842 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
843 for(Int_t i=0; i<tracks->GetNTracks(); i++)
845 AliL3Track *track = tracks->GetCheckedTrack(i);
847 if(track->GetNHits() < 20) continue;
848 ft->SortTrackClusters(track);
850 track->UpdateToFirstPoint();
854 //Write the final tracks
855 fitter->WriteTracks(20);
859 // remove the event number from the file names
861 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
862 gSystem->Exec(command);
863 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
864 gSystem->Exec(command);
865 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
866 gSystem->Exec(command);
871 //_____________________________________________________________________________
872 Bool_t AliMonitorProcess::WriteHistos()
874 // write the monitor tree and the monitor histograms to the file
875 // "monitor_<run number>[_<sub_run_number>].root"
876 // if at least fNEventsMin events were monitored
880 // rename tree file and create a new one
887 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
888 if (fSubRunNumber > 0) {
889 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
891 if (fNEvents < fNEventsMin) {
892 gSystem->Unlink("monitor_tree.root");
894 gSystem->Rename("monitor_tree.root", fileName);
897 fFile = TFile::Open("monitor_tree.root", "RECREATE");
898 if (!fFile || !fFile->IsOpen()) {
899 Fatal("WriteHistos", "could not open file for tree");
901 fTree = new TTree("MonitorTree", "tree for monitoring");
902 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
903 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
907 // write the histograms
908 if (fNEvents < fNEventsMin) return kTRUE;
910 if (!fWriteHistoList) {
911 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
912 while (TFolder* folder = (TFolder*) iFolder->Next()) {
913 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
914 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
922 Bool_t result = kTRUE;
923 sprintf(fileName, "monitor_%d.root", fRunNumber);
924 if (fSubRunNumber > 0) {
925 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
927 TFile* file = TFile::Open(fileName, "recreate");
928 if (!file || !file->IsOpen()) {
929 Error("WriteHistos", "could not open file %s", fileName);
935 if (file) delete file;
940 //_____________________________________________________________________________
941 void AliMonitorProcess::StartNewRun()
943 // reset the histograms for a new run
945 SetStatus(kResetting);
946 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
947 while (TFolder* folder = (TFolder*) iFolder->Next()) {
948 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
949 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
960 //_____________________________________________________________________________
961 void AliMonitorProcess::CheckForConnections()
963 // check if new clients want to connect and add them to the list of sockets
966 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
967 socket->SetOption(kNoBlock, 1);
968 char socketType[256];
969 if (socket->Recv(socketType, 255) <= 0) {
970 gSystem->Sleep(1000);
971 if (socket->Recv(socketType, 255) <= 0) {
972 TInetAddress adr = socket->GetInetAddress();
973 Error("CheckForConnections", "no socket type received - "
974 "disconnect client:\n %s (%s), port %d\n",
975 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
980 if (strcmp(socketType, "client") == 0) {
981 fSockets.Add(socket);
982 TInetAddress adr = socket->GetInetAddress();
983 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
984 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
985 if (fNEvents > 0) BroadcastHistos(socket);
986 } else if (strcmp(socketType, "display") == 0) {
987 if (fDisplaySocket) {
988 fDisplaySocket->Close();
989 delete fDisplaySocket;
991 fDisplaySocket = socket;
992 TInetAddress adr = socket->GetInetAddress();
993 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
994 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
996 TInetAddress adr = socket->GetInetAddress();
997 Error("CheckForConnections", "unknown socket type %s - "
998 "disconnect client:\n %s (%s), port %d\n", socketType,
999 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1005 // remove finished or invalid clients
1006 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1007 socket = (TSocket*) fSockets[iSocket];
1008 if (!socket) continue;
1009 char controlMessage[256];
1010 if (socket->Recv(controlMessage, 255)) {
1011 if (strcmp(controlMessage, "disconnect") == 0) {
1012 TInetAddress adr = socket->GetInetAddress();
1013 Info("CheckForConnections",
1014 "disconnect client:\n %s (%s), port %d\n",
1015 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1016 delete fSockets.RemoveAt(iSocket);
1020 if (!socket->IsValid()) {
1021 // remove invalid sockets from the list
1022 TInetAddress adr = socket->GetInetAddress();
1023 Error("CheckForConnections",
1024 "disconnect invalid client:\n %s (%s), port %d\n",
1025 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1026 delete fSockets.RemoveAt(iSocket);
1029 fSockets.Compress();
1032 //_____________________________________________________________________________
1033 void AliMonitorProcess::BroadcastHistos(TSocket* toSocket)
1035 // send the monitor histograms to the clients
1037 SetStatus(kBroadcasting);
1038 TMessage message(kMESS_OBJECT);
1039 message.WriteObject(fTopFolder);
1041 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1042 TSocket* socket = (TSocket*) fSockets[iSocket];
1043 if (!socket) continue;
1044 if (toSocket && (socket != toSocket)) continue;
1046 // send control message
1047 if (!socket->IsValid() || (socket->Send("histograms") <= 0)) {
1048 TInetAddress adr = socket->GetInetAddress();
1049 Error("BroadcastHistos", "connection to client failed - "
1050 "disconnect client:\n %s (%s), port %d\n",
1051 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1052 delete fSockets.RemoveAt(iSocket);
1055 // receive control message
1056 char controlMessage[256];
1057 Int_t result = socket->Recv(controlMessage, 255);
1059 gSystem->Sleep(1000); // wait one second and try again
1060 result = socket->Recv(controlMessage, 255);
1063 TInetAddress adr = socket->GetInetAddress();
1064 Error("BroadcastHistos", "no response from client - "
1065 "disconnect client:\n %s (%s), port %d\n",
1066 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1067 delete fSockets.RemoveAt(iSocket);
1070 if (strcmp(controlMessage, "ok") != 0) {
1071 TInetAddress adr = socket->GetInetAddress();
1072 Error("BroadcastHistos", "no \"ok\" message from client - "
1073 "disconnect client:\n %s (%s), port %d\n",
1074 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1075 delete fSockets.RemoveAt(iSocket);
1079 socket->SetOption(kNoBlock, 0);
1080 if (socket->Send(message) < 0) {
1081 // remove the socket from the list if there was an error
1082 TInetAddress adr = socket->GetInetAddress();
1083 Error("BroadcastHistos", "sending histograms failed - "
1084 "disconnect client:\n %s (%s), port %d\n",
1085 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1086 delete fSockets.RemoveAt(iSocket);
1088 gSystem->Sleep(100);
1089 socket->SetOption(kNoBlock, 1);
1092 fSockets.Compress();
1096 //_____________________________________________________________________________
1097 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1098 (AliMonitorProcess* process):
1099 TSignalHandler(kSigUser1, kFALSE),
1102 // constructor: set process
1105 //_____________________________________________________________________________
1106 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1107 (const AliMonitorInterruptHandler& handler):
1108 TSignalHandler(handler)
1112 Fatal("AliMonitorInterruptHandler", "copy constructor not implemented");
1115 //_____________________________________________________________________________
1116 AliMonitorProcess::AliMonitorInterruptHandler&
1117 AliMonitorProcess::AliMonitorInterruptHandler::operator =
1118 (const AliMonitorInterruptHandler& /*handler*/)
1120 // assignment operator
1122 Fatal("operator =", "assignment operator not implemented");
1126 //_____________________________________________________________________________
1127 Bool_t AliMonitorProcess::AliMonitorInterruptHandler::Notify()
1129 // interrupt signal -> stop process
1131 Info("Notify", "the monitoring process will be stopped.");