- handling of global AliHLTSystem singleton moved to BASE
[u/mrichter/AliRoot.git] / HLT / sim / AliHLTSimulation.cxx
CommitLineData
4cbaf07b 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 AliHLTSimulation.cxx
20 @author Matthias Richter
21 @date
22 @brief Binding class for HLT simulation in AliRoot. */
23
24#include <cassert>
25#include <cerrno>
7777fa45 26#include "TObjArray.h"
27#include "TObjString.h"
4cbaf07b 28#include "AliHLTSimulation.h"
29#include "AliLog.h"
30#include "AliRunLoader.h"
31#include "AliHLTSystem.h"
7777fa45 32#include "AliRawReaderFile.h"
33#include "AliRawReaderDate.h"
34#include "AliRawReaderRoot.h"
a8420176 35#include "AliESDEvent.h"
2c0e5942 36#include "AliHLTOUTComponent.h"
4cbaf07b 37
38#if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION
39#error library version in header file and lib*.pkg do not match
40#endif
41
42/** ROOT macro for the implementation of ROOT specific class methods */
43ClassImp(AliHLTSimulation);
44
45AliHLTSimulation::AliHLTSimulation()
46 :
47 fOptions(),
7777fa45 48 fpRawReader(NULL)
4cbaf07b 49{
50 // see header file for class documentation
51 // or
52 // refer to README to build package
53 // or
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55}
56
57AliHLTSimulation::~AliHLTSimulation()
58{
59 // see header file for function documentation
7777fa45 60 if (fpRawReader) {
61 delete fpRawReader;
62 }
63 fpRawReader=NULL;
4cbaf07b 64}
65
66AliHLTSimulation* AliHLTSimulation::CreateInstance()
67{
68 // see header file for function documentation
69 return new AliHLTSimulation;
70}
71
72int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim)
73{
74 // see header file for function documentation
75 assert(pSim!=NULL);
76 delete pSim;
77 return 0;
78}
79
80int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options)
81{
82 // init the simulation
83 fOptions=options;
7777fa45 84 TString sysOp;
4cbaf07b 85
2c0e5942 86 AliHLTSystem* pSystem=GetInstance();
87 if (!pSystem) {
88 AliError("can not get AliHLTSystem instance");
4cbaf07b 89 return -ENOMEM;
90 }
2c0e5942 91 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
4cbaf07b 92 AliError("HLT system in error state");
93 return -EFAULT;
94 }
95
7777fa45 96 // scan options for specific entries
97 TObjArray* pTokens=fOptions.Tokenize(" ");
98 if (pTokens) {
99 int iEntries=pTokens->GetEntries();
100 for (int i=0; i<iEntries; i++) {
101 TString token=(((TObjString*)pTokens->At(i))->GetString());
102 if (token.Contains("rawfile=")) {
103 TString param=token.ReplaceAll("rawfile=", "");
104 if (param.EndsWith("/")) {
105 AliInfo(Form("creating AliRawReaderFile (%s)", param.Data()));
106 fpRawReader = new AliRawReaderFile(param);
107 } else if (param.EndsWith(".root")) {
108 AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data()));
109 fpRawReader = new AliRawReaderRoot(param);
110 } else if (!param.IsNull()) {
111 AliInfo(Form("creating AliRawReaderDate (%s)", param.Data()));
112 fpRawReader = new AliRawReaderDate(param);
113 fpRawReader->SelectEvents(7);
114 }
115 if (fpRawReader) {
116 fpRawReader->RewindEvents();
117 int count=0;
118 for (; fpRawReader->NextEvent(); count++);
119 if (count!=pRunLoader->GetNumberOfEvents()) {
120 AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader",
121 pRunLoader->GetNumberOfEvents(), count));
122 count=0;
123 }
124 if (count>0) {
125 fpRawReader->RewindEvents();
126 fpRawReader->NextEvent();
127 } else {
128 delete fpRawReader;
129 fpRawReader=NULL;
130 }
131 }
2c0e5942 132 } else if (token.Contains("writerawfiles=")) {
133 if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) {
134 AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles);
135 }
7777fa45 136 } else {
137 if (sysOp.Length()>0) sysOp+=" ";
138 sysOp+=token;
139 }
140 }
141 delete pTokens;
142 }
143
144 // scan options
2c0e5942 145 if (pSystem->ScanOptions(sysOp.Data())<0) {
4cbaf07b 146 AliError("error setting options for HLT system");
147 return -EINVAL;
148 }
149
2c0e5942 150 if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
151 if ((pSystem->Configure(pRunLoader))<0) {
4cbaf07b 152 AliError("error during HLT system configuration");
153 return -EFAULT;
154 }
155 }
156
157 return 0;
158}
159
160
161int AliHLTSimulation::Run(AliRunLoader* pRunLoader)
162{
163 // HLT reconstruction for simulated data
164 if(!pRunLoader) {
165 AliError("Missing RunLoader! 0x0");
166 return -EINVAL;
167 }
168
7777fa45 169 int nEvents = pRunLoader->GetNumberOfEvents();
4cbaf07b 170 int iResult=0;
171
2c0e5942 172 AliHLTSystem* pSystem=GetInstance();
173 if (!pSystem) {
174 AliError("can not get AliHLTSystem instance");
175 return -ENOMEM;
176 }
177 if (pSystem->CheckStatus(AliHLTSystem::kError)) {
4cbaf07b 178 AliError("HLT system in error state");
179 return -EFAULT;
180 }
7777fa45 181
182 // Note: the rawreader is already placed at the first event
2c0e5942 183 if ((iResult=pSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) {
184 pSystem->FillESD(0, pRunLoader, NULL);
7777fa45 185 for (int i=1; i<nEvents; i++) {
186 if (fpRawReader && !fpRawReader->NextEvent()) {
187 AliError("missmatch in event count, rawreader corrupted");
188 break;
189 }
2c0e5942 190 pSystem->Reconstruct(1, pRunLoader, fpRawReader);
191 pSystem->FillESD(i, pRunLoader, NULL);
7777fa45 192 }
dee38f1b 193 // send specific 'event' to execute the stop sequence
2c0e5942 194 pSystem->Reconstruct(0, NULL, NULL);
4cbaf07b 195 }
196 return iResult;
197}
198
199
200AliHLTSimulation* AliHLTSimulationCreateInstance()
201{
202 // see header file for function documentation
203 return AliHLTSimulation::CreateInstance();
204}
205
206int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim)
207{
208 // see header file for function documentation
209 return AliHLTSimulation::DeleteInstance(pSim);
210}
211
212int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options)
213{
214 assert(pSim!=NULL);
215 if (pSim) {
216 return pSim->Init(pRunLoader, options);
217 }
218 return -ENODEV;
219}
220
221int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader)
222{
223 assert(pSim!=NULL);
224 if (pSim) {
225 return pSim->Run(pRunLoader);
226 }
227 return -ENODEV;
228}
229
230int AliHLTSimulationGetLibraryVersion()
231{
232 // see header file for function documentation
233 return LIBHLTSIM_VERSION;
234}