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"
36 #include "AliHLTPluginBase.h"
38 ClassImp(AliHLTReconstructor)
40 AliHLTReconstructor::AliHLTReconstructor()
43 fFctProcessHLTOUT(NULL),
45 fpPluginBase(new AliHLTPluginBase)
50 AliHLTReconstructor::AliHLTReconstructor(const char* options)
53 fFctProcessHLTOUT(NULL),
55 fpPluginBase(new AliHLTPluginBase)
58 if (options) Init(options);
61 AliHLTReconstructor::~AliHLTReconstructor()
66 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
68 AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
69 if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
70 // send specific 'event' to execute the stop sequence
71 pSystem->Reconstruct(0, NULL, NULL);
78 if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
82 void AliHLTReconstructor::Init(const char* options)
84 // init the reconstructor
89 void AliHLTReconstructor::Init()
91 // init the reconstructor
93 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
97 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
99 AliError("can not create AliHLTSystem object");
102 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
103 AliError("HLT system in error state");
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.
111 TString option = GetOption();
112 TObjArray* pTokens=option.Tokenize(" ");
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()) {
121 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
122 } else if (param.BeginsWith("0x") &&
123 param.Replace(0,2,"",0).IsHex()) {
125 sscanf(param.Data(),"%x", &severity);
126 pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
128 AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
130 } else if (token.Contains("alilog=off")) {
131 pSystem->SwitchAliLog(0);
132 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
136 if (option.Length()>0) option+=" ";
143 if (!libs.IsNull() &&
144 (!pSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
145 (pSystem->LoadComponentLibraries(libs.Data())<0)) {
146 AliError("error while loading HLT libraries");
150 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
151 typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
152 gSystem->Load("libHLTinterface.so");
153 AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
155 if ((pFunc)(pSystem, option.Data())<0) {
156 AliError("error setting options for HLT system");
159 } else if (option.Length()>0) {
160 AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
163 if ((pSystem->Configure())<0) {
164 AliError("error during HLT system configuration");
169 gSystem->Load("libHLTinterface.so");
170 fFctProcessHLTOUT=(void (*)())gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
172 fpEsdManager=AliHLTEsdManager::New();
175 void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const
177 // reconstruction of real data without writing of ESD
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
182 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
187 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
190 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
191 AliError("HLT system in error state");
194 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
195 AliError("HLT system in wrong state");
198 if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
203 void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/,
204 AliESDEvent* esd) const
206 // reconstruct real data and fill ESD
207 if (!rawReader || !esd) {
208 AliError("missing raw reader or esd object");
213 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
217 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
220 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
221 AliError("HLT system in error state");
224 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
225 AliError("HLT system in wrong state");
228 pSystem->FillESD(-1, NULL, esd);
230 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
232 ProcessHLTOUT(pHLTOUT, esd);
235 AliError("error creating HLTOUT handler");
240 void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
242 // reconstruct simulated data
244 // all reconstruction has been moved to FillESD
245 //AliReconstructor::Reconstruct(digitsTree,clustersTree);
246 AliInfo("running digit data reconstruction");
249 void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
251 // reconstruct simulated data and fill ESD
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
256 TString option = GetOption();
257 if (!option.IsNull() &&
258 (option.Contains("config=") || option.Contains("chains="))) {
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."
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"
271 " /*********************************************************/", option.Data()));
274 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
278 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
280 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
281 AliError("HLT system in error state");
284 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
285 AliError("HLT system in wrong state");
289 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
291 ProcessHLTOUT(pHLTOUT, esd);
294 AliError("error creating HLTOUT handler");
299 void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bool bVerbose) const
301 // treatment of simulated or real HLTOUT data
302 if (!pHLTOUT) return;
304 AliError("internal memory error: can not get AliHLTSystem instance from plugin");
308 AliHLTSystem* pSystem=fpPluginBase->GetInstance();
310 AliError("error getting HLT system instance");
314 if (pHLTOUT->Init()<0) {
315 AliError("error : initialization of HLTOUT handler failed");
320 PrintHLTOUTContent(pHLTOUT);
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");
332 void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const
334 // debugging/helper function to examine simulated data
335 if (!digitFile) return;
337 // read the number of events
339 if (f.IsZombie()) return;
341 f.GetObject("rawhltout", pTree);
343 AliWarning(Form("can not find tree rawhltout in file %s", digitFile));
346 int nofEvents=pTree->GetEntries();
348 //delete pTree; OF COURSE NOT! its an object in the file
351 for (int event=0; event<nofEvents; event++) {
352 AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(event, fpEsdManager, digitFile);
354 AliInfo(Form("event %d", event));
355 ProcessHLTOUT(pHLTOUT, pEsd, true);
358 AliError("error creating HLTOUT handler");
363 void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* pEsd) const
365 // debugging/helper function to examine simulated or real HLTOUT data
366 if (!pRawReader) return;
368 pRawReader->RewindEvents();
369 for (int event=0; pRawReader->NextEvent(); event++) {
370 AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(pRawReader, event, fpEsdManager);
372 AliInfo(Form("event %d", event));
373 ProcessHLTOUT(pHLTOUT, pEsd, true);
376 AliError("error creating HLTOUT handler");
381 void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
383 // print the block specifications of the HLTOUT data blocks
384 if (!pHLTOUT) return;
387 for (iResult=pHLTOUT->SelectFirstDataBlock();
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
399 AliInfo(Form(" %s 0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));