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>
24 //______________________________________________________________________________
25 // Full description of AliOnlineReco
28 ClassImp(AliOnlineReco)
30 AliOnlineReco::AliOnlineReco() :
31 TGMainFrame(gClient->GetRoot(), 400, 400),
33 fRunList(0), fAutoRun(0), fStartButt(0), fStopButt(0), fExitButt(0),
34 fAutoRunTimer(0), fAutoRunScheduled(0), fAutoRunRunning(0),
39 fRunList = new TGListBox(this);
40 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
42 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 20);
44 fAutoRun = new TGCheckButton(hf, "AutoRun");
45 hf->AddFrame(fAutoRun, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
46 fAutoRun->Connect("Clicked()", "AliOnlineReco", this, "DoAutoRun()");
48 fStartButt = new TGTextButton(hf, "Start");
49 hf->AddFrame(fStartButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
50 fStartButt->Connect("Clicked()", "AliOnlineReco", this, "DoStart()");
52 fStopButt = new TGTextButton(hf, "Stop");
53 hf->AddFrame(fStopButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
54 fStopButt->Connect("Clicked()", "AliOnlineReco", this, "DoStop()");
56 fExitButt = new TGTextButton(hf, "Exit");
57 hf->AddFrame(fExitButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
58 fExitButt->Connect("Clicked()", "AliOnlineReco", this, "DoExit()");
60 AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
64 SetWindowName("Alice Online Reconstruction");
67 for (Int_t i = 0; i < 5; ++i)
71 fSOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
72 fEOR[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
76 fSOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i));
77 fEOR[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i));
80 fSOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "StartOfRun(Int_t)");
81 fEOR[i]->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "EndOfRun(Int_t)");
84 const Int_t autoRunDelay = 10; // should go to config
85 fAutoRunTimer = new TTimer(autoRunDelay * 1000l);
86 fAutoRunTimer->Connect("Timeout()", "AliOnlineReco", this, "AutoRunTimerTimeout()");
89 // ROOT's TSignalHAndler works not SIGCHLD ...
90 AliChildProcTerminator::Instance()->Connect("ChildProcTerm(Int_t,Int_t)", "AliOnlineReco", this, "ChildProcTerm(Int_t,Int_t)");
93 AliOnlineReco::~AliOnlineReco()
98 Int_t AliOnlineReco::GetLastRun() const
100 return fRun2PidMap.empty() ? 0 : fRun2PidMap.rbegin()->first;
103 Bool_t AliOnlineReco::GetAutoRunMode() const
105 return fAutoRun->IsOn();
108 void AliOnlineReco::SetAutoRunMode(Bool_t ar)
110 if (ar == fAutoRun->IsOn())
113 fAutoRun->SetState(ar ? kButtonDown : kButtonUp, kTRUE);
116 //------------------------------------------------------------------------------
118 //------------------------------------------------------------------------------
120 AliOnlineReco::mIntInt_i AliOnlineReco::FindMapEntryByPid(Int_t pid)
122 for (mIntInt_i i = fRun2PidMap.begin(); i != fRun2PidMap.end(); ++i)
124 if (i->second == pid)
128 return fRun2PidMap.end();
131 void AliOnlineReco::StartAliEve(mIntInt_i& mi)
133 Int_t run = mi->first;
140 perror("DoStart -- Fork failed");
147 fRunList->RemoveEntry(run);
148 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
156 s = execlp("alitestproc", "alitestproc", TString::Format("%d", run).Data(), (char*) 0);
160 Int_t procPID = gSystem->GetPid();
161 TString logFile = Form("%s/reco/log/run%d_%d.log",
162 gSystem->Getenv("ONLINERECO_BASE_DIR"),
165 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
166 gSystem->RedirectOutput(logFile.Data());
168 gSystem->cd(Form("%s/reco",gSystem->Getenv("ONLINERECO_BASE_DIR")));
171 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull())
174 gSystem->Setenv("DATE_RUN_NUMBER", Form("%d", run));
176 // AliCDBManager * man = AliCDBManager::Instance();
177 // man->SetDefaultStorage("local:///local/cdb");
178 // man->SetSpecificStorage("GRP/GRP/Data",
179 // Form("local://%s",gSystem->pwd()));
180 // man->SetSpecificStorage("GRP/CTP/Config",
181 // Form("local://%s",gSystem->pwd()));
182 // man->SetSpecificStorage("ACORDE/Align/Data",
183 // "local://$ALICE_ROOT/OCDB");
185 gSystem->mkdir(Form("run%d_%d", run, (Int_t)procPID));
186 gSystem->cd(Form("run%d_%d", run, (Int_t)procPID));
188 TString recMacroPath(gSystem->Getenv("ONLINERECO_MACRO"));
189 if (recMacroPath.IsNull()) {
190 recMacroPath = "$ALICE_ROOT/MONITOR/rec.C";
196 Form("%s(\"mem://@*:\")", gSystem->ExpandPathName(recMacroPath.Data())),
202 perror("execlp failed - this will not end well");
209 Error("DoStart", "Process already running.");
213 void AliOnlineReco::KillPid(Int_t pid)
215 // Send terminate signal to process ...
223 // alieve will auto-destruct on SIGUSR1
228 void AliOnlineReco::StartAutoRunTimer(Int_t run)
230 // Start timer for given run.
231 // If an auto-started run is already active, this call is ignored.
232 // If timer is already active, it is restarted.
237 fAutoRunTimer->Reset();
238 fAutoRunTimer->TurnOn();
239 fAutoRunScheduled = run;
241 Info("StartAutoRunTimer", "Scheduling run %d for auto-display.", run);
244 void AliOnlineReco::StopAutoRunTimer()
246 fAutoRunTimer->TurnOff();
247 fAutoRunScheduled = 0;
250 void AliOnlineReco::AutoRunTimerTimeout()
252 Int_t run = fAutoRunScheduled;
256 mIntInt_i i = fRun2PidMap.find(run);
258 if (i == fRun2PidMap.end())
260 Warning("AutoRunTimerTimeout", "run no longer active.");
264 Info("AutoRunTimerTimeout", "Starting display for run %d.", run);
267 fAutoRunRunning = run;
270 //------------------------------------------------------------------------------
271 // Handlers of DIM signals.
272 //------------------------------------------------------------------------------
274 void AliOnlineReco::StartOfRun(Int_t run)
276 mIntInt_i i = fRun2PidMap.find(run);
277 if (i == fRun2PidMap.end())
279 fRun2PidMap[run] = 0;
280 fRunList->AddEntrySort(TString::Format("%d", run), run);
283 if (fAutoRun->IsOn())
285 StartAutoRunTimer(run);
290 Error("StartOfRun", "Run %d already registered.", run);
294 void AliOnlineReco::EndOfRun(Int_t run)
296 mIntInt_i i = fRun2PidMap.find(run);
297 if (i != fRun2PidMap.end())
299 Int_t pid = i->second;
300 fRunList->RemoveEntry(run);
302 fRun2PidMap.erase(i);
307 gClient->NeedRedraw(fRunList);
309 if (fAutoRunRunning == run)
316 Error("EndOfRun", "Run %d not registered.", run);
320 //------------------------------------------------------------------------------
321 // Handlers of OS signals.
322 //------------------------------------------------------------------------------
324 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
326 printf("child process termination pid=%d, status=%d...\n", pid, status);
328 mIntInt_i i = FindMapEntryByPid(pid);
329 if (i != fRun2PidMap.end())
331 Int_t run = i->first;
332 fRunList->RemoveEntry(run);
335 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
339 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
344 if (fAutoRunRunning == run && fAutoRun->IsOn())
347 StartAutoRunTimer(run);
356 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
360 //------------------------------------------------------------------------------
361 // Handlers of button signals.
362 //------------------------------------------------------------------------------
364 void AliOnlineReco::DoAutoRun()
366 Bool_t autoRun = fAutoRun->IsOn();
369 fStartButt->SetEnabled(kFALSE);
371 fStartButt->SetEnabled(kTRUE);
374 void AliOnlineReco::DoStart()
376 Int_t run = fRunList->GetSelected();
377 mIntInt_i i = fRun2PidMap.find(run);
379 if (i == fRun2PidMap.end())
381 Error("DoStart", "no selection");
388 void AliOnlineReco::DoStop()
390 Int_t run = fRunList->GetSelected();
391 mIntInt_i i = fRun2PidMap.find(run);
393 if (i == fRun2PidMap.end())
395 Error("DoStop", "no selection");
399 Int_t pid = i->second;
406 Error("DoStop", "Process not running.");
410 void AliOnlineReco::DoExit()
415 void AliOnlineReco::CloseWindow()
420 Int_t AliOnlineReco::RetrieveGRP(UInt_t run, TString &gdc) {
422 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, "aldaqdb", 0, "LOGBOOK", "logbook", "alice",
423 Form("local://%s",gSystem->pwd()),
425 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
426 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
427 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);