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