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 "AliESDEvent.h"
38 #include "AliITSclustererV2.h"
39 #include "AliITSgeom.h"
40 #include "AliITStrackerV2.h"
41 #include "AliLoader.h"
42 // Matthias 2007-10-03 HLT legacy code disabled
43 // everything encapsulated by ENABLE_ALIMONITORPROCESS_HLT
44 // set the define in the header file to include the code
45 #ifdef ENABLE_ALIMONITORPROCESS_HLT
46 #include "AliMonitorHLT.h"
47 #include "AliMonitorHLTHough.h"
48 #endif // ENABLE_ALIMONITORPROCESS_HLT
49 #include "AliMonitorITS.h"
50 #include "AliMonitorProcess.h"
51 #include "AliMonitorTPC.h"
52 #include "AliMonitorV0s.h"
53 #include "AliRawReaderRoot.h"
56 #include "AliTPCclustererMI.h"
57 #include "AliTPCtrackerMI.h"
58 #include "AliV0vertexer.h"
60 #ifdef ENABLE_ALIMONITORPROCESS_HLT
61 #include <AliHLTStandardIncludes.h>
62 #include <AliHLTMemHandler.h>
63 #include <AliHLTClusterFitter.h>
64 #include <AliHLTFitter.h>
65 #include <AliHLTHough.h>
66 #include <AliHLTHoughBaseTransformer.h>
67 #include <AliHLTStandardIncludes.h>
68 #include <AliHLTTrack.h>
69 #include <AliHLTTrackArray.h>
70 #include <AliHLTTransform.h>
71 #include <AliHLTVertex.h>
72 #include <AliLevel3.h>
73 #endif // ENABLE_ALIMONITORPROCESS_HLT
75 ClassImp(AliMonitorProcess)
78 const Int_t AliMonitorProcess::fgkPort = 9327;
81 //_____________________________________________________________________________
82 AliMonitorProcess::AliMonitorProcess(
83 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
84 const char* /*alienHost*/,
86 const char* alienHost,
89 const char* selection,
90 const char* fileNameGalice):
91 fSelection(selection),
106 fWriteHistoList(kFALSE),
115 fDisplaySocket(NULL),
120 fInterruptHandler(NULL)
122 // initialize the monitoring process and the monitor histograms
124 fSelection = selection;
126 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
127 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
129 fGrid = TGrid::Connect(alienHost, gSystem->Getenv("USER"));
131 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
133 AliFatal("could not connect to alien");
135 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
139 fRunLoader = AliRunLoader::Open(fileNameGalice);
140 if (!fRunLoader) AliFatal(Form("could not get run loader from file %s",
143 fRunLoader->CdGAFile();
144 fTPCParam = AliTPC::LoadTPCParam(gFile);
145 if (!fTPCParam) AliFatal("could not load TPC parameters");
147 fRunLoader->LoadgAlice();
148 gAlice = fRunLoader->GetAliRun();
149 if (!gAlice) AliFatal("no gAlice object found");
150 fITSgeom = (AliITSgeom*)gDirectory->Get("AliITSgeom");
151 if (!fITSgeom) AliFatal("could not load ITS geometry");
153 #ifdef ENABLE_ALIMONITORPROCESS_HLT
154 // Init TPC parameters for HLT
155 Bool_t isinit=AliHLTTransform::Init(const_cast<char*>(fileNameGalice),kTRUE);
157 AliFatal("Could not create transform settings, please check log for error messages!");
159 #endif // ENABLE_ALIMONITORPROCESS_HLT
161 fTopFolder = new TFolder("Monitor", "monitor histograms");
162 fTopFolder->SetOwner(kTRUE);
164 if (IsSelected("TPC")) fMonitors.Add(new AliMonitorTPC(fTPCParam));
165 if (IsSelected("ITS")) fMonitors.Add(new AliMonitorITS(fITSgeom));
166 if (IsSelected("V0s")) fMonitors.Add(new AliMonitorV0s);
167 #ifdef ENABLE_ALIMONITORPROCESS_HLT
168 if (IsSelected("HLTConfMap")) fMonitors.Add(new AliMonitorHLT(fTPCParam));
169 if (IsSelected("HLTHough")) fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
170 #endif // ENABLE_ALIMONITORPROCESS_HLT
172 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
173 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
176 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
177 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
180 fFile = TFile::Open("monitor_tree.root", "RECREATE");
181 if (!fFile || !fFile->IsOpen()) {
182 AliFatal("could not open file for tree");
184 fTree = new TTree("MonitorTree", "tree for monitoring");
185 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
186 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
190 fServerSocket = new TServerSocket(fgkPort, kTRUE);
191 fServerSocket->SetOption(kNoBlock, 1);
192 CheckForConnections();
194 fInterruptHandler = new AliMonitorInterruptHandler(this);
195 gSystem->AddSignalHandler(fInterruptHandler);
198 //_____________________________________________________________________________
199 AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
208 fLogicalFileName(""),
217 fWriteHistoList(kFALSE),
226 fDisplaySocket(NULL),
231 fInterruptHandler(NULL)
234 AliFatal("copy constructor not implemented");
237 //_____________________________________________________________________________
238 AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
241 AliFatal("assignment operator not implemented");
245 //_____________________________________________________________________________
246 AliMonitorProcess::~AliMonitorProcess()
254 delete fServerSocket;
256 delete fDisplaySocket;
258 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
265 gSystem->Unlink("monitor_tree.root");
267 #ifdef ENABLE_ALIMONITORPROCESS_HLT
270 #endif // ENABLE_ALIMONITORPROCESS_HLT
272 gSystem->RemoveSignalHandler(fInterruptHandler);
273 delete fInterruptHandler;
277 //_____________________________________________________________________________
278 const char* AliMonitorProcess::GetRevision()
284 //_____________________________________________________________________________
285 void AliMonitorProcess::SetStatus(EStatus status)
287 // set the current status and process system events
290 gSystem->ProcessEvents();
294 //_____________________________________________________________________________
295 void AliMonitorProcess::Run()
297 // run the monitor process:
298 // check for a raw data file, process the raw data file and delete it
304 while (!CheckForNewFile()) {
305 CheckForConnections();
307 if (fStopping) break;
310 if (fStopping) break;
322 //_____________________________________________________________________________
323 void AliMonitorProcess::Stop()
325 // set the fStopping flag to terminate the monitor process after the current
326 // event was processed
328 if (GetStatus() != kStopped) fStopping = kTRUE;
332 //_____________________________________________________________________________
333 void AliMonitorProcess::ProcessFile(const char* fileName)
335 // create a file with monitor histograms for a single file
337 if (GetStatus() != kStopped) {
338 AliError("ProcessFile can not be called"
339 " while the monitor process is running");
343 fFileName = fileName;
344 Int_t nEventMin = fNEventsMin;
348 fNEventsMin = nEventMin;
353 //_____________________________________________________________________________
354 Bool_t AliMonitorProcess::CheckForNewFile()
356 // check whether a new file was registered in alien
358 #if ROOT_VERSION_CODE < ROOT_VERSION(5,0,0)
359 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
360 TGridResult* result = fGrid->Ls();
364 sprintf(dirName, "%s/adc-%d", fAlienDir.Data(), datime.GetDate());
366 sprintf(findName, "*.root");
367 Grid_ResultHandle_t handle = fGrid->Find(dirName, findName);
369 AliError(Form("could not open alien directory %s",
373 TGridResult* result = fGrid->CreateGridResult(handle);
379 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
380 while (const char* entry = result->Next()) {
382 while (Grid_Result_t* resultEntry = result->Next()) {
383 const char* entry = resultEntry->name.c_str();
385 if (strrchr(entry, '/')) entry = strrchr(entry, '/')+1;
386 // entry = host_date_time.root
387 TString entryCopy(entry);
388 char* p = const_cast<char*>(entryCopy.Data());
389 if (!strtok(p, "_") || !p) continue; // host name
390 char* dateStr = strtok(NULL, "_");
391 if (!dateStr || !p) continue;
392 char* timeStr = strtok(NULL, ".");
393 if (!timeStr || !p) continue;
394 Long_t date = atoi(dateStr);
395 Long_t time = atoi(timeStr);
397 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
405 if (maxDate < 0) return kFALSE; // no files found
406 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
408 fLogicalFileName = fileName;
409 #if ROOT_VERSION_CODE <= 199169 // 3.10/01
410 result = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
411 fFileName = result->Next();
413 fileName = dirName + ("/" + fLogicalFileName);
414 handle = fGrid->GetPhysicalFileNames(fileName.Data());
416 AliError(Form("could not get physical file names for %s",
420 result = fGrid->CreateGridResult(handle);
422 Grid_Result_t* resultEntry = result->Next();
424 AliError(Form("could not get physical file names for %s",
428 fFileName = resultEntry->name2.c_str();
429 fFileName.ReplaceAll("castor:/", "rfio:/");
433 Error("CheckForNewFile", "needs to be ported to new TGrid");
438 //_____________________________________________________________________________
439 Bool_t AliMonitorProcess::ProcessFile()
441 // loop over all events in the raw data file, run the reconstruction
442 // and fill the monitor histograms
444 Int_t nEvents = GetNumberOfEvents(fFileName);
445 if (nEvents <= 0) return kFALSE;
446 AliDebug(1, Form("found %d event(s) in file %s",
447 nEvents, fFileName.Data()));
448 #ifdef ENABLE_ALIMONITORPROCESS_HLT
449 if (IsSelected("HLTConfMap")) CreateHLT(fFileName);
450 if (IsSelected("HLTHough")) CreateHLTHough(fFileName);
451 #endif // ENABLE_ALIMONITORPROCESS_HLT
453 // loop over the events
454 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
455 CheckForConnections();
457 fRunLoader->SetEventNumber(0);
458 AliRawReaderRoot rawReader(fFileName, iEvent);
459 if (fStopping) break;
460 if (rawReader.GetRunNumber() != fRunNumber) {
463 fRunNumber = rawReader.GetRunNumber();
464 fEventNumber[0] = rawReader.GetEventId()[0];
465 fEventNumber[1] = rawReader.GetEventId()[1];
467 if (fStopping) break;
470 // monitor only central physics events
471 if (rawReader.GetType() != 7) continue;
472 if ((rawReader.GetAttributes()[0] & 0x02) == 0) continue;
473 AliInfo(Form("run: %d event: %d %d\n", rawReader.GetRunNumber(),
474 rawReader.GetEventId()[0], rawReader.GetEventId()[1]));
477 if (IsSelected("TPC")) {
478 CheckForConnections();
479 if (!ReconstructTPC(&rawReader, &esd)) return kFALSE;
480 if (fStopping) break;
482 if (IsSelected("ITS")) {
483 CheckForConnections();
484 if (!ReconstructITS(&rawReader, &esd)) return kFALSE;
485 if (fStopping) break;
487 if (IsSelected("V0s")) {
488 CheckForConnections();
489 if (!ReconstructV0s(&esd)) return kFALSE;
490 if (fStopping) break;
492 #ifdef ENABLE_ALIMONITORPROCESS_HLT
493 if (IsSelected("HLTConfMap")) {
494 CheckForConnections();
495 if (!ReconstructHLT(iEvent)) return kFALSE;
496 if (fStopping) break;
498 if (IsSelected("HLTHough")) {
499 CheckForConnections();
500 if (!ReconstructHLTHough(iEvent)) return kFALSE;
501 if (fStopping) break;
503 #endif // ENABLE_ALIMONITORPROCESS_HLT
505 if (fDisplaySocket) fDisplaySocket->Send("new event");
507 AliDebug(1, "filling histograms...");
508 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
509 CheckForConnections();
511 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader,
513 if (fStopping) break;
515 if (fStopping) break;
517 AliDebug(1, "updating histograms...");
518 CheckForConnections();
519 SetStatus(kUpdating);
520 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
521 while (TFolder* folder = (TFolder*) iFolder->Next()) {
522 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
523 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
529 if (fStopping) break;
531 AliDebug(1, "filling the tree...");
534 AliDebug(1, "broadcasting histograms...");
535 CheckForConnections();
539 if (fStopping) break;
542 #ifdef ENABLE_ALIMONITORPROCESS_HLT
551 #endif // ENABLE_ALIMONITORPROCESS_HLT
556 //_____________________________________________________________________________
557 void AliMonitorProcess::Reset()
559 // write the current histograms to a file and reset them
561 if (fSubRunNumber == 0) fSubRunNumber++;
568 //_____________________________________________________________________________
569 UInt_t AliMonitorProcess::GetEventPeriodNumber() const
571 // get the period number from the event id
573 return (fEventNumber[1] >> 4);
576 //_____________________________________________________________________________
577 UInt_t AliMonitorProcess::GetEventOrbitNumber() const
579 // get the orbit number from the event id
581 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
584 //_____________________________________________________________________________
585 UInt_t AliMonitorProcess::GetEventBunchNumber() const
587 // get the bunch number from the event id
589 return (fEventNumber[0] % 0x0FFF);
592 //_____________________________________________________________________________
593 Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
595 // determine the number of events in the given raw data file
599 TFile* file = TFile::Open(fileName);
600 if (!file || !file->IsOpen()) {
601 AliError(Form("could not open file %s", fileName));
602 if (file) delete file;
606 TTree* tree = (TTree*) file->Get("RAW");
608 AliError("could not find tree with raw data");
610 nEvents = (Int_t) tree->GetEntries();
618 //_____________________________________________________________________________
619 Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader, AliESDEvent* esd)
621 // find TPC clusters and tracks
625 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
627 AliError("no TPC loader found");
630 gSystem->Unlink("TPC.RecPoints.root");
633 AliDebug(1, "reconstructing clusters...");
634 tpcLoader->LoadRecPoints("recreate");
635 AliTPCclustererMI clusterer(fTPCParam);
636 tpcLoader->MakeRecPointsContainer();
637 clusterer.SetOutput(tpcLoader->TreeR());
638 clusterer.Digits2Clusters(rawReader);
639 tpcLoader->WriteRecPoints("OVERWRITE");
642 AliDebug(1, "reconstructing tracks...");
643 AliTPCtrackerMI tracker(fTPCParam);
644 tracker.LoadClusters(tpcLoader->TreeR());
645 tracker.Clusters2Tracks(esd);
646 tracker.UnloadClusters();
647 tpcLoader->UnloadRecPoints();
652 //_____________________________________________________________________________
653 Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader, AliESDEvent* esd)
655 // find ITS clusters and tracks
659 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
661 AliError("no ITS loader found");
664 gSystem->Unlink("ITS.RecPoints.root");
667 AliDebug(1, "reconstructing clusters...");
668 itsLoader->LoadRecPoints("recreate");
669 AliITSclustererV2 clusterer(0);
670 itsLoader->MakeRecPointsContainer();
671 clusterer.Digits2Clusters(rawReader);
674 AliDebug(1, "reconstructing tracks...");
675 AliITStrackerV2 tracker(0);
676 tracker.LoadClusters(itsLoader->TreeR());
677 tracker.Clusters2Tracks(esd);
678 tracker.UnloadClusters();
680 itsLoader->UnloadRecPoints();
684 //_____________________________________________________________________________
685 Bool_t AliMonitorProcess::ReconstructV0s(AliESDEvent* esd)
692 AliDebug(1, "reconstructing V0s...");
693 AliV0vertexer vertexer;
694 vertexer.Tracks2V0vertices(esd);
699 #ifdef ENABLE_ALIMONITORPROCESS_HLT
700 //_____________________________________________________________________________
701 void AliMonitorProcess::CreateHLT(const char* fileName)
704 // create the HLT (Level3) object
706 if (fHLT) delete fHLT;
709 strcpy(name, fileName);
710 fHLT = new AliLevel3(name);
711 fHLT->Init("./", AliLevel3::kRaw, 1);
713 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
715 Int_t phiSegments = 50;
716 Int_t etaSegments = 100;
717 Int_t trackletlength = 3;
718 Int_t tracklength = 20;//40 or 5
719 Int_t rowscopetracklet = 2;
720 Int_t rowscopetrack = 10;
721 Double_t minPtFit = 0;
722 Double_t maxangle = 0.1745;
723 Double_t goodDist = 5;
724 Double_t maxphi = 0.1;
725 Double_t maxeta = 0.1;
726 Double_t hitChi2Cut = 15;//100 or 15
727 Double_t goodHitChi2 = 5;//20 or 5
728 Double_t trackChi2Cut = 10;//50 or 10
729 fHLT->SetTrackerParam(phiSegments, etaSegments,
730 trackletlength, tracklength,
731 rowscopetracklet, rowscopetrack,
732 minPtFit, maxangle, goodDist, hitChi2Cut,
733 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
735 fHLT->WriteFiles("./hlt/");
737 #endif // ENABLE_ALIMONITORPROCESS_HLT
739 #ifdef ENABLE_ALIMONITORPROCESS_HLT
740 //_____________________________________________________________________________
741 void AliMonitorProcess::CreateHLTHough(const char* fileName)
744 // create the HLT Hough transform (L3Hough) object
746 if (fHLTHough) delete fHLTHough;
749 strcpy(name, fileName);
751 fHLTHough = new AliHLTHough();
752 fHLTHough->SetThreshold(4);
753 fHLTHough->SetTransformerParams(140,150,0.5,-1);
754 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
755 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
756 fHLTHough->SetAddHistograms();
757 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
760 #endif // ENABLE_ALIMONITORPROCESS_HLT
762 #ifdef ENABLE_ALIMONITORPROCESS_HLT
763 //_____________________________________________________________________________
764 Bool_t AliMonitorProcess::ReconstructHLT(Int_t iEvent)
766 // run the HLT cluster and track finder
770 gSystem->Exec("rm -rf hlt");
771 gSystem->MakeDirectory("hlt");
772 if (!fHLT) return kFALSE;
774 fHLT->ProcessEvent(0, 35, iEvent);
776 // remove the event number from the file names
778 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
779 gSystem->Exec(command);
780 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
781 gSystem->Exec(command);
782 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
783 gSystem->Exec(command);
784 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
785 gSystem->Exec(command);
788 #endif // ENABLE_ALIMONITORPROCESS_HLT
790 #ifdef ENABLE_ALIMONITORPROCESS_HLT
791 //_____________________________________________________________________________
792 Bool_t AliMonitorProcess::ReconstructHLTHough(Int_t iEvent)
794 // run the HLT Hough transformer
798 gSystem->Exec("rm -rf hlt/hough");
799 gSystem->MakeDirectory("hlt/hough");
800 gSystem->Exec("rm -rf hlt/fitter");
801 gSystem->MakeDirectory("hlt/fitter");
802 if (!fHLTHough) return kFALSE;
804 // fHLTHough->Process(0, 35);
805 // Loop over TPC sectors and process the data
806 for(Int_t i=0; i<=35; i++)
808 fHLTHough->ReadData(i,iEvent);
809 fHLTHough->Transform();
810 // if(fHLTHough->fAddHistograms)
811 fHLTHough->AddAllHistograms();
812 fHLTHough->FindTrackCandidates();
813 fHLTHough->AddTracks();
815 fHLTHough->WriteTracks("./hlt/hough");
817 // Run cluster fitter
818 AliHLTClusterFitter *fitter = new AliHLTClusterFitter("./hlt");
820 // Set debug flag for the cluster fitter
823 // Setting fitter parameters
824 fitter->SetInnerWidthFactor(1,1.5);
825 fitter->SetOuterWidthFactor(1,1.5);
826 fitter->SetNmaxOverlaps(5);
828 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
829 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
831 Int_t rowrange[2] = {0,AliHLTTransform::GetNRows()-1};
833 // Takes input from global hough tracks produced by HT
834 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
838 for(Int_t islice = 0; islice <= 35; islice++)
840 for(Int_t ipatch = 0; ipatch < AliHLTTransform::GetNPatches(); ipatch++)
843 fHLTHough->GetMemHandler(ipatch)->Free();
844 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
845 AliHLTDigitRowData *digits = (AliHLTDigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
847 fitter->Init(islice,ipatch);
848 fitter->SetInputData(digits);
849 fitter->FindClusters();
850 fitter->WriteClusters();
854 // Refit of the clusters
856 //The seeds are the input tracks from circle HT
857 AliHLTTrackArray *tracks = fitter->GetSeeds();
858 AliHLTFitter *ft = new AliHLTFitter(&vertex,1);
860 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
861 for(Int_t i=0; i<tracks->GetNTracks(); i++)
863 AliHLTTrack *track = tracks->GetCheckedTrack(i);
865 if(track->GetNHits() < 20) continue;
866 ft->SortTrackClusters(track);
868 track->UpdateToFirstPoint();
872 //Write the final tracks
873 fitter->WriteTracks(20);
877 // remove the event number from the file names
879 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
880 gSystem->Exec(command);
881 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
882 gSystem->Exec(command);
883 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
884 gSystem->Exec(command);
887 #endif // ENABLE_ALIMONITORPROCESS_HLT
889 //_____________________________________________________________________________
890 Bool_t AliMonitorProcess::WriteHistos()
892 // write the monitor tree and the monitor histograms to the file
893 // "monitor_<run number>[_<sub_run_number>].root"
894 // if at least fNEventsMin events were monitored
898 // rename tree file and create a new one
905 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
906 if (fSubRunNumber > 0) {
907 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
909 if (fNEvents < fNEventsMin) {
910 gSystem->Unlink("monitor_tree.root");
912 gSystem->Rename("monitor_tree.root", fileName);
915 fFile = TFile::Open("monitor_tree.root", "RECREATE");
916 if (!fFile || !fFile->IsOpen()) {
917 AliFatal("could not open file for tree");
919 fTree = new TTree("MonitorTree", "tree for monitoring");
920 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
921 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
925 // write the histograms
926 if (fNEvents < fNEventsMin) return kTRUE;
928 if (!fWriteHistoList) {
929 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
930 while (TFolder* folder = (TFolder*) iFolder->Next()) {
931 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
932 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
940 Bool_t result = kTRUE;
941 sprintf(fileName, "monitor_%d.root", fRunNumber);
942 if (fSubRunNumber > 0) {
943 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
945 TFile* file = TFile::Open(fileName, "recreate");
946 if (!file || !file->IsOpen()) {
947 AliError(Form("could not open file %s", fileName));
953 if (file) delete file;
958 //_____________________________________________________________________________
959 void AliMonitorProcess::StartNewRun()
961 // reset the histograms for a new run
963 SetStatus(kResetting);
964 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
965 while (TFolder* folder = (TFolder*) iFolder->Next()) {
966 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
967 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
978 //_____________________________________________________________________________
979 void AliMonitorProcess::CheckForConnections()
981 // check if new clients want to connect and add them to the list of sockets
984 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
985 socket->SetOption(kNoBlock, 1);
986 char socketType[256];
987 if (socket->Recv(socketType, 255) <= 0) {
988 gSystem->Sleep(1000);
989 if (socket->Recv(socketType, 255) <= 0) {
990 TInetAddress adr = socket->GetInetAddress();
991 AliError(Form("no socket type received - "
992 "disconnect client: %s (%s), port %d",
993 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
998 if (strcmp(socketType, "client") == 0) {
999 fSockets.Add(socket);
1000 TInetAddress adr = socket->GetInetAddress();
1001 AliInfo(Form("new client: %s (%s), port %d",
1002 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1003 if (fNEvents > 0) BroadcastHistos(socket);
1004 } else if (strcmp(socketType, "display") == 0) {
1005 if (fDisplaySocket) {
1006 fDisplaySocket->Close();
1007 delete fDisplaySocket;
1009 fDisplaySocket = socket;
1010 TInetAddress adr = socket->GetInetAddress();
1011 AliInfo(Form("new display: %s (%s), port %d",
1012 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1014 TInetAddress adr = socket->GetInetAddress();
1015 AliError(Form("unknown socket type %s - "
1016 "disconnect client: %s (%s), port %d", socketType,
1017 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1023 // remove finished or invalid clients
1024 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1025 socket = (TSocket*) fSockets[iSocket];
1026 if (!socket) continue;
1027 char controlMessage[256];
1028 if (socket->Recv(controlMessage, 255)) {
1029 if (strcmp(controlMessage, "disconnect") == 0) {
1030 TInetAddress adr = socket->GetInetAddress();
1031 AliInfo(Form("disconnect client: %s (%s), port %d",
1032 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1033 delete fSockets.RemoveAt(iSocket);
1037 if (!socket->IsValid()) {
1038 // remove invalid sockets from the list
1039 TInetAddress adr = socket->GetInetAddress();
1040 AliError(Form("disconnect invalid client: %s (%s), port %d",
1041 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1042 delete fSockets.RemoveAt(iSocket);
1045 fSockets.Compress();
1048 //_____________________________________________________________________________
1049 void AliMonitorProcess::BroadcastHistos(TSocket* toSocket)
1051 // send the monitor histograms to the clients
1053 SetStatus(kBroadcasting);
1054 TMessage message(kMESS_OBJECT);
1055 message.WriteObject(fTopFolder);
1057 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1058 TSocket* socket = (TSocket*) fSockets[iSocket];
1059 if (!socket) continue;
1060 if (toSocket && (socket != toSocket)) continue;
1062 // send control message
1063 if (!socket->IsValid() || (socket->Send("histograms") <= 0)) {
1064 TInetAddress adr = socket->GetInetAddress();
1065 AliError(Form("connection to client failed - "
1066 "disconnect client: %s (%s), port %d",
1067 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1068 delete fSockets.RemoveAt(iSocket);
1071 // receive control message
1072 char controlMessage[256];
1073 Int_t result = socket->Recv(controlMessage, 255);
1075 gSystem->Sleep(1000); // wait one second and try again
1076 result = socket->Recv(controlMessage, 255);
1079 TInetAddress adr = socket->GetInetAddress();
1080 AliError(Form("no response from client - "
1081 "disconnect client: %s (%s), port %d",
1082 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1083 delete fSockets.RemoveAt(iSocket);
1086 if (strcmp(controlMessage, "ok") != 0) {
1087 TInetAddress adr = socket->GetInetAddress();
1088 AliError(Form("no \"ok\" message from client - "
1089 "disconnect client: %s (%s), port %d",
1090 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1091 delete fSockets.RemoveAt(iSocket);
1095 socket->SetOption(kNoBlock, 0);
1096 if (socket->Send(message) < 0) {
1097 // remove the socket from the list if there was an error
1098 TInetAddress adr = socket->GetInetAddress();
1099 AliError(Form("sending histograms failed - "
1100 "disconnect client: %s (%s), port %d",
1101 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()));
1102 delete fSockets.RemoveAt(iSocket);
1104 gSystem->Sleep(100);
1105 socket->SetOption(kNoBlock, 1);
1108 fSockets.Compress();
1112 //_____________________________________________________________________________
1113 AliMonitorProcess::AliMonitorInterruptHandler::AliMonitorInterruptHandler
1114 (AliMonitorProcess* process):
1115 TSignalHandler(kSigUser1, kFALSE),
1118 // constructor: set process
1121 //_____________________________________________________________________________
1122 Bool_t AliMonitorProcess::AliMonitorInterruptHandler::Notify()
1124 // interrupt signal -> stop process
1126 AliInfo("the monitoring process will be stopped.");