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 <TGridResult.h>
32 #include <TServerSocket.h>
36 #include "AliITSLoader.h"
37 #include "AliITSclustererV2.h"
38 #include "AliITStrackerV2.h"
39 #include "AliLoader.h"
40 #include "AliMonitorHLT.h"
41 #include "AliMonitorHLTHough.h"
42 #include "AliMonitorITS.h"
43 #include "AliMonitorProcess.h"
44 #include "AliMonitorTPC.h"
45 #include "AliMonitorV0s.h"
46 #include "AliRawReaderRoot.h"
49 #include "AliTPCclustererMI.h"
50 #include "AliTPCtrackerMI.h"
51 #include "AliV0vertexer.h"
54 #include <AliL3ClusterFitter.h>
55 #include <AliL3DDLDataFileHandler.h>
56 #include <AliL3Fitter.h>
57 #include <AliL3Hough.h>
58 #include <AliL3HoughBaseTransformer.h>
59 #include <AliL3HoughMaxFinder.h>
60 #include <AliL3StandardIncludes.h>
61 #include <AliL3Track.h>
62 #include <AliL3TrackArray.h>
63 #include <AliL3Transform.h>
64 #include <AliL3Vertex.h>
65 #include <AliLevel3.h>
68 ClassImp(AliMonitorProcess)
71 const Int_t AliMonitorProcess::fgkPort = 9327;
74 //_____________________________________________________________________________
75 AliMonitorProcess::AliMonitorProcess(
76 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
77 const char* /*alienHost*/,
79 const char* alienHost,
82 const char* fileNameGalice)
84 // initialize the monitoring process and the monitor histograms
86 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
87 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
89 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
91 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
93 Fatal("AliMonitorProcess", "could not connect to alien");
95 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
100 fLogicalFileName = "";
103 fRunLoader = AliRunLoader::Open(fileNameGalice);
104 if (!fRunLoader) Fatal("AliMonitorProcess",
105 "could not get run loader from file %s",
108 fRunLoader->CdGAFile();
109 fTPCParam = AliTPC::LoadTPCParam(gFile);
110 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
112 fRunLoader->LoadgAlice();
113 gAlice = fRunLoader->GetAliRun();
114 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
115 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
116 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
117 fITSgeom = its->GetITSgeom();
118 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
121 // Init TPC parameters for HLT
122 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
124 cerr << "Could not create transform settings, please check log for error messages!" << endl;
133 fWriteHistoList = kFALSE;
135 fTopFolder = new TFolder("Monitor", "monitor histograms");
136 fTopFolder->SetOwner(kTRUE);
138 fMonitors.Add(new AliMonitorTPC(fTPCParam));
139 fMonitors.Add(new AliMonitorITS(fITSgeom));
140 fMonitors.Add(new AliMonitorV0s);
142 fMonitors.Add(new AliMonitorHLT(fTPCParam));
143 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
146 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
147 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
150 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
151 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
154 fFile = TFile::Open("monitor_tree.root", "RECREATE");
155 if (!fFile || !fFile->IsOpen()) {
156 Fatal("AliMonitorProcess", "could not open file for tree");
158 fTree = new TTree("MonitorTree", "tree for monitoring");
159 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
160 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
164 fServerSocket = new TServerSocket(fgkPort, kTRUE);
165 fServerSocket->SetOption(kNoBlock, 1);
166 fDisplaySocket = NULL;
167 CheckForConnections();
175 fInterruptHandler = new AliMonitorInterruptHandler(this);
176 gSystem->AddSignalHandler(fInterruptHandler);
179 //_____________________________________________________________________________
180 AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
183 Fatal("AliMonitorProcess", "copy constructor not implemented");
186 //_____________________________________________________________________________
187 AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
190 Fatal("operator =", "assignment operator not implemented");
194 //_____________________________________________________________________________
195 AliMonitorProcess::~AliMonitorProcess()
203 delete fServerSocket;
205 delete fDisplaySocket;
207 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
214 gSystem->Unlink("monitor_tree.root");
221 gSystem->RemoveSignalHandler(fInterruptHandler);
222 delete fInterruptHandler;
226 //_____________________________________________________________________________
227 const char* AliMonitorProcess::GetRevision()
233 //_____________________________________________________________________________
234 void AliMonitorProcess::SetStatus(EStatus status)
236 // set the current status and process system events
239 gSystem->ProcessEvents();
243 //_____________________________________________________________________________
244 void AliMonitorProcess::Run()
246 // run the monitor process:
247 // check for a raw data file, process the raw data file and delete it
253 while (!CheckForNewFile()) {
254 CheckForConnections();
256 if (fStopping) break;
259 if (fStopping) break;
271 //_____________________________________________________________________________
272 void AliMonitorProcess::Stop()
274 // set the fStopping flag to terminate the monitor process after the current
275 // event was processed
277 if (GetStatus() != kStopped) fStopping = kTRUE;
281 //_____________________________________________________________________________
282 void AliMonitorProcess::ProcessFile(const char* fileName)
284 // create a file with monitor histograms for a single file
286 if (GetStatus() != kStopped) {
287 Error("ProcessFile", "ProcessFile can not be called"
288 " while the monitor process is running");
292 fFileName = fileName;
293 Int_t nEventMin = fNEventsMin;
297 fNEventsMin = nEventMin;
302 //_____________________________________________________________________________
303 Bool_t AliMonitorProcess::CheckForNewFile()
305 // check whether a new file was registered in alien
307 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
308 TGridResult* result = fGrid->Ls();
312 sprintf(dirName, "%s/adc-%d", fAlienDir.Data(), datime.GetDate());
314 sprintf(findName, "*.root");
315 Grid_ResultHandle_t handle = fGrid->Find(dirName, findName);
317 Error("CheckForNewFile", "could not open alien directory %s",
321 TGridResult* result = fGrid->CreateGridResult(handle);
327 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
328 while (const char* entry = result->Next()) {
330 while (Grid_Result_t* resultEntry = result->Next()) {
331 const char* entry = resultEntry->name.c_str();
333 if (strrchr(entry, '/')) entry = strrchr(entry, '/')+1;
334 // entry = host_date_time.root
335 TString entryCopy(entry);
336 char* p = const_cast<char*>(entryCopy.Data());
337 if (!strtok(p, "_") || !p) continue; // host name
338 char* dateStr = strtok(NULL, "_");
339 if (!dateStr || !p) continue;
340 char* timeStr = strtok(NULL, ".");
341 if (!timeStr || !p) continue;
342 Long_t date = atoi(dateStr);
343 Long_t time = atoi(timeStr);
345 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
353 if (maxDate < 0) return kFALSE; // no files found
354 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
356 fLogicalFileName = fileName;
357 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
358 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
359 fFileName = result->Next();
361 fileName = dirName + ("/" + fLogicalFileName);
362 handle = fGrid->GetPhysicalFileNames(fileName.Data());
364 Error("CheckForNewFile", "could not get physical file names for %s",
368 result = fGrid->CreateGridResult(handle);
370 Grid_Result_t* resultEntry = result->Next();
372 Error("CheckForNewFile", "could not get physical file names for %s",
376 fFileName = resultEntry->name2.c_str();
377 fFileName.ReplaceAll("castor:/", "rfio:/");
384 //_____________________________________________________________________________
385 Bool_t AliMonitorProcess::ProcessFile()
387 // loop over all events in the raw data file, run the reconstruction
388 // and fill the monitor histograms
390 Int_t nEvents = GetNumberOfEvents(fFileName);
391 if (nEvents <= 0) return kFALSE;
392 Info("ProcessFile", "found %d event(s) in file %s",
393 nEvents, fFileName.Data());
395 CreateHLT(fFileName);
396 CreateHLTHough(fFileName);
399 // loop over the events
400 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
401 CheckForConnections();
403 fRunLoader->SetEventNumber(0);
404 AliRawReaderRoot rawReader(fFileName, iEvent);
405 if (fStopping) break;
406 if (rawReader.GetRunNumber() != fRunNumber) {
409 fRunNumber = rawReader.GetRunNumber();
410 fEventNumber[0] = rawReader.GetEventId()[0];
411 fEventNumber[1] = rawReader.GetEventId()[1];
413 if (fStopping) break;
416 // monitor only central physics events
417 if (rawReader.GetType() != 7) continue;
418 if ((rawReader.GetAttributes()[0] & 0x02) == 0) continue;
419 Info("ProcessFile", "run: %d event: %d %d\n", rawReader.GetRunNumber(),
420 rawReader.GetEventId()[0], rawReader.GetEventId()[1]);
422 CheckForConnections();
423 if (!ReconstructTPC(&rawReader)) return kFALSE;
424 if (fStopping) break;
425 CheckForConnections();
426 if (!ReconstructITS(&rawReader)) return kFALSE;
427 if (fStopping) break;
428 CheckForConnections();
429 if (!ReconstructV0s()) return kFALSE;
430 if (fStopping) break;
431 CheckForConnections();
432 if (!ReconstructHLT(iEvent)) return kFALSE;
433 if (fStopping) break;
434 CheckForConnections();
435 if (!ReconstructHLTHough(iEvent)) return kFALSE;
436 if (fStopping) break;
438 if (fDisplaySocket) fDisplaySocket->Send("new event");
440 Info("ProcessFile", "filling histograms...");
441 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
442 CheckForConnections();
444 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
445 if (fStopping) break;
447 if (fStopping) break;
449 Info("ProcessFile", "updating histograms...");
450 CheckForConnections();
451 SetStatus(kUpdating);
452 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
453 while (TFolder* folder = (TFolder*) iFolder->Next()) {
454 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
455 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
461 if (fStopping) break;
463 Info("ProcessFile", "filling the tree...");
466 Info("ProcessFile", "broadcasting histograms...");
467 CheckForConnections();
471 if (fStopping) break;
482 //_____________________________________________________________________________
483 void AliMonitorProcess::Reset()
485 // write the current histograms to a file and reset them
487 if (fSubRunNumber == 0) fSubRunNumber++;
494 //_____________________________________________________________________________
495 UInt_t AliMonitorProcess::GetEventPeriodNumber() const
497 // get the period number from the event id
499 return (fEventNumber[1] >> 4);
502 //_____________________________________________________________________________
503 UInt_t AliMonitorProcess::GetEventOrbitNumber() const
505 // get the orbit number from the event id
507 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
510 //_____________________________________________________________________________
511 UInt_t AliMonitorProcess::GetEventBunchNumber() const
513 // get the bunch number from the event id
515 return (fEventNumber[0] % 0x0FFF);
518 //_____________________________________________________________________________
519 Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
521 // determine the number of events in the given raw data file
525 TFile* file = TFile::Open(fileName);
526 if (!file || !file->IsOpen()) {
527 Error("GetNumberOfEvents", "could not open file %s", fileName);
528 if (file) delete file;
532 TTree* tree = (TTree*) file->Get("RAW");
534 Error("GetNumberOfEvents", "could not find tree with raw data");
536 nEvents = (Int_t) tree->GetEntries();
544 //_____________________________________________________________________________
545 Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
547 // find TPC clusters and tracks
551 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
553 Error("ReconstructTPC", "no TPC loader found");
556 gSystem->Unlink("TPC.RecPoints.root");
557 gSystem->Unlink("TPC.Tracks.root");
560 Info("ReconstructTPC", "reconstructing clusters...");
561 tpcLoader->LoadRecPoints("recreate");
562 AliTPCclustererMI clusterer(fTPCParam);
563 tpcLoader->MakeRecPointsContainer();
564 clusterer.SetOutput(tpcLoader->TreeR());
565 clusterer.Digits2Clusters(rawReader);
566 tpcLoader->WriteRecPoints("OVERWRITE");
569 Info("ReconstructTPC", "reconstructing tracks...");
570 tpcLoader->LoadTracks("recreate");
572 AliTPCtrackerMI tracker(fTPCParam);
574 tracker.LoadClusters();
575 tracker.Clusters2Tracks();
576 tracker.WriteTracks();
577 tracker.UnloadClusters();
578 tpcLoader->WriteTracks("OVERWRITE");
581 tpcLoader->UnloadRecPoints();
582 tpcLoader->UnloadTracks();
586 //_____________________________________________________________________________
587 Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
589 // find ITS clusters and tracks
593 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
595 Error("ReconstructITS", "no ITS loader found");
598 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
600 Error("ReconstructITS", "no TPC loader found");
603 gSystem->Unlink("ITS.RecPoints.root");
604 gSystem->Unlink("ITS.Tracks.root");
607 Info("ReconstructITS", "reconstructing clusters...");
608 itsLoader->LoadRecPoints("recreate");
609 AliITSclustererV2 clusterer(fITSgeom);
610 itsLoader->MakeRecPointsContainer();
611 clusterer.Digits2Clusters(rawReader);
614 Info("ReconstructITS", "reconstructing tracks...");
615 itsLoader->LoadTracks("recreate");
616 itsLoader->MakeTracksContainer();
617 tpcLoader->LoadTracks();
618 AliITStrackerV2 tracker(fITSgeom);
619 tracker.LoadClusters(itsLoader->TreeR());
620 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
621 tracker.UnloadClusters();
622 itsLoader->WriteTracks("OVERWRITE");
624 itsLoader->UnloadRecPoints();
625 itsLoader->UnloadTracks();
626 tpcLoader->UnloadTracks();
630 //_____________________________________________________________________________
631 Bool_t AliMonitorProcess::ReconstructV0s()
637 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
639 Error("ReconstructV0", "no ITS loader found");
642 gSystem->Unlink("ITS.V0s.root");
645 Info("ReconstructV0s", "reconstructing V0s...");
646 itsLoader->LoadTracks("read");
647 itsLoader->LoadV0s("recreate");
648 AliV0vertexer vertexer;
649 TTree* tracks = itsLoader->TreeT();
651 Error("ReconstructV0s", "no ITS tracks tree found");
654 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
655 TTree* v0s = itsLoader->TreeV0();
656 vertexer.Tracks2V0vertices(tracks, v0s);
657 itsLoader->WriteV0s("OVERWRITE");
659 itsLoader->UnloadTracks();
660 itsLoader->UnloadV0s();
664 //_____________________________________________________________________________
666 void AliMonitorProcess::CreateHLT(const char* fileName)
669 // create the HLT (Level3) object
671 if (fHLT) delete fHLT;
674 strcpy(name, fileName);
675 fHLT = new AliLevel3(name);
676 fHLT->Init("./", AliLevel3::kRaw, 1);
678 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
680 Int_t phiSegments = 50;
681 Int_t etaSegments = 100;
682 Int_t trackletlength = 3;
683 Int_t tracklength = 20;//40 or 5
684 Int_t rowscopetracklet = 2;
685 Int_t rowscopetrack = 10;
686 Double_t minPtFit = 0;
687 Double_t maxangle = 0.1745;
688 Double_t goodDist = 5;
689 Double_t maxphi = 0.1;
690 Double_t maxeta = 0.1;
691 Double_t hitChi2Cut = 15;//100 or 15
692 Double_t goodHitChi2 = 5;//20 or 5
693 Double_t trackChi2Cut = 10;//50 or 10
694 fHLT->SetTrackerParam(phiSegments, etaSegments,
695 trackletlength, tracklength,
696 rowscopetracklet, rowscopetrack,
697 minPtFit, maxangle, goodDist, hitChi2Cut,
698 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
700 fHLT->WriteFiles("./hlt/");
703 //_____________________________________________________________________________
704 void AliMonitorProcess::CreateHLTHough(const char* fileName)
707 // create the HLT Hough transform (L3Hough) object
709 if (fHLTHough) delete fHLTHough;
712 strcpy(name, fileName);
714 fHLTHough = new AliL3Hough();
715 fHLTHough->SetThreshold(4);
716 fHLTHough->SetTransformerParams(140,150,0.5,-1);
717 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
718 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
719 fHLTHough->SetAddHistograms();
720 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
725 //_____________________________________________________________________________
726 Bool_t AliMonitorProcess::ReconstructHLT(
734 // run the HLT cluster and track finder
739 Warning("ReconstructHLT", "the code was compiled without HLT support");
743 gSystem->Exec("rm -rf hlt");
744 gSystem->MakeDirectory("hlt");
745 if (!fHLT) return kFALSE;
747 fHLT->ProcessEvent(0, 35, iEvent);
749 // remove the event number from the file names
751 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
752 gSystem->Exec(command);
753 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
754 gSystem->Exec(command);
755 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
756 gSystem->Exec(command);
757 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
758 gSystem->Exec(command);
763 //_____________________________________________________________________________
764 Bool_t AliMonitorProcess::ReconstructHLTHough(
772 // run the HLT Hough transformer
777 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
781 gSystem->Exec("rm -rf hlt/hough");
782 gSystem->MakeDirectory("hlt/hough");
783 gSystem->Exec("rm -rf hlt/fitter");
784 gSystem->MakeDirectory("hlt/fitter");
785 if (!fHLTHough) return kFALSE;
787 // fHLTHough->Process(0, 35);
788 // Loop over TPC sectors and process the data
789 for(Int_t i=0; i<=35; i++)
791 fHLTHough->ReadData(i,iEvent);
792 fHLTHough->Transform();
793 // if(fHLTHough->fAddHistograms)
794 fHLTHough->AddAllHistograms();
795 fHLTHough->FindTrackCandidates();
796 fHLTHough->AddTracks();
798 fHLTHough->WriteTracks("./hlt/hough");
800 // Run cluster fitter
801 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
803 // Set debug flag for the cluster fitter
806 // Setting fitter parameters
807 fitter->SetInnerWidthFactor(1,1.5);
808 fitter->SetOuterWidthFactor(1,1.5);
809 fitter->SetNmaxOverlaps(5);
811 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
812 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
814 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
816 // Takes input from global hough tracks produced by HT
817 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
821 for(Int_t islice = 0; islice <= 35; islice++)
823 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
826 fHLTHough->GetMemHandler(ipatch)->Free();
827 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
828 AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
830 fitter->Init(islice,ipatch);
831 fitter->SetInputData(digits);
832 fitter->FindClusters();
833 fitter->WriteClusters();
837 // Refit of the clusters
839 //The seeds are the input tracks from circle HT
840 AliL3TrackArray *tracks = fitter->GetSeeds();
841 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
843 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
844 for(Int_t i=0; i<tracks->GetNTracks(); i++)
846 AliL3Track *track = tracks->GetCheckedTrack(i);
848 if(track->GetNHits() < 20) continue;
849 ft->SortTrackClusters(track);
851 track->UpdateToFirstPoint();
855 //Write the final tracks
856 fitter->WriteTracks(20);
860 // remove the event number from the file names
862 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
863 gSystem->Exec(command);
864 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
865 gSystem->Exec(command);
866 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
867 gSystem->Exec(command);
872 //_____________________________________________________________________________
873 Bool_t AliMonitorProcess::WriteHistos()
875 // write the monitor tree and the monitor histograms to the file
876 // "monitor_<run number>[_<sub_run_number>].root"
877 // if at least fNEventsMin events were monitored
881 // rename tree file and create a new one
888 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
889 if (fSubRunNumber > 0) {
890 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
892 if (fNEvents < fNEventsMin) {
893 gSystem->Unlink("monitor_tree.root");
895 gSystem->Rename("monitor_tree.root", fileName);
898 fFile = TFile::Open("monitor_tree.root", "RECREATE");
899 if (!fFile || !fFile->IsOpen()) {
900 Fatal("WriteHistos", "could not open file for tree");
902 fTree = new TTree("MonitorTree", "tree for monitoring");
903 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
904 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
908 // write the histograms
909 if (fNEvents < fNEventsMin) return kTRUE;
911 if (!fWriteHistoList) {
912 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
913 while (TFolder* folder = (TFolder*) iFolder->Next()) {
914 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
915 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
923 Bool_t result = kTRUE;
924 sprintf(fileName, "monitor_%d.root", fRunNumber);
925 if (fSubRunNumber > 0) {
926 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
928 TFile* file = TFile::Open(fileName, "recreate");
929 if (!file || !file->IsOpen()) {
930 Error("WriteHistos", "could not open file %s", fileName);
936 if (file) delete file;
941 //_____________________________________________________________________________
942 void AliMonitorProcess::StartNewRun()
944 // reset the histograms for a new run
946 SetStatus(kResetting);
947 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
948 while (TFolder* folder = (TFolder*) iFolder->Next()) {
949 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
950 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
961 //_____________________________________________________________________________
962 void AliMonitorProcess::CheckForConnections()
964 // check if new clients want to connect and add them to the list of sockets
967 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
968 socket->SetOption(kNoBlock, 1);
969 char socketType[256];
970 if (socket->Recv(socketType, 255) <= 0) {
971 gSystem->Sleep(1000);
972 if (socket->Recv(socketType, 255) <= 0) {
973 TInetAddress adr = socket->GetInetAddress();
974 Error("CheckForConnections", "no socket type received - "
975 "disconnect client:\n %s (%s), port %d\n",
976 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
981 if (strcmp(socketType, "client") == 0) {
982 fSockets.Add(socket);
983 TInetAddress adr = socket->GetInetAddress();
984 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
985 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
986 if (fNEvents > 0) BroadcastHistos(socket);
987 } else if (strcmp(socketType, "display") == 0) {
988 if (fDisplaySocket) {
989 fDisplaySocket->Close();
990 delete fDisplaySocket;
992 fDisplaySocket = socket;
993 TInetAddress adr = socket->GetInetAddress();
994 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
995 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
997 TInetAddress adr = socket->GetInetAddress();
998 Error("CheckForConnections", "unknown socket type %s - "
999 "disconnect client:\n %s (%s), port %d\n", socketType,
1000 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1006 // remove finished or invalid clients
1007 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1008 socket = (TSocket*) fSockets[iSocket];
1009 if (!socket) continue;
1010 char controlMessage[256];
1011 if (socket->Recv(controlMessage, 255)) {
1012 if (strcmp(controlMessage, "disconnect") == 0) {
1013 TInetAddress adr = socket->GetInetAddress();
1014 Info("CheckForConnections",
1015 "disconnect client:\n %s (%s), port %d\n",
1016 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1017 delete fSockets.RemoveAt(iSocket);
1021 if (!socket->IsValid()) {
1022 // remove invalid sockets from the list
1023 TInetAddress adr = socket->GetInetAddress();
1024 Error("CheckForConnections",
1025 "disconnect invalid client:\n %s (%s), port %d\n",
1026 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1027 delete fSockets.RemoveAt(iSocket);
1030 fSockets.Compress();
1033 //_____________________________________________________________________________
1034 void AliMonitorProcess::BroadcastHistos(TSocket* toSocket)
1036 // send the monitor histograms to the clients
1038 SetStatus(kBroadcasting);
1039 TMessage message(kMESS_OBJECT);
1040 message.WriteObject(fTopFolder);
1042 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1043 TSocket* socket = (TSocket*) fSockets[iSocket];
1044 if (!socket) continue;
1045 if (toSocket && (socket != toSocket)) continue;
1047 // send control message
1048 if (!socket->IsValid() || (socket->Send("histograms") <= 0)) {
1049 TInetAddress adr = socket->GetInetAddress();
1050 Error("BroadcastHistos", "connection to client failed - "
1051 "disconnect client:\n %s (%s), port %d\n",
1052 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1053 delete fSockets.RemoveAt(iSocket);
1056 // receive control message
1057 char controlMessage[256];
1058 Int_t result = socket->Recv(controlMessage, 255);
1060 gSystem->Sleep(1000); // wait one second and try again
1061 result = socket->Recv(controlMessage, 255);
1064 TInetAddress adr = socket->GetInetAddress();
1065 Error("BroadcastHistos", "no response from client - "
1066 "disconnect client:\n %s (%s), port %d\n",
1067 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1068 delete fSockets.RemoveAt(iSocket);
1071 if (strcmp(controlMessage, "ok") != 0) {
1072 TInetAddress adr = socket->GetInetAddress();
1073 Error("BroadcastHistos", "no \"ok\" message from client - "
1074 "disconnect client:\n %s (%s), port %d\n",
1075 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1076 delete fSockets.RemoveAt(iSocket);
1080 socket->SetOption(kNoBlock, 0);
1081 if (socket->Send(message) < 0) {
1082 // remove the socket from the list if there was an error
1083 TInetAddress adr = socket->GetInetAddress();
1084 Error("BroadcastHistos", "sending histograms failed - "
1085 "disconnect client:\n %s (%s), port %d\n",
1086 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1087 delete fSockets.RemoveAt(iSocket);
1089 gSystem->Sleep(100);
1090 socket->SetOption(kNoBlock, 1);
1093 fSockets.Compress();
1097 //_____________________________________________________________________________
1098 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1099 (AliMonitorProcess* process):
1100 TSignalHandler(kSigUser1, kFALSE),
1103 // constructor: set process
1106 //_____________________________________________________________________________
1107 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1108 (const AliMonitorInterruptHandler& handler):
1109 TSignalHandler(handler)
1113 Fatal("AliMonitorInterruptHandler", "copy constructor not implemented");
1116 //_____________________________________________________________________________
1117 AliMonitorProcess::AliMonitorInterruptHandler&
1118 AliMonitorProcess::AliMonitorInterruptHandler::operator =
1119 (const AliMonitorInterruptHandler& /*handler*/)
1121 // assignment operator
1123 Fatal("operator =", "assignment operator not implemented");
1127 //_____________________________________________________________________________
1128 Bool_t AliMonitorProcess::AliMonitorInterruptHandler::Notify()
1130 // interrupt signal -> stop process
1132 Info("Notify", "the monitoring process will be stopped.");