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),
50 AliEventServerReconstruction::~AliEventServerReconstruction()
53 if(fSettings){delete fSettings;fSettings=0;}
56 void AliEventServerReconstruction::Close()
60 Info("AliRecoServer::Close", "Closing Server");
62 fIsListenning = kFALSE;
66 Bool_t AliEventServerReconstruction::StartReconstruction(Int_t run, const char* input)
73 if(fSettings){delete fSettings;}
74 fSettings = new TEnv(AliEventServerUtil::GetPathToServerConf());
76 TString recoBaseDir = fSettings->GetValue("server.saveRecoDir",
77 DEFAULT_SERVER_SAVE_RECO_DIR);
79 // Create directories and logfile
80 TString logFile = Form("%s/log/run%d.log",
84 Info("DoStart","Reconstruction log will be written to %s",logFile.Data());
85 if( gSystem->RedirectOutput(logFile.Data())!=0)
87 printf(Form("AliRecoServer::StartReconstruction [] Error while trying to redirect output to [%s]. Exiting...", logFile.Data()) );
91 gSystem->cd(recoBaseDir.Data());
94 if (RetrieveGRP(run,gdcs) <= 0 || gdcs.IsNull()){return kFALSE;}
96 gSystem->mkdir(Form("run%d", run));
97 gSystem->cd(Form("run%d", run));
99 // Create Reco and Reco Thread
101 fAliReco->InitRun(input);
103 fHost = (const char*)Form("%s:%d", fSettings->GetValue("server.host", DEFAULT_SERVER_HOST), fSettings->GetValue("server.port", DEFAULT_SERVER_PORT));
105 fRecoThread = new TThread("AliEventServerReconstruction",
109 fIsListenning = kTRUE;
114 void AliEventServerReconstruction::StopReconstruction()
116 if(!fRecoThread) return;
121 if(fAliReco){delete fAliReco;fAliReco=0;}
122 if(fCDBmanager){delete fCDBmanager;fCDBmanager=0;}
125 void AliEventServerReconstruction::ReconstructionHandle()
127 TThread::SetCancelAsynchronous();
128 TThread::SetCancelOn();
130 if(!fAliReco) return;
134 AliStorageEventManager *eventManager = AliStorageEventManager::GetEventManagerInstance();
135 eventManager->CreateSocket(EVENTS_SERVER_PUB);
136 eventManager->CreateSocket(XML_PUB);
138 fAliReco->Begin(NULL);
139 if (fAliReco->GetAbort() != TSelector::kContinue) return;
140 fAliReco->SlaveBegin(NULL);
141 if (fAliReco->GetAbort() != TSelector::kContinue) return;
143 //******* The loop over events
145 while (fAliReco->HasNextEventAfter(iEvent))
147 // check if process has enough resources
148 if (!fAliReco->HasEnoughResources(iEvent)) break;
149 Bool_t status = fAliReco->ProcessEvent(iEvent);
153 event = fAliReco->GetESDEvent();
154 eventManager->Send(event,EVENTS_SERVER_PUB);
155 eventManager->SendAsXml(event,XML_PUB);
159 fAliReco->Abort("ProcessEvent",TSelector::kAbortFile);
162 fAliReco->CleanProcessedEvent();
165 fAliReco->SlaveTerminate();
166 if (fAliReco->GetAbort() != TSelector::kContinue) return;
167 fAliReco->Terminate();
168 if (fAliReco->GetAbort() != TSelector::kContinue) return;
171 Int_t AliEventServerReconstruction::RetrieveGRP(UInt_t run, TString &gdc)
173 if(!fSettings) return (-1);
175 // Retrieve GRP entry for given run from aldaqdb.
176 TString dbHost = fSettings->GetValue("logbook.host", DEFAULT_LOGBOOK_HOST);
177 Int_t dbPort = fSettings->GetValue("logbook.port", DEFAULT_LOGBOOK_PORT);
178 TString dbName = fSettings->GetValue("logbook.db", DEFAULT_LOGBOOK_DB);
179 TString user = fSettings->GetValue("logbook.user", DEFAULT_LOGBOOK_USER);
180 TString password = fSettings->GetValue("logbook.pass", DEFAULT_LOGBOOK_PASS);
182 Int_t ret=AliGRPPreprocessor::ReceivePromptRecoParameters(run, dbHost.Data(),
183 dbPort, dbName.Data(),
184 user.Data(), password.Data(),
185 Form("local://%s",gSystem->pwd()),
188 if(ret>0) Info("RetrieveGRP","Last run of the same type is: %d",ret);
189 else if(ret==0) Warning("RetrieveGRP","No previous run of the same type found");
190 else if(ret<0) Error("Retrieve","Error code while retrieving GRP parameters returned: %d",ret);
194 void AliEventServerReconstruction::SetupReco(const char* input)
196 if(!fSettings) return;
198 //AliTPCRecoParam::SetUseTimeCalibration(kFALSE); //-- !probably should be set from conf file!
200 printf(Form("=========================[local://%s/..]===========\n",gSystem->pwd()));
203 fCDBmanager = AliCDBManager::Instance();
205 fCDBmanager->SetDefaultStorage(fSettings->GetValue("cdb.defaultStorage", DEFAULT_CDB_STORAGE));
206 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath1", DEFAULT_CDB_SPEC_STORAGE_PATH1),
207 fSettings->GetValue( "cdb.specificStorageValue1", DEFAULT_CDB_SPEC_STORAGE_VALUE1));
209 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath2", DEFAULT_CDB_SPEC_STORAGE_PATH2),
210 fSettings->GetValue( "cdb.specificStorageValue2", DEFAULT_CDB_SPEC_STORAGE_VALUE2));
212 fCDBmanager->SetSpecificStorage(fSettings->GetValue( "cdb.specificStoragePath3", DEFAULT_CDB_SPEC_STORAGE_PATH3),
213 fSettings->GetValue( "cdb.specificStorageValue3", DEFAULT_CDB_SPEC_STORAGE_VALUE3));
215 /* Reconstruction settings */
216 if(fAliReco) delete fAliReco;
218 AliReconstruction* rec = new AliReconstruction;
221 rec->SetRunQA(fSettings->GetValue( "qa.runDetectors", DEFAULT_QA_RUN));
222 rec->SetRunGlobalQA(fSettings->GetValue( "qa.runGlobal", DEFAULT_QA_RUN_GLOBAL));
223 rec->SetQARefDefaultStorage(fSettings->GetValue( "qa.defaultStorage",DEFAULT_QAREF_STORAGE)) ;
224 rec->SetRunPlaneEff(fSettings->GetValue( "reco.runPlaneEff", DEFAULT_RECO_RUN_PLANE_EFF));
226 // AliReconstruction settings
227 rec->SetWriteESDfriend(fSettings->GetValue( "reco.writeESDfriend", DEFAULT_RECO_WRITE_ESDF));
228 rec->SetWriteAlignmentData(fSettings->GetValue( "reco.writeAlignment",DEFAULT_RECO_WRITE_ALIGN));
229 rec->SetInput(input); // reconstruct data from this input
230 rec->SetRunReconstruction(fSettings->GetValue( "reco.detectors", DEFAULT_RECO_DETECTORS));
231 rec->SetUseTrackingErrorsForAlignment("ITS"); //-- !should be set from conf file!
233 // switch off cleanESD
234 rec->SetCleanESD(fSettings->GetValue( "reco.cleanESD",DEFAULT_RECO_CLEAN_ESD));