]>
Commit | Line | Data |
---|---|---|
7e0cf530 | 1 | // Author: Mihai Niculesu 2013 |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-2013, ALICE Experiment at CERN, all rights reserved. *) | |
5 | * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for * | |
6 | * full copyright notice. * | |
7 | **************************************************************************/ | |
8 | ||
9 | #include <TEnv.h> | |
10 | #include <TSystem.h> | |
11 | ||
12 | #include <TSQLServer.h> | |
13 | #include <TSQLResult.h> | |
14 | #include <TSQLRow.h> | |
15 | ||
16 | #include <TTimeStamp.h> | |
17 | #include <TTimer.h> | |
18 | ||
19 | #include <TGButton.h> | |
20 | #include <TGListBox.h> | |
21 | #include <TGTab.h> | |
22 | #include <TGTextEntry.h> | |
23 | #include <TGToolBar.h> | |
24 | #include <TG3DLine.h> | |
25 | ||
26 | #include <AliLog.h> | |
27 | #include <AliReconstruction.h> | |
164d3d29 | 28 | #include <AliDimIntNotifier.h> |
7e0cf530 | 29 | |
30 | #include "AliEventServerUtil.h" | |
31 | #include "AliEventServerWindow.h" | |
32 | #include "AliEventServerPreferencesWindow.h" | |
164d3d29 | 33 | #include "AliEventServerReconstruction.h" |
7e0cf530 | 34 | |
35 | //______________________________________________________________________________ | |
36 | // Full description of AliEventServerWindow | |
37 | // | |
38 | ||
39 | ClassImp(AliEventServerWindow) | |
40 | ||
41 | AliEventServerWindow::AliEventServerWindow() : | |
164d3d29 | 42 | TGMainFrame(gClient->GetRoot(), 400, 400), |
43 | fRunList(0), | |
44 | fStartServButt(0), | |
45 | fStopServButt(0), | |
46 | fExitButt(0), | |
47 | fRunRunning(0), | |
48 | fRecoServer(0) | |
7e0cf530 | 49 | { |
50 | SetCleanup(kDeepCleanup); | |
7e0cf530 | 51 | SetupToolbar(); |
52 | ||
53 | fRunList = new TGListBox(this); | |
54 | ||
55 | AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY)); | |
56 | ||
164d3d29 | 57 | for(Int_t i=0; i<5; ++i) |
58 | { | |
59 | fDimSORListener[i] = 0; | |
60 | fDimEORListener[i] = 0; | |
61 | } | |
7e0cf530 | 62 | |
164d3d29 | 63 | Connect("CloseWindow()", "AliEventServerWindow", this, "onExit()"); |
64 | SetWindowName("ALICE Event Server"); | |
7e0cf530 | 65 | |
164d3d29 | 66 | MapSubwindows(); |
67 | Resize(250,300); | |
68 | MapWindow(); | |
7e0cf530 | 69 | |
164d3d29 | 70 | FillRunsFromDatabase(); |
71 | InitDIMListeners(); | |
7e0cf530 | 72 | } |
73 | ||
74 | AliEventServerWindow::~AliEventServerWindow() | |
75 | { | |
7e0cf530 | 76 | for (Int_t i = 0; i < 5; ++i) |
77 | { | |
78 | if(fDimSORListener[i]) delete fDimSORListener[i]; | |
79 | if(fDimEORListener[i]) delete fDimEORListener[i]; | |
80 | ||
81 | fDimSORListener[i] = 0; | |
82 | fDimEORListener[i] = 0; | |
83 | } | |
7e0cf530 | 84 | } |
85 | ||
86 | void AliEventServerWindow::InitDIMListeners() | |
87 | { | |
88 | // DIM interface. | |
164d3d29 | 89 | for (Int_t i = 0; i < 5; ++i) |
90 | { | |
91 | if (i == 0) | |
92 | { | |
93 | fDimSORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS"); | |
94 | fDimEORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS"); | |
95 | } | |
96 | else | |
97 | { | |
98 | fDimSORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i)); | |
99 | fDimEORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i)); | |
100 | } | |
7e0cf530 | 101 | |
164d3d29 | 102 | fDimSORListener[i]->Connect("DimMessage(Int_t)", "AliEventServerWindow", this, "StartOfRun(Int_t)"); |
103 | fDimEORListener[i]->Connect("DimMessage(Int_t)", "AliEventServerWindow", this, "EndOfRun(Int_t)"); | |
104 | } | |
7e0cf530 | 105 | |
106 | } | |
107 | ||
108 | void AliEventServerWindow::FillRunsFromDatabase() | |
109 | { | |
666f0fc7 | 110 | TEnv settings; |
111 | settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser); | |
112 | ||
7e0cf530 | 113 | TString dbHost = settings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST); |
114 | TString dbPort = Form("%d", settings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT)); | |
115 | TString dbName = settings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB); | |
116 | TString user = settings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER); | |
117 | TString password = settings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS); | |
118 | ||
666f0fc7 | 119 | TString connStr = Form("mysql://%s:%s/%s", dbHost.Data(), dbPort.Data(), dbName.Data()) ; |
120 | ||
121 | AliInfo(Form("connecting to %s", connStr.Data()) ); | |
122 | ||
164d3d29 | 123 | TSQLServer* server = TSQLServer::Connect(connStr.Data(), user.Data(), password.Data()); |
124 | if (!server) | |
125 | { | |
126 | AliWarning("ERROR: Could not connect to DAQ Logbook"); | |
127 | return; | |
128 | } | |
129 | TString sqlQuery; | |
130 | TTimeStamp ts; | |
131 | sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND `partition` REGEXP 'PHYSICS.*'", | |
132 | (UInt_t)ts.GetSec()-86400); | |
133 | TSQLResult* result = server->Query(sqlQuery); | |
134 | if (!result) | |
135 | { | |
136 | AliWarning( Form("ERROR: Can't execute query <%s>!", sqlQuery.Data()) ); | |
137 | return; | |
138 | } | |
139 | if (result->GetRowCount() != 0) | |
140 | { | |
141 | for (Int_t iRow = 0; iRow < result->GetRowCount(); iRow++) | |
142 | { | |
143 | TSQLRow* row = result->Next(); | |
144 | TString runStr = row->GetField(0); | |
145 | if (runStr.IsDigit()) | |
146 | StartOfRun(runStr.Atoi()); | |
147 | delete row; | |
148 | } | |
149 | } | |
150 | delete result; | |
7e0cf530 | 151 | |
152 | } | |
153 | ||
154 | void AliEventServerWindow::SetupToolbar() | |
155 | { | |
156 | TGToolBar* mToolBar = new TGToolBar(this); | |
157 | mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/start.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_START ) ); | |
158 | mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/stop.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_STOP) ); | |
159 | mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/preferences.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_PREFERENCES) ); | |
160 | mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/exit.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_EXIT) ); | |
82de8691 | 161 | |
162 | TGTextButton *fakeButton= new TGTextButton(this,"Fake",TOOLBUTTON_FAKE); | |
7e0cf530 | 163 | |
82de8691 | 164 | fakeButton->Connect("Clicked()", "AliEventServerWindow", this, "onFake()"); |
7e0cf530 | 165 | mToolBar->Connect("Clicked(Int_t)", "AliEventServerWindow", this, "HandleToolBarAction(Int_t)"); |
166 | ||
167 | AddFrame(mToolBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX)); | |
168 | AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsNormal | kLHintsExpandX)); | |
82de8691 | 169 | AddFrame(fakeButton,new TGLayoutHints(kLHintsNormal)); |
7e0cf530 | 170 | } |
171 | ||
172 | void AliEventServerWindow::HandleToolBarAction(Int_t id) | |
173 | { | |
174 | if(id==-1) return; | |
175 | ||
176 | switch(id){ | |
177 | case TOOLBUTTON_START:{ | |
178 | onStartServer(); | |
179 | break; | |
180 | } | |
181 | case TOOLBUTTON_STOP:{ | |
182 | onStopServer(); | |
183 | break; | |
184 | } | |
185 | case TOOLBUTTON_PREFERENCES:{ | |
186 | new AliEventServerPreferencesWindow(this, "Settings"); | |
187 | break; | |
188 | } | |
189 | case TOOLBUTTON_EXIT:{ | |
190 | onExit(); | |
191 | break; | |
192 | } | |
164d3d29 | 193 | default:break; |
7e0cf530 | 194 | } |
195 | ||
196 | } | |
197 | ||
198 | /* | |
13a64a87 | 199 | void AliEventServerWindow::FinishedReconstruction(Int_t status) |
200 | { | |
201 | // Slot called on termination of child process. | |
202 | Int_t run = fServer->GetRunId(); | |
7e0cf530 | 203 | |
13a64a87 | 204 | Info("FinishedReconstruction", "Reconstruction Thread finished \tRunId:%d \tstatus=%d", run, status); |
7e0cf530 | 205 | |
13a64a87 | 206 | mIntInt_i i =fRun2PidMap.find(run); |
207 | if (i != fRun2PidMap.end()) | |
208 | { | |
209 | fRunList->RemoveEntry(run); | |
7e0cf530 | 210 | |
13a64a87 | 211 | // clean (remove) run's reconstructed directory |
212 | //gSystem->Exec(Form("rm -rf %s/reco/run%d_%d",gSystem->Getenv("ONLINERECO_BASE_DIR"),run,pid)); | |
7e0cf530 | 213 | |
13a64a87 | 214 | if (status == 0) |
215 | { | |
216 | fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run); | |
217 | } | |
218 | else | |
219 | { | |
220 | fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run); | |
221 | } | |
222 | fRunList->Layout(); | |
7e0cf530 | 223 | |
13a64a87 | 224 | } |
225 | else | |
226 | { | |
227 | Warning("FinishedReconstruction", "Run number %d not registered.", run); | |
228 | } | |
229 | ||
230 | }*/ | |
7e0cf530 | 231 | |
164d3d29 | 232 | //------------------------------------------------------------------------------ |
233 | // Private methods | |
234 | //------------------------------------------------------------------------------ | |
7e0cf530 | 235 | |
236 | void AliEventServerWindow::StartReco(Int_t run) | |
237 | { | |
82de8691 | 238 | TEnv settings; |
239 | settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser); | |
240 | ||
241 | TString dataSource = settings.GetValue("data.source", DEFAULT_DATA_SOURCE); | |
242 | TString eventSource; | |
243 | ||
244 | if(dataSource=="local") | |
245 | { | |
246 | AliInfo(Form("Starting Reco for run %d", run)); | |
247 | eventSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), run); | |
248 | } | |
249 | else if(dataSource=="run") | |
250 | { | |
251 | AliInfo("Starting Reco for GDCs active in current run"); | |
252 | eventSource = "mem://@*:"; | |
253 | } | |
254 | ||
164d3d29 | 255 | if(!fRecoServer) LaunchRecoServer(); |
7e0cf530 | 256 | |
164d3d29 | 257 | fRecoServer->StartReconstruction(run, eventSource.Data()); |
7e0cf530 | 258 | |
164d3d29 | 259 | if(fRecoServer->IsListenning()) |
260 | { | |
261 | fRunList->RemoveEntry(run); | |
262 | fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run); | |
263 | fRunList->Layout(); | |
264 | } | |
7e0cf530 | 265 | } |
266 | ||
267 | ||
268 | //------------------------------------------------------------------------------ | |
269 | // Handlers of DIM signals. | |
270 | //------------------------------------------------------------------------------ | |
271 | ||
272 | void AliEventServerWindow::StartOfRun(Int_t run) | |
273 | { | |
274 | if(run<=0) return; | |
275 | ||
164d3d29 | 276 | // Slot called from DIM handler on start of run. |
7e0cf530 | 277 | AliInfo(Form("called for Run %d ", run)); |
7e0cf530 | 278 | fRunList->AddEntrySort(TString::Format("%d", run), run); |
279 | fRunList->Layout(); | |
280 | gClient->NeedRedraw(fRunList); | |
13a64a87 | 281 | |
282 | if(fRecoServer){fRecoServer->StopReconstruction();} | |
7e0cf530 | 283 | StartReco(run); |
284 | } | |
285 | ||
286 | void AliEventServerWindow::EndOfRun(Int_t run) | |
287 | { | |
288 | if(run<=0) return; | |
289 | ||
164d3d29 | 290 | // Slot called from DIM handler on stop of run. |
7e0cf530 | 291 | AliInfo(Form("called for Run %d", run) ); |
13a64a87 | 292 | if(fRecoServer){fRecoServer->StopReconstruction();} |
7e0cf530 | 293 | |
13a64a87 | 294 | printf("Updating GUI"); |
164d3d29 | 295 | fRunList->RemoveEntry(run); |
296 | fRunList->Layout(); | |
297 | gClient->NeedRedraw(fRunList); | |
7e0cf530 | 298 | } |
299 | ||
300 | ///------------------------------------------------------------------------------ | |
301 | // Handlers of button signals. | |
302 | //------------------------------------------------------------------------------ | |
303 | ||
304 | void AliEventServerWindow::onStartServer() | |
305 | { | |
164d3d29 | 306 | // Slot called from Start button. |
307 | AliInfo("Starting server..."); | |
7e0cf530 | 308 | if(fRecoServer!=0) StopRecoServer(); |
309 | ||
310 | LaunchRecoServer(); | |
311 | } | |
312 | ||
313 | void AliEventServerWindow::onStopServer() | |
314 | { | |
164d3d29 | 315 | // Slot called from Stop button. |
7e0cf530 | 316 | AliInfo("Closing server..."); |
317 | ||
318 | StopRecoServer(); | |
319 | } | |
320 | ||
321 | void AliEventServerWindow::onExit() | |
322 | { | |
323 | AliInfo("Closing server & Exiting..."); | |
324 | ||
325 | StopRecoServer(); | |
326 | CloseWindow(); | |
327 | ||
328 | gSystem->ExitLoop(); | |
329 | } | |
330 | ||
82de8691 | 331 | void AliEventServerWindow::onFake() |
332 | { | |
333 | AliInfo("Faking Dim signal: starting reco for run 197669"); | |
334 | StartOfRun(197669); | |
335 | } | |
336 | ||
7e0cf530 | 337 | void AliEventServerWindow::LaunchRecoServer() |
338 | { | |
164d3d29 | 339 | fRecoServer = new AliEventServerReconstruction(); |
7e0cf530 | 340 | } |
341 | ||
342 | bool AliEventServerWindow::StopRecoServer() | |
343 | { | |
344 | if(fRecoServer==0) return true; | |
345 | ||
346 | AliInfo("Closing server and stoping process..."); | |
347 | ||
348 | delete fRecoServer; | |
349 | fRecoServer=0; | |
350 | ||
351 | return true; | |
352 | } |