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"
14 #include <TGListBox.h>
20 //______________________________________________________________________________
21 // Full description of AliOnlineReco
24 ClassImp(AliOnlineReco)
26 AliOnlineReco::AliOnlineReco() :
27 TGMainFrame(gClient->GetRoot(), 400, 400),
29 fRunList(0), fStartButt(0), fStopButt(0), fXyzzButt(0),
31 fSOR(new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS")),
32 fEOR(new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS")),
37 fRunList = new TGListBox(this);
38 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
40 TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 20);
42 fStartButt = new TGTextButton(hf, "Start");
43 hf->AddFrame(fStartButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
44 fStartButt->Connect("Clicked()", "AliOnlineReco", this, "DoStart()");
46 fStopButt = new TGTextButton(hf, "Stop");
47 hf->AddFrame(fStopButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
48 fStopButt->Connect("Clicked()", "AliOnlineReco", this, "DoStop()");
50 fXyzzButt = new TGTextButton(hf, "Exit");
51 hf->AddFrame(fXyzzButt, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
52 fXyzzButt->Connect("Clicked()", "AliOnlineReco", this, "DoXyzz()");
54 AddFrame(hf, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
58 SetWindowName("Alice Online Reconstruction");
61 fSOR->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "StartOfRun(Int_t)");
62 fEOR->Connect("DimMessage(Int_t)", "AliOnlineReco", this, "EndOfRun(Int_t)");
65 // ROOT's TSignalHAndler works not SIGCHLD ...
66 AliChildProcTerminator::Instance()->Connect("ChildProcTerm(Int_t,Int_t)", "AliOnlineReco", this, "ChildProcTerm(Int_t,Int_t)");
69 AliOnlineReco::mIntInt_i AliOnlineReco::FindMapEntryByPid(Int_t pid)
71 for (mIntInt_i i = fRun2PidMap.begin(); i != fRun2PidMap.end(); ++i)
77 return fRun2PidMap.end();
80 //------------------------------------------------------------------------------
81 // Handlers of DIM signals.
82 //------------------------------------------------------------------------------
84 void AliOnlineReco::StartOfRun(Int_t run)
86 mIntInt_i i = fRun2PidMap.find(run);
87 if (i == fRun2PidMap.end())
90 fRunList->AddEntrySort(TString::Format("%d", run), run);
95 Error("StartOfRun", "Run %d already registered.", run);
99 void AliOnlineReco::EndOfRun(Int_t run)
101 mIntInt_i i = fRun2PidMap.find(run);
102 if (i != fRun2PidMap.end())
104 Int_t pid = i->second;
105 fRunList->RemoveEntry(run);
107 fRun2PidMap.erase(i);
110 // Send terminate signal to process ...
117 // alieve will auto-destruct on SIGUSR1
121 gClient->NeedRedraw(fRunList);
125 Error("EndOfRun", "Run %d not registered.", run);
129 //------------------------------------------------------------------------------
130 // Handlers of OS signals.
131 //------------------------------------------------------------------------------
133 void AliOnlineReco::ChildProcTerm(Int_t pid, Int_t status)
135 printf("child process termination pid=%d, status=%d...\n", pid, status);
137 mIntInt_i i = FindMapEntryByPid(pid);
138 if (i != fRun2PidMap.end())
140 Int_t run = i->first;
141 fRunList->RemoveEntry(run);
144 fRunList->AddEntrySort(TString::Format("%-20d -- FINISHED", run), run);
148 fRunList->AddEntrySort(TString::Format("%-20d -- CRASHED [%d]", run, status), run);
155 Warning("ChildProcTerm", "Process with pid=%d not registered.", pid);
159 //------------------------------------------------------------------------------
160 // Handlers of button signals.
161 //------------------------------------------------------------------------------
163 void AliOnlineReco::DoStart()
165 Int_t run = fRunList->GetSelected();
166 mIntInt_i i = fRun2PidMap.find(run);
168 if (i == fRun2PidMap.end())
170 Error("DoStart", "no selection");
179 perror("DoStart -- Fork failed");
186 fRunList->RemoveEntry(run);
187 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
195 s = execlp("alitestproc", "alitestproc", TString::Format("%d", run).Data(), (char*) 0);
199 // !!!! Cvetan, add proper args here ...
200 s = execlp("alieve", "alieve", TString::Format("%d", run).Data(), (char*) 0);
205 perror("execlp failed - this will not end well");
212 Error("DoStart", "Process already running.");
216 void AliOnlineReco::DoStop()
218 Int_t run = fRunList->GetSelected();
219 mIntInt_i i = fRun2PidMap.find(run);
221 if (i == fRun2PidMap.end())
223 Error("DoStop", "no selection");
227 Int_t pid = i->second;
236 // alieve will auto-destruct on SIGUSR1
242 Error("DoStop", "Process not running.");
246 void AliOnlineReco::DoXyzz()
251 void AliOnlineReco::CloseWindow()