]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliMonitorProcess.cxx
Changes in order to obey to our coding conventions
[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();
6c6810ae 551 tracker.UnloadClusters();
04fa961a 552 }
553
554 tpcLoader->UnloadRecPoints();
555 tpcLoader->UnloadTracks();
556 return kTRUE;
557}
558
559//_____________________________________________________________________________
560Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader)
561{
562// find ITS clusters and tracks
563
1899848d 564 SetStatus(kRecITS);
04fa961a 565
566 AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader");
567 if (!itsLoader) {
568 Error("ReconstructITS", "no ITS loader found");
569 return kFALSE;
570 }
571 AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader");
572 if (!tpcLoader) {
573 Error("ReconstructITS", "no TPC loader found");
574 return kFALSE;
575 }
576 gSystem->Unlink("ITS.RecPoints.root");
577 gSystem->Unlink("ITS.Tracks.root");
578
579 // cluster finder
580 Info("ReconstructITS", "reconstructing clusters...");
581 itsLoader->LoadRecPoints("recreate");
582 AliITSclustererV2 clusterer(fITSgeom);
583 itsLoader->MakeRecPointsContainer();
584 clusterer.Digits2Clusters(rawReader);
585
586 // track finder
587 Info("ReconstructITS", "reconstructing tracks...");
588 itsLoader->LoadTracks("recreate");
589 itsLoader->MakeTracksContainer();
590 tpcLoader->LoadTracks();
591 AliITStrackerV2 tracker(fITSgeom);
592 tracker.LoadClusters(itsLoader->TreeR());
593 tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT());
594 tracker.UnloadClusters();
595 itsLoader->WriteTracks("OVERWRITE");
596
597 itsLoader->UnloadRecPoints();
598 itsLoader->UnloadTracks();
599 tpcLoader->UnloadTracks();
600 return kTRUE;
601}
602
603//_____________________________________________________________________________
604Bool_t AliMonitorProcess::ReconstructV0s()
605{
606// find V0s
607
1899848d 608 SetStatus(kRecV0s);
04fa961a 609
610 AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader");
611 if (!itsLoader) {
612 Error("ReconstructV0", "no ITS loader found");
613 return kFALSE;
614 }
615 gSystem->Unlink("ITS.V0s.root");
616
617 // V0 finder
618 Info("ReconstructV0s", "reconstructing V0s...");
619 itsLoader->LoadTracks("read");
620 itsLoader->LoadV0s("recreate");
621 AliV0vertexer vertexer;
622 TTree* tracks = itsLoader->TreeT();
623 if (!tracks) {
624 Error("ReconstructV0s", "no ITS tracks tree found");
625 return kFALSE;
626 }
627 if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0");
628 TTree* v0s = itsLoader->TreeV0();
629 vertexer.Tracks2V0vertices(tracks, v0s);
630 itsLoader->WriteV0s("OVERWRITE");
631
632 itsLoader->UnloadTracks();
633 itsLoader->UnloadV0s();
634 return kTRUE;
635}
636
97d6eb66 637//_____________________________________________________________________________
638#ifdef ALI_HLT
639void AliMonitorProcess::CreateHLT(const char* fileName)
640{
1899848d 641
97d6eb66 642// create the HLT (Level3) object
643
644 if (fHLT) delete fHLT;
645
646 char name[256];
647 strcpy(name, fileName);
648 fHLT = new AliLevel3(name);
649 fHLT->Init("./", AliLevel3::kRaw, 1);
650
524a85e8 651 fHLT->SetClusterFinderParam(-1, -1, kTRUE);
97d6eb66 652
c4bd737c 653 Int_t phiSegments = 50;
654 Int_t etaSegments = 100;
97d6eb66 655 Int_t trackletlength = 3;
524a85e8 656 Int_t tracklength = 20;//40 or 5
97d6eb66 657 Int_t rowscopetracklet = 2;
524a85e8 658 Int_t rowscopetrack = 10;
c4bd737c 659 Double_t minPtFit = 0;
524a85e8 660 Double_t maxangle = 0.1745;
97d6eb66 661 Double_t goodDist = 5;
524a85e8 662 Double_t maxphi = 0.1;
663 Double_t maxeta = 0.1;
1899848d 664 Double_t hitChi2Cut = 15;//100 or 15
665 Double_t goodHitChi2 = 5;//20 or 5
666 Double_t trackChi2Cut = 10;//50 or 10
c4bd737c 667 fHLT->SetTrackerParam(phiSegments, etaSegments,
97d6eb66 668 trackletlength, tracklength,
669 rowscopetracklet, rowscopetrack,
c4bd737c 670 minPtFit, maxangle, goodDist, hitChi2Cut,
97d6eb66 671 goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE);
672
673 fHLT->WriteFiles("./hlt/");
674}
c6ba6205 675
676//_____________________________________________________________________________
677void AliMonitorProcess::CreateHLTHough(const char* fileName)
678{
679
680// create the HLT Hough transform (L3Hough) object
681
682 if (fHLTHough) delete fHLTHough;
683
684 char name[256];
685 strcpy(name, fileName);
686
687 fHLTHough = new AliL3Hough();
4a69f9c7 688 fHLTHough->SetThreshold(4);
8aad0cd3 689 fHLTHough->SetTransformerParams(140,150,0.5,-1);
690 fHLTHough->SetPeakThreshold(9000,-1);// or 6000
4a69f9c7 691 fHLTHough->Init("./", kFALSE, 50, kFALSE,0,name);
c6ba6205 692 fHLTHough->SetAddHistograms();
4a69f9c7 693 // fHLTHough->GetMaxFinder()->SetThreshold(14000);
c6ba6205 694
695}
97d6eb66 696#endif
697
698//_____________________________________________________________________________
54a41755 699Bool_t AliMonitorProcess::ReconstructHLT(
700#ifdef ALI_HLT
701 Int_t iEvent
702#else
9abb4463 703 Int_t /* iEvent */
54a41755 704#endif
705)
97d6eb66 706{
707// run the HLT cluster and track finder
708
1899848d 709 SetStatus(kRecHLT);
97d6eb66 710
711#ifndef ALI_HLT
712 Warning("ReconstructHLT", "the code was compiled without HLT support");
713 return kTRUE;
714
715#else
716 gSystem->Exec("rm -rf hlt");
717 gSystem->MakeDirectory("hlt");
718 if (!fHLT) return kFALSE;
719
720 fHLT->ProcessEvent(0, 35, iEvent);
721
722 // remove the event number from the file names
723 char command[256];
724 sprintf(command, "rename points_%d points hlt/*.raw", iEvent);
725 gSystem->Exec(command);
726 sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent);
727 gSystem->Exec(command);
728 sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent);
729 gSystem->Exec(command);
730 sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent);
731 gSystem->Exec(command);
732 return kTRUE;
733#endif
734}
735
c6ba6205 736//_____________________________________________________________________________
737Bool_t AliMonitorProcess::ReconstructHLTHough(
738#ifdef ALI_HLT
739 Int_t iEvent
740#else
741 Int_t /* iEvent */
742#endif
743)
744{
745// run the HLT Hough transformer
746
747 SetStatus(kRecHLT);
748
749#ifndef ALI_HLT
750 Warning("ReconstructHLTHough", "the code was compiled without HLT support");
751 return kTRUE;
752
753#else
4a69f9c7 754 gSystem->Exec("rm -rf hlt/hough");
755 gSystem->MakeDirectory("hlt/hough");
756 gSystem->Exec("rm -rf hlt/fitter");
757 gSystem->MakeDirectory("hlt/fitter");
c6ba6205 758 if (!fHLTHough) return kFALSE;
759
760 // fHLTHough->Process(0, 35);
761 // Loop over TPC sectors and process the data
762 for(Int_t i=0; i<=35; i++)
763 {
764 fHLTHough->ReadData(i,iEvent);
765 fHLTHough->Transform();
766 // if(fHLTHough->fAddHistograms)
767 fHLTHough->AddAllHistograms();
768 fHLTHough->FindTrackCandidates();
4a69f9c7 769 fHLTHough->AddTracks();
c6ba6205 770 }
4a69f9c7 771 fHLTHough->WriteTracks("./hlt/hough");
772
773 // Run cluster fitter
774 AliL3ClusterFitter *fitter = new AliL3ClusterFitter("./hlt");
775
776 // Set debug flag for the cluster fitter
777 // fitter->Debug();
778
779 // Setting fitter parameters
780 fitter->SetInnerWidthFactor(1,1.5);
781 fitter->SetOuterWidthFactor(1,1.5);
782 fitter->SetNmaxOverlaps(5);
783
784 //fitter->SetChiSqMax(5,kFALSE); //isolated clusters
785 fitter->SetChiSqMax(5,kTRUE); //overlapping clusters
786
787 Int_t rowrange[2] = {0,AliL3Transform::GetNRows()-1};
788
789 // Takes input from global hough tracks produced by HT
790 fitter->LoadSeeds(rowrange,kFALSE,iEvent);
791
8aad0cd3 792 UInt_t ndigits;
793
4a69f9c7 794 for(Int_t islice = 0; islice <= 35; islice++)
795 {
796 for(Int_t ipatch = 0; ipatch < AliL3Transform::GetNPatches(); ipatch++)
797 {
4a69f9c7 798 // Read digits
b934a9ae 799 fHLTHough->GetMemHandler(ipatch)->Free();
8aad0cd3 800 fHLTHough->GetMemHandler(ipatch)->Init(islice,ipatch);
801 AliL3DigitRowData *digits = (AliL3DigitRowData *)fHLTHough->GetMemHandler(ipatch)->AliAltroDigits2Memory(ndigits,iEvent);
802
803 fitter->Init(islice,ipatch);
4a69f9c7 804 fitter->SetInputData(digits);
805 fitter->FindClusters();
806 fitter->WriteClusters();
807 }
808 }
809
810 // Refit of the clusters
811 AliL3Vertex vertex;
812 //The seeds are the input tracks from circle HT
813 AliL3TrackArray *tracks = fitter->GetSeeds();
814 AliL3Fitter *ft = new AliL3Fitter(&vertex,1);
815
4a69f9c7 816 ft->LoadClusters("./hlt/fitter/",iEvent,kFALSE);
817 for(Int_t i=0; i<tracks->GetNTracks(); i++)
818 {
819 AliL3Track *track = tracks->GetCheckedTrack(i);
820 if(!track) continue;
8aad0cd3 821 if(track->GetNHits() < 20) continue;
4a69f9c7 822 ft->SortTrackClusters(track);
823 ft->FitHelix(track);
824 ft->UpdateTrack(track);
825 }
826 delete ft;
827
828 //Write the final tracks
8aad0cd3 829 fitter->WriteTracks(20);
4a69f9c7 830
831 delete fitter;
29504bd3 832
833 // remove the event number from the file names
834 char command[256];
4a69f9c7 835 sprintf(command, "rename tracks_%d tracks hlt/hough/*.raw", iEvent);
836 gSystem->Exec(command);
837 sprintf(command, "rename tracks_%d tracks hlt/fitter/*.raw", iEvent);
838 gSystem->Exec(command);
839 sprintf(command, "rename points_%d points hlt/fitter/*.raw", iEvent);
29504bd3 840 gSystem->Exec(command);
c6ba6205 841 return kTRUE;
842#endif
843}
04fa961a 844
845//_____________________________________________________________________________
846Bool_t AliMonitorProcess::WriteHistos()
847{
848// write the monitor tree and the monitor histograms to the file
849// "monitor_<run number>[_<sub_run_number>].root"
850// if at least fNEventsMin events were monitored
851
1899848d 852 SetStatus(kWriting);
04fa961a 853
854 // rename tree file and create a new one
855 fFile->cd();
856 fTree->Write();
857 fFile->Close();
858 delete fFile;
859
860 char fileName[256];
861 sprintf(fileName, "monitor_tree_%d.root", fRunNumber);
862 if (fSubRunNumber > 0) {
863 sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber);
864 }
865 if (fNEvents < fNEventsMin) {
866 gSystem->Unlink("monitor_tree.root");
867 } else {
868 gSystem->Rename("monitor_tree.root", fileName);
869 }
870
871 fFile = TFile::Open("monitor_tree.root", "RECREATE");
872 if (!fFile || !fFile->IsOpen()) {
873 Fatal("WriteHistos", "could not open file for tree");
874 }
875 fTree = new TTree("MonitorTree", "tree for monitoring");
876 for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) {
877 ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree);
878 }
879 gROOT->cd();
880
881 // write the histograms
882 if (fNEvents < fNEventsMin) return kTRUE;
883
884 if (!fWriteHistoList) {
885 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
886 while (TFolder* folder = (TFolder*) iFolder->Next()) {
887 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
888 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
889 histo->ResetList();
890 }
891 delete iHisto;
892 }
893 delete iFolder;
894 }
895
896 Bool_t result = kTRUE;
897 sprintf(fileName, "monitor_%d.root", fRunNumber);
898 if (fSubRunNumber > 0) {
899 sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber);
900 }
901 TFile* file = TFile::Open(fileName, "recreate");
902 if (!file || !file->IsOpen()) {
903 Error("WriteHistos", "could not open file %s", fileName);
904 result = kFALSE;
905 } else {
906 fTopFolder->Write();
907 file->Close();
908 }
909 if (file) delete file;
910
911 return result;
912}
913
914//_____________________________________________________________________________
915void AliMonitorProcess::StartNewRun()
916{
917// reset the histograms for a new run
918
1899848d 919 SetStatus(kResetting);
04fa961a 920 TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator();
921 while (TFolder* folder = (TFolder*) iFolder->Next()) {
922 TIterator* iHisto = folder->GetListOfFolders()->MakeIterator();
923 while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) {
924 histo->Reset();
925 }
926 delete iHisto;
927 }
928 delete iFolder;
929
930 fNEvents = 0;
931}
932
933
934//_____________________________________________________________________________
935void AliMonitorProcess::CheckForConnections()
936{
937// check if new clients want to connect and add them to the list of sockets
938
939 TMessage message(kMESS_OBJECT);
940 message.WriteObject(fTopFolder);
1899848d 941 SetStatus(kConnecting);
04fa961a 942
943 TSocket* socket;
944 while ((socket = fServerSocket->Accept()) != (TSocket*)-1) {
54a41755 945 socket->SetOption(kNoBlock, 1);
04fa961a 946 char socketType[256];
947 if (!socket->Recv(socketType, 255)) continue;
948 if (strcmp(socketType, "client") == 0) {
949 if ((fNEvents == 0) || (socket->Send(message) >= 0)) {
950 fSockets.Add(socket);
951 TInetAddress adr = socket->GetInetAddress();
952 Info("CheckForConnections", "new client:\n %s (%s), port %d\n",
953 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
954 }
955 } else if (strcmp(socketType, "display") == 0) {
956 if (fDisplaySocket) {
957 fDisplaySocket->Close();
958 delete fDisplaySocket;
959 }
960 fDisplaySocket = socket;
961 fDisplaySocket->SetOption(kNoBlock, 1);
962 TInetAddress adr = socket->GetInetAddress();
963 Info("CheckForConnections", "new display:\n %s (%s), port %d\n",
964 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
965 }
966 }
967
968 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
969 socket = (TSocket*) fSockets[iSocket];
970 if (!socket) continue;
1899848d 971 // remove finished client
972 char str[256];
973 if (socket->Recv(str, 255)) {
974 TString socketMessage(str);
975 if(socketMessage.CompareTo("Finished") == 0) {
976 TInetAddress adr = socket->GetInetAddress();
977 Info("CheckForConnections",
978 "disconnect finished client:\n %s (%s), port %d\n",
979 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
980 delete fSockets.RemoveAt(iSocket);
981 continue;
982 }
983 }
04fa961a 984 if (!socket->IsValid()) {
985 // remove invalid sockets from the list
986 TInetAddress adr = socket->GetInetAddress();
987 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
988 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
989 delete fSockets.RemoveAt(iSocket);
990 }
991 }
992 fSockets.Compress();
993}
994
995//_____________________________________________________________________________
996void AliMonitorProcess::BroadcastHistos()
997{
998// send the monitor histograms to the clients
999
1899848d 1000 SetStatus(kBroadcasting);
04fa961a 1001 TMessage message(kMESS_OBJECT);
1002 message.WriteObject(fTopFolder);
1003
1004 for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) {
1005 TSocket* socket = (TSocket*) fSockets[iSocket];
1006 if (!socket) continue;
54a41755 1007 socket->SetOption(kNoBlock, 0);
04fa961a 1008 if (!socket->IsValid() || (socket->Send(message) < 0)) {
1009 // remove the socket from the list if there was an error
1010 TInetAddress adr = socket->GetInetAddress();
1011 Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n",
1012 adr.GetHostName(), adr.GetHostAddress(), adr.GetPort());
1013 delete fSockets.RemoveAt(iSocket);
54a41755 1014 } else {
1015 socket->SetOption(kNoBlock, 1);
04fa961a 1016 }
1017 }
1018 fSockets.Compress();
1019}