1 // Author: Mihai Niculesu 2013
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 **************************************************************************/
12 #include <TSQLServer.h>
13 #include <TSQLResult.h>
16 #include <TTimeStamp.h>
20 #include <TGListBox.h>
22 #include <TGTextEntry.h>
23 #include <TGToolBar.h>
27 #include <AliReconstruction.h>
29 #include "AliEventServerUtil.h"
30 #include "AliEventServerWindow.h"
31 #include "AliEventServerPreferencesWindow.h"
32 #include "AliDimIntNotifier.h"
33 #include "AliRecoServer.h"
35 //______________________________________________________________________________
36 // Full description of AliEventServerWindow
39 ClassImp(AliEventServerWindow)
41 AliEventServerWindow::AliEventServerWindow() :
42 TGMainFrame(gClient->GetRoot(), 400, 400),
50 SetCleanup(kDeepCleanup);
54 fRunList = new TGListBox(this);
56 AddFrame(fRunList, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
58 for(Int_t i=0; i<5; ++i)
60 fDimSORListener[i] = 0;
61 fDimEORListener[i] = 0;
64 Connect("CloseWindow()", "AliEventServerWindow", this, "onExit()");
65 SetWindowName("ALICE Event Server");
71 FillRunsFromDatabase();
75 AliEventServerWindow::~AliEventServerWindow()
79 for (Int_t i = 0; i < 5; ++i)
81 if(fDimSORListener[i]) delete fDimSORListener[i];
82 if(fDimEORListener[i]) delete fDimEORListener[i];
84 fDimSORListener[i] = 0;
85 fDimEORListener[i] = 0;
90 void AliEventServerWindow::InitDIMListeners()
93 for (Int_t i = 0; i < 5; ++i)
97 fDimSORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
98 fDimEORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
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));
106 fDimSORListener[i]->Connect("DimMessage(Int_t)", "AliEventServerWindow", this, "StartOfRun(Int_t)");
107 fDimEORListener[i]->Connect("DimMessage(Int_t)", "AliEventServerWindow", this, "EndOfRun(Int_t)");
112 void AliEventServerWindow::FillRunsFromDatabase()
114 TEnv settings(ALIEVENTSERVER_CONF);
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);
122 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%s/%s", dbHost.Data(), dbPort.Data(), dbName.Data()), user.Data(), password.Data());
124 AliWarning("ERROR: Could not connect to DAQ Logbook");
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);
134 AliWarning( Form("ERROR: Can't execute query <%s>!", sqlQuery.Data()) );
137 if (result->GetRowCount() != 0)
139 for (Int_t iRow = 0; iRow < result->GetRowCount(); iRow++)
141 TSQLRow* row = result->Next();
142 TString runStr = row->GetField(0);
143 if (runStr.IsDigit())
144 StartOfRun(runStr.Atoi());
152 void AliEventServerWindow::SetupToolbar()
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) );
160 mToolBar->Connect("Clicked(Int_t)", "AliEventServerWindow", this, "HandleToolBarAction(Int_t)");
162 AddFrame(mToolBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
163 AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
166 void AliEventServerWindow::HandleToolBarAction(Int_t id)
171 case TOOLBUTTON_START:{
175 case TOOLBUTTON_STOP:{
179 case TOOLBUTTON_PREFERENCES:{
180 new AliEventServerPreferencesWindow(this, "Settings");
183 case TOOLBUTTON_EXIT:{
193 void AliEventServerWindow::FinishedReconstruction(Int_t status)
195 // Slot called on termination of child process.
196 Int_t run = fServer->GetRunId();
198 Info("FinishedReconstruction", "Reconstruction Thread finished \tRunId:%d \tstatus=%d", run, status);
200 mIntInt_i i =fRun2PidMap.find(run);
201 if (i != fRun2PidMap.end())
203 fRunList->RemoveEntry(run);
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));
210 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
214 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
221 Warning("FinishedReconstruction", "Run number %d not registered.", run);
226 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
230 void AliEventServerWindow::StartReco(Int_t run)
232 AliInfo(Form("Starting Reco for run %d", run));
234 TString eventSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), run);
236 if(!fRecoServer) LaunchRecoServer();
238 fRecoServer->StartReconstruction(run, eventSource.Data());
240 if(fRecoServer->IsListenning()){
241 fRunList->RemoveEntry(run);
242 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
248 //------------------------------------------------------------------------------
249 // Handlers of DIM signals.
250 //------------------------------------------------------------------------------
252 void AliEventServerWindow::StartOfRun(Int_t run)
256 // Slot called from DIM handler on start of run.
257 AliInfo(Form("called for Run %d ", run));
259 fRunList->AddEntrySort(TString::Format("%d", run), run);
261 gClient->NeedRedraw(fRunList);
266 void AliEventServerWindow::EndOfRun(Int_t run)
270 // Slot called from DIM handler on stop of run.
271 AliInfo(Form("called for Run %d", run) );
272 if(fRecoServer) fRecoServer->StopReconstruction();
274 fRunList->RemoveEntry(run);
276 gClient->NeedRedraw(fRunList);
279 ///------------------------------------------------------------------------------
280 // Handlers of button signals.
281 //------------------------------------------------------------------------------
283 void AliEventServerWindow::onStartServer()
285 // Slot called from Start button.
286 AliInfo("Starting server...");
287 if(fRecoServer!=0) StopRecoServer();
292 void AliEventServerWindow::onStopServer()
294 // Slot called from Stop button.
295 AliInfo("Closing server...");
300 void AliEventServerWindow::onExit()
302 AliInfo("Closing server & Exiting...");
310 void AliEventServerWindow::LaunchRecoServer()
312 fRecoServer = new AliRecoServer;
315 bool AliEventServerWindow::StopRecoServer()
317 if(fRecoServer==0) return true;
319 AliInfo("Closing server and stoping process...");