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