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