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