]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/rec/AliHLTReconstructor.cxx
- fix pointer deletion
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
CommitLineData
3e820254 1// $Id$
2
c5123824 3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
c534985b 18
3a7c0444 19/** @file AliHLTReconstructor.cxx
c534985b 20 @author Matthias Richter
21 @date
22 @brief Binding class for HLT reconstruction in AliRoot. */
3e820254 23
24#include <TSystem.h>
25#include <TObjString.h>
032c5e5e 26#include "TFile.h"
27#include "TTree.h"
3e820254 28#include "AliHLTReconstructor.h"
29#include "AliLog.h"
032c5e5e 30#include "AliRawReader.h"
c5123824 31#include "AliESDEvent.h"
3e820254 32#include "AliHLTSystem.h"
c5123824 33#include "AliHLTOUTRawReader.h"
34#include "AliHLTOUTDigitReader.h"
35#include "AliHLTEsdManager.h"
00ddfaca 36#include "AliHLTPluginBase.h"
3e820254 37
38ClassImp(AliHLTReconstructor)
39
40AliHLTReconstructor::AliHLTReconstructor()
41 :
42 AliReconstructor(),
c5123824 43 fFctProcessHLTOUT(NULL),
00ddfaca 44 fpEsdManager(NULL),
45 fpPluginBase(new AliHLTPluginBase)
3e820254 46{
47 //constructor
48}
49
032c5e5e 50AliHLTReconstructor::AliHLTReconstructor(const char* options)
51 :
52 AliReconstructor(),
032c5e5e 53 fFctProcessHLTOUT(NULL),
00ddfaca 54 fpEsdManager(NULL),
55 fpPluginBase(new AliHLTPluginBase)
032c5e5e 56{
57 //constructor
58 if (options) Init(options);
59}
60
3e820254 61AliHLTReconstructor::~AliHLTReconstructor()
62{
63 //destructor
dee38f1b 64
00ddfaca 65 if (fpPluginBase) {
66 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 67 if (pSystem) {
00ddfaca 68 AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
3dd8541e 69 if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
dee38f1b 70 // send specific 'event' to execute the stop sequence
a3ef3c1d 71 pSystem->Reconstruct(0, NULL, NULL);
dee38f1b 72 }
3e820254 73 }
00ddfaca 74 delete fpPluginBase;
75 }
76 fpPluginBase=NULL;
c5123824 77
f1207f29 78 if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
c5123824 79 fpEsdManager=NULL;
3e820254 80}
81
032c5e5e 82void AliHLTReconstructor::Init(const char* options)
83{
84 // init the reconstructor
85 SetOption(options);
86 Init();
87}
88
3e820254 89void AliHLTReconstructor::Init()
90{
91 // init the reconstructor
00ddfaca 92 if (!fpPluginBase) {
93 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
94 return;
95 }
96
97 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
a3ef3c1d 98 if (!pSystem) {
3e820254 99 AliError("can not create AliHLTSystem object");
100 return;
101 }
a3ef3c1d 102 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 103 AliError("HLT system in error state");
104 return;
105 }
106
107 // the options scan has been moved to AliHLTSystem, the old code
108 // here is kept to be able to run an older version of the HLT code
109 // with newer AliRoot versions.
110 TString libs("");
111 TString option = GetOption();
112 TObjArray* pTokens=option.Tokenize(" ");
113 option="";
114 if (pTokens) {
115 int iEntries=pTokens->GetEntries();
116 for (int i=0; i<iEntries; i++) {
117 TString token=(((TObjString*)pTokens->At(i))->GetString());
118 if (token.Contains("loglevel=")) {
119 TString param=token.ReplaceAll("loglevel=", "");
120 if (param.IsDigit()) {
a3ef3c1d 121 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
3e820254 122 } else if (param.BeginsWith("0x") &&
123 param.Replace(0,2,"",0).IsHex()) {
124 int severity=0;
125 sscanf(param.Data(),"%x", &severity);
a3ef3c1d 126 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
3e820254 127 } else {
128 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
129 }
130 } else if (token.Contains("alilog=off")) {
a3ef3c1d 131 pSystem->SwitchAliLog(0);
3e820254 132 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
133 libs+=token;
134 libs+=" ";
135 } else {
136 if (option.Length()>0) option+=" ";
137 option+=token;
138 }
139 }
140 delete pTokens;
141 }
7f9ab840 142
3e820254 143 if (!libs.IsNull() &&
a3ef3c1d 144 (!pSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
145 (pSystem->LoadComponentLibraries(libs.Data())<0)) {
3e820254 146 AliError("error while loading HLT libraries");
147 return;
148 }
149
a3ef3c1d 150 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
3e820254 151 typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
152 gSystem->Load("libHLTinterface.so");
153 AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
154 if (pFunc) {
a3ef3c1d 155 if ((pFunc)(pSystem, option.Data())<0) {
3e820254 156 AliError("error setting options for HLT system");
157 return;
158 }
159 } else if (option.Length()>0) {
160 AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
161 return;
162 }
a3ef3c1d 163 if ((pSystem->Configure())<0) {
3e820254 164 AliError("error during HLT system configuration");
165 return;
166 }
167 }
c5123824 168
169 gSystem->Load("libHLTinterface.so");
d93ec7ca 170 fFctProcessHLTOUT=(void (*)())gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
c5123824 171
f1207f29 172 fpEsdManager=AliHLTEsdManager::New();
3e820254 173}
174
06995b88 175void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const
3e820254 176{
177 // reconstruction of real data without writing of ESD
c5123824 178 // For each event, HLT reconstruction chains can be executed and
179 // added to the existing HLTOUT data
180 // The HLTOUT data is finally processed in FillESD
00ddfaca 181 if (!fpPluginBase) {
182 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
183 return;
184 }
185
3e820254 186 int iResult=0;
00ddfaca 187 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
06995b88 188
a3ef3c1d 189 if (pSystem) {
190 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
3e820254 191 AliError("HLT system in error state");
192 return;
193 }
a3ef3c1d 194 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
3e820254 195 AliError("HLT system in wrong state");
196 return;
197 }
a3ef3c1d 198 if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
c5123824 199 }
200 }
06995b88 201}
202
203void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/,
204 AliESDEvent* esd) const
205{
206 // reconstruct real data and fill ESD
207 if (!rawReader || !esd) {
208 AliError("missing raw reader or esd object");
209 return;
210 }
211
00ddfaca 212 if (!fpPluginBase) {
213 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
214 return;
215 }
216
217 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 218
219 if (pSystem) {
220 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
221 AliError("HLT system in error state");
222 return;
223 }
224 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
225 AliError("HLT system in wrong state");
226 return;
227 }
228 pSystem->FillESD(-1, NULL, esd);
229
230 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
231 if (pHLTOUT) {
232 ProcessHLTOUT(pHLTOUT, esd);
f94e8c27 233 delete pHLTOUT;
c5123824 234 } else {
235 AliError("error creating HLTOUT handler");
3e820254 236 }
237 }
238}
7f9ab840 239
29312178 240void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
7f9ab840 241{
242 // reconstruct simulated data
243
244 // all reconstruction has been moved to FillESD
245 //AliReconstructor::Reconstruct(digitsTree,clustersTree);
032c5e5e 246 AliInfo("running digit data reconstruction");
7f9ab840 247}
248
c5123824 249void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
7f9ab840 250{
251 // reconstruct simulated data and fill ESD
252
253 // later this is the place to extract the simulated HLT data
254 // for now it's only an user failure condition as he tries to run HLT reconstruction
255 // on simulated data
256 TString option = GetOption();
c5123824 257 if (!option.IsNull() &&
258 (option.Contains("config=") || option.Contains("chains="))) {
f8e0e3d3 259 AliWarning(Form("HLT reconstruction can be run embedded into Alireconstruction from\n"
260 "raw data (real or simulated)). Reconstruction of of digit data takes\n"
261 "place in AliSimulation, appropriate input conversion is needed.\n"
262 "Consider running embedded into AliSimulation."
7f9ab840 263 " /*** run macro *****************************************/\n"
264 " AliSimulation sim;\n"
265 " sim.SetRunHLT(\"%s\");\n"
266 " sim.SetRunGeneration(kFALSE);\n"
267 " sim.SetMakeDigits(\"\");\n"
268 " sim.SetMakeSDigits(\"\");\n"
269 " sim.SetMakeDigitsFromHits(\"\");\n"
270 " sim.Run();\n"
271 " /*********************************************************/", option.Data()));
272 }
00ddfaca 273 if (!fpPluginBase) {
274 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
275 return;
276 }
277
278 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 279 if (pSystem) {
280 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
281 AliError("HLT system in error state");
282 return;
283 }
284 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
285 AliError("HLT system in wrong state");
286 return;
287 }
288
289 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
290 if (pHLTOUT) {
291 ProcessHLTOUT(pHLTOUT, esd);
f94e8c27 292 delete pHLTOUT;
c5123824 293 } else {
294 AliError("error creating HLTOUT handler");
295 }
296 }
297}
298
b005ef92 299void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bool bVerbose) const
c5123824 300{
f94e8c27 301 // treatment of simulated or real HLTOUT data
c5123824 302 if (!pHLTOUT) return;
00ddfaca 303 if (!fpPluginBase) {
304 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
305 return;
306 }
307
308 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
c5123824 309 if (!pSystem) {
310 AliError("error getting HLT system instance");
311 return;
312 }
313
314 if (pHLTOUT->Init()<0) {
315 AliError("error : initialization of HLTOUT handler failed");
316 return;
317 }
318
b005ef92 319 if (bVerbose)
320 PrintHLTOUTContent(pHLTOUT);
321
c5123824 322 if (fFctProcessHLTOUT) {
323 typedef int (*AliHLTSystemProcessHLTOUT)(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd);
324 AliHLTSystemProcessHLTOUT pFunc=(AliHLTSystemProcessHLTOUT)fFctProcessHLTOUT;
325 if ((pFunc)(pSystem, pHLTOUT, esd)<0) {
326 AliError("error processing HLTOUT");
327 }
328 }
b005ef92 329 pHLTOUT->Reset();
7f9ab840 330}
032c5e5e 331
332void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
333{
334 // debugging/helper function to examine simulated data
335 if (!digitFile) return;
336
337 // read the number of events
338 TFile f(digitFile);
339 if (f.IsZombie()) return;
340 TTree* pTree=NULL;
341 f.GetObject("rawhltout", pTree);
342 if (!pTree) {
343 AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
344 return ;
345 }
346 int nofEvents=pTree->GetEntries();
347 f.Close();
348 //delete pTree; OF COURSE NOT! its an object in the file
349 pTree=NULL;
350
351 for (int event=0; event<nofEvents; event++) {
352 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
353 if (pHLTOUT) {
354 AliInfo(Form("event %d", event));
b005ef92 355 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 356 delete pHLTOUT;
357 } else {
358 AliError("error creating HLTOUT handler");
359 }
360 }
361}
362
363void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
364{
365 // debugging/helper function to examine simulated or real HLTOUT data
366 if (!pRawReader) return;
367
368 pRawReader->RewindEvents();
369 for (int event=0; pRawReader->NextEvent(); event++) {
370 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
371 if (pHLTOUT) {
372 AliInfo(Form("event %d", event));
b005ef92 373 ProcessHLTOUT(pHLTOUT, pEsd, true);
032c5e5e 374 delete pHLTOUT;
375 } else {
376 AliError("error creating HLTOUT handler");
377 }
378 }
379}
380
381void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
382{
383 // print the block specifications of the HLTOUT data blocks
384 if (!pHLTOUT) return;
385 int iResult=0;
386
387 for (iResult=pHLTOUT->SelectFirstDataBlock();
388 iResult>=0;
389 iResult=pHLTOUT->SelectNextDataBlock()) {
390 AliHLTComponentDataType dt=kAliHLTVoidDataType;
391 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
392 pHLTOUT->GetDataBlockDescription(dt, spec);
393 const AliHLTUInt8_t* pBuffer=NULL;
394 AliHLTUInt32_t size=0;
395 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
396 pHLTOUT->ReleaseDataBuffer(pBuffer);
397 pBuffer=NULL; // just a dummy
398 }
399 AliInfo(Form(" %s 0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));
400 }
401}