2 // Author: Matevz Tadel 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *)
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliOnlineReco.h"
11 #include "AliChildProcTerminator.h"
12 #include "AliDimIntNotifier.h"
13 #include "AliCDBManager.h"
14 #include "AliGRPPreprocessor.h"
18 #include <TGListBox.h>
21 #include <TInterpreter.h>
26 //______________________________________________________________________________
27 // Full description of AliOnlineReco
30 ClassImp(AliOnlineReco)
32 AliOnlineReco::AliOnlineReco() :
33 TGMainFrame(gClient->GetRoot(), 400, 400),
35 fRunList(0), fAutoRun(0), fStartButt(0), fStopButt(0), fExitButt(0),
36 fAutoRunTimer(0), fAutoRunScheduled(0), fAutoRunRunning(0),
43 fRunList = new TGListBox(this);
44 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
46 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 20);
48 fAutoRun = new TGCheckButton(hf, "AutoRun");
49 hf->AddFrame(fAutoRun, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
50 fAutoRun->Connect("Clicked()", "AliOnlineReco", this, "DoAutoRun()");
52 fStartButt = new TGTextButton(hf, "Start");
53 hf->AddFrame(fStartButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
54 fStartButt->Connect("Clicked()", "AliOnlineReco", this, "DoStart()");
56 fStopButt = new TGTextButton(hf, "Stop");
57 hf->AddFrame(fStopButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
58 fStopButt->Connect("Clicked()", "AliOnlineReco", this, "DoStop()");
60 fExitButt = new TGTextButton(hf, "Exit");
61 hf->AddFrame(fExitButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
62 fExitButt->Connect("Clicked()", "AliOnlineReco", this, "DoExit()");
64 AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
68 SetWindowName("Alice Online Reconstruction");
71 for (Int_t i = 0; i < 5; ++i)
75 fSOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
76 fEOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
80 fSOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i));
81 fEOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i));
84 fSOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "StartOfRun(Int_t)");
85 fEOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "EndOfRun(Int_t)");
88 const Int_t autoRunDelay = 10; // should go to config
89 fAutoRunTimer = new TTimer(autoRunDelay * 1000l);
90 fAutoRunTimer->Connect("Timeout()", "AliOnlineReco", this, "AutoRunTimerTimeout()");
93 // ROOT's TSignalHAndler works not SIGCHLD ...
94 AliChildProcTerminator::Instance()->Connect("ChildProcTerm(Int_t,Int_t)", "AliOnlineReco", this, "ChildProcTerm(Int_t,Int_t)");
97 AliOnlineReco::~AliOnlineReco()
101 delete fAutoRunTimer;
104 Int_t AliOnlineReco::GetLastRun() const
106 // Returns the last started run.
108 return fRun2PidMap.empty() ? 0 : fRun2PidMap.rbegin()->first;
111 Bool_t AliOnlineReco::GetAutoRunMode() const
113 // Return state of auto-run flag.
115 return fAutoRun->IsOn();
118 void AliOnlineReco::SetAutoRunMode(Bool_t ar)
120 // Set auto-run flag.
122 if (ar == fAutoRun->IsOn())
125 fAutoRun->SetState(ar ? kButtonDown : kButtonUp, kTRUE);
128 //------------------------------------------------------------------------------
130 //------------------------------------------------------------------------------
132 AliOnlineReco::mIntInt_i AliOnlineReco::FindMapEntryByPid(Int_t pid)
134 // Find run-to-pid map iterator by pid.
135 // Requires iteration over map.
137 for (mIntInt_i i = fRun2PidMap.begin(); i != fRun2PidMap.end(); ++i)
139 if (i->second == pid)
143 return fRun2PidMap.end();
146 void AliOnlineReco::StartAliEve(mIntInt_i& mi)
148 // Start alieve to process run given my the run-pid entry.
150 Int_t run = mi->first;
157 perror("DoStart -- Fork failed");
164 fRunList->RemoveEntry(run);
165 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
172 struct sigaction sac;
174 sigemptyset(&sac.sa_mask);
176 sigaction(SIGCHLD, &sac, 0);
181 s = execlp("alitestproc", "alitestproc", TString::Format("%d", run).Data(), (char*) 0);
185 Int_t procPID = gSystem->GetPid();
186 TString logFile = Form("%s/reco/log/run%d_%d.log",
187 gSystem->Getenv("ONLINERECO_BASE_DIR"),
190 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
191 gSystem->RedirectOutput(logFile.Data());
193 gSystem->cd(Form("%s/reco",gSystem->Getenv("ONLINERECO_BASE_DIR")));
196 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
199 gSystem->Setenv("DATE_RUN_NUMBER", Form("%d", run));
201 // AliCDBManager * man = AliCDBManager::Instance();
202 // man->SetDefaultStorage("local:///local/cdb");
203 // man->SetSpecificStorage("GRP/GRP/Data",
204 // Form("local://%s",gSystem->pwd()));
205 // man->SetSpecificStorage("GRP/CTP/Config",
206 // Form("local://%s",gSystem->pwd()));
207 // man->SetSpecificStorage("ACORDE/Align/Data",
208 // "local://$ALICE_ROOT/OCDB");
210 gSystem->mkdir(Form("run%d_%d", run, (Int_t)procPID));
211 gSystem->cd(Form("run%d_%d", run, (Int_t)procPID));
213 TString recMacroPath(gSystem->Getenv("ONLINERECO_MACRO"));
214 if (recMacroPath.IsNull()) {
215 recMacroPath = "$ALICE_ROOT/MONITOR/rec.C";
221 Form("%s(\"mem://@*:\")", gSystem->ExpandPathName(recMacroPath.Data())),
224 gSystem->Exec(Form("rm -rf %s/reco/run%d_%d",gSystem->Getenv("ONLINERECO_BASE_DIR"),run,(Int_t)procPID));
229 perror("execlp failed - this will not end well");
236 Error("DoStart", "Process already running.");
240 void AliOnlineReco::KillPid(Int_t pid)
242 // Terminate process given by pid.
244 // Send terminate signal to process ...
252 // alieve will auto-destruct on SIGUSR1
257 void AliOnlineReco::StartAutoRunTimer(Int_t run)
259 // Start timer for given run.
260 // If an auto-started run is already active, this call is ignored.
261 // If timer is already active, it is restarted.
266 fAutoRunTimer->Reset();
267 fAutoRunTimer->TurnOn();
268 fAutoRunScheduled = run;
270 Info("StartAutoRunTimer", "Scheduling run %d for auto-display.", run);
273 void AliOnlineReco::StopAutoRunTimer()
275 // Stop auto-run timer.
277 fAutoRunTimer->TurnOff();
278 fAutoRunScheduled = 0;
281 void AliOnlineReco::AutoRunTimerTimeout()
283 // Slot called on auto-timer timeout.
285 Int_t run = fAutoRunScheduled;
289 mIntInt_i i = fRun2PidMap.find(run);
291 if (i == fRun2PidMap.end())
293 Warning("AutoRunTimerTimeout", "run no longer active.");
297 Info("AutoRunTimerTimeout", "Starting display for run %d.", run);
300 fAutoRunRunning = run;
303 //------------------------------------------------------------------------------
304 // Handlers of DIM signals.
305 //------------------------------------------------------------------------------
307 void AliOnlineReco::StartOfRun(Int_t run)
309 // Slot called from DIM handler on start of run.
311 mIntInt_i i = fRun2PidMap.find(run);
312 if (i == fRun2PidMap.end())
314 fRun2PidMap[run] = 0;
315 fRunList->AddEntrySort(TString::Format("%d", run), run);
318 if (fAutoRun->IsOn())
320 StartAutoRunTimer(run);
325 Error("StartOfRun", "Run %d already registered.", run);
329 void AliOnlineReco::EndOfRun(Int_t run)
331 // Slot called from DIM handler on stop of run.
333 mIntInt_i i = fRun2PidMap.find(run);
334 if (i != fRun2PidMap.end())
336 Int_t pid = i->second;
337 fRunList->RemoveEntry(run);
339 fRun2PidMap.erase(i);
344 gClient->NeedRedraw(fRunList);
346 if (fAutoRunRunning == run)
353 Error("EndOfRun", "Run %d not registered.", run);
357 //------------------------------------------------------------------------------
358 // Handlers of OS signals.
359 //------------------------------------------------------------------------------
361 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
363 // Slot called on termination of child process.
365 printf("child process termination pid=%d, status=%d...\n", pid, status);
367 mIntInt_i i = FindMapEntryByPid(pid);
368 if (i != fRun2PidMap.end())
370 Int_t run = i->first;
371 fRunList->RemoveEntry(run);
374 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
378 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
383 if (fAutoRunRunning == run && fAutoRun->IsOn())
386 StartAutoRunTimer(run);
395 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
399 //------------------------------------------------------------------------------
400 // Handlers of button signals.
401 //------------------------------------------------------------------------------
403 void AliOnlineReco::DoAutoRun()
405 // Slot called from auto-run check-box.
407 Bool_t autoRun = fAutoRun->IsOn();
410 fStartButt->SetEnabled(kFALSE);
412 fStartButt->SetEnabled(kTRUE);
415 void AliOnlineReco::DoStart()
417 // Slot called from Start button.
419 Int_t run = fRunList->GetSelected();
420 mIntInt_i i = fRun2PidMap.find(run);
422 if (i == fRun2PidMap.end())
424 Error("DoStart", "no selection");
431 void AliOnlineReco::DoStop()
433 // Slot called from Stop button.
435 Int_t run = fRunList->GetSelected();
436 mIntInt_i i = fRun2PidMap.find(run);
438 if (i == fRun2PidMap.end())
440 Error("DoStop", "no selection");
444 Int_t pid = i->second;
451 Error("DoStop", "Process not running.");
455 void AliOnlineReco::DoExit()
457 // Slot called from Exit button.
462 void AliOnlineReco::CloseWindow()
464 // Virtual method called when window-manager close-window button is pressed.
469 Int_t AliOnlineReco::RetrieveGRP(UInt_t run, TString &gdc)
471 // Retrieve GRP entry for given run from aldaqdb.
473 TString dbHost = gSystem->Getenv("ONLINERECO_DB_HOST");
479 TString dbPort = gSystem->Getenv("ONLINERECO_DB_PORT");
485 TString dbName = gSystem->Getenv("ONLINERECO_DB_NAME");
491 TString user = gSystem->Getenv("ONLINERECO_DB_USER");
497 TString password = gSystem->Getenv("ONLINERECO_DB_PASSWORD");
498 if (password.IsNull())
503 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
504 dbPort.Atoi(), dbName.Data(),
505 user.Data(), password.Data(),
506 Form("local://%s",gSystem->pwd()),
509 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
510 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
511 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);