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