]>
Commit | Line | Data |
---|---|---|
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 */ | |
43 | ClassImp(AliHLTSimulation); | |
44 | ||
45 | AliHLTSimulation::AliHLTSimulation() | |
46 | : | |
47 | fOptions(), | |
57034f7f | 48 | fpSystem(NULL), |
7777fa45 | 49 | fpRawReader(NULL) |
4cbaf07b | 50 | { |
51 | // see header file for class documentation | |
52 | // or | |
53 | // refer to README to build package | |
54 | // or | |
55 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
56 | } | |
57 | ||
58 | AliHLTSimulation::~AliHLTSimulation() | |
59 | { | |
60 | // see header file for function documentation | |
57034f7f | 61 | if (fpSystem) { |
62 | delete fpSystem; | |
63 | } | |
64 | fpSystem=NULL; | |
7777fa45 | 65 | if (fpRawReader) { |
66 | delete fpRawReader; | |
67 | } | |
68 | fpRawReader=NULL; | |
4cbaf07b | 69 | } |
70 | ||
71 | AliHLTSimulation* AliHLTSimulation::CreateInstance() | |
72 | { | |
73 | // see header file for function documentation | |
74 | return new AliHLTSimulation; | |
75 | } | |
76 | ||
77 | int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim) | |
78 | { | |
79 | // see header file for function documentation | |
80 | assert(pSim!=NULL); | |
81 | delete pSim; | |
82 | return 0; | |
83 | } | |
84 | ||
85 | int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options) | |
86 | { | |
87 | // init the simulation | |
88 | fOptions=options; | |
7777fa45 | 89 | TString sysOp; |
4cbaf07b | 90 | |
57034f7f | 91 | if (!fpSystem) fpSystem=new AliHLTSystem; |
92 | if (!fpSystem) { | |
93 | AliError("can not create AliHLTSystem object"); | |
4cbaf07b | 94 | return -ENOMEM; |
95 | } | |
57034f7f | 96 | if (fpSystem->CheckStatus(AliHLTSystem::kError)) { |
4cbaf07b | 97 | AliError("HLT system in error state"); |
98 | return -EFAULT; | |
99 | } | |
100 | ||
7777fa45 | 101 | // scan options for specific entries |
102 | TObjArray* pTokens=fOptions.Tokenize(" "); | |
103 | if (pTokens) { | |
104 | int iEntries=pTokens->GetEntries(); | |
105 | for (int i=0; i<iEntries; i++) { | |
106 | TString token=(((TObjString*)pTokens->At(i))->GetString()); | |
107 | if (token.Contains("rawfile=")) { | |
108 | TString param=token.ReplaceAll("rawfile=", ""); | |
109 | if (param.EndsWith("/")) { | |
110 | AliInfo(Form("creating AliRawReaderFile (%s)", param.Data())); | |
111 | fpRawReader = new AliRawReaderFile(param); | |
112 | } else if (param.EndsWith(".root")) { | |
113 | AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data())); | |
114 | fpRawReader = new AliRawReaderRoot(param); | |
115 | } else if (!param.IsNull()) { | |
116 | AliInfo(Form("creating AliRawReaderDate (%s)", param.Data())); | |
117 | fpRawReader = new AliRawReaderDate(param); | |
118 | fpRawReader->SelectEvents(7); | |
119 | } | |
120 | if (fpRawReader) { | |
121 | fpRawReader->RewindEvents(); | |
122 | int count=0; | |
123 | for (; fpRawReader->NextEvent(); count++); | |
124 | if (count!=pRunLoader->GetNumberOfEvents()) { | |
125 | AliError(Form("missmatch in event count: runloader %d, rawreader %d; ignoring rawreader", | |
126 | pRunLoader->GetNumberOfEvents(), count)); | |
127 | count=0; | |
128 | } | |
129 | if (count>0) { | |
130 | fpRawReader->RewindEvents(); | |
131 | fpRawReader->NextEvent(); | |
132 | } else { | |
133 | delete fpRawReader; | |
134 | fpRawReader=NULL; | |
135 | } | |
136 | } | |
2c0e5942 | 137 | } else if (token.Contains("writerawfiles=")) { |
138 | if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) { | |
139 | AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles); | |
140 | } | |
7777fa45 | 141 | } else { |
142 | if (sysOp.Length()>0) sysOp+=" "; | |
143 | sysOp+=token; | |
144 | } | |
145 | } | |
146 | delete pTokens; | |
147 | } | |
148 | ||
149 | // scan options | |
57034f7f | 150 | if (fpSystem->ScanOptions(sysOp.Data())<0) { |
4cbaf07b | 151 | AliError("error setting options for HLT system"); |
152 | return -EINVAL; | |
153 | } | |
154 | ||
57034f7f | 155 | if (!fpSystem->CheckStatus(AliHLTSystem::kReady)) { |
156 | if ((fpSystem->Configure(pRunLoader))<0) { | |
4cbaf07b | 157 | AliError("error during HLT system configuration"); |
158 | return -EFAULT; | |
159 | } | |
160 | } | |
161 | ||
162 | return 0; | |
163 | } | |
164 | ||
165 | ||
166 | int AliHLTSimulation::Run(AliRunLoader* pRunLoader) | |
167 | { | |
168 | // HLT reconstruction for simulated data | |
169 | if(!pRunLoader) { | |
170 | AliError("Missing RunLoader! 0x0"); | |
171 | return -EINVAL; | |
172 | } | |
173 | ||
7777fa45 | 174 | int nEvents = pRunLoader->GetNumberOfEvents(); |
4cbaf07b | 175 | int iResult=0; |
176 | ||
57034f7f | 177 | if (fpSystem->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 | |
57034f7f | 183 | if ((iResult=fpSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) { |
184 | fpSystem->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 | } | |
57034f7f | 190 | fpSystem->Reconstruct(1, pRunLoader, fpRawReader); |
191 | fpSystem->FillESD(i, pRunLoader, NULL); | |
7777fa45 | 192 | } |
dee38f1b | 193 | // send specific 'event' to execute the stop sequence |
57034f7f | 194 | fpSystem->Reconstruct(0, NULL, NULL); |
4cbaf07b | 195 | } |
196 | return iResult; | |
197 | } | |
198 | ||
199 | ||
200 | AliHLTSimulation* AliHLTSimulationCreateInstance() | |
201 | { | |
202 | // see header file for function documentation | |
203 | return AliHLTSimulation::CreateInstance(); | |
204 | } | |
205 | ||
206 | int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim) | |
207 | { | |
208 | // see header file for function documentation | |
209 | return AliHLTSimulation::DeleteInstance(pSim); | |
210 | } | |
211 | ||
212 | int 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 | ||
221 | int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader) | |
222 | { | |
223 | assert(pSim!=NULL); | |
224 | if (pSim) { | |
225 | return pSim->Run(pRunLoader); | |
226 | } | |
227 | return -ENODEV; | |
228 | } | |
229 | ||
230 | int AliHLTSimulationGetLibraryVersion() | |
231 | { | |
232 | // see header file for function documentation | |
233 | return LIBHLTSIM_VERSION; | |
234 | } |