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