3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTReconstructor.cxx
20 @author Matthias Richter
22 @brief Binding class for HLT reconstruction in AliRoot. */
25 #include <TObjString.h>
28 #include "AliHLTReconstructor.h"
30 #include "AliRawReader.h"
31 #include "AliESDEvent.h"
32 #include "AliHLTSystem.h"
33 #include "AliHLTOUTRawReader.h"
34 #include "AliHLTOUTDigitReader.h"
35 #include "AliHLTEsdManager.h"
37 ClassImp(AliHLTReconstructor)
39 AliHLTReconstructor::AliHLTReconstructor()
42 AliHLTReconstructorBase(),
43 fFctProcessHLTOUT(NULL),
49 AliHLTReconstructor::AliHLTReconstructor(const char* options)
52 AliHLTReconstructorBase(),
53 fFctProcessHLTOUT(NULL),
57 if (options) Init(options);
60 AliHLTReconstructor::~AliHLTReconstructor()
64 AliHLTSystem* pSystem=GetInstance();
66 AliDebug(0, Form("delete HLT system: status %#x", pSystem->GetStatusFlags()));
67 if (pSystem->CheckStatus(AliHLTSystem::kReady)) {
68 // send specific 'event' to execute the stop sequence
69 pSystem->Reconstruct(0, NULL, NULL);
73 if (fpEsdManager) delete fpEsdManager;
77 void AliHLTReconstructor::Init(const char* options)
79 // init the reconstructor
84 void AliHLTReconstructor::Init()
86 // init the reconstructor
87 AliHLTSystem* pSystem=GetInstance();
89 AliError("can not create AliHLTSystem object");
92 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
93 AliError("HLT system in error state");
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.
101 TString option = GetOption();
102 TObjArray* pTokens=option.Tokenize(" ");
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()) {
111 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
112 } else if (param.BeginsWith("0x") &&
113 param.Replace(0,2,"",0).IsHex()) {
115 sscanf(param.Data(),"%x", &severity);
116 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
118 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
120 } else if (token.Contains("alilog=off")) {
121 pSystem->SwitchAliLog(0);
122 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
126 if (option.Length()>0) option+=" ";
133 if (!libs.IsNull() &&
134 (!pSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
135 (pSystem->LoadComponentLibraries(libs.Data())<0)) {
136 AliError("error while loading HLT libraries");
140 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
141 typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
142 gSystem->Load("libHLTinterface.so");
143 AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
145 if ((pFunc)(pSystem, option.Data())<0) {
146 AliError("error setting options for HLT system");
149 } else if (option.Length()>0) {
150 AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
153 if ((pSystem->Configure())<0) {
154 AliError("error during HLT system configuration");
159 gSystem->Load("libHLTinterface.so");
160 fFctProcessHLTOUT=gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
162 fpEsdManager=new AliHLTEsdManager;
165 void AliHLTReconstructor::Reconstruct(AliRawReader* /*rawReader*/, TTree* /*clustersTree*/) const
167 // reconstruction of real data without writing of ESD
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
171 AliHLTSystem* pSystem=GetInstance();
172 AliInfo("running raw data reconstruction");
175 void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/,
176 AliESDEvent* esd) const
178 // reconstruct real data and fill ESD
179 if (!rawReader || !esd) {
180 AliError("missing raw reader or esd object");
184 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
185 // code needs to be moved back to Reconstruct as soon es HLT loader is implemented
187 AliHLTSystem* pSystem=GetInstance();
189 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
190 AliError("HLT system in error state");
193 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
194 AliError("HLT system in wrong state");
197 if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
200 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
203 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
204 AliError("HLT system in error state");
207 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
208 AliError("HLT system in wrong state");
211 pSystem->FillESD(-1, NULL, esd);
213 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
215 ProcessHLTOUT(pHLTOUT, esd);
218 AliError("error creating HLTOUT handler");
223 void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
225 // reconstruct simulated data
227 // all reconstruction has been moved to FillESD
228 //AliReconstructor::Reconstruct(digitsTree,clustersTree);
229 AliInfo("running digit data reconstruction");
232 void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
234 // reconstruct simulated data and fill ESD
236 // later this is the place to extract the simulated HLT data
237 // for now it's only an user failure condition as he tries to run HLT reconstruction
239 TString option = GetOption();
240 if (!option.IsNull() &&
241 (option.Contains("config=") || option.Contains("chains="))) {
242 AliWarning(Form("HLT reconstruction of simulated data takes place in AliSimulation\n"
243 " /*** run macro *****************************************/\n"
244 " AliSimulation sim;\n"
245 " sim.SetRunHLT(\"%s\");\n"
246 " sim.SetRunGeneration(kFALSE);\n"
247 " sim.SetMakeDigits(\"\");\n"
248 " sim.SetMakeSDigits(\"\");\n"
249 " sim.SetMakeDigitsFromHits(\"\");\n"
251 " /*********************************************************/", option.Data()));
253 AliHLTSystem* pSystem=GetInstance();
255 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
256 AliError("HLT system in error state");
259 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
260 AliError("HLT system in wrong state");
264 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
266 ProcessHLTOUT(pHLTOUT, esd);
269 AliError("error creating HLTOUT handler");
274 void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) const
276 // treatment of simulated or real HLTOUT data
277 if (!pHLTOUT) return;
278 AliHLTSystem* pSystem=GetInstance();
280 AliError("error getting HLT system instance");
284 if (pHLTOUT->Init()<0) {
285 AliError("error : initialization of HLTOUT handler failed");
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");
298 void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
300 // debugging/helper function to examine simulated data
301 if (!digitFile) return;
303 // read the number of events
305 if (f.IsZombie()) return;
307 f.GetObject("rawhltout", pTree);
309 AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
312 int nofEvents=pTree->GetEntries();
314 //delete pTree; OF COURSE NOT! its an object in the file
317 for (int event=0; event<nofEvents; event++) {
318 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
320 AliInfo(Form("event %d", event));
321 ProcessHLTOUT(pHLTOUT, pEsd);
322 PrintHLTOUTContent(pHLTOUT);
325 AliError("error creating HLTOUT handler");
330 void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
332 // debugging/helper function to examine simulated or real HLTOUT data
333 if (!pRawReader) return;
335 pRawReader->RewindEvents();
336 for (int event=0; pRawReader->NextEvent(); event++) {
337 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
339 AliInfo(Form("event %d", event));
340 ProcessHLTOUT(pHLTOUT, pEsd);
341 PrintHLTOUTContent(pHLTOUT);
344 AliError("error creating HLTOUT handler");
349 void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
351 // print the block specifications of the HLTOUT data blocks
352 if (!pHLTOUT) return;
355 for (iResult=pHLTOUT->SelectFirstDataBlock();
357 iResult=pHLTOUT->SelectNextDataBlock()) {
358 AliHLTComponentDataType dt=kAliHLTVoidDataType;
359 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
360 pHLTOUT->GetDataBlockDescription(dt, spec);
361 const AliHLTUInt8_t* pBuffer=NULL;
362 AliHLTUInt32_t size=0;
363 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
364 pHLTOUT->ReleaseDataBuffer(pBuffer);
365 pBuffer=NULL; // just a dummy
367 AliInfo(Form(" %s 0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));