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()
115 settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
117 TString dbHost = settings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
118 TString dbPort = Form("%d", settings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT));
119 TString dbName = settings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
120 TString user = settings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
121 TString password = settings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
123 TString connStr = Form("mysql://%s:%s/%s", dbHost.Data(), dbPort.Data(), dbName.Data()) ;
125 AliInfo(Form("connecting to %s", connStr.Data()) );
127 TSQLServer* server = TSQLServer::Connect(connStr.Data(), user.Data(), password.Data());
129 AliWarning("ERROR: Could not connect to DAQ Logbook");
134 sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND partition REGEXP 'PHYSICS.*'",
135 (UInt_t)ts.GetSec()-86400);
136 TSQLResult* result = server->Query(sqlQuery);
139 AliWarning( Form("ERROR: Can't execute query <%s>!", sqlQuery.Data()) );
142 if (result->GetRowCount() != 0)
144 for (Int_t iRow = 0; iRow < result->GetRowCount(); iRow++)
146 TSQLRow* row = result->Next();
147 TString runStr = row->GetField(0);
148 if (runStr.IsDigit())
149 StartOfRun(runStr.Atoi());
157 void AliEventServerWindow::SetupToolbar()
159 TGToolBar* mToolBar = new TGToolBar(this);
160 mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/start.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_START ) );
161 mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/stop.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_STOP) );
162 mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/preferences.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_PREFERENCES) );
163 mToolBar->AddButton(this, new TGPictureButton(mToolBar, Form("%s/MONITOR/icons/exit.png", gSystem->Getenv("ALICE_ROOT")), TOOLBUTTON_EXIT) );
165 mToolBar->Connect("Clicked(Int_t)", "AliEventServerWindow", this, "HandleToolBarAction(Int_t)");
167 AddFrame(mToolBar, new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
168 AddFrame(new TGHorizontal3DLine(this), new TGLayoutHints(kLHintsNormal | kLHintsExpandX));
171 void AliEventServerWindow::HandleToolBarAction(Int_t id)
176 case TOOLBUTTON_START:{
180 case TOOLBUTTON_STOP:{
184 case TOOLBUTTON_PREFERENCES:{
185 new AliEventServerPreferencesWindow(this, "Settings");
188 case TOOLBUTTON_EXIT:{
198 void AliEventServerWindow::FinishedReconstruction(Int_t status)
200 // Slot called on termination of child process.
201 Int_t run = fServer->GetRunId();
203 Info("FinishedReconstruction", "Reconstruction Thread finished \tRunId:%d \tstatus=%d", run, status);
205 mIntInt_i i =fRun2PidMap.find(run);
206 if (i != fRun2PidMap.end())
208 fRunList->RemoveEntry(run);
210 // clean (remove) run's reconstructed directory
211 //gSystem->Exec(Form("rm -rf %s/reco/run%d_%d",gSystem->Getenv("ONLINERECO_BASE_DIR"),run,pid));
215 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
219 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
226 Warning("FinishedReconstruction", "Run number %d not registered.", run);
231 //------------------------------------------------------------------------------
233 //------------------------------------------------------------------------------
235 void AliEventServerWindow::StartReco(Int_t run)
237 AliInfo(Form("Starting Reco for run %d", run));
239 TString eventSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), run);
241 if(!fRecoServer) LaunchRecoServer();
243 fRecoServer->StartReconstruction(run, eventSource.Data());
245 if(fRecoServer->IsListenning()){
246 fRunList->RemoveEntry(run);
247 fRunList->AddEntrySort(TString::Format("%-20d -- RUNNING", run), run);
253 //------------------------------------------------------------------------------
254 // Handlers of DIM signals.
255 //------------------------------------------------------------------------------
257 void AliEventServerWindow::StartOfRun(Int_t run)
261 // Slot called from DIM handler on start of run.
262 AliInfo(Form("called for Run %d ", run));
264 fRunList->AddEntrySort(TString::Format("%d", run), run);
266 gClient->NeedRedraw(fRunList);
271 void AliEventServerWindow::EndOfRun(Int_t run)
275 // Slot called from DIM handler on stop of run.
276 AliInfo(Form("called for Run %d", run) );
277 if(fRecoServer) fRecoServer->StopReconstruction();
279 fRunList->RemoveEntry(run);
281 gClient->NeedRedraw(fRunList);
284 ///------------------------------------------------------------------------------
285 // Handlers of button signals.
286 //------------------------------------------------------------------------------
288 void AliEventServerWindow::onStartServer()
290 // Slot called from Start button.
291 AliInfo("Starting server...");
292 if(fRecoServer!=0) StopRecoServer();
297 void AliEventServerWindow::onStopServer()
299 // Slot called from Stop button.
300 AliInfo("Closing server...");
305 void AliEventServerWindow::onExit()
307 AliInfo("Closing server & Exiting...");
315 void AliEventServerWindow::LaunchRecoServer()
317 fRecoServer = new AliRecoServer;
320 bool AliEventServerWindow::StopRecoServer()
322 if(fRecoServer==0) return true;
324 AliInfo("Closing server and stoping process...");