]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliMonitorProcess.cxx
bugfix
[u/mrichter/AliRoot.git] / MONITOR / AliMonitorProcess.cxx
CommitLineData
04fa961a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
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. //
25// //
26///////////////////////////////////////////////////////////////////////////////
27
28
29#include "AliMonitorProcess.h"
30#include "AliMonitorTPC.h"
31#include "AliMonitorITS.h"
32#include "AliMonitorV0s.h"
97d6eb66 33#include "AliMonitorHLT.h"
c6ba6205 34#include "AliMonitorHLTHough.h"
04fa961a 35#include "AliRawReaderRoot.h"
36#include "AliLoader.h"
37#include "AliRun.h"
38#include "AliTPC.h"
39#include "AliTPCclustererMI.h"
40#include "AliTPCtrackerMI.h"
41#include "AliITS.h"
42#include "AliITSclustererV2.h"
43#include "AliITStrackerV2.h"
44#include "AliITSLoader.h"
45#include "AliV0vertexer.h"
c4bd737c 46#include <TGrid.h>
04fa961a 47#include <TSocket.h>
c4bd737c 48#include <TServerSocket.h>
04fa961a 49#include <TMessage.h>
50#include <TGridResult.h>
51#include <TROOT.h>
1899848d 52#ifdef ALI_HLT
c4bd737c 53#include <AliLevel3.h>
1899848d 54#include <AliL3Transform.h>
4a69f9c7 55#include <AliL3Track.h>
56#include <AliL3TrackArray.h>
c6ba6205 57#include <AliL3StandardIncludes.h>
58#include <AliL3HoughMaxFinder.h>
4a69f9c7 59#include <AliL3HoughBaseTransformer.h>
c6ba6205 60#include <AliL3Hough.h>
4a69f9c7 61#include <AliL3ClusterFitter.h>
62#include <AliL3Vertex.h>
63#include <AliL3Fitter.h>
1899848d 64#endif
04fa961a 65
66ClassImp(AliMonitorProcess)
67
68
c4bd737c 69const Int_t AliMonitorProcess::fgkPort = 9327;
04fa961a 70
71
72//_____________________________________________________________________________
73AliMonitorProcess::AliMonitorProcess(const char* alienDir,
74 const char* fileNameGalice)
75{
76// initialize the monitoring process and the monitor histograms
77
78 fGrid = TGrid::Connect("alien", gSystem->Getenv("USER"));
79 if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) {
80 delete fGrid;
81 Fatal("AliMonitorProcess", "could not connect to alien");
82 }
83 fGrid->cd(alienDir);
84 fLogicalFileName = "";
85 fFileName = "";
86
87 fRunLoader = AliRunLoader::Open(fileNameGalice);
88 if (!fRunLoader) Fatal("AliMonitorProcess",
89 "could not get run loader from file %s",
90 fileNameGalice);
91
92 fRunLoader->CdGAFile();
93 fTPCParam = AliTPC::LoadTPCParam(gFile);
94 if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters");
95
96 fRunLoader->LoadgAlice();
97 gAlice = fRunLoader->GetAliRun();
98 if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found");
c4bd737c 99 AliITS* its = (AliITS*) gAlice->GetModule("ITS");
100 if (!its) Fatal("AliMonitorProcess", "no ITS detector found");
101 fITSgeom = its->GetITSgeom();
04fa961a 102 if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry");
103
1899848d 104#ifdef ALI_HLT
105// Init TPC parameters for HLT
106 Bool_t isinit=AliL3Transform::Init(const_cast<char*>(fileNameGalice),kTRUE);
107 if(!isinit){
108 cerr << "Could not create transform settings, please check log for error messages!" << endl;
109 return;
110 }
111#endif
112
04fa961a 113 fRunNumber = 0;
114 fSubRunNumber = 0;
115 fNEvents = 0;
116 fNEventsMin = 2;
117 fWriteHistoList = kFALSE;
118
119 fTopFolder = new TFolder("Monitor", "monitor histograms");
120 fTopFolder->SetOwner(kTRUE);
121
122 fMonitors.Add(new AliMonitorTPC(fTPCParam));
123 fMonitors.Add(new AliMonitorITS(fITSgeom));
124 fMonitors.Add(new AliMonitorV0s);
97d6eb66 125#ifdef ALI_HLT
126 fMonitors.Add(new AliMonitorHLT(fTPCParam));
c6ba6205 127 fMonitors.Add(new AliMonitorHLTHough(fTPCParam));
97d6eb66 128#endif
04fa961a 129
130 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
131 ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder);
132 }
133
134 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
135 while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE);
136 delete iFolder;
137
138 fFile = TFile::Open("monitor_tree.root", "RECREATE");
139 if (!fFile || !fFile->IsOpen()) {
140 Fatal("AliMonitorProcess", "could not open file for tree");
141 }
142 fTree = new TTree("MonitorTree", "tree for monitoring");
143 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
144 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
145 }
146 gROOT->cd();
147
c4bd737c 148 fServerSocket = new TServerSocket(fgkPort, kTRUE);
04fa961a 149 fServerSocket->SetOption(kNoBlock, 1);
150 fDisplaySocket = NULL;
151 CheckForConnections();
97d6eb66 152#ifdef ALI_HLT
153 fHLT = NULL;
154#endif
04fa961a 155
1899848d 156 SetStatus(kStopped);
04fa961a 157 fStopping = kFALSE;
158}
159
c4bd737c 160//_____________________________________________________________________________
161AliMonitorProcess::AliMonitorProcess(const AliMonitorProcess& process) :
162 TObject(process)
163{
164 Fatal("AliMonitorProcess", "copy constructor not implemented");
165}
166
167//_____________________________________________________________________________
168AliMonitorProcess& AliMonitorProcess::operator = (const AliMonitorProcess&
169 /*process*/)
170{
171 Fatal("operator =", "assignment operator not implemented");
172 return *this;
173}
174
04fa961a 175//_____________________________________________________________________________
176AliMonitorProcess::~AliMonitorProcess()
177{
178// clean up
179
180 fMonitors.Delete();
181 delete fTopFolder;
182 delete fRunLoader;
183
184 delete fServerSocket;
185 fSockets.Delete();
186 delete fDisplaySocket;
187
188 fGrid->Close();
189 delete fGrid;
190
191 fFile->Close();
192 delete fFile;
193 gSystem->Unlink("monitor_tree.root");
97d6eb66 194
195#ifdef ALI_HLT
196 delete fHLT;
4a69f9c7 197 delete fHLTHough;
97d6eb66 198#endif
04fa961a 199}
200
201
202//_____________________________________________________________________________
203const char* AliMonitorProcess::GetRevision()
204{
205 return "$Revision$";
206}
207
208
1899848d 209//_____________________________________________________________________________
210void AliMonitorProcess::SetStatus(EStatus status)
211{
c4bd737c 212// set the current status and process system events
213
1899848d 214 fStatus = status;
215 gSystem->ProcessEvents();
216}
217
218
04fa961a 219//_____________________________________________________________________________
220void AliMonitorProcess::Run()
221{
222// run the monitor process:
223// check for a raw data file, process the raw data file and delete it
224
225 fStopping = kFALSE;
226
227 while (!fStopping) {
1899848d 228 SetStatus(kWaiting);
04fa961a 229 while (!CheckForNewFile()) {
230 CheckForConnections();
1899848d 231 SetStatus(kWaiting);
04fa961a 232 if (fStopping) break;
233 gSystem->Sleep(10);
234 }
235 if (fStopping) break;
236
237 ProcessFile();
238 }
239
240 WriteHistos();
241
242 fStopping = kFALSE;
1899848d 243 SetStatus(kStopped);
04fa961a 244}
245
246
247//_____________________________________________________________________________
248void AliMonitorProcess::Stop()
249{
250// set the fStopping flag to terminate the monitor process after the current
251// event was processed
252
1899848d 253 if (GetStatus() != kStopped) fStopping = kTRUE;
04fa961a 254}
255
256
257//_____________________________________________________________________________
258void AliMonitorProcess::ProcessFile(const char* fileName)
259{
260// create a file with monitor histograms for a single file
261
1899848d 262 if (GetStatus() != kStopped) {
04fa961a 263 Error("ProcessFile", "ProcessFile can not be called"
264 " while the monitor process is running");
265 return;
266 }
267
268 fFileName = fileName;
269 Int_t nEventMin = fNEventsMin;
270 fNEventsMin = 1;
271 ProcessFile();
272 WriteHistos();
273 fNEventsMin = nEventMin;
1899848d 274 SetStatus(kStopped);
04fa961a 275}
276
277
278//_____________________________________________________________________________
279Bool_t AliMonitorProcess::CheckForNewFile()
280{
281// check whether a new file was registered in alien
282
283 TGridResult* result = fGrid->Ls();
284 Long_t maxDate = -1;
285 Long_t maxTime = -1;
286 TString fileName;
287
288 while (const char* entry = result->Next()) {
289 // entry = host_date_time.root
290 TString entryCopy(entry);
291 char* p = const_cast<char*>(entryCopy.Data());
6ad9b9d5 292 if (!strtok(p, "_") || !p) continue; // host name
97d6eb66 293 char* dateStr = strtok(NULL, "_");
04fa961a 294 if (!dateStr || !p) continue;
97d6eb66 295 char* timeStr = strtok(NULL, ".");
04fa961a 296 if (!timeStr || !p) continue;
297 Long_t date = atoi(dateStr);
298 Long_t time = atoi(timeStr);
299
300 if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) {
301 maxDate = date;
302 maxTime = time;
303 fileName = entry;
304 }
305 }
306
307 if (maxDate < 0) return kFALSE; // no files found
308 if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file
309
310 fLogicalFileName = fileName;
1899848d 311 TGridResult* result2 = fGrid->GetPhysicalFileNames(fLogicalFileName.Data());
312 fFileName = result2->Next();
313
04fa961a 314 return kTRUE;
315}
316
317//_____________________________________________________________________________
318Bool_t AliMonitorProcess::ProcessFile()
319{
320// loop over all events in the raw data file, run the reconstruction
321// and fill the monitor histograms
322
323 Int_t nEvents = GetNumberOfEvents(fFileName);
324 if (nEvents <= 0) return kFALSE;
325 Info("ProcessFile", "found %d event(s) in file %s",
326 nEvents, fFileName.Data());
97d6eb66 327#ifdef ALI_HLT
328 CreateHLT(fFileName);
c6ba6205 329 CreateHLTHough(fFileName);
97d6eb66 330#endif
04fa961a 331
332 // loop over the events
333 for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) {
1899848d 334 SetStatus(kReading);
04fa961a 335 fRunLoader->SetEventNumber(0);
336 AliRawReaderRoot rawReader(fFileName, iEvent);
337 if (fStopping) break;
338 if (rawReader.GetRunNumber() != fRunNumber) {
339 WriteHistos();
340 StartNewRun();
341 fRunNumber = rawReader.GetRunNumber();
342 fEventNumber[0] = rawReader.GetEventId()[0];
343 fEventNumber[1] = rawReader.GetEventId()[1];
344 fSubRunNumber = 0;
345 if (fStopping) break;
346 }
347
348 if (!ReconstructTPC(&rawReader)) return kFALSE;
349 if (fStopping) break;
350 if (!ReconstructITS(&rawReader)) return kFALSE;
351 if (fStopping) break;
352 if (!ReconstructV0s()) return kFALSE;
353 if (fStopping) break;
97d6eb66 354 if (!ReconstructHLT(iEvent)) return kFALSE;
355 if (fStopping) break;
c6ba6205 356 if (!ReconstructHLTHough(iEvent)) return kFALSE;
357 if (fStopping) break;
04fa961a 358
359 if (fDisplaySocket) fDisplaySocket->Send("new event");
360
361 Info("ProcessFile", "filling histograms...");
1899848d 362 SetStatus(kFilling);
04fa961a 363 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
364 ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader);
365 if (fStopping) break;
366 }
367 if (fStopping) break;
368
369 Info("ProcessFile", "updating histograms...");
1899848d 370 SetStatus(kUpdating);
04fa961a 371 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
372 while (TFolder* folder = (TFolder*) iFolder->Next()) {
373 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
374 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
375 histo->Update();
376 }
377 delete iHisto;
378 }
379 delete iFolder;
380 if (fStopping) break;
381
382 Info("ProcessFile", "filling the tree...");
383 fTree->Fill();
384
385 Info("ProcessFile", "broadcasting histograms...");
386 CheckForConnections();
387 BroadcastHistos();
388
389 fNEvents++;
390 if (fStopping) break;
391 }
392
97d6eb66 393#ifdef ALI_HLT
394 delete fHLT;
395 fHLT = NULL;
396#endif
397
04fa961a 398 return kTRUE;
399}
400
401//_____________________________________________________________________________
402void AliMonitorProcess::Reset()
403{
404// write the current histograms to a file and reset them
405
406 if (fSubRunNumber == 0) fSubRunNumber++;
407 WriteHistos();
408 StartNewRun();
409 fSubRunNumber++;
410}
411
412
413//_____________________________________________________________________________
c4bd737c 414UInt_t AliMonitorProcess::GetEventPeriodNumber() const
04fa961a 415{
416// get the period number from the event id
417
418 return (fEventNumber[1] >> 4);
419}
420
421//_____________________________________________________________________________
c4bd737c 422UInt_t AliMonitorProcess::GetEventOrbitNumber() const
04fa961a 423{
424// get the orbit number from the event id
425
426 return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12);
427}
428
429//_____________________________________________________________________________
c4bd737c 430UInt_t AliMonitorProcess::GetEventBunchNumber() const
04fa961a 431{
432// get the bunch number from the event id
433
434 return (fEventNumber[0] % 0x0FFF);
435}
436
437//_____________________________________________________________________________
c4bd737c 438Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) const
04fa961a 439{
440// determine the number of events in the given raw data file
441
442 Int_t nEvents = -1;
443
444 TFile* file = TFile::Open(fileName);
445 if (!file || !file->IsOpen()) {
446 Error("GetNumberOfEvents", "could not open file %s", fileName);
447 if (file) delete file;
448 return -1;
449 }
450
451 TTree* tree = (TTree*) file->Get("RAW");
452 if (!tree) {
453 Error("GetNumberOfEvents", "could not find tree with raw data");
454 } else {
455 nEvents = (Int_t) tree->GetEntries();
456 }
457 file->Close();
458 delete file;
459
460 return nEvents;
461}
462
463//_____________________________________________________________________________
464Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader)
465{
466// find TPC clusters and tracks
467
1899848d 468 SetStatus(kRecTPC);
04fa961a 469
470 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
471 if (!tpcLoader) {
472 Error("ReconstructTPC", "no TPC loader found");
473 return kFALSE;
474 }
475 gSystem->Unlink("TPC.RecPoints.root");
476 gSystem->Unlink("TPC.Tracks.root");
477
478 // cluster finder
479 Info("ReconstructTPC", "reconstructing clusters...");
480 tpcLoader->LoadRecPoints("recreate");
481 AliTPCclustererMI clusterer(fTPCParam);
482 tpcLoader->MakeRecPointsContainer();
483 clusterer.SetOutput(tpcLoader->TreeR());
484 clusterer.Digits2Clusters(rawReader);
485 tpcLoader->WriteRecPoints("OVERWRITE");
486
487 // track finder
488 Info("ReconstructTPC", "reconstructing tracks...");
489 tpcLoader->LoadTracks("recreate");
490 {
491 AliTPCtrackerMI tracker(fTPCParam);
492 tracker.Clusters2Tracks();
493 }
494
495 tpcLoader->UnloadRecPoints();
496 tpcLoader->UnloadTracks();
497 return kTRUE;
498}
499
500//_____________________________________________________________________________
501Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
502{
503// find ITS clusters and tracks
504
1899848d 505 SetStatus(kRecITS);
04fa961a 506
507 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
508 if (!itsLoader) {
509 Error("ReconstructITS", "no ITS loader found");
510 return kFALSE;
511 }
512 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
513 if (!tpcLoader) {
514 Error("ReconstructITS", "no TPC loader found");
515 return kFALSE;
516 }
517 gSystem->Unlink("ITS.RecPoints.root");
518 gSystem->Unlink("ITS.Tracks.root");
519
520 // cluster finder
521 Info("ReconstructITS", "reconstructing clusters...");
522 itsLoader->LoadRecPoints("recreate");
523 AliITSclustererV2 clusterer(fITSgeom);
524 itsLoader->MakeRecPointsContainer();
525 clusterer.Digits2Clusters(rawReader);
526
527 // track finder
528 Info("ReconstructITS", "reconstructing tracks...");
529 itsLoader->LoadTracks("recreate");
530 itsLoader->MakeTracksContainer();
531 tpcLoader->LoadTracks();
532 AliITStrackerV2 tracker(fITSgeom);
533 tracker.LoadClusters(itsLoader->TreeR());
534 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
535 tracker.UnloadClusters();
536 itsLoader->WriteTracks("OVERWRITE");
537
538 itsLoader->UnloadRecPoints();
539 itsLoader->UnloadTracks();
540 tpcLoader->UnloadTracks();
541 return kTRUE;
542}
543
544//_____________________________________________________________________________
545Bool_t AliMonitorProcess::ReconstructV0s()
546{
547// find V0s
548
1899848d 549 SetStatus(kRecV0s);
04fa961a 550
551 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
552 if (!itsLoader) {
553 Error("ReconstructV0", "no ITS loader found");
554 return kFALSE;
555 }
556 gSystem->Unlink("ITS.V0s.root");
557
558 // V0 finder
559 Info("ReconstructV0s", "reconstructing V0s...");
560 itsLoader->LoadTracks("read");
561 itsLoader->LoadV0s("recreate");
562 AliV0vertexer vertexer;
563 TTree* tracks = itsLoader->TreeT();
564 if (!tracks) {
565 Error("ReconstructV0s", "no ITS tracks tree found");
566 return kFALSE;
567 }
568 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
569 TTree* v0s = itsLoader->TreeV0();
570 vertexer.Tracks2V0vertices(tracks, v0s);
571 itsLoader->WriteV0s("OVERWRITE");
572
573 itsLoader->UnloadTracks();
574 itsLoader->UnloadV0s();
575 return kTRUE;
576}
577
97d6eb66 578//_____________________________________________________________________________
579#ifdef ALI_HLT
580void AliMonitorProcess::CreateHLT(const char* fileName)
581{
1899848d 582
97d6eb66 583// create the HLT (Level3) object
584
585 if (fHLT) delete fHLT;
586
587 char name[256];
588 strcpy(name, fileName);
589 fHLT = new AliLevel3(name);
590 fHLT->Init("./", AliLevel3::kRaw, 1);
591
524a85e8 592 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
97d6eb66 593
c4bd737c 594 Int_t phiSegments = 50;
595 Int_t etaSegments = 100;
97d6eb66 596 Int_t trackletlength = 3;
524a85e8 597 Int_t tracklength = 20;//40 or 5
97d6eb66 598 Int_t rowscopetracklet = 2;
524a85e8 599 Int_t rowscopetrack = 10;
c4bd737c 600 Double_t minPtFit = 0;
524a85e8 601 Double_t maxangle = 0.1745;
97d6eb66 602 Double_t goodDist = 5;
524a85e8 603 Double_t maxphi = 0.1;
604 Double_t maxeta = 0.1;
1899848d 605 Double_t hitChi2Cut = 15;//100 or 15
606 Double_t goodHitChi2 = 5;//20 or 5
607 Double_t trackChi2Cut = 10;//50 or 10
c4bd737c 608 fHLT->SetTrackerParam(phiSegments, etaSegments,
97d6eb66 609 trackletlength, tracklength,
610 rowscopetracklet, rowscopetrack,
c4bd737c 611 minPtFit, maxangle, goodDist, hitChi2Cut,
97d6eb66 612 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
613
614 fHLT->WriteFiles("./hlt/");
615}
c6ba6205 616
617//_____________________________________________________________________________
618void AliMonitorProcess::CreateHLTHough(const char* fileName)
619{
620
621// create the HLT Hough transform (L3Hough) object
622
623 if (fHLTHough) delete fHLTHough;
624
625 char name[256];
626 strcpy(name, fileName);
627
628 fHLTHough = new AliL3Hough();
4a69f9c7 629 fHLTHough->SetThreshold(4);
630 fHLTHough->SetTransformerParams(140,150,0.2,-1);
631 fHLTHough->SetPeakThreshold(6000,-1);
632 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
c6ba6205 633 fHLTHough->SetAddHistograms();
4a69f9c7 634 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
c6ba6205 635
636}
97d6eb66 637#endif
638
639//_____________________________________________________________________________
54a41755 640Bool_t AliMonitorProcess::ReconstructHLT(
641#ifdef ALI_HLT
642 Int_t iEvent
643#else
9abb4463 644 Int_t /* iEvent */
54a41755 645#endif
646)
97d6eb66 647{
648// run the HLT cluster and track finder
649
1899848d 650 SetStatus(kRecHLT);
97d6eb66 651
652#ifndef ALI_HLT
653 Warning("ReconstructHLT", "the code was compiled without HLT support");
654 return kTRUE;
655
656#else
657 gSystem->Exec("rm -rf hlt");
658 gSystem->MakeDirectory("hlt");
659 if (!fHLT) return kFALSE;
660
661 fHLT->ProcessEvent(0, 35, iEvent);
662
663 // remove the event number from the file names
664 char command[256];
665 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
666 gSystem->Exec(command);
667 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
668 gSystem->Exec(command);
669 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
670 gSystem->Exec(command);
671 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
672 gSystem->Exec(command);
673 return kTRUE;
674#endif
675}
676
c6ba6205 677//_____________________________________________________________________________
678Bool_t AliMonitorProcess::ReconstructHLTHough(
679#ifdef ALI_HLT
680 Int_t iEvent
681#else
682 Int_t /* iEvent */
683#endif
684)
685{
686// run the HLT Hough transformer
687
688 SetStatus(kRecHLT);
689
690#ifndef ALI_HLT
691 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
692 return kTRUE;
693
694#else
4a69f9c7 695 gSystem->Exec("rm -rf hlt/hough");
696 gSystem->MakeDirectory("hlt/hough");
697 gSystem->Exec("rm -rf hlt/fitter");
698 gSystem->MakeDirectory("hlt/fitter");
c6ba6205 699 if (!fHLTHough) return kFALSE;
700
701 // fHLTHough->Process(0, 35);
702 // Loop over TPC sectors and process the data
703 for(Int_t i=0; i<=35; i++)
704 {
705 fHLTHough->ReadData(i,iEvent);
706 fHLTHough->Transform();
707 // if(fHLTHough->fAddHistograms)
708 fHLTHough->AddAllHistograms();
709 fHLTHough->FindTrackCandidates();
4a69f9c7 710 fHLTHough->AddTracks();
c6ba6205 711 }
4a69f9c7 712 fHLTHough->WriteTracks("./hlt/hough");
713
714 // Run cluster fitter
715 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
716
717 // Set debug flag for the cluster fitter
718 // fitter->Debug();
719
720 // Setting fitter parameters
721 fitter->SetInnerWidthFactor(1,1.5);
722 fitter->SetOuterWidthFactor(1,1.5);
723 fitter->SetNmaxOverlaps(5);
724
725 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
726 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
727
728 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
729
730 // Takes input from global hough tracks produced by HT
731 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
732
733 for(Int_t islice = 0; islice <= 35; islice++)
734 {
735 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
736 {
737 fitter->Init(islice,ipatch);
738
739 // Read digits
740 AliL3DigitRowData *digits = fHLTHough->GetTransformer(ipatch)->GetDataPointer();
741 fitter->SetInputData(digits);
742 fitter->FindClusters();
743 fitter->WriteClusters();
744 }
745 }
746
747 // Refit of the clusters
748 AliL3Vertex vertex;
749 //The seeds are the input tracks from circle HT
750 AliL3TrackArray *tracks = fitter->GetSeeds();
751 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
752
753 // Temporary solution !
754 // sprintf(command, "rename _5.raw _-1.raw hlt/fitter/points*.raw", iEvent);
755 // gSystem->Exec(command);
756
757 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
758 for(Int_t i=0; i<tracks->GetNTracks(); i++)
759 {
760 AliL3Track *track = tracks->GetCheckedTrack(i);
761 if(!track) continue;
762 if(track->GetNHits() < 40) continue;
763 ft->SortTrackClusters(track);
764 ft->FitHelix(track);
765 ft->UpdateTrack(track);
766 }
767 delete ft;
768
769 //Write the final tracks
770 fitter->WriteTracks(5);
771
772 delete fitter;
29504bd3 773
774 // remove the event number from the file names
775 char command[256];
4a69f9c7 776 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
777 gSystem->Exec(command);
778 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
779 gSystem->Exec(command);
780 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
29504bd3 781 gSystem->Exec(command);
c6ba6205 782 return kTRUE;
783#endif
784}
04fa961a 785
786//_____________________________________________________________________________
787Bool_t AliMonitorProcess::WriteHistos()
788{
789// write the monitor tree and the monitor histograms to the file
790// "monitor_<run number>[_<sub_run_number>].root"
791// if at least fNEventsMin events were monitored
792
1899848d 793 SetStatus(kWriting);
04fa961a 794
795 // rename tree file and create a new one
796 fFile->cd();
797 fTree->Write();
798 fFile->Close();
799 delete fFile;
800
801 char fileName[256];
802 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
803 if (fSubRunNumber > 0) {
804 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
805 }
806 if (fNEvents < fNEventsMin) {
807 gSystem->Unlink("monitor_tree.root");
808 } else {
809 gSystem->Rename("monitor_tree.root", fileName);
810 }
811
812 fFile = TFile::Open("monitor_tree.root", "RECREATE");
813 if (!fFile || !fFile->IsOpen()) {
814 Fatal("WriteHistos", "could not open file for tree");
815 }
816 fTree = new TTree("MonitorTree", "tree for monitoring");
817 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
818 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
819 }
820 gROOT->cd();
821
822 // write the histograms
823 if (fNEvents < fNEventsMin) return kTRUE;
824
825 if (!fWriteHistoList) {
826 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
827 while (TFolder* folder = (TFolder*) iFolder->Next()) {
828 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
829 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
830 histo->ResetList();
831 }
832 delete iHisto;
833 }
834 delete iFolder;
835 }
836
837 Bool_t result = kTRUE;
838 sprintf(fileName, "monitor_%d.root", fRunNumber);
839 if (fSubRunNumber > 0) {
840 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
841 }
842 TFile* file = TFile::Open(fileName, "recreate");
843 if (!file || !file->IsOpen()) {
844 Error("WriteHistos", "could not open file %s", fileName);
845 result = kFALSE;
846 } else {
847 fTopFolder->Write();
848 file->Close();
849 }
850 if (file) delete file;
851
852 return result;
853}
854
855//_____________________________________________________________________________
856void AliMonitorProcess::StartNewRun()
857{
858// reset the histograms for a new run
859
1899848d 860 SetStatus(kResetting);
04fa961a 861 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
862 while (TFolder* folder = (TFolder*) iFolder->Next()) {
863 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
864 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
865 histo->Reset();
866 }
867 delete iHisto;
868 }
869 delete iFolder;
870
871 fNEvents = 0;
872}
873
874
875//_____________________________________________________________________________
876void AliMonitorProcess::CheckForConnections()
877{
878// check if new clients want to connect and add them to the list of sockets
879
880 TMessage message(kMESS_OBJECT);
881 message.WriteObject(fTopFolder);
1899848d 882 SetStatus(kConnecting);
04fa961a 883
884 TSocket* socket;
885 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
54a41755 886 socket->SetOption(kNoBlock, 1);
04fa961a 887 char socketType[256];
888 if (!socket->Recv(socketType, 255)) continue;
889 if (strcmp(socketType, "client") == 0) {
890 if ((fNEvents == 0) || (socket->Send(message) >= 0)) {
891 fSockets.Add(socket);
892 TInetAddress adr = socket->GetInetAddress();
893 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
894 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
895 }
896 } else if (strcmp(socketType, "display") == 0) {
897 if (fDisplaySocket) {
898 fDisplaySocket->Close();
899 delete fDisplaySocket;
900 }
901 fDisplaySocket = socket;
902 fDisplaySocket->SetOption(kNoBlock, 1);
903 TInetAddress adr = socket->GetInetAddress();
904 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
905 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
906 }
907 }
908
909 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
910 socket = (TSocket*) fSockets[iSocket];
911 if (!socket) continue;
1899848d 912 // remove finished client
913 char str[256];
914 if (socket->Recv(str, 255)) {
915 TString socketMessage(str);
916 if(socketMessage.CompareTo("Finished") == 0) {
917 TInetAddress adr = socket->GetInetAddress();
918 Info("CheckForConnections",
919 "disconnect finished client:\n %s (%s), port %d\n",
920 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
921 delete fSockets.RemoveAt(iSocket);
922 continue;
923 }
924 }
04fa961a 925 if (!socket->IsValid()) {
926 // remove invalid sockets from the list
927 TInetAddress adr = socket->GetInetAddress();
928 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
929 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
930 delete fSockets.RemoveAt(iSocket);
931 }
932 }
933 fSockets.Compress();
934}
935
936//_____________________________________________________________________________
937void AliMonitorProcess::BroadcastHistos()
938{
939// send the monitor histograms to the clients
940
1899848d 941 SetStatus(kBroadcasting);
04fa961a 942 TMessage message(kMESS_OBJECT);
943 message.WriteObject(fTopFolder);
944
945 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
946 TSocket* socket = (TSocket*) fSockets[iSocket];
947 if (!socket) continue;
54a41755 948 socket->SetOption(kNoBlock, 0);
04fa961a 949 if (!socket->IsValid() || (socket->Send(message) < 0)) {
950 // remove the socket from the list if there was an error
951 TInetAddress adr = socket->GetInetAddress();
952 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
953 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
954 delete fSockets.RemoveAt(iSocket);
54a41755 955 } else {
956 socket->SetOption(kNoBlock, 1);
04fa961a 957 }
958 }
959 fSockets.Compress();
960}