]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/rec/AliHLTReconstructor.cxx
documentation
[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   AliHLTReconstruction.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 "AliHLTSystem.h"
29
30 ClassImp(AliHLTReconstructor)
31
32 AliHLTReconstructor::AliHLTReconstructor()
33   : 
34   AliReconstructor(),
35   fpSystem(NULL)
36
37   //constructor
38 }
39
40 AliHLTReconstructor::~AliHLTReconstructor()
41
42   //destructor
43   if (fpSystem) {
44     delete fpSystem;
45   }
46   fpSystem=NULL;
47 }
48
49 void AliHLTReconstructor::Init()
50 {
51   // init the reconstructor
52   if (!fpSystem) fpSystem=new AliHLTSystem;
53   if (!fpSystem) {
54     AliError("can not create AliHLTSystem object");
55     return;
56   }
57   if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
58     AliError("HLT system in error state");
59     return;
60   }
61
62   // the options scan has been moved to AliHLTSystem, the old code
63   // here is kept to be able to run an older version of the HLT code
64   // with newer AliRoot versions.
65   TString libs("");
66   TString option = GetOption();
67   TObjArray* pTokens=option.Tokenize(" ");
68   option="";
69   if (pTokens) {
70     int iEntries=pTokens->GetEntries();
71     for (int i=0; i<iEntries; i++) {
72       TString token=(((TObjString*)pTokens->At(i))->GetString());
73       if (token.Contains("loglevel=")) {
74         TString param=token.ReplaceAll("loglevel=", "");
75         if (param.IsDigit()) {
76           fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
77         } else if (param.BeginsWith("0x") &&
78                    param.Replace(0,2,"",0).IsHex()) {
79           int severity=0;
80           sscanf(param.Data(),"%x", &severity);
81           fpSystem->SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
82         } else {
83           AliWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
84         }
85       } else if (token.Contains("alilog=off")) {
86         fpSystem->SwitchAliLog(0);
87       } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
88         libs+=token;
89         libs+=" ";
90       } else {
91         if (option.Length()>0) option+=" ";
92         option+=token;
93       }
94     }
95     delete pTokens;
96   }
97
98   if (!libs.IsNull() &&
99       (!fpSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
100       (fpSystem->LoadComponentLibraries(libs.Data())<0)) {
101     AliError("error while loading HLT libraries");
102     return;
103   }
104
105   if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
106     typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
107     gSystem->Load("libHLTinterface.so");
108     AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
109     if (pFunc) {
110       if ((pFunc)(fpSystem, option.Data())<0) {
111       AliError("error setting options for HLT system");
112       return;   
113       }
114     } else if (option.Length()>0) {
115       AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
116       return;
117     }
118     if ((fpSystem->Configure())<0) {
119       AliError("error during HLT system configuration");
120       return;
121     }
122   }
123 }
124
125 void AliHLTReconstructor::Reconstruct(AliRawReader* /*rawReader*/, TTree* /*clustersTree*/) const 
126 {
127   // reconstruction of real data without writing of ESD
128
129   // all reconstruction has been moved to FillESD
130 //   int iResult=0;
131 //   if (fpSystem) {
132 //     if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
133 //       AliError("HLT system in error state");
134 //       return;
135 //     }
136 //     if ((iResult=fpSystem->Reconstruct(1, NULL, rawReader))>=0) {
137 //     }
138 //   }
139 }
140
141 void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree*/, 
142                                   AliESDEvent* esd) const
143 {
144   // reconstruct real data and fill ESD
145   int iResult=0;
146   if (fpSystem) {
147     if (fpSystem->CheckStatus(AliHLTSystem::kError)) {
148       AliError("HLT system in error state");
149       return;
150     }
151     if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) {
152       AliError("HLT system in wrong state");
153       return;
154     }
155     if ((iResult=fpSystem->Reconstruct(1, NULL, rawReader))>=0) {
156       fpSystem->FillESD(-1, NULL, esd);
157     }
158   }
159 }
160
161 void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTree*/) const
162 {
163   // reconstruct simulated data
164
165   // all reconstruction has been moved to FillESD
166   //AliReconstructor::Reconstruct(digitsTree,clustersTree);
167 }
168
169 void AliHLTReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree, AliESDEvent* esd) const
170 {
171   // reconstruct simulated data and fill ESD
172
173   // later this is the place to extract the simulated HLT data
174   // for now it's only an user failure condition as he tries to run HLT reconstruction
175   // on simulated data 
176   TString option = GetOption();
177   if (!option.IsNull()) {
178     AliWarning(Form("HLT reconstruction of simulated data takes place in AliSimulation\n"
179                     "        /***  run macro *****************************************/\n"
180                     "        AliSimulation sim;\n"
181                     "        sim.SetRunHLT(\"%s\");\n"
182                     "        sim.SetRunGeneration(kFALSE);\n"
183                     "        sim.SetMakeDigits(\"\");\n"
184                     "        sim.SetMakeSDigits(\"\");\n"
185                     "        sim.SetMakeDigitsFromHits(\"\");\n"
186                     "        sim.Run();\n"
187                     "        /*********************************************************/", option.Data()));
188   }
189   AliReconstructor::FillESD(digitsTree,clustersTree,esd);
190 }