]>
Commit | Line | Data |
---|---|---|
164d3d29 | 1 | // Author: Mihai Niculescu 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 | #include <TThread.h> | |
12 | #include <TXMLEngine.h> | |
13 | ||
14 | #include <AliLog.h> | |
15 | #include <AliESDEvent.h> | |
16 | #include <AliCDBManager.h> | |
17 | #include <AliGRPPreprocessor.h> | |
18 | #include <AliReconstruction.h> | |
19 | #include <AliTPCRecoParam.h> | |
20 | ||
21 | #include <iostream> | |
22 | #include <sstream> | |
23 | ||
24 | #include "AliEventServerUtil.h" | |
25 | #include "AliEventServerReconstruction.h" | |
26 | #include "AliStorageEventManager.h" | |
27 | #include "AliStorageTypes.h" | |
28 | ||
29 | #include "AliESDEvent.h" | |
30 | #include "AliESDtrack.h" | |
31 | #include "AliTrackPointArray.h" | |
32 | #include "AliESDfriendTrack.h" | |
33 | #include "AliExternalTrackParam.h" | |
34 | #include "AliTrackerBase.h" | |
35 | #include "AliTracker.h" | |
36 | ||
37 | using namespace std; | |
38 | ||
39 | AliEventServerReconstruction::AliEventServerReconstruction() | |
40 | : TQObject(), | |
41 | fAliReco(0), | |
42 | fCDBmanager(0), | |
43 | fCurrentRunId(0), | |
44 | fIsListenning(kFALSE), | |
45 | fSettings(0), | |
46 | fHost(0), | |
13a64a87 | 47 | fRecoThread(0), |
345fab05 | 48 | fRecoIsRunning(false), |
49 | fRecoWasInitialized(false) | |
164d3d29 | 50 | {} |
51 | ||
52 | AliEventServerReconstruction::~AliEventServerReconstruction() | |
53 | { | |
54 | Close(); | |
55 | if(fSettings){delete fSettings;fSettings=0;} | |
13a64a87 | 56 | if(fAliReco){delete fAliReco;fAliReco=0;} |
164d3d29 | 57 | } |
58 | ||
59 | void AliEventServerReconstruction::Close() | |
60 | { | |
61 | if(fIsListenning) | |
62 | { | |
63 | Info("AliRecoServer::Close", "Closing Server"); | |
64 | StopReconstruction(); | |
65 | fIsListenning = kFALSE; | |
66 | } | |
67 | } | |
68 | ||
69 | Bool_t AliEventServerReconstruction::StartReconstruction(Int_t run, const char* input) | |
70 | { | |
345fab05 | 71 | cout<<"Start of run:"<<run<<endl; |
164d3d29 | 72 | fCurrentRunId = run; |
73 | ||
164d3d29 | 74 | // re-read settings |
13a64a87 | 75 | if(fSettings){delete fSettings;fSettings=0;} |
164d3d29 | 76 | fSettings = new TEnv(AliEventServerUtil::GetPathToServerConf()); |
77 | ||
13a64a87 | 78 | TString recoBaseDir = fSettings->GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR); |
164d3d29 | 79 | |
80 | // Create directories and logfile | |
13a64a87 | 81 | TString logFile = Form("%s/log/run%d.log",recoBaseDir.Data(),run); |
164d3d29 | 82 | Info("DoStart","Reconstruction log will be written to %s",logFile.Data()); |
83 | if( gSystem->RedirectOutput(logFile.Data())!=0) | |
84 | { | |
85 | printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) ); | |
86 | return kFALSE; | |
87 | } | |
164d3d29 | 88 | gSystem->cd(recoBaseDir.Data()); |
89 | ||
345fab05 | 90 | |
164d3d29 | 91 | TString gdcs; |
92 | if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull()){return kFALSE;} | |
93 | ||
94 | gSystem->mkdir(Form("run%d", run)); | |
95 | gSystem->cd(Form("run%d", run)); | |
96 | ||
97 | // Create Reco and Reco Thread | |
345fab05 | 98 | cout<<"Setup reco will be called"<<endl; |
164d3d29 | 99 | SetupReco(input); |
13a64a87 | 100 | |
164d3d29 | 101 | fHost = (const char*)Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT)); |
102 | ||
345fab05 | 103 | cout<<"Creating new thread"<<endl; |
104 | fRecoThread = new TThread("AliEventServerReconstruction",Dispatch, (void*)this); | |
164d3d29 | 105 | fRecoThread->Run(); |
106 | fIsListenning = kTRUE; | |
13a64a87 | 107 | fRecoIsRunning=true; |
345fab05 | 108 | cout<<"Reco started"<<endl; |
164d3d29 | 109 | return true; |
110 | } | |
111 | ||
345fab05 | 112 | bool AliEventServerReconstruction::StopReconstruction() |
164d3d29 | 113 | { |
13a64a87 | 114 | cout<<"Reco server -- StopPeconstruction() called"<<endl; |
345fab05 | 115 | if(!fRecoIsRunning || !fRecoThread) |
13a64a87 | 116 | { |
345fab05 | 117 | cout<<"Reco is not running. No need to stop it."<<endl; |
118 | return true; | |
13a64a87 | 119 | } |
345fab05 | 120 | if(!fRecoWasInitialized) |
13a64a87 | 121 | { |
345fab05 | 122 | cout<<"Reco is under initialization. Wait until it's finished"<<endl; |
123 | ||
124 | return false; | |
13a64a87 | 125 | } |
126 | cout<<"killing thread"<<endl; | |
127 | fRecoThread->Kill(); | |
128 | cout<<"thread killed"<<endl; | |
129 | delete fRecoThread; | |
130 | fRecoThread=0; | |
131 | cout<<"Reco server -- thread removed"<<endl; | |
132 | // Emit("Stopped()"); | |
133 | ||
134 | cout<<"Reco server -- terminating reconstruction"<<endl; | |
135 | fAliReco->SlaveTerminate(); | |
345fab05 | 136 | if (fAliReco->GetAbort() != TSelector::kContinue) return false; |
13a64a87 | 137 | fAliReco->Terminate(); |
345fab05 | 138 | if (fAliReco->GetAbort() != TSelector::kContinue) return false; |
13a64a87 | 139 | |
140 | if(fAliReco){delete fAliReco;fAliReco=0;} | |
141 | cout<<"Reco server -- deleting CDBManager"<<endl; | |
345fab05 | 142 | if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;} |
13a64a87 | 143 | cout<<"Reco server -- recontruction stopped"<<endl; |
144 | fRecoIsRunning=false; | |
345fab05 | 145 | fRecoWasInitialized=false; |
146 | return true; | |
164d3d29 | 147 | } |
148 | ||
149 | void AliEventServerReconstruction::ReconstructionHandle() | |
150 | { | |
151 | TThread::SetCancelAsynchronous(); | |
152 | TThread::SetCancelOn(); | |
153 | ||
154 | if(!fAliReco) return; | |
345fab05 | 155 | |
164d3d29 | 156 | AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance(); |
157 | eventManager->CreateSocket(EVENTS_SERVER_PUB); | |
158 | eventManager->CreateSocket(XML_PUB); | |
345fab05 | 159 | cout<<"Sockets created"<<endl; |
164d3d29 | 160 | fAliReco->Begin(NULL); |
345fab05 | 161 | cout<<"Reco began"<<endl; |
164d3d29 | 162 | if (fAliReco->GetAbort() != TSelector::kContinue) return; |
163 | fAliReco->SlaveBegin(NULL); | |
345fab05 | 164 | cout<<"Slave began"<<endl; |
164d3d29 | 165 | if (fAliReco->GetAbort() != TSelector::kContinue) return; |
166 | ||
345fab05 | 167 | fRecoWasInitialized=true; |
164d3d29 | 168 | //******* The loop over events |
169 | Int_t iEvent = 0; | |
345fab05 | 170 | AliESDEvent* event; |
164d3d29 | 171 | while (fAliReco->HasNextEventAfter(iEvent)) |
172 | { | |
173 | // check if process has enough resources | |
174 | if (!fAliReco->HasEnoughResources(iEvent)) break; | |
175 | Bool_t status = fAliReco->ProcessEvent(iEvent); | |
176 | ||
177 | if (status) | |
178 | { | |
179 | event = fAliReco->GetESDEvent(); | |
cc94dac0 | 180 | cout<<"Event server -- sending event"<<endl; |
164d3d29 | 181 | eventManager->Send(event,EVENTS_SERVER_PUB); |
cc94dac0 | 182 | cout<<"Event server -- sending event as xml"<<endl; |
164d3d29 | 183 | eventManager->SendAsXml(event,XML_PUB); |
184 | } | |
185 | else | |
186 | { | |
187 | fAliReco->Abort("ProcessEvent",TSelector::kAbortFile); | |
188 | } | |
189 | ||
190 | fAliReco->CleanProcessedEvent(); | |
191 | iEvent++; | |
192 | } | |
13a64a87 | 193 | StopReconstruction(); |
164d3d29 | 194 | } |
195 | ||
196 | Int_t AliEventServerReconstruction::RetrieveGRP(UInt_t run, TString &gdc) | |
197 | { | |
198 | if(!fSettings) return (-1); | |
199 | ||
200 | // Retrieve GRP entry for given run from aldaqdb. | |
201 | TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST); | |
202 | Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT); | |
203 | TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB); | |
204 | TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER); | |
205 | TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS); | |
206 | ||
207 | Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(), | |
208 | dbPort, dbName.Data(), | |
209 | user.Data(), password.Data(), | |
210 | Form("local://%s",gSystem->pwd()), | |
211 | gdc); | |
212 | ||
213 | if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret); | |
214 | else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found"); | |
215 | else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret); | |
216 | return(ret); | |
217 | } | |
218 | ||
219 | void AliEventServerReconstruction::SetupReco(const char* input) | |
220 | { | |
221 | if(!fSettings) return; | |
222 | ||
223 | //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file! | |
224 | ||
225 | printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd())); | |
226 | ||
227 | /* Settings CDB */ | |
228 | fCDBmanager = AliCDBManager::Instance(); | |
229 | ||
230 | fCDBmanager->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE)); | |
231 | fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1), | |
232 | fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1)); | |
233 | ||
234 | fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2), | |
235 | fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2)); | |
236 | ||
237 | fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3), | |
238 | fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3)); | |
239 | ||
13a64a87 | 240 | /* Reconstruction settings */ |
241 | if(!fAliReco)fAliReco = new AliReconstruction(); | |
242 | ||
164d3d29 | 243 | // QA options |
13a64a87 | 244 | //rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN)); |
245 | //rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL)); | |
246 | fAliReco->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ; | |
247 | //rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF)); | |
248 | ||
249 | fAliReco->SetRunQA(":"); | |
250 | fAliReco->SetRunGlobalQA(false); | |
251 | fAliReco->SetRunPlaneEff(false); | |
164d3d29 | 252 | |
253 | // AliReconstruction settings | |
13a64a87 | 254 | fAliReco->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF)); |
255 | fAliReco->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN)); | |
256 | fAliReco->SetInput(input); // reconstruct data from this input | |
257 | fAliReco->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS)); | |
258 | fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file! | |
164d3d29 | 259 | |
260 | // switch off cleanESD | |
13a64a87 | 261 | fAliReco->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD)); |
164d3d29 | 262 | |
13a64a87 | 263 | // init reco for given run |
264 | fAliReco->InitRun(input); | |
164d3d29 | 265 | } |