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 ///////////////////////////////////////////////////////////////////////////////
30 #include <TGridResult.h>
33 #include <TServerSocket.h>
37 #include "AliITSLoader.h"
38 #include "AliITSclustererV2.h"
39 #include "AliITStrackerV2.h"
40 #include "AliLoader.h"
41 #include "AliMonitorHLT.h"
42 #include "AliMonitorHLTHough.h"
43 #include "AliMonitorITS.h"
44 #include "AliMonitorProcess.h"
45 #include "AliMonitorTPC.h"
46 #include "AliMonitorV0s.h"
47 #include "AliRawReaderRoot.h"
50 #include "AliTPCclustererMI.h"
51 #include "AliTPCtrackerMI.h"
52 #include "AliV0vertexer.h"
55 #include <AliL3ClusterFitter.h>
56 #include <AliL3DDLDataFileHandler.h>
57 #include <AliL3Fitter.h>
58 #include <AliL3Hough.h>
59 #include <AliL3HoughBaseTransformer.h>
60 #include <AliL3HoughMaxFinder.h>
61 #include <AliL3StandardIncludes.h>
62 #include <AliL3Track.h>
63 #include <AliL3TrackArray.h>
64 #include <AliL3Transform.h>
65 #include <AliL3Vertex.h>
66 #include <AliLevel3.h>
69 ClassImp(AliMonitorProcess)
72 const Int_t AliMonitorProcess::fgkPort = 9327;
75 //_____________________________________________________________________________
76 AliMonitorProcess::AliMonitorProcess(
77 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
78 const char* /*alienHost*/,
80 const char* alienHost,
83 const char* fileNameGalice)
85 // initialize the monitoring process and the monitor histograms
87 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
88 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
90 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
92 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
94 Fatal("AliMonitorProcess", "could not connect to alien");
96 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
101 fLogicalFileName = "";
104 fRunLoader = AliRunLoader::Open(fileNameGalice);
105 if (!fRunLoader) Fatal("AliMonitorProcess",
106 "could not get run loader from file %s",
109 fRunLoader->CdGAFile();
110 fTPCParam = AliTPC::LoadTPCParam(gFile);
111 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
113 fRunLoader->LoadgAlice();
114 gAlice = fRunLoader->GetAliRun();
115 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
116 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
117 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
118 fITSgeom = its->GetITSgeom();
119 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
122 // Init TPC parameters for HLT
123 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
125 cerr << "Could not create transform settings, please check log for error messages!" << endl;
134 fWriteHistoList = kFALSE;
136 fTopFolder = new TFolder("Monitor", "monitor histograms");
137 fTopFolder->SetOwner(kTRUE);
139 fMonitors.Add(new AliMonitorTPC(fTPCParam));
140 fMonitors.Add(new AliMonitorITS(fITSgeom));
141 fMonitors.Add(new AliMonitorV0s);
143 fMonitors.Add(new AliMonitorHLT(fTPCParam));
144 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
147 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
148 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
151 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
152 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
155 fFile = TFile::Open("monitor_tree.root", "RECREATE");
156 if (!fFile || !fFile->IsOpen()) {
157 Fatal("AliMonitorProcess", "could not open file for tree");
159 fTree = new TTree("MonitorTree", "tree for monitoring");
160 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
161 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
165 fServerSocket = new TServerSocket(fgkPort, kTRUE);
166 fServerSocket->SetOption(kNoBlock, 1);
167 fDisplaySocket = NULL;
168 CheckForConnections();
176 fInterruptHandler = new AliMonitorInterruptHandler(this);
177 gSystem->AddSignalHandler(fInterruptHandler);
180 //_____________________________________________________________________________
181 AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
184 Fatal("AliMonitorProcess", "copy constructor not implemented");
187 //_____________________________________________________________________________
188 AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
191 Fatal("operator =", "assignment operator not implemented");
195 //_____________________________________________________________________________
196 AliMonitorProcess::~AliMonitorProcess()
204 delete fServerSocket;
206 delete fDisplaySocket;
208 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
215 gSystem->Unlink("monitor_tree.root");
222 gSystem->RemoveSignalHandler(fInterruptHandler);
223 delete fInterruptHandler;
227 //_____________________________________________________________________________
228 const char* AliMonitorProcess::GetRevision()
234 //_____________________________________________________________________________
235 void AliMonitorProcess::SetStatus(EStatus status)
237 // set the current status and process system events
240 gSystem->ProcessEvents();
244 //_____________________________________________________________________________
245 void AliMonitorProcess::Run()
247 // run the monitor process:
248 // check for a raw data file, process the raw data file and delete it
254 while (!CheckForNewFile()) {
255 CheckForConnections();
257 if (fStopping) break;
260 if (fStopping) break;
272 //_____________________________________________________________________________
273 void AliMonitorProcess::Stop()
275 // set the fStopping flag to terminate the monitor process after the current
276 // event was processed
278 if (GetStatus() != kStopped) fStopping = kTRUE;
282 //_____________________________________________________________________________
283 void AliMonitorProcess::ProcessFile(const char* fileName)
285 // create a file with monitor histograms for a single file
287 if (GetStatus() != kStopped) {
288 Error("ProcessFile", "ProcessFile can not be called"
289 " while the monitor process is running");
293 fFileName = fileName;
294 Int_t nEventMin = fNEventsMin;
298 fNEventsMin = nEventMin;
303 //_____________________________________________________________________________
304 Bool_t AliMonitorProcess::CheckForNewFile()
306 // check whether a new file was registered in alien
308 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
309 TGridResult* result = fGrid->Ls();
313 sprintf(dirName, "%s/adc-%d", fAlienDir.Data(), datime.GetDate());
315 sprintf(findName, "*.root");
316 Grid_ResultHandle_t handle = fGrid->Find(dirName, findName);
318 Error("CheckForNewFile", "could not open alien directory %s",
322 TGridResult* result = fGrid->CreateGridResult(handle);
328 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
329 while (const char* entry = result->Next()) {
331 while (Grid_Result_t* resultEntry = result->Next()) {
332 const char* entry = resultEntry->name.c_str();
334 if (strrchr(entry, '/')) entry = strrchr(entry, '/')+1;
335 // entry = host_date_time.root
336 TString entryCopy(entry);
337 char* p = const_cast<char*>(entryCopy.Data());
338 if (!strtok(p, "_") || !p) continue; // host name
339 char* dateStr = strtok(NULL, "_");
340 if (!dateStr || !p) continue;
341 char* timeStr = strtok(NULL, ".");
342 if (!timeStr || !p) continue;
343 Long_t date = atoi(dateStr);
344 Long_t time = atoi(timeStr);
346 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
354 if (maxDate < 0) return kFALSE; // no files found
355 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
357 fLogicalFileName = fileName;
358 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
359 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
360 fFileName = result->Next();
362 fileName = dirName + ("/" + fLogicalFileName);
363 handle = fGrid->GetPhysicalFileNames(fileName.Data());
365 Error("CheckForNewFile", "could not get physical file names for %s",
369 result = fGrid->CreateGridResult(handle);
371 Grid_Result_t* resultEntry = result->Next();
373 Error("CheckForNewFile", "could not get physical file names for %s",
377 fFileName = resultEntry->name2.c_str();
378 fFileName.ReplaceAll("castor:/", "rfio:/");
385 //_____________________________________________________________________________
386 Bool_t AliMonitorProcess::ProcessFile()
388 // loop over all events in the raw data file, run the reconstruction
389 // and fill the monitor histograms
391 Int_t nEvents = GetNumberOfEvents(fFileName);
392 if (nEvents <= 0) return kFALSE;
393 Info("ProcessFile", "found %d event(s) in file %s",
394 nEvents, fFileName.Data());
396 CreateHLT(fFileName);
397 CreateHLTHough(fFileName);
400 // loop over the events
401 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
402 CheckForConnections();
404 fRunLoader->SetEventNumber(0);
405 AliRawReaderRoot rawReader(fFileName, iEvent);
406 if (fStopping) break;
407 if (rawReader.GetRunNumber() != fRunNumber) {
410 fRunNumber = rawReader.GetRunNumber();
411 fEventNumber[0] = rawReader.GetEventId()[0];
412 fEventNumber[1] = rawReader.GetEventId()[1];
414 if (fStopping) break;
417 // monitor only central physics events
418 if (rawReader.GetType() != 7) continue;
419 if ((rawReader.GetAttributes()[0] & 0x02) == 0) continue;
420 Info("ProcessFile", "run: %d event: %d %d\n", rawReader.GetRunNumber(),
421 rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
423 CheckForConnections();
424 if (!ReconstructTPC(&rawReader)) return kFALSE;
425 if (fStopping) break;
426 CheckForConnections();
427 if (!ReconstructITS(&rawReader)) return kFALSE;
428 if (fStopping) break;
429 CheckForConnections();
430 if (!ReconstructV0s()) return kFALSE;
431 if (fStopping) break;
432 CheckForConnections();
433 if (!ReconstructHLT(iEvent)) return kFALSE;
434 if (fStopping) break;
435 CheckForConnections();
436 if (!ReconstructHLTHough(iEvent)) return kFALSE;
437 if (fStopping) break;
439 if (fDisplaySocket) fDisplaySocket->Send("new event");
441 Info("ProcessFile", "filling histograms...");
442 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
443 CheckForConnections();
445 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
446 if (fStopping) break;
448 if (fStopping) break;
450 Info("ProcessFile", "updating histograms...");
451 CheckForConnections();
452 SetStatus(kUpdating);
453 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
454 while (TFolder* folder = (TFolder*) iFolder->Next()) {
455 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
456 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
462 if (fStopping) break;
464 Info("ProcessFile", "filling the tree...");
467 Info("ProcessFile", "broadcasting histograms...");
468 CheckForConnections();
472 if (fStopping) break;
483 //_____________________________________________________________________________
484 void AliMonitorProcess::Reset()
486 // write the current histograms to a file and reset them
488 if (fSubRunNumber == 0) fSubRunNumber++;
495 //_____________________________________________________________________________
496 UInt_t AliMonitorProcess::GetEventPeriodNumber() const
498 // get the period number from the event id
500 return (fEventNumber[1] >> 4);
503 //_____________________________________________________________________________
504 UInt_t AliMonitorProcess::GetEventOrbitNumber() const
506 // get the orbit number from the event id
508 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
511 //_____________________________________________________________________________
512 UInt_t AliMonitorProcess::GetEventBunchNumber() const
514 // get the bunch number from the event id
516 return (fEventNumber[0] % 0x0FFF);
519 //_____________________________________________________________________________
520 Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
522 // determine the number of events in the given raw data file
526 TFile* file = TFile::Open(fileName);
527 if (!file || !file->IsOpen()) {
528 Error("GetNumberOfEvents", "could not open file %s", fileName);
529 if (file) delete file;
533 TTree* tree = (TTree*) file->Get("RAW");
535 Error("GetNumberOfEvents", "could not find tree with raw data");
537 nEvents = (Int_t) tree->GetEntries();
545 //_____________________________________________________________________________
546 Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
548 // find TPC clusters and tracks
552 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
554 Error("ReconstructTPC", "no TPC loader found");
557 gSystem->Unlink("TPC.RecPoints.root");
558 gSystem->Unlink("TPC.Tracks.root");
561 Info("ReconstructTPC", "reconstructing clusters...");
562 tpcLoader->LoadRecPoints("recreate");
563 AliTPCclustererMI clusterer(fTPCParam);
564 tpcLoader->MakeRecPointsContainer();
565 clusterer.SetOutput(tpcLoader->TreeR());
566 clusterer.Digits2Clusters(rawReader);
567 tpcLoader->WriteRecPoints("OVERWRITE");
570 Info("ReconstructTPC", "reconstructing tracks...");
571 tpcLoader->LoadTracks("recreate");
573 AliTPCtrackerMI tracker(fTPCParam);
575 tracker.LoadClusters();
576 tracker.Clusters2Tracks();
577 tracker.WriteTracks();
578 tracker.UnloadClusters();
579 tpcLoader->WriteTracks("OVERWRITE");
582 tpcLoader->UnloadRecPoints();
583 tpcLoader->UnloadTracks();
587 //_____________________________________________________________________________
588 Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
590 // find ITS clusters and tracks
594 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
596 Error("ReconstructITS", "no ITS loader found");
599 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
601 Error("ReconstructITS", "no TPC loader found");
604 gSystem->Unlink("ITS.RecPoints.root");
605 gSystem->Unlink("ITS.Tracks.root");
608 Info("ReconstructITS", "reconstructing clusters...");
609 itsLoader->LoadRecPoints("recreate");
610 AliITSclustererV2 clusterer(fITSgeom);
611 itsLoader->MakeRecPointsContainer();
612 clusterer.Digits2Clusters(rawReader);
615 Info("ReconstructITS", "reconstructing tracks...");
616 itsLoader->LoadTracks("recreate");
617 itsLoader->MakeTracksContainer();
618 tpcLoader->LoadTracks();
619 AliITStrackerV2 tracker(fITSgeom);
620 tracker.LoadClusters(itsLoader->TreeR());
621 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
622 tracker.UnloadClusters();
623 itsLoader->WriteTracks("OVERWRITE");
625 itsLoader->UnloadRecPoints();
626 itsLoader->UnloadTracks();
627 tpcLoader->UnloadTracks();
631 //_____________________________________________________________________________
632 Bool_t AliMonitorProcess::ReconstructV0s()
638 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
640 Error("ReconstructV0", "no ITS loader found");
643 gSystem->Unlink("ITS.V0s.root");
646 Info("ReconstructV0s", "reconstructing V0s...");
647 itsLoader->LoadTracks("read");
648 itsLoader->LoadV0s("recreate");
649 AliV0vertexer vertexer;
650 TTree* tracks = itsLoader->TreeT();
652 Error("ReconstructV0s", "no ITS tracks tree found");
655 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
656 TTree* v0s = itsLoader->TreeV0();
657 vertexer.Tracks2V0vertices(tracks, v0s);
658 itsLoader->WriteV0s("OVERWRITE");
660 itsLoader->UnloadTracks();
661 itsLoader->UnloadV0s();
665 //_____________________________________________________________________________
667 void AliMonitorProcess::CreateHLT(const char* fileName)
670 // create the HLT (Level3) object
672 if (fHLT) delete fHLT;
675 strcpy(name, fileName);
676 fHLT = new AliLevel3(name);
677 fHLT->Init("./", AliLevel3::kRaw, 1);
679 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
681 Int_t phiSegments = 50;
682 Int_t etaSegments = 100;
683 Int_t trackletlength = 3;
684 Int_t tracklength = 20;//40 or 5
685 Int_t rowscopetracklet = 2;
686 Int_t rowscopetrack = 10;
687 Double_t minPtFit = 0;
688 Double_t maxangle = 0.1745;
689 Double_t goodDist = 5;
690 Double_t maxphi = 0.1;
691 Double_t maxeta = 0.1;
692 Double_t hitChi2Cut = 15;//100 or 15
693 Double_t goodHitChi2 = 5;//20 or 5
694 Double_t trackChi2Cut = 10;//50 or 10
695 fHLT->SetTrackerParam(phiSegments, etaSegments,
696 trackletlength, tracklength,
697 rowscopetracklet, rowscopetrack,
698 minPtFit, maxangle, goodDist, hitChi2Cut,
699 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
701 fHLT->WriteFiles("./hlt/");
704 //_____________________________________________________________________________
705 void AliMonitorProcess::CreateHLTHough(const char* fileName)
708 // create the HLT Hough transform (L3Hough) object
710 if (fHLTHough) delete fHLTHough;
713 strcpy(name, fileName);
715 fHLTHough = new AliL3Hough();
716 fHLTHough->SetThreshold(4);
717 fHLTHough->SetTransformerParams(140,150,0.5,-1);
718 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
719 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
720 fHLTHough->SetAddHistograms();
721 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
726 //_____________________________________________________________________________
727 Bool_t AliMonitorProcess::ReconstructHLT(
735 // run the HLT cluster and track finder
740 Warning("ReconstructHLT", "the code was compiled without HLT support");
744 gSystem->Exec("rm -rf hlt");
745 gSystem->MakeDirectory("hlt");
746 if (!fHLT) return kFALSE;
748 fHLT->ProcessEvent(0, 35, iEvent);
750 // remove the event number from the file names
752 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
753 gSystem->Exec(command);
754 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
755 gSystem->Exec(command);
756 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
757 gSystem->Exec(command);
758 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
759 gSystem->Exec(command);
764 //_____________________________________________________________________________
765 Bool_t AliMonitorProcess::ReconstructHLTHough(
773 // run the HLT Hough transformer
778 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
782 gSystem->Exec("rm -rf hlt/hough");
783 gSystem->MakeDirectory("hlt/hough");
784 gSystem->Exec("rm -rf hlt/fitter");
785 gSystem->MakeDirectory("hlt/fitter");
786 if (!fHLTHough) return kFALSE;
788 // fHLTHough->Process(0, 35);
789 // Loop over TPC sectors and process the data
790 for(Int_t i=0; i<=35; i++)
792 fHLTHough->ReadData(i,iEvent);
793 fHLTHough->Transform();
794 // if(fHLTHough->fAddHistograms)
795 fHLTHough->AddAllHistograms();
796 fHLTHough->FindTrackCandidates();
797 fHLTHough->AddTracks();
799 fHLTHough->WriteTracks("./hlt/hough");
801 // Run cluster fitter
802 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
804 // Set debug flag for the cluster fitter
807 // Setting fitter parameters
808 fitter->SetInnerWidthFactor(1,1.5);
809 fitter->SetOuterWidthFactor(1,1.5);
810 fitter->SetNmaxOverlaps(5);
812 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
813 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
815 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
817 // Takes input from global hough tracks produced by HT
818 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
822 for(Int_t islice = 0; islice <= 35; islice++)
824 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
827 fHLTHough->GetMemHandler(ipatch)->Free();
828 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
829 AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
831 fitter->Init(islice,ipatch);
832 fitter->SetInputData(digits);
833 fitter->FindClusters();
834 fitter->WriteClusters();
838 // Refit of the clusters
840 //The seeds are the input tracks from circle HT
841 AliL3TrackArray *tracks = fitter->GetSeeds();
842 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
844 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
845 for(Int_t i=0; i<tracks->GetNTracks(); i++)
847 AliL3Track *track = tracks->GetCheckedTrack(i);
849 if(track->GetNHits() < 20) continue;
850 ft->SortTrackClusters(track);
852 track->UpdateToFirstPoint();
856 //Write the final tracks
857 fitter->WriteTracks(20);
861 // remove the event number from the file names
863 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
864 gSystem->Exec(command);
865 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
866 gSystem->Exec(command);
867 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
868 gSystem->Exec(command);
873 //_____________________________________________________________________________
874 Bool_t AliMonitorProcess::WriteHistos()
876 // write the monitor tree and the monitor histograms to the file
877 // "monitor_<run number>[_<sub_run_number>].root"
878 // if at least fNEventsMin events were monitored
882 // rename tree file and create a new one
889 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
890 if (fSubRunNumber > 0) {
891 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
893 if (fNEvents < fNEventsMin) {
894 gSystem->Unlink("monitor_tree.root");
896 gSystem->Rename("monitor_tree.root", fileName);
899 fFile = TFile::Open("monitor_tree.root", "RECREATE");
900 if (!fFile || !fFile->IsOpen()) {
901 Fatal("WriteHistos", "could not open file for tree");
903 fTree = new TTree("MonitorTree", "tree for monitoring");
904 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
905 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
909 // write the histograms
910 if (fNEvents < fNEventsMin) return kTRUE;
912 if (!fWriteHistoList) {
913 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
914 while (TFolder* folder = (TFolder*) iFolder->Next()) {
915 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
916 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
924 Bool_t result = kTRUE;
925 sprintf(fileName, "monitor_%d.root", fRunNumber);
926 if (fSubRunNumber > 0) {
927 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
929 TFile* file = TFile::Open(fileName, "recreate");
930 if (!file || !file->IsOpen()) {
931 Error("WriteHistos", "could not open file %s", fileName);
937 if (file) delete file;
942 //_____________________________________________________________________________
943 void AliMonitorProcess::StartNewRun()
945 // reset the histograms for a new run
947 SetStatus(kResetting);
948 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
949 while (TFolder* folder = (TFolder*) iFolder->Next()) {
950 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
951 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
962 //_____________________________________________________________________________
963 void AliMonitorProcess::CheckForConnections()
965 // check if new clients want to connect and add them to the list of sockets
968 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
969 socket->SetOption(kNoBlock, 1);
970 char socketType[256];
971 if (socket->Recv(socketType, 255) <= 0) {
972 gSystem->Sleep(1000);
973 if (socket->Recv(socketType, 255) <= 0) {
974 TInetAddress adr = socket->GetInetAddress();
975 Error("CheckForConnections", "no socket type received - "
976 "disconnect client:\n %s (%s), port %d\n",
977 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
982 if (strcmp(socketType, "client") == 0) {
983 fSockets.Add(socket);
984 TInetAddress adr = socket->GetInetAddress();
985 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
986 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
987 if (fNEvents > 0) BroadcastHistos(socket);
988 } else if (strcmp(socketType, "display") == 0) {
989 if (fDisplaySocket) {
990 fDisplaySocket->Close();
991 delete fDisplaySocket;
993 fDisplaySocket = socket;
994 TInetAddress adr = socket->GetInetAddress();
995 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
996 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
998 TInetAddress adr = socket->GetInetAddress();
999 Error("CheckForConnections", "unknown socket type %s - "
1000 "disconnect client:\n %s (%s), port %d\n", socketType,
1001 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1007 // remove finished or invalid clients
1008 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1009 socket = (TSocket*) fSockets[iSocket];
1010 if (!socket) continue;
1011 char controlMessage[256];
1012 if (socket->Recv(controlMessage, 255)) {
1013 if (strcmp(controlMessage, "disconnect") == 0) {
1014 TInetAddress adr = socket->GetInetAddress();
1015 Info("CheckForConnections",
1016 "disconnect client:\n %s (%s), port %d\n",
1017 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1018 delete fSockets.RemoveAt(iSocket);
1022 if (!socket->IsValid()) {
1023 // remove invalid sockets from the list
1024 TInetAddress adr = socket->GetInetAddress();
1025 Error("CheckForConnections",
1026 "disconnect invalid client:\n %s (%s), port %d\n",
1027 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1028 delete fSockets.RemoveAt(iSocket);
1031 fSockets.Compress();
1034 //_____________________________________________________________________________
1035 void AliMonitorProcess::BroadcastHistos(TSocket* toSocket)
1037 // send the monitor histograms to the clients
1039 SetStatus(kBroadcasting);
1040 TMessage message(kMESS_OBJECT);
1041 message.WriteObject(fTopFolder);
1043 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1044 TSocket* socket = (TSocket*) fSockets[iSocket];
1045 if (!socket) continue;
1046 if (toSocket && (socket != toSocket)) continue;
1048 // send control message
1049 if (!socket->IsValid() || (socket->Send("histograms") <= 0)) {
1050 TInetAddress adr = socket->GetInetAddress();
1051 Error("BroadcastHistos", "connection to client failed - "
1052 "disconnect client:\n %s (%s), port %d\n",
1053 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1054 delete fSockets.RemoveAt(iSocket);
1057 // receive control message
1058 char controlMessage[256];
1059 Int_t result = socket->Recv(controlMessage, 255);
1061 gSystem->Sleep(1000); // wait one second and try again
1062 result = socket->Recv(controlMessage, 255);
1065 TInetAddress adr = socket->GetInetAddress();
1066 Error("BroadcastHistos", "no response from client - "
1067 "disconnect client:\n %s (%s), port %d\n",
1068 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1069 delete fSockets.RemoveAt(iSocket);
1072 if (strcmp(controlMessage, "ok") != 0) {
1073 TInetAddress adr = socket->GetInetAddress();
1074 Error("BroadcastHistos", "no \"ok\" message from client - "
1075 "disconnect client:\n %s (%s), port %d\n",
1076 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1077 delete fSockets.RemoveAt(iSocket);
1081 socket->SetOption(kNoBlock, 0);
1082 if (socket->Send(message) < 0) {
1083 // remove the socket from the list if there was an error
1084 TInetAddress adr = socket->GetInetAddress();
1085 Error("BroadcastHistos", "sending histograms failed - "
1086 "disconnect client:\n %s (%s), port %d\n",
1087 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1088 delete fSockets.RemoveAt(iSocket);
1090 gSystem->Sleep(100);
1091 socket->SetOption(kNoBlock, 1);
1094 fSockets.Compress();
1098 //_____________________________________________________________________________
1099 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1100 (AliMonitorProcess* process):
1101 TSignalHandler(kSigUser1, kFALSE),
1104 // constructor: set process
1107 //_____________________________________________________________________________
1108 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1109 (const AliMonitorInterruptHandler& handler):
1110 TSignalHandler(handler)
1114 Fatal("AliMonitorInterruptHandler", "copy constructor not implemented");
1117 //_____________________________________________________________________________
1118 AliMonitorProcess::AliMonitorInterruptHandler&
1119 AliMonitorProcess::AliMonitorInterruptHandler::operator =
1120 (const AliMonitorInterruptHandler& /*handler*/)
1122 // assignment operator
1124 Fatal("operator =", "assignment operator not implemented");
1128 //_____________________________________________________________________________
1129 Bool_t AliMonitorProcess::AliMonitorInterruptHandler::Notify()
1131 // interrupt signal -> stop process
1133 Info("Notify", "the monitoring process will be stopped.");