1 // Author: Mihai Niculescu 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 <TXMLEngine.h>
15 #include <AliESDEvent.h>
16 #include <AliCDBManager.h>
17 #include <AliGRPPreprocessor.h>
18 #include <AliReconstruction.h>
19 #include <AliTPCRecoParam.h>
24 #include "AliEventServerUtil.h"
25 #include "AliEventServerReconstruction.h"
26 #include "AliStorageEventManager.h"
27 #include "AliStorageTypes.h"
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"
39 AliEventServerReconstruction::AliEventServerReconstruction()
44 fIsListenning(kFALSE),
48 fRecoIsRunning(false),
49 fRecoWasInitialized(false)
52 AliEventServerReconstruction::~AliEventServerReconstruction()
55 if(fSettings){delete fSettings;fSettings=0;}
56 if(fAliReco){delete fAliReco;fAliReco=0;}
59 void AliEventServerReconstruction::Close()
63 Info("AliRecoServer::Close", "Closing Server");
65 fIsListenning = kFALSE;
69 Bool_t AliEventServerReconstruction::StartReconstruction(Int_t run, const char* input)
71 cout<<"Start of run:"<<run<<endl;
75 if(fSettings){delete fSettings;fSettings=0;}
76 fSettings = new TEnv(AliEventServerUtil::GetPathToServerConf());
78 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir",DEFAULT_SERVER_SAVE_RECO_DIR);
80 // Create directories and logfile
81 TString logFile = Form("%s/log/run%d.log",recoBaseDir.Data(),run);
82 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
83 if( gSystem->RedirectOutput(logFile.Data())!=0)
85 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
88 gSystem->cd(recoBaseDir.Data());
92 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull()){return kFALSE;}
94 gSystem->mkdir(Form("run%d", run));
95 gSystem->cd(Form("run%d", run));
97 // Create Reco and Reco Thread
98 cout<<"Setup reco will be called"<<endl;
101 fHost = (const char*)Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT));
103 cout<<"Creating new thread"<<endl;
104 fRecoThread = new TThread("AliEventServerReconstruction",Dispatch, (void*)this);
106 fIsListenning = kTRUE;
108 cout<<"Reco started"<<endl;
112 bool AliEventServerReconstruction::StopReconstruction()
114 cout<<"Reco server -- StopPeconstruction() called"<<endl;
115 if(!fRecoIsRunning || !fRecoThread)
117 cout<<"Reco is not running. No need to stop it."<<endl;
120 if(!fRecoWasInitialized)
122 cout<<"Reco is under initialization. Wait until it's finished"<<endl;
126 cout<<"killing thread"<<endl;
128 cout<<"thread killed"<<endl;
131 cout<<"Reco server -- thread removed"<<endl;
132 // Emit("Stopped()");
134 cout<<"Reco server -- terminating reconstruction"<<endl;
135 fAliReco->SlaveTerminate();
136 if (fAliReco->GetAbort() != TSelector::kContinue) return false;
137 fAliReco->Terminate();
138 if (fAliReco->GetAbort() != TSelector::kContinue) return false;
140 if(fAliReco){delete fAliReco;fAliReco=0;}
141 cout<<"Reco server -- deleting CDBManager"<<endl;
142 if(fCDBmanager){fCDBmanager->Destroy();fCDBmanager=0;}
143 cout<<"Reco server -- recontruction stopped"<<endl;
144 fRecoIsRunning=false;
145 fRecoWasInitialized=false;
149 void AliEventServerReconstruction::ReconstructionHandle()
151 TThread::SetCancelAsynchronous();
152 TThread::SetCancelOn();
154 if(!fAliReco) return;
156 AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
157 eventManager->CreateSocket(EVENTS_SERVER_PUB);
158 eventManager->CreateSocket(XML_PUB);
159 cout<<"Sockets created"<<endl;
160 fAliReco->Begin(NULL);
161 cout<<"Reco began"<<endl;
162 if (fAliReco->GetAbort() != TSelector::kContinue) return;
163 fAliReco->SlaveBegin(NULL);
164 cout<<"Slave began"<<endl;
165 if (fAliReco->GetAbort() != TSelector::kContinue) return;
167 fRecoWasInitialized=true;
168 //******* The loop over events
171 while (fAliReco->HasNextEventAfter(iEvent))
173 // check if process has enough resources
174 cout<<"Event server -- checking resources"<<endl;
175 if (!fAliReco->HasEnoughResources(iEvent)) break;
176 cout<<"Event server -- resources checked"<<endl;
177 Bool_t status = fAliReco->ProcessEvent(iEvent);
178 cout<<"Event server -- event processed"<<endl;
182 event = fAliReco->GetESDEvent();
183 cout<<"Event server -- sending event"<<endl;
184 eventManager->Send(event,EVENTS_SERVER_PUB);
185 cout<<"Event server -- sending event as xml"<<endl;
186 eventManager->SendAsXml(event,XML_PUB);
187 cout<<"Event server -- xml sent"<<endl;
191 cout<<"Event server -- aborting"<<endl;
192 fAliReco->Abort("ProcessEvent",TSelector::kAbortFile);
194 cout<<"Event server -- cleaning event"<<endl;
195 fAliReco->CleanProcessedEvent();
196 cout<<"Event server -- event cleaned"<<endl;
199 StopReconstruction();
202 Int_t AliEventServerReconstruction::RetrieveGRP(UInt_t run, TString &gdc)
204 if(!fSettings) return (-1);
206 // Retrieve GRP entry for given run from aldaqdb.
207 TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
208 Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
209 TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
210 TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
211 TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
213 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
214 dbPort, dbName.Data(),
215 user.Data(), password.Data(),
216 Form("local://%s",gSystem->pwd()),
219 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
220 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
221 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
225 void AliEventServerReconstruction::SetupReco(const char* input)
227 if(!fSettings) return;
229 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
231 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
234 fCDBmanager = AliCDBManager::Instance();
236 fCDBmanager->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
237 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
238 fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
240 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
241 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
243 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
244 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
246 /* Reconstruction settings */
247 if(!fAliReco)fAliReco = new AliReconstruction();
250 //rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN));
251 //rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL));
252 fAliReco->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
253 //rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF));
255 fAliReco->SetRunQA(":");
256 fAliReco->SetRunGlobalQA(false);
257 fAliReco->SetRunPlaneEff(false);
259 // AliReconstruction settings
260 fAliReco->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF));
261 fAliReco->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
262 fAliReco->SetInput(input); // reconstruct data from this input
263 fAliReco->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
264 fAliReco->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
266 // switch off cleanESD
267 fAliReco->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));
269 // init reco for given run
270 fAliReco->InitRun(input);