]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/rec/AliHLTReconstructor.cxx
- bugfix component handler: library load via gSystem pretended to fail in some
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
1 // $Id$
2
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 //**************************************************************************
18
19 /** @file   AliHLTReconstructor.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Binding class for HLT reconstruction in AliRoot. */
23
24 #include <TSystem.h>
25 #include <TObjString.h>
26 #include "AliHLTReconstructor.h"
27 #include "AliLog.h"
28 #include "AliESDEvent.h"
29 #include "AliHLTSystem.h"
30 #include "AliHLTOUTRawReader.h"
31 #include "AliHLTOUTDigitReader.h"
32 #include "AliHLTEsdManager.h"
33
34 ClassImp(AliHLTReconstructor)
35
36 AliHLTReconstructor::AliHLTReconstructor()
37   : 
38   AliReconstructor(),
39   AliHLTReconstructorBase(),
40   fFctProcessHLTOUT(NULL),
41   fpEsdManager(NULL)
42
43   //constructor
44 }
45
46 AliHLTReconstructor::~AliHLTReconstructor()
47
48   //destructor
49
50   AliHLTSystem* pSystem=GetInstance();
51   if (pSystem) {
52     AliDebug(0, Form("delete HLT system: status %#x", pSystem->GetStatusFlags()));
53     if (pSystem->CheckStatus(AliHLTSystem::kReady)) {
54       // send specific 'event' to execute the stop sequence
55       pSystem->Reconstruct(0, NULL, NULL);
56     }
57   }
58
59   if (fpEsdManager) delete fpEsdManager;
60   fpEsdManager=NULL;
61 }
62
63 void AliHLTReconstructor::Init()
64 {
65   // init the reconstructor
66   AliHLTSystem* pSystem=GetInstance();
67   if (!pSystem) {
68     AliError("can not create AliHLTSystem object");
69     return;
70   }
71   if (pSystem->CheckStatus(AliHLTSystem::kError)) {
72     AliError("HLT system in error state");
73     return;
74   }
75
76   // the options scan has been moved to AliHLTSystem, the old code
77   // here is kept to be able to run an older version of the HLT code
78   // with newer AliRoot versions.
79   TString libs("");
80   TString option = GetOption();
81   TObjArray* pTokens=option.Tokenize(" ");
82   option="";
83   if (pTokens) {
84     int iEntries=pTokens->GetEntries();
85     for (int i=0; i<iEntries; i++) {
86       TString token=(((TObjString*)pTokens->At(i))->GetString());
87       if (token.Contains("loglevel=")) {
88         TString param=token.ReplaceAll("loglevel=", "");
89         if (param.IsDigit()) {
90           pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
91         } else if (param.BeginsWith("0x") &&
92                    param.Replace(0,2,"",0).IsHex()) {
93           int severity=0;
94           sscanf(param.Data(),"%x", &severity);
95           pSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
96         } else {
97           AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
98         }
99       } else if (token.Contains("alilog=off")) {
100         pSystem->SwitchAliLog(0);
101       } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
102         libs+=token;
103         libs+=" ";
104       } else {
105         if (option.Length()>0) option+=" ";
106         option+=token;
107       }
108     }
109     delete pTokens;
110   }
111
112   if (!libs.IsNull() &&
113       (!pSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
114       (pSystem->LoadComponentLibraries(libs.Data())<0)) {
115     AliError("error while loading HLT libraries");
116     return;
117   }
118
119   if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
120     typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
121     gSystem->Load("libHLTinterface.so");
122     AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
123     if (pFunc) {
124       if ((pFunc)(pSystem, option.Data())<0) {
125       AliError("error setting options for HLT system");
126       return;   
127       }
128     } else if (option.Length()>0) {
129       AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
130       return;
131     }
132     if ((pSystem->Configure())<0) {
133       AliError("error during HLT system configuration");
134       return;
135     }
136   }
137
138   gSystem->Load("libHLTinterface.so");
139   fFctProcessHLTOUT=gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
140
141   fpEsdManager=new AliHLTEsdManager;
142 }
143
144 void AliHLTReconstructor::Reconstruct(AliRawReader* /*rawReader*/, TTree* /*clustersTree*/) const 
145 {
146   // reconstruction of real data without writing of ESD
147   // For each event, HLT reconstruction chains can be executed and
148   // added to the existing HLTOUT data
149   // The HLTOUT data is finally processed in FillESD
150   AliHLTSystem* pSystem=GetInstance();
151 }
152
153 void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/, 
154                                   AliESDEvent* esd) const
155 {
156   // reconstruct real data and fill ESD
157   if (!rawReader || !esd) {
158     AliError("missing raw reader or esd object");
159     return;
160   }
161
162   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
163   // code needs to be moved back to Reconstruct as soon es HLT loader is implemented
164   int iResult=0;
165   AliHLTSystem* pSystem=GetInstance();
166   if (pSystem) {
167     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
168       AliError("HLT system in error state");
169       return;
170     }
171     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
172       AliError("HLT system in wrong state");
173       return;
174     }
175     if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
176     }
177   }
178   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
179
180   if (pSystem) {
181     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
182       AliError("HLT system in error state");
183       return;
184     }
185     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
186       AliError("HLT system in wrong state");
187       return;
188     }
189     pSystem->FillESD(-1, NULL, esd);
190
191     AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
192     if (pHLTOUT) {
193       ProcessHLTOUT(pHLTOUT, esd);
194       delete pHLTOUT;
195     } else {
196       AliError("error creating HLTOUT handler");
197     }
198   }
199 }
200
201 void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
202 {
203   // reconstruct simulated data
204
205   // all reconstruction has been moved to FillESD
206   //AliReconstructor::Reconstruct(digitsTree,clustersTree);
207 }
208
209 void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
210 {
211   // reconstruct simulated data and fill ESD
212
213   // later this is the place to extract the simulated HLT data
214   // for now it's only an user failure condition as he tries to run HLT reconstruction
215   // on simulated data 
216   TString option = GetOption();
217   if (!option.IsNull() && 
218       (option.Contains("config=") || option.Contains("chains="))) {
219     AliWarning(Form("HLT reconstruction of simulated data takes place in AliSimulation\n"
220                     "        /***  run macro *****************************************/\n"
221                     "        AliSimulation sim;\n"
222                     "        sim.SetRunHLT(\"%s\");\n"
223                     "        sim.SetRunGeneration(kFALSE);\n"
224                     "        sim.SetMakeDigits(\"\");\n"
225                     "        sim.SetMakeSDigits(\"\");\n"
226                     "        sim.SetMakeDigitsFromHits(\"\");\n"
227                     "        sim.Run();\n"
228                     "        /*********************************************************/", option.Data()));
229   }
230   AliHLTSystem* pSystem=GetInstance();
231   if (pSystem) {
232     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
233       AliError("HLT system in error state");
234       return;
235     }
236     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
237       AliError("HLT system in wrong state");
238       return;
239     }
240
241     AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
242     if (pHLTOUT) {
243       ProcessHLTOUT(pHLTOUT, esd);
244       delete pHLTOUT;
245     } else {
246       AliError("error creating HLTOUT handler");
247     }
248   }
249 }
250
251 void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) const
252 {
253   // treatment of simulated or real HLTOUT data
254   if (!pHLTOUT) return;
255   AliHLTSystem* pSystem=GetInstance();
256   if (!pSystem) {
257     AliError("error getting HLT system instance");
258     return;
259   }
260
261   if (pHLTOUT->Init()<0) {
262     AliError("error : initialization of HLTOUT handler failed");
263     return;
264   }
265
266   if (fFctProcessHLTOUT) {
267     typedef int (*AliHLTSystemProcessHLTOUT)(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd);
268     AliHLTSystemProcessHLTOUT pFunc=(AliHLTSystemProcessHLTOUT)fFctProcessHLTOUT;
269     if ((pFunc)(pSystem, pHLTOUT, esd)<0) {
270       AliError("error processing HLTOUT");
271     }
272   }
273 }