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