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),
41 fRunList = new TGListBox(this);
42 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
44 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 20);
46 fAutoRun = new TGCheckButton(hf, "AutoRun");
47 hf->AddFrame(fAutoRun, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
48 fAutoRun->Connect("Clicked()", "AliOnlineReco", this, "DoAutoRun()");
50 fStartButt = new TGTextButton(hf, "Start");
51 hf->AddFrame(fStartButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
52 fStartButt->Connect("Clicked()", "AliOnlineReco", this, "DoStart()");
54 fStopButt = new TGTextButton(hf, "Stop");
55 hf->AddFrame(fStopButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
56 fStopButt->Connect("Clicked()", "AliOnlineReco", this, "DoStop()");
58 fExitButt = new TGTextButton(hf, "Exit");
59 hf->AddFrame(fExitButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
60 fExitButt->Connect("Clicked()", "AliOnlineReco", this, "DoExit()");
62 AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
66 SetWindowName("Alice Online Reconstruction");
69 for (Int_t i = 0; i < 5; ++i)
73 fSOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
74 fEOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
78 fSOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i));
79 fEOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i));
82 fSOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "StartOfRun(Int_t)");
83 fEOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "EndOfRun(Int_t)");
86 const Int_t autoRunDelay = 10; // should go to config
87 fAutoRunTimer = new TTimer(autoRunDelay * 1000l);
88 fAutoRunTimer->Connect("Timeout()", "AliOnlineReco", this, "AutoRunTimerTimeout()");
91 // ROOT's TSignalHAndler works not SIGCHLD ...
92 AliChildProcTerminator::Instance()->Connect("ChildProcTerm(Int_t,Int_t)", "AliOnlineReco", this, "ChildProcTerm(Int_t,Int_t)");
95 AliOnlineReco::~AliOnlineReco()
100 Int_t AliOnlineReco::GetLastRun() const
102 return fRun2PidMap.empty() ? 0 : fRun2PidMap.rbegin()->first;
105 Bool_t AliOnlineReco::GetAutoRunMode() const
107 return fAutoRun->IsOn();
110 void AliOnlineReco::SetAutoRunMode(Bool_t ar)
112 if (ar == fAutoRun->IsOn())
115 fAutoRun->SetState(ar ? kButtonDown : kButtonUp, kTRUE);
118 //------------------------------------------------------------------------------
120 //------------------------------------------------------------------------------
122 AliOnlineReco::mIntInt_i AliOnlineReco::FindMapEntryByPid(Int_t pid)
124 for (mIntInt_i i = fRun2PidMap.begin(); i != fRun2PidMap.end(); ++i)
126 if (i->second == pid)
130 return fRun2PidMap.end();
133 void AliOnlineReco::StartAliEve(mIntInt_i& mi)
135 Int_t run = mi->first;
142 perror("DoStart -- Fork failed");
149 fRunList->RemoveEntry(run);
150 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
157 struct sigaction sac;
159 sigemptyset(&sac.sa_mask);
161 sigaction(SIGCHLD, &sac, 0);
166 s = execlp("alitestproc", "alitestproc", TString::Format("%d", run).Data(), (char*) 0);
170 Int_t procPID = gSystem->GetPid();
171 TString logFile = Form("%s/reco/log/run%d_%d.log",
172 gSystem->Getenv("ONLINERECO_BASE_DIR"),
175 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
176 gSystem->RedirectOutput(logFile.Data());
178 gSystem->cd(Form("%s/reco",gSystem->Getenv("ONLINERECO_BASE_DIR")));
181 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
184 gSystem->Setenv("DATE_RUN_NUMBER", Form("%d", run));
186 // AliCDBManager * man = AliCDBManager::Instance();
187 // man->SetDefaultStorage("local:///local/cdb");
188 // man->SetSpecificStorage("GRP/GRP/Data",
189 // Form("local://%s",gSystem->pwd()));
190 // man->SetSpecificStorage("GRP/CTP/Config",
191 // Form("local://%s",gSystem->pwd()));
192 // man->SetSpecificStorage("ACORDE/Align/Data",
193 // "local://$ALICE_ROOT/OCDB");
195 gSystem->mkdir(Form("run%d_%d", run, (Int_t)procPID));
196 gSystem->cd(Form("run%d_%d", run, (Int_t)procPID));
198 TString recMacroPath(gSystem->Getenv("ONLINERECO_MACRO"));
199 if (recMacroPath.IsNull()) {
200 recMacroPath = "$ALICE_ROOT/MONITOR/rec.C";
206 Form("%s(\"mem://@*:\")", gSystem->ExpandPathName(recMacroPath.Data())),
212 perror("execlp failed - this will not end well");
219 Error("DoStart", "Process already running.");
223 void AliOnlineReco::KillPid(Int_t pid)
225 // Send terminate signal to process ...
233 // alieve will auto-destruct on SIGUSR1
238 void AliOnlineReco::StartAutoRunTimer(Int_t run)
240 // Start timer for given run.
241 // If an auto-started run is already active, this call is ignored.
242 // If timer is already active, it is restarted.
247 fAutoRunTimer->Reset();
248 fAutoRunTimer->TurnOn();
249 fAutoRunScheduled = run;
251 Info("StartAutoRunTimer", "Scheduling run %d for auto-display.", run);
254 void AliOnlineReco::StopAutoRunTimer()
256 fAutoRunTimer->TurnOff();
257 fAutoRunScheduled = 0;
260 void AliOnlineReco::AutoRunTimerTimeout()
262 Int_t run = fAutoRunScheduled;
266 mIntInt_i i = fRun2PidMap.find(run);
268 if (i == fRun2PidMap.end())
270 Warning("AutoRunTimerTimeout", "run no longer active.");
274 Info("AutoRunTimerTimeout", "Starting display for run %d.", run);
277 fAutoRunRunning = run;
280 //------------------------------------------------------------------------------
281 // Handlers of DIM signals.
282 //------------------------------------------------------------------------------
284 void AliOnlineReco::StartOfRun(Int_t run)
286 mIntInt_i i = fRun2PidMap.find(run);
287 if (i == fRun2PidMap.end())
289 fRun2PidMap[run] = 0;
290 fRunList->AddEntrySort(TString::Format("%d", run), run);
293 if (fAutoRun->IsOn())
295 StartAutoRunTimer(run);
300 Error("StartOfRun", "Run %d already registered.", run);
304 void AliOnlineReco::EndOfRun(Int_t run)
306 mIntInt_i i = fRun2PidMap.find(run);
307 if (i != fRun2PidMap.end())
309 Int_t pid = i->second;
310 fRunList->RemoveEntry(run);
312 fRun2PidMap.erase(i);
317 gClient->NeedRedraw(fRunList);
319 if (fAutoRunRunning == run)
326 Error("EndOfRun", "Run %d not registered.", run);
330 //------------------------------------------------------------------------------
331 // Handlers of OS signals.
332 //------------------------------------------------------------------------------
334 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
336 printf("child process termination pid=%d, status=%d...\n", pid, status);
338 mIntInt_i i = FindMapEntryByPid(pid);
339 if (i != fRun2PidMap.end())
341 Int_t run = i->first;
342 fRunList->RemoveEntry(run);
345 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
349 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
354 if (fAutoRunRunning == run && fAutoRun->IsOn())
357 StartAutoRunTimer(run);
366 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
370 //------------------------------------------------------------------------------
371 // Handlers of button signals.
372 //------------------------------------------------------------------------------
374 void AliOnlineReco::DoAutoRun()
376 Bool_t autoRun = fAutoRun->IsOn();
379 fStartButt->SetEnabled(kFALSE);
381 fStartButt->SetEnabled(kTRUE);
384 void AliOnlineReco::DoStart()
386 Int_t run = fRunList->GetSelected();
387 mIntInt_i i = fRun2PidMap.find(run);
389 if (i == fRun2PidMap.end())
391 Error("DoStart", "no selection");
398 void AliOnlineReco::DoStop()
400 Int_t run = fRunList->GetSelected();
401 mIntInt_i i = fRun2PidMap.find(run);
403 if (i == fRun2PidMap.end())
405 Error("DoStop", "no selection");
409 Int_t pid = i->second;
416 Error("DoStop", "Process not running.");
420 void AliOnlineReco::DoExit()
425 void AliOnlineReco::CloseWindow()
430 Int_t AliOnlineReco::RetrieveGRP(UInt_t run, TString &gdc) {
432 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, "aldaqdb", 0, "LOGBOOK", "logbook", "alice",
433 Form("local://%s",gSystem->pwd()),
435 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
436 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
437 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);