]>
Commit | Line | Data |
---|---|---|
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" |
04fa961a | 34 | #include "AliRawReaderRoot.h" |
35 | #include "AliLoader.h" | |
36 | #include "AliRun.h" | |
37 | #include "AliTPC.h" | |
38 | #include "AliTPCclustererMI.h" | |
39 | #include "AliTPCtrackerMI.h" | |
40 | #include "AliITS.h" | |
41 | #include "AliITSclustererV2.h" | |
42 | #include "AliITStrackerV2.h" | |
43 | #include "AliITSLoader.h" | |
44 | #include "AliV0vertexer.h" | |
45 | #include <TSystem.h> | |
46 | #include <TSocket.h> | |
47 | #include <TMessage.h> | |
48 | #include <TGridResult.h> | |
49 | #include <TROOT.h> | |
50 | ||
51 | ||
52 | ClassImp(AliMonitorProcess) | |
53 | ||
54 | ||
55 | const Int_t AliMonitorProcess::kgPort = 9327; | |
56 | ||
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMonitorProcess::AliMonitorProcess(const char* alienDir, | |
60 | const char* fileNameGalice) | |
61 | { | |
62 | // initialize the monitoring process and the monitor histograms | |
63 | ||
64 | fGrid = TGrid::Connect("alien", gSystem->Getenv("USER")); | |
65 | if (!fGrid || fGrid->IsZombie() || !fGrid->IsConnected()) { | |
66 | delete fGrid; | |
67 | Fatal("AliMonitorProcess", "could not connect to alien"); | |
68 | } | |
69 | fGrid->cd(alienDir); | |
70 | fLogicalFileName = ""; | |
71 | fFileName = ""; | |
72 | ||
73 | fRunLoader = AliRunLoader::Open(fileNameGalice); | |
74 | if (!fRunLoader) Fatal("AliMonitorProcess", | |
75 | "could not get run loader from file %s", | |
76 | fileNameGalice); | |
77 | ||
78 | fRunLoader->CdGAFile(); | |
79 | fTPCParam = AliTPC::LoadTPCParam(gFile); | |
80 | if (!fTPCParam) Fatal("AliMonitorProcess", "could not load TPC parameters"); | |
81 | ||
82 | fRunLoader->LoadgAlice(); | |
83 | gAlice = fRunLoader->GetAliRun(); | |
84 | if (!gAlice) Fatal("AliMonitorProcess", "no gAlice object found"); | |
85 | AliITS* ITS = (AliITS*) gAlice->GetModule("ITS"); | |
86 | if (!ITS) Fatal("AliMonitorProcess", "no ITS detector found"); | |
87 | fITSgeom = ITS->GetITSgeom(); | |
88 | if (!fITSgeom) Fatal("AliMonitorProcess", "could not load ITS geometry"); | |
89 | ||
90 | fRunNumber = 0; | |
91 | fSubRunNumber = 0; | |
92 | fNEvents = 0; | |
93 | fNEventsMin = 2; | |
94 | fWriteHistoList = kFALSE; | |
95 | ||
96 | fTopFolder = new TFolder("Monitor", "monitor histograms"); | |
97 | fTopFolder->SetOwner(kTRUE); | |
98 | ||
99 | fMonitors.Add(new AliMonitorTPC(fTPCParam)); | |
100 | fMonitors.Add(new AliMonitorITS(fITSgeom)); | |
101 | fMonitors.Add(new AliMonitorV0s); | |
97d6eb66 | 102 | #ifdef ALI_HLT |
103 | fMonitors.Add(new AliMonitorHLT(fTPCParam)); | |
104 | #endif | |
04fa961a | 105 | |
106 | for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) { | |
107 | ((AliMonitor*) fMonitors[iMonitor])->CreateHistos(fTopFolder); | |
108 | } | |
109 | ||
110 | TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator(); | |
111 | while (TFolder* folder = (TFolder*) iFolder->Next()) folder->SetOwner(kTRUE); | |
112 | delete iFolder; | |
113 | ||
114 | fFile = TFile::Open("monitor_tree.root", "RECREATE"); | |
115 | if (!fFile || !fFile->IsOpen()) { | |
116 | Fatal("AliMonitorProcess", "could not open file for tree"); | |
117 | } | |
118 | fTree = new TTree("MonitorTree", "tree for monitoring"); | |
119 | for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) { | |
120 | ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree); | |
121 | } | |
122 | gROOT->cd(); | |
123 | ||
124 | fServerSocket = new TServerSocket(kgPort, kTRUE); | |
125 | fServerSocket->SetOption(kNoBlock, 1); | |
126 | fDisplaySocket = NULL; | |
127 | CheckForConnections(); | |
97d6eb66 | 128 | #ifdef ALI_HLT |
129 | fHLT = NULL; | |
130 | #endif | |
04fa961a | 131 | |
132 | fStatus = kStopped; | |
133 | fStopping = kFALSE; | |
134 | } | |
135 | ||
136 | //_____________________________________________________________________________ | |
137 | AliMonitorProcess::~AliMonitorProcess() | |
138 | { | |
139 | // clean up | |
140 | ||
141 | fMonitors.Delete(); | |
142 | delete fTopFolder; | |
143 | delete fRunLoader; | |
144 | ||
145 | delete fServerSocket; | |
146 | fSockets.Delete(); | |
147 | delete fDisplaySocket; | |
148 | ||
149 | fGrid->Close(); | |
150 | delete fGrid; | |
151 | ||
152 | fFile->Close(); | |
153 | delete fFile; | |
154 | gSystem->Unlink("monitor_tree.root"); | |
97d6eb66 | 155 | |
156 | #ifdef ALI_HLT | |
157 | delete fHLT; | |
158 | #endif | |
04fa961a | 159 | } |
160 | ||
161 | ||
162 | //_____________________________________________________________________________ | |
163 | const char* AliMonitorProcess::GetRevision() | |
164 | { | |
165 | return "$Revision$"; | |
166 | } | |
167 | ||
168 | ||
169 | //_____________________________________________________________________________ | |
170 | void AliMonitorProcess::Run() | |
171 | { | |
172 | // run the monitor process: | |
173 | // check for a raw data file, process the raw data file and delete it | |
174 | ||
175 | fStopping = kFALSE; | |
176 | ||
177 | while (!fStopping) { | |
178 | fStatus = kWaiting; | |
179 | while (!CheckForNewFile()) { | |
180 | CheckForConnections(); | |
181 | fStatus = kWaiting; | |
182 | if (fStopping) break; | |
183 | gSystem->Sleep(10); | |
184 | } | |
185 | if (fStopping) break; | |
186 | ||
187 | ProcessFile(); | |
188 | } | |
189 | ||
190 | WriteHistos(); | |
191 | ||
192 | fStopping = kFALSE; | |
193 | fStatus = kStopped; | |
194 | } | |
195 | ||
196 | ||
197 | //_____________________________________________________________________________ | |
198 | void AliMonitorProcess::Stop() | |
199 | { | |
200 | // set the fStopping flag to terminate the monitor process after the current | |
201 | // event was processed | |
202 | ||
203 | if (fStatus != kStopped) fStopping = kTRUE; | |
204 | } | |
205 | ||
206 | ||
207 | //_____________________________________________________________________________ | |
208 | void AliMonitorProcess::ProcessFile(const char* fileName) | |
209 | { | |
210 | // create a file with monitor histograms for a single file | |
211 | ||
212 | if (fStatus != kStopped) { | |
213 | Error("ProcessFile", "ProcessFile can not be called" | |
214 | " while the monitor process is running"); | |
215 | return; | |
216 | } | |
217 | ||
218 | fFileName = fileName; | |
219 | Int_t nEventMin = fNEventsMin; | |
220 | fNEventsMin = 1; | |
221 | ProcessFile(); | |
222 | WriteHistos(); | |
223 | fNEventsMin = nEventMin; | |
224 | fStatus = kStopped; | |
225 | } | |
226 | ||
227 | ||
228 | //_____________________________________________________________________________ | |
229 | Bool_t AliMonitorProcess::CheckForNewFile() | |
230 | { | |
231 | // check whether a new file was registered in alien | |
232 | ||
233 | TGridResult* result = fGrid->Ls(); | |
234 | Long_t maxDate = -1; | |
235 | Long_t maxTime = -1; | |
236 | TString fileName; | |
237 | ||
238 | while (const char* entry = result->Next()) { | |
239 | // entry = host_date_time.root | |
240 | TString entryCopy(entry); | |
241 | char* p = const_cast<char*>(entryCopy.Data()); | |
6ad9b9d5 | 242 | if (!strtok(p, "_") || !p) continue; // host name |
97d6eb66 | 243 | char* dateStr = strtok(NULL, "_"); |
04fa961a | 244 | if (!dateStr || !p) continue; |
97d6eb66 | 245 | char* timeStr = strtok(NULL, "."); |
04fa961a | 246 | if (!timeStr || !p) continue; |
247 | Long_t date = atoi(dateStr); | |
248 | Long_t time = atoi(timeStr); | |
249 | ||
250 | if ((date > maxDate) || ((date == maxDate) && (time > maxTime))) { | |
251 | maxDate = date; | |
252 | maxTime = time; | |
253 | fileName = entry; | |
254 | } | |
255 | } | |
256 | ||
257 | if (maxDate < 0) return kFALSE; // no files found | |
258 | if (fLogicalFileName.CompareTo(fileName) == 0) return kFALSE; // no new file | |
259 | ||
260 | fLogicalFileName = fileName; | |
261 | fFileName = fGrid->GetPhysicalFileName(fLogicalFileName.Data()); | |
262 | return kTRUE; | |
263 | } | |
264 | ||
265 | //_____________________________________________________________________________ | |
266 | Bool_t AliMonitorProcess::ProcessFile() | |
267 | { | |
268 | // loop over all events in the raw data file, run the reconstruction | |
269 | // and fill the monitor histograms | |
270 | ||
271 | Int_t nEvents = GetNumberOfEvents(fFileName); | |
272 | if (nEvents <= 0) return kFALSE; | |
273 | Info("ProcessFile", "found %d event(s) in file %s", | |
274 | nEvents, fFileName.Data()); | |
97d6eb66 | 275 | #ifdef ALI_HLT |
276 | CreateHLT(fFileName); | |
277 | #endif | |
04fa961a | 278 | |
279 | // loop over the events | |
280 | for (Int_t iEvent = 0; iEvent < nEvents; iEvent++) { | |
281 | fStatus = kReading; | |
282 | fRunLoader->SetEventNumber(0); | |
283 | AliRawReaderRoot rawReader(fFileName, iEvent); | |
284 | if (fStopping) break; | |
285 | if (rawReader.GetRunNumber() != fRunNumber) { | |
286 | WriteHistos(); | |
287 | StartNewRun(); | |
288 | fRunNumber = rawReader.GetRunNumber(); | |
289 | fEventNumber[0] = rawReader.GetEventId()[0]; | |
290 | fEventNumber[1] = rawReader.GetEventId()[1]; | |
291 | fSubRunNumber = 0; | |
292 | if (fStopping) break; | |
293 | } | |
294 | ||
295 | if (!ReconstructTPC(&rawReader)) return kFALSE; | |
296 | if (fStopping) break; | |
297 | if (!ReconstructITS(&rawReader)) return kFALSE; | |
298 | if (fStopping) break; | |
299 | if (!ReconstructV0s()) return kFALSE; | |
300 | if (fStopping) break; | |
97d6eb66 | 301 | if (!ReconstructHLT(iEvent)) return kFALSE; |
302 | if (fStopping) break; | |
04fa961a | 303 | |
304 | if (fDisplaySocket) fDisplaySocket->Send("new event"); | |
305 | ||
306 | Info("ProcessFile", "filling histograms..."); | |
307 | fStatus = kFilling; | |
308 | for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) { | |
309 | ((AliMonitor*) fMonitors[iMonitor])->FillHistos(fRunLoader, &rawReader); | |
310 | if (fStopping) break; | |
311 | } | |
312 | if (fStopping) break; | |
313 | ||
314 | Info("ProcessFile", "updating histograms..."); | |
315 | fStatus = kUpdating; | |
316 | TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator(); | |
317 | while (TFolder* folder = (TFolder*) iFolder->Next()) { | |
318 | TIterator* iHisto = folder->GetListOfFolders()->MakeIterator(); | |
319 | while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) { | |
320 | histo->Update(); | |
321 | } | |
322 | delete iHisto; | |
323 | } | |
324 | delete iFolder; | |
325 | if (fStopping) break; | |
326 | ||
327 | Info("ProcessFile", "filling the tree..."); | |
328 | fTree->Fill(); | |
329 | ||
330 | Info("ProcessFile", "broadcasting histograms..."); | |
331 | CheckForConnections(); | |
332 | BroadcastHistos(); | |
333 | ||
334 | fNEvents++; | |
335 | if (fStopping) break; | |
336 | } | |
337 | ||
97d6eb66 | 338 | #ifdef ALI_HLT |
339 | delete fHLT; | |
340 | fHLT = NULL; | |
341 | #endif | |
342 | ||
04fa961a | 343 | return kTRUE; |
344 | } | |
345 | ||
346 | //_____________________________________________________________________________ | |
347 | void AliMonitorProcess::Reset() | |
348 | { | |
349 | // write the current histograms to a file and reset them | |
350 | ||
351 | if (fSubRunNumber == 0) fSubRunNumber++; | |
352 | WriteHistos(); | |
353 | StartNewRun(); | |
354 | fSubRunNumber++; | |
355 | } | |
356 | ||
357 | ||
358 | //_____________________________________________________________________________ | |
359 | UInt_t AliMonitorProcess::GetEventPeriodNumber() | |
360 | { | |
361 | // get the period number from the event id | |
362 | ||
363 | return (fEventNumber[1] >> 4); | |
364 | } | |
365 | ||
366 | //_____________________________________________________________________________ | |
367 | UInt_t AliMonitorProcess::GetEventOrbitNumber() | |
368 | { | |
369 | // get the orbit number from the event id | |
370 | ||
371 | return ((fEventNumber[1] & 0x000F) << 20) + (fEventNumber[0] >> 12); | |
372 | } | |
373 | ||
374 | //_____________________________________________________________________________ | |
375 | UInt_t AliMonitorProcess::GetEventBunchNumber() | |
376 | { | |
377 | // get the bunch number from the event id | |
378 | ||
379 | return (fEventNumber[0] % 0x0FFF); | |
380 | } | |
381 | ||
382 | //_____________________________________________________________________________ | |
383 | Int_t AliMonitorProcess::GetNumberOfEvents(const char* fileName) | |
384 | { | |
385 | // determine the number of events in the given raw data file | |
386 | ||
387 | Int_t nEvents = -1; | |
388 | ||
389 | TFile* file = TFile::Open(fileName); | |
390 | if (!file || !file->IsOpen()) { | |
391 | Error("GetNumberOfEvents", "could not open file %s", fileName); | |
392 | if (file) delete file; | |
393 | return -1; | |
394 | } | |
395 | ||
396 | TTree* tree = (TTree*) file->Get("RAW"); | |
397 | if (!tree) { | |
398 | Error("GetNumberOfEvents", "could not find tree with raw data"); | |
399 | } else { | |
400 | nEvents = (Int_t) tree->GetEntries(); | |
401 | } | |
402 | file->Close(); | |
403 | delete file; | |
404 | ||
405 | return nEvents; | |
406 | } | |
407 | ||
408 | //_____________________________________________________________________________ | |
409 | Bool_t AliMonitorProcess::ReconstructTPC(AliRawReader* rawReader) | |
410 | { | |
411 | // find TPC clusters and tracks | |
412 | ||
413 | fStatus = kRecTPC; | |
414 | ||
415 | AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader"); | |
416 | if (!tpcLoader) { | |
417 | Error("ReconstructTPC", "no TPC loader found"); | |
418 | return kFALSE; | |
419 | } | |
420 | gSystem->Unlink("TPC.RecPoints.root"); | |
421 | gSystem->Unlink("TPC.Tracks.root"); | |
422 | ||
423 | // cluster finder | |
424 | Info("ReconstructTPC", "reconstructing clusters..."); | |
425 | tpcLoader->LoadRecPoints("recreate"); | |
426 | AliTPCclustererMI clusterer(fTPCParam); | |
427 | tpcLoader->MakeRecPointsContainer(); | |
428 | clusterer.SetOutput(tpcLoader->TreeR()); | |
429 | clusterer.Digits2Clusters(rawReader); | |
430 | tpcLoader->WriteRecPoints("OVERWRITE"); | |
431 | ||
432 | // track finder | |
433 | Info("ReconstructTPC", "reconstructing tracks..."); | |
434 | tpcLoader->LoadTracks("recreate"); | |
435 | { | |
436 | AliTPCtrackerMI tracker(fTPCParam); | |
437 | tracker.Clusters2Tracks(); | |
438 | } | |
439 | ||
440 | tpcLoader->UnloadRecPoints(); | |
441 | tpcLoader->UnloadTracks(); | |
442 | return kTRUE; | |
443 | } | |
444 | ||
445 | //_____________________________________________________________________________ | |
446 | Bool_t AliMonitorProcess::ReconstructITS(AliRawReader* rawReader) | |
447 | { | |
448 | // find ITS clusters and tracks | |
449 | ||
450 | fStatus = kRecITS; | |
451 | ||
452 | AliLoader* itsLoader = fRunLoader->GetLoader("ITSLoader"); | |
453 | if (!itsLoader) { | |
454 | Error("ReconstructITS", "no ITS loader found"); | |
455 | return kFALSE; | |
456 | } | |
457 | AliLoader* tpcLoader = fRunLoader->GetLoader("TPCLoader"); | |
458 | if (!tpcLoader) { | |
459 | Error("ReconstructITS", "no TPC loader found"); | |
460 | return kFALSE; | |
461 | } | |
462 | gSystem->Unlink("ITS.RecPoints.root"); | |
463 | gSystem->Unlink("ITS.Tracks.root"); | |
464 | ||
465 | // cluster finder | |
466 | Info("ReconstructITS", "reconstructing clusters..."); | |
467 | itsLoader->LoadRecPoints("recreate"); | |
468 | AliITSclustererV2 clusterer(fITSgeom); | |
469 | itsLoader->MakeRecPointsContainer(); | |
470 | clusterer.Digits2Clusters(rawReader); | |
471 | ||
472 | // track finder | |
473 | Info("ReconstructITS", "reconstructing tracks..."); | |
474 | itsLoader->LoadTracks("recreate"); | |
475 | itsLoader->MakeTracksContainer(); | |
476 | tpcLoader->LoadTracks(); | |
477 | AliITStrackerV2 tracker(fITSgeom); | |
478 | tracker.LoadClusters(itsLoader->TreeR()); | |
479 | tracker.Clusters2Tracks(tpcLoader->TreeT(), itsLoader->TreeT()); | |
480 | tracker.UnloadClusters(); | |
481 | itsLoader->WriteTracks("OVERWRITE"); | |
482 | ||
483 | itsLoader->UnloadRecPoints(); | |
484 | itsLoader->UnloadTracks(); | |
485 | tpcLoader->UnloadTracks(); | |
486 | return kTRUE; | |
487 | } | |
488 | ||
489 | //_____________________________________________________________________________ | |
490 | Bool_t AliMonitorProcess::ReconstructV0s() | |
491 | { | |
492 | // find V0s | |
493 | ||
494 | fStatus = kRecV0s; | |
495 | ||
496 | AliITSLoader* itsLoader = (AliITSLoader*) fRunLoader->GetLoader("ITSLoader"); | |
497 | if (!itsLoader) { | |
498 | Error("ReconstructV0", "no ITS loader found"); | |
499 | return kFALSE; | |
500 | } | |
501 | gSystem->Unlink("ITS.V0s.root"); | |
502 | ||
503 | // V0 finder | |
504 | Info("ReconstructV0s", "reconstructing V0s..."); | |
505 | itsLoader->LoadTracks("read"); | |
506 | itsLoader->LoadV0s("recreate"); | |
507 | AliV0vertexer vertexer; | |
508 | TTree* tracks = itsLoader->TreeT(); | |
509 | if (!tracks) { | |
510 | Error("ReconstructV0s", "no ITS tracks tree found"); | |
511 | return kFALSE; | |
512 | } | |
513 | if (!itsLoader->TreeV0()) itsLoader->MakeTree("V0"); | |
514 | TTree* v0s = itsLoader->TreeV0(); | |
515 | vertexer.Tracks2V0vertices(tracks, v0s); | |
516 | itsLoader->WriteV0s("OVERWRITE"); | |
517 | ||
518 | itsLoader->UnloadTracks(); | |
519 | itsLoader->UnloadV0s(); | |
520 | return kTRUE; | |
521 | } | |
522 | ||
97d6eb66 | 523 | //_____________________________________________________________________________ |
524 | #ifdef ALI_HLT | |
525 | void AliMonitorProcess::CreateHLT(const char* fileName) | |
526 | { | |
527 | // create the HLT (Level3) object | |
528 | ||
529 | if (fHLT) delete fHLT; | |
530 | ||
531 | char name[256]; | |
532 | strcpy(name, fileName); | |
533 | fHLT = new AliLevel3(name); | |
534 | fHLT->Init("./", AliLevel3::kRaw, 1); | |
535 | ||
536 | fHLT->SetClusterFinderParam(0, 0, kTRUE); | |
537 | ||
538 | Int_t phi_segments = 50; | |
539 | Int_t eta_segments = 100; | |
540 | Int_t trackletlength = 3; | |
541 | Int_t tracklength = 5; | |
542 | Int_t rowscopetracklet = 2; | |
543 | Int_t rowscopetrack = 2; | |
544 | Double_t min_pt_fit = 0; | |
545 | Double_t maxangle = 1.31; | |
546 | Double_t goodDist = 5; | |
547 | Double_t maxphi = 100; | |
548 | Double_t maxeta = 100; | |
549 | Double_t hitChi2Cut = 15;//100 | |
550 | Double_t goodHitChi2 = 5;//20; | |
551 | Double_t trackChi2Cut = 10; | |
552 | fHLT->SetTrackerParam(phi_segments, eta_segments, | |
553 | trackletlength, tracklength, | |
554 | rowscopetracklet, rowscopetrack, | |
555 | min_pt_fit, maxangle, goodDist, hitChi2Cut, | |
556 | goodHitChi2, trackChi2Cut, 50, maxphi, maxeta, kTRUE); | |
557 | ||
558 | fHLT->WriteFiles("./hlt/"); | |
559 | } | |
560 | #endif | |
561 | ||
562 | //_____________________________________________________________________________ | |
563 | Bool_t AliMonitorProcess::ReconstructHLT(Int_t iEvent) | |
564 | { | |
565 | // run the HLT cluster and track finder | |
566 | ||
567 | fStatus = kRecHLT; | |
568 | ||
569 | #ifndef ALI_HLT | |
570 | Warning("ReconstructHLT", "the code was compiled without HLT support"); | |
571 | return kTRUE; | |
572 | ||
573 | #else | |
574 | gSystem->Exec("rm -rf hlt"); | |
575 | gSystem->MakeDirectory("hlt"); | |
576 | if (!fHLT) return kFALSE; | |
577 | ||
578 | fHLT->ProcessEvent(0, 35, iEvent); | |
579 | ||
580 | // remove the event number from the file names | |
581 | char command[256]; | |
582 | sprintf(command, "rename points_%d points hlt/*.raw", iEvent); | |
583 | gSystem->Exec(command); | |
584 | sprintf(command, "rename tracks_tr_%d tracks_tr hlt/*.raw", iEvent); | |
585 | gSystem->Exec(command); | |
586 | sprintf(command, "rename tracks_gl_%d tracks_gl hlt/*.raw", iEvent); | |
587 | gSystem->Exec(command); | |
588 | sprintf(command, "rename tracks_%d tracks hlt/*.raw", iEvent); | |
589 | gSystem->Exec(command); | |
590 | return kTRUE; | |
591 | #endif | |
592 | } | |
593 | ||
04fa961a | 594 | |
595 | //_____________________________________________________________________________ | |
596 | Bool_t AliMonitorProcess::WriteHistos() | |
597 | { | |
598 | // write the monitor tree and the monitor histograms to the file | |
599 | // "monitor_<run number>[_<sub_run_number>].root" | |
600 | // if at least fNEventsMin events were monitored | |
601 | ||
602 | fStatus = kWriting; | |
603 | ||
604 | // rename tree file and create a new one | |
605 | fFile->cd(); | |
606 | fTree->Write(); | |
607 | fFile->Close(); | |
608 | delete fFile; | |
609 | ||
610 | char fileName[256]; | |
611 | sprintf(fileName, "monitor_tree_%d.root", fRunNumber); | |
612 | if (fSubRunNumber > 0) { | |
613 | sprintf(fileName, "monitor_tree_%d_%d.root", fRunNumber, fSubRunNumber); | |
614 | } | |
615 | if (fNEvents < fNEventsMin) { | |
616 | gSystem->Unlink("monitor_tree.root"); | |
617 | } else { | |
618 | gSystem->Rename("monitor_tree.root", fileName); | |
619 | } | |
620 | ||
621 | fFile = TFile::Open("monitor_tree.root", "RECREATE"); | |
622 | if (!fFile || !fFile->IsOpen()) { | |
623 | Fatal("WriteHistos", "could not open file for tree"); | |
624 | } | |
625 | fTree = new TTree("MonitorTree", "tree for monitoring"); | |
626 | for (Int_t iMonitor = 0; iMonitor < fMonitors.GetEntriesFast(); iMonitor++) { | |
627 | ((AliMonitor*) fMonitors[iMonitor])->CreateBranches(fTree); | |
628 | } | |
629 | gROOT->cd(); | |
630 | ||
631 | // write the histograms | |
632 | if (fNEvents < fNEventsMin) return kTRUE; | |
633 | ||
634 | if (!fWriteHistoList) { | |
635 | TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator(); | |
636 | while (TFolder* folder = (TFolder*) iFolder->Next()) { | |
637 | TIterator* iHisto = folder->GetListOfFolders()->MakeIterator(); | |
638 | while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) { | |
639 | histo->ResetList(); | |
640 | } | |
641 | delete iHisto; | |
642 | } | |
643 | delete iFolder; | |
644 | } | |
645 | ||
646 | Bool_t result = kTRUE; | |
647 | sprintf(fileName, "monitor_%d.root", fRunNumber); | |
648 | if (fSubRunNumber > 0) { | |
649 | sprintf(fileName, "monitor_%d_%d.root", fRunNumber, fSubRunNumber); | |
650 | } | |
651 | TFile* file = TFile::Open(fileName, "recreate"); | |
652 | if (!file || !file->IsOpen()) { | |
653 | Error("WriteHistos", "could not open file %s", fileName); | |
654 | result = kFALSE; | |
655 | } else { | |
656 | fTopFolder->Write(); | |
657 | file->Close(); | |
658 | } | |
659 | if (file) delete file; | |
660 | ||
661 | return result; | |
662 | } | |
663 | ||
664 | //_____________________________________________________________________________ | |
665 | void AliMonitorProcess::StartNewRun() | |
666 | { | |
667 | // reset the histograms for a new run | |
668 | ||
669 | fStatus = kResetting; | |
670 | TIterator* iFolder = fTopFolder->GetListOfFolders()->MakeIterator(); | |
671 | while (TFolder* folder = (TFolder*) iFolder->Next()) { | |
672 | TIterator* iHisto = folder->GetListOfFolders()->MakeIterator(); | |
673 | while (AliMonitorPlot* histo = (AliMonitorPlot*) iHisto->Next()) { | |
674 | histo->Reset(); | |
675 | } | |
676 | delete iHisto; | |
677 | } | |
678 | delete iFolder; | |
679 | ||
680 | fNEvents = 0; | |
681 | } | |
682 | ||
683 | ||
684 | //_____________________________________________________________________________ | |
685 | void AliMonitorProcess::CheckForConnections() | |
686 | { | |
687 | // check if new clients want to connect and add them to the list of sockets | |
688 | ||
689 | TMessage message(kMESS_OBJECT); | |
690 | message.WriteObject(fTopFolder); | |
691 | fStatus = kConnecting; | |
692 | ||
693 | TSocket* socket; | |
694 | while ((socket = fServerSocket->Accept()) != (TSocket*)-1) { | |
695 | char socketType[256]; | |
696 | if (!socket->Recv(socketType, 255)) continue; | |
697 | if (strcmp(socketType, "client") == 0) { | |
698 | if ((fNEvents == 0) || (socket->Send(message) >= 0)) { | |
699 | fSockets.Add(socket); | |
700 | TInetAddress adr = socket->GetInetAddress(); | |
701 | Info("CheckForConnections", "new client:\n %s (%s), port %d\n", | |
702 | adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()); | |
703 | } | |
704 | } else if (strcmp(socketType, "display") == 0) { | |
705 | if (fDisplaySocket) { | |
706 | fDisplaySocket->Close(); | |
707 | delete fDisplaySocket; | |
708 | } | |
709 | fDisplaySocket = socket; | |
710 | fDisplaySocket->SetOption(kNoBlock, 1); | |
711 | TInetAddress adr = socket->GetInetAddress(); | |
712 | Info("CheckForConnections", "new display:\n %s (%s), port %d\n", | |
713 | adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()); | |
714 | } | |
715 | } | |
716 | ||
717 | for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) { | |
718 | socket = (TSocket*) fSockets[iSocket]; | |
719 | if (!socket) continue; | |
720 | if (!socket->IsValid()) { | |
721 | // remove invalid sockets from the list | |
722 | TInetAddress adr = socket->GetInetAddress(); | |
723 | Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n", | |
724 | adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()); | |
725 | delete fSockets.RemoveAt(iSocket); | |
726 | } | |
727 | } | |
728 | fSockets.Compress(); | |
729 | } | |
730 | ||
731 | //_____________________________________________________________________________ | |
732 | void AliMonitorProcess::BroadcastHistos() | |
733 | { | |
734 | // send the monitor histograms to the clients | |
735 | ||
736 | fStatus = kBroadcasting; | |
737 | TMessage message(kMESS_OBJECT); | |
738 | message.WriteObject(fTopFolder); | |
739 | ||
740 | for (Int_t iSocket = 0; iSocket < fSockets.GetEntriesFast(); iSocket++) { | |
741 | TSocket* socket = (TSocket*) fSockets[iSocket]; | |
742 | if (!socket) continue; | |
743 | if (!socket->IsValid() || (socket->Send(message) < 0)) { | |
744 | // remove the socket from the list if there was an error | |
745 | TInetAddress adr = socket->GetInetAddress(); | |
746 | Info("BroadcastHistos", "disconnect client:\n %s (%s), port %d\n", | |
747 | adr.GetHostName(), adr.GetHostAddress(), adr.GetPort()); | |
748 | delete fSockets.RemoveAt(iSocket); | |
749 | } | |
750 | } | |
751 | fSockets.Compress(); | |
752 | } |