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>
21 #include <AliReconstruction.h>
22 #include <AliDimIntNotifier.h>
24 #include "AliEventServerUtil.h"
25 #include "AliEventServer.h"
26 #include "AliEventServerReconstruction.h"
28 ClassImp(AliEventServer)
32 AliEventServer::AliEventServer() :
35 fRecoServer = new AliEventServerReconstruction();
36 for(Int_t i=0; i<5; ++i)
38 fDimSORListener[i] = 0;
39 fDimEORListener[i] = 0;
41 FillRunsFromDatabase();
45 AliEventServer::~AliEventServer()
47 for (Int_t i = 0; i < 5; ++i)
49 if(fDimSORListener[i]) delete fDimSORListener[i];
50 if(fDimEORListener[i]) delete fDimEORListener[i];
52 fDimSORListener[i] = 0;
53 fDimEORListener[i] = 0;
55 if(fRecoServer){delete fRecoServer;fRecoServer=0;}
58 void AliEventServer::InitDIMListeners()
61 for (Int_t i = 0; i < 5; ++i)
65 fDimSORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS");
66 fDimEORListener[i] = new AliDimIntNotifier("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS");
70 fDimSORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_SOR_PHYSICS_%d", i));
71 fDimEORListener[i] = new AliDimIntNotifier(Form("/LOGBOOK/SUBSCRIBE/DAQ_EOR_PHYSICS_%d", i));
74 fDimSORListener[i]->Connect("DimMessage(Int_t)", "AliEventServer", this, "StartOfRun(Int_t)");
75 fDimEORListener[i]->Connect("DimMessage(Int_t)", "AliEventServer", this, "EndOfRun(Int_t)");
80 void AliEventServer::StartOfRun(Int_t run)
82 cout<<"SOR signal received for run:"<<run<<endl;
85 while(!fRecoServer->StopReconstruction())
87 cout<<"Waiting for previous reco to be fully initialized"<<endl;
90 fRecoServer->StopReconstruction();
93 settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
95 TString dataSource = settings.GetValue("data.source", DEFAULT_DATA_SOURCE);
98 if(dataSource=="local")
100 cout<<"Starting Reco for run "<<run<<endl;
101 eventSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), run);
103 else if(dataSource=="run")
105 cout<<"Starting Reco for GDCs active in current run:"<<run<<endl;
106 eventSource = "mem://@*:";
109 fRecoServer->StartReconstruction(run, eventSource.Data());
112 void AliEventServer::EndOfRun(Int_t run)
114 cout<<"EOR signal received for run:"<<run<<endl;
116 fRecoServer->StopReconstruction();
119 void AliEventServer::FillRunsFromDatabase()
122 settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
124 TString dbHost = settings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
125 TString dbPort = Form("%d", settings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT));
126 TString dbName = settings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
127 TString user = settings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
128 TString password = settings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
130 TString connStr = Form("mysql://%s:%s/%s", dbHost.Data(), dbPort.Data(), dbName.Data()) ;
132 cout<<"connecting to:"<<connStr<<endl;
134 TSQLServer* server = TSQLServer::Connect(connStr.Data(), user.Data(), password.Data());
137 cout<<"ERROR: Could not connect to DAQ Logbook"<<endl;
142 sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND `partition` REGEXP 'PHYSICS.*'",
143 (UInt_t)ts.GetSec()-86400);
144 TSQLResult* result = server->Query(sqlQuery);
147 cout<<"ERROR: Can't execute query:"<< sqlQuery<<endl;
150 if (result->GetRowCount() != 0)
152 for (Int_t iRow = 0; iRow < result->GetRowCount(); iRow++)
154 TSQLRow* row = result->Next();
155 TString runStr = row->GetField(0);
156 if (runStr.IsDigit())
157 StartOfRun(runStr.Atoi());
167 void AliEventServer::FinishedReconstruction(Int_t status)
169 // Slot called on termination of child process.
170 Int_t run = fServer->GetRunId();
172 Info("FinishedReconstruction", "Reconstruction Thread finished \tRunId:%d \tstatus=%d", run, status);
174 mIntInt_i i =fRun2PidMap.find(run);
175 if (i != fRun2PidMap.end())
177 fRunList->RemoveEntry(run);
179 // clean (remove) run's reconstructed directory
180 //gSystem->Exec(Form("rm -rf %s/reco/run%d_%d",gSystem->Getenv("ONLINERECO_BASE_DIR"),run,pid));
184 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
188 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
195 Warning("FinishedReconstruction", "Run number %d not registered.", run);