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;
84 fRecoServer->StopReconstruction();
87 settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
89 TString dataSource = settings.GetValue("data.source", DEFAULT_DATA_SOURCE);
92 if(dataSource=="local")
94 cout<<"Starting Reco for run "<<run<<endl;
95 eventSource = Form("mem://%s/run%d", gSystem->Getenv("ONLINERECO_RAWFILES_DIR"), run);
97 else if(dataSource=="run")
99 cout<<"Starting Reco for GDCs active in current run:"<<run<<endl;
100 eventSource = "mem://@*:";
103 fRecoServer->StartReconstruction(run, eventSource.Data());
106 void AliEventServer::EndOfRun(Int_t run)
108 cout<<"EOR signal received for run:"<<run<<endl;
110 fRecoServer->StopReconstruction();
113 void AliEventServer::FillRunsFromDatabase()
116 settings.ReadFile(AliEventServerUtil::GetPathToServerConf(), kEnvUser);
118 TString dbHost = settings.GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
119 TString dbPort = Form("%d", settings.GetValue("logbook.port", DEFAULT_LOGBOOK_PORT));
120 TString dbName = settings.GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
121 TString user = settings.GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
122 TString password = settings.GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
124 TString connStr = Form("mysql://%s:%s/%s", dbHost.Data(), dbPort.Data(), dbName.Data()) ;
126 cout<<"connecting to:"<<connStr<<endl;
128 TSQLServer* server = TSQLServer::Connect(connStr.Data(), user.Data(), password.Data());
131 cout<<"ERROR: Could not connect to DAQ Logbook"<<endl;
136 sqlQuery.Form("SELECT run FROM logbook WHERE DAQ_time_start > %u AND DAQ_time_end IS NULL AND `partition` REGEXP 'PHYSICS.*'",
137 (UInt_t)ts.GetSec()-86400);
138 TSQLResult* result = server->Query(sqlQuery);
141 cout<<"ERROR: Can't execute query:"<< sqlQuery<<endl;
144 if (result->GetRowCount() != 0)
146 for (Int_t iRow = 0; iRow < result->GetRowCount(); iRow++)
148 TSQLRow* row = result->Next();
149 TString runStr = row->GetField(0);
150 if (runStr.IsDigit())
151 StartOfRun(runStr.Atoi());
161 void AliEventServer::FinishedReconstruction(Int_t status)
163 // Slot called on termination of child process.
164 Int_t run = fServer->GetRunId();
166 Info("FinishedReconstruction", "Reconstruction Thread finished \tRunId:%d \tstatus=%d", run, status);
168 mIntInt_i i =fRun2PidMap.find(run);
169 if (i != fRun2PidMap.end())
171 fRunList->RemoveEntry(run);
173 // clean (remove) run's reconstructed directory
174 //gSystem->Exec(Form("rm -rf %s/reco/run%d_%d",gSystem->Getenv("ONLINERECO_BASE_DIR"),run,pid));
178 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED", run), run);
182 fRunList->AddEntrySort(TString::Format("%-20d -- PROCESSED [%d]", run, status), run);
189 Warning("FinishedReconstruction", "Run number %d not registered.", run);