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 const char *recMacroPath = "$ALICE_ROOT/test/cosmic/rec.C";
193 Form("%s(\"mem://@*:\")", gSystem->ExpandPathName(recMacroPath)),
199 perror("execlp failed - this will not end well");
206 Error("DoStart", "Process already running.");
210 void AliOnlineReco::KillPid(Int_t pid)
212 // Send terminate signal to process ...
220 // alieve will auto-destruct on SIGUSR1
225 void AliOnlineReco::StartAutoRunTimer(Int_t run)
227 // Start timer for given run.
228 // If an auto-started run is already active, this call is ignored.
229 // If timer is already active, it is restarted.
234 fAutoRunTimer->Reset();
235 fAutoRunTimer->TurnOn();
236 fAutoRunScheduled = run;
238 Info("StartAutoRunTimer", "Scheduling run %d for auto-display.", run);
241 void AliOnlineReco::StopAutoRunTimer()
243 fAutoRunTimer->TurnOff();
244 fAutoRunScheduled = 0;
247 void AliOnlineReco::AutoRunTimerTimeout()
249 Int_t run = fAutoRunScheduled;
253 mIntInt_i i = fRun2PidMap.find(run);
255 if (i == fRun2PidMap.end())
257 Warning("AutoRunTimerTimeout", "run no longer active.");
261 Info("AutoRunTimerTimeout", "Starting display for run %d.", run);
264 fAutoRunRunning = run;
267 //------------------------------------------------------------------------------
268 // Handlers of DIM signals.
269 //------------------------------------------------------------------------------
271 void AliOnlineReco::StartOfRun(Int_t run)
273 mIntInt_i i = fRun2PidMap.find(run);
274 if (i == fRun2PidMap.end())
276 fRun2PidMap[run] = 0;
277 fRunList->AddEntrySort(TString::Format("%d", run), run);
280 if (fAutoRun->IsOn())
282 StartAutoRunTimer(run);
287 Error("StartOfRun", "Run %d already registered.", run);
291 void AliOnlineReco::EndOfRun(Int_t run)
293 mIntInt_i i = fRun2PidMap.find(run);
294 if (i != fRun2PidMap.end())
296 Int_t pid = i->second;
297 fRunList->RemoveEntry(run);
299 fRun2PidMap.erase(i);
304 gClient->NeedRedraw(fRunList);
306 if (fAutoRunRunning == run)
313 Error("EndOfRun", "Run %d not registered.", run);
317 //------------------------------------------------------------------------------
318 // Handlers of OS signals.
319 //------------------------------------------------------------------------------
321 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
323 printf("child process termination pid=%d, status=%d...\n", pid, status);
325 mIntInt_i i = FindMapEntryByPid(pid);
326 if (i != fRun2PidMap.end())
328 Int_t run = i->first;
329 fRunList->RemoveEntry(run);
332 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
336 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
341 if (fAutoRunRunning == run && fAutoRun->IsOn())
344 StartAutoRunTimer(run);
353 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
357 //------------------------------------------------------------------------------
358 // Handlers of button signals.
359 //------------------------------------------------------------------------------
361 void AliOnlineReco::DoAutoRun()
363 Bool_t autoRun = fAutoRun->IsOn();
366 fStartButt->SetEnabled(kFALSE);
368 fStartButt->SetEnabled(kTRUE);
371 void AliOnlineReco::DoStart()
373 Int_t run = fRunList->GetSelected();
374 mIntInt_i i = fRun2PidMap.find(run);
376 if (i == fRun2PidMap.end())
378 Error("DoStart", "no selection");
385 void AliOnlineReco::DoStop()
387 Int_t run = fRunList->GetSelected();
388 mIntInt_i i = fRun2PidMap.find(run);
390 if (i == fRun2PidMap.end())
392 Error("DoStop", "no selection");
396 Int_t pid = i->second;
403 Error("DoStop", "Process not running.");
407 void AliOnlineReco::DoExit()
412 void AliOnlineReco::CloseWindow()
417 Int_t AliOnlineReco::RetrieveGRP(UInt_t run, TString &gdc) {
419 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, "aldaqdb", 0, "LOGBOOK", "logbook", "alice",
420 Form("local://%s",gSystem->pwd()),
422 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
423 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
424 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);