]>
Commit | Line | Data |
---|---|---|
4cbaf07b | 1 | // $Id$ |
2 | ||
c5123824 | 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 | //************************************************************************** | |
4cbaf07b | 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" |
5a29e5cb | 29 | #include "AliSimulation.h" |
4cbaf07b | 30 | #include "AliLog.h" |
90c37647 | 31 | #include "AliRun.h" |
4cbaf07b | 32 | #include "AliRunLoader.h" |
90c37647 | 33 | #include "AliHeader.h" |
90c37647 | 34 | #include "AliCDBManager.h" |
35 | #include "AliCDBEntry.h" | |
36 | #include "AliCDBPath.h" | |
37 | #include "AliCDBId.h" | |
38 | #include "AliCDBMetaData.h" | |
8dd79235 | 39 | #include "AliCDBStorage.h" |
40 | #include "AliGRPObject.h" | |
9f199018 | 41 | #include "AliGRPManager.h" |
4cbaf07b | 42 | #include "AliHLTSystem.h" |
7bf6c76d | 43 | #include "AliHLTPluginBase.h" |
7777fa45 | 44 | #include "AliRawReaderFile.h" |
45 | #include "AliRawReaderDate.h" | |
46 | #include "AliRawReaderRoot.h" | |
a8420176 | 47 | #include "AliESDEvent.h" |
2c0e5942 | 48 | #include "AliHLTOUTComponent.h" |
9f199018 | 49 | #include "AliTracker.h" |
8dd79235 | 50 | #include "TGeoGlobalMagField.h" |
51 | #include "TSystem.h" | |
4e1f4995 | 52 | #include "TMath.h" |
9f199018 | 53 | #include "TGeoGlobalMagField.h" |
4cbaf07b | 54 | |
55 | #if ALIHLTSIMULATION_LIBRARY_VERSION != LIBHLTSIM_VERSION | |
56 | #error library version in header file and lib*.pkg do not match | |
57 | #endif | |
58 | ||
59 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
60 | ClassImp(AliHLTSimulation); | |
61 | ||
62 | AliHLTSimulation::AliHLTSimulation() | |
63 | : | |
64 | fOptions(), | |
7bf6c76d | 65 | fpPluginBase(new AliHLTPluginBase), |
7777fa45 | 66 | fpRawReader(NULL) |
4cbaf07b | 67 | { |
68 | // see header file for class documentation | |
69 | // or | |
70 | // refer to README to build package | |
71 | // or | |
72 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
73 | } | |
74 | ||
75 | AliHLTSimulation::~AliHLTSimulation() | |
76 | { | |
77 | // see header file for function documentation | |
7bf6c76d | 78 | if (fpPluginBase) delete fpPluginBase; |
79 | fpPluginBase=NULL; | |
80 | ||
7777fa45 | 81 | if (fpRawReader) { |
82 | delete fpRawReader; | |
83 | } | |
84 | fpRawReader=NULL; | |
4cbaf07b | 85 | } |
86 | ||
87 | AliHLTSimulation* AliHLTSimulation::CreateInstance() | |
88 | { | |
89 | // see header file for function documentation | |
90 | return new AliHLTSimulation; | |
91 | } | |
92 | ||
93 | int AliHLTSimulation::DeleteInstance(AliHLTSimulation* pSim) | |
94 | { | |
95 | // see header file for function documentation | |
96 | assert(pSim!=NULL); | |
97 | delete pSim; | |
98 | return 0; | |
99 | } | |
100 | ||
101 | int AliHLTSimulation::Init(AliRunLoader* pRunLoader, const char* options) | |
102 | { | |
103 | // init the simulation | |
104 | fOptions=options; | |
7777fa45 | 105 | TString sysOp; |
4cbaf07b | 106 | |
7bf6c76d | 107 | if(!fpPluginBase) { |
108 | AliError("internal initialization failed"); | |
109 | return -EINVAL; | |
110 | } | |
111 | ||
112 | AliHLTSystem* pSystem=fpPluginBase->GetInstance(); | |
113 | if (!pSystem) { | |
114 | AliError("can not get AliHLTSystem instance"); | |
4cbaf07b | 115 | return -ENOMEM; |
116 | } | |
7bf6c76d | 117 | if (pSystem->CheckStatus(AliHLTSystem::kError)) { |
4cbaf07b | 118 | AliError("HLT system in error state"); |
119 | return -EFAULT; | |
120 | } | |
121 | ||
7777fa45 | 122 | // scan options for specific entries |
123 | TObjArray* pTokens=fOptions.Tokenize(" "); | |
124 | if (pTokens) { | |
125 | int iEntries=pTokens->GetEntries(); | |
126 | for (int i=0; i<iEntries; i++) { | |
127 | TString token=(((TObjString*)pTokens->At(i))->GetString()); | |
128 | if (token.Contains("rawfile=")) { | |
129 | TString param=token.ReplaceAll("rawfile=", ""); | |
130 | if (param.EndsWith("/")) { | |
131 | AliInfo(Form("creating AliRawReaderFile (%s)", param.Data())); | |
132 | fpRawReader = new AliRawReaderFile(param); | |
133 | } else if (param.EndsWith(".root")) { | |
134 | AliInfo(Form("creating AliRawReaderRoot (%s)", param.Data())); | |
135 | fpRawReader = new AliRawReaderRoot(param); | |
136 | } else if (!param.IsNull()) { | |
137 | AliInfo(Form("creating AliRawReaderDate (%s)", param.Data())); | |
138 | fpRawReader = new AliRawReaderDate(param); | |
7777fa45 | 139 | } |
140 | if (fpRawReader) { | |
141 | fpRawReader->RewindEvents(); | |
142 | int count=0; | |
32f88fc5 | 143 | for ( ; fpRawReader->NextEvent(); count++) {/* empty body */}; |
7777fa45 | 144 | if (count!=pRunLoader->GetNumberOfEvents()) { |
c5123824 | 145 | AliError(Form("mismatch in event count: runloader %d, rawreader %d; ignoring rawreader", |
7777fa45 | 146 | pRunLoader->GetNumberOfEvents(), count)); |
147 | count=0; | |
148 | } | |
149 | if (count>0) { | |
150 | fpRawReader->RewindEvents(); | |
151 | fpRawReader->NextEvent(); | |
152 | } else { | |
153 | delete fpRawReader; | |
154 | fpRawReader=NULL; | |
155 | } | |
156 | } | |
2c0e5942 | 157 | } else if (token.Contains("writerawfiles=")) { |
158 | if (!token.ReplaceAll("writerawfiles=", "").Contains("HLT")) { | |
159 | AliHLTOUTComponent::ClearGlobalOption(AliHLTOUTComponent::kWriteRawFiles); | |
160 | } | |
7777fa45 | 161 | } else { |
162 | if (sysOp.Length()>0) sysOp+=" "; | |
163 | sysOp+=token; | |
164 | } | |
165 | } | |
166 | delete pTokens; | |
167 | } | |
168 | ||
90c37647 | 169 | AliCDBManager* man = AliCDBManager::Instance(); |
170 | if (man && man->IsDefaultStorageSet()) | |
171 | { | |
8dd79235 | 172 | // init solenoid field |
9f199018 | 173 | // 2009-11-07 magnetic field handling fo HLT components has been switched to the |
174 | // global AliMagF instance, the HLT/ConfigHLT/SolenoidBz entry is obsolete | |
175 | // The global instance is either established by the AliRoot environment or the | |
176 | // component external interface. | |
177 | if (TGeoGlobalMagField::Instance()->GetField()) { | |
178 | AliDebug(0, Form("magnetic field: %f", AliTracker::GetBz())); | |
8dd79235 | 179 | } else { |
180 | // workaround for bug #51285 | |
9f199018 | 181 | AliGRPManager grpman; |
182 | if (grpman.ReadGRPEntry() && | |
183 | grpman.SetMagField()) { | |
184 | // nothing to do any more | |
8dd79235 | 185 | } |
9f199018 | 186 | AliError(Form("can not get the AliMagF instance, falling back to GRP entry (%f)", AliTracker::GetBz())); |
90c37647 | 187 | } |
8dd79235 | 188 | } else if (man) { |
189 | AliError("OCDB default storage not yet set, can not prepare OCDB entries"); | |
190 | } else { | |
191 | AliError("unable to get instance of AliCDBMetaData, can not prepare OCDB entries"); | |
90c37647 | 192 | } |
193 | ||
7777fa45 | 194 | // scan options |
7bf6c76d | 195 | if (pSystem->ScanOptions(sysOp.Data())<0) { |
4cbaf07b | 196 | AliError("error setting options for HLT system"); |
197 | return -EINVAL; | |
198 | } | |
199 | ||
7bf6c76d | 200 | if (!pSystem->CheckStatus(AliHLTSystem::kReady)) { |
201 | if ((pSystem->Configure(fpRawReader, pRunLoader))<0) { | |
4cbaf07b | 202 | AliError("error during HLT system configuration"); |
203 | return -EFAULT; | |
204 | } | |
205 | } | |
206 | ||
207 | return 0; | |
208 | } | |
209 | ||
210 | ||
211 | int AliHLTSimulation::Run(AliRunLoader* pRunLoader) | |
212 | { | |
213 | // HLT reconstruction for simulated data | |
7bf6c76d | 214 | if(!fpPluginBase) { |
215 | AliError("internal initialization failed"); | |
216 | return -EINVAL; | |
217 | } | |
218 | ||
4cbaf07b | 219 | if(!pRunLoader) { |
220 | AliError("Missing RunLoader! 0x0"); | |
221 | return -EINVAL; | |
222 | } | |
223 | ||
7777fa45 | 224 | int nEvents = pRunLoader->GetNumberOfEvents(); |
4cbaf07b | 225 | int iResult=0; |
226 | ||
7bf6c76d | 227 | AliHLTSystem* pSystem=fpPluginBase->GetInstance(); |
228 | if (!pSystem) { | |
229 | AliError("can not get AliHLTSystem instance"); | |
230 | return -ENOMEM; | |
231 | } | |
232 | ||
233 | if (pSystem->CheckStatus(AliHLTSystem::kError)) { | |
4cbaf07b | 234 | AliError("HLT system in error state"); |
235 | return -EFAULT; | |
236 | } | |
7777fa45 | 237 | |
238 | // Note: the rawreader is already placed at the first event | |
7bf6c76d | 239 | if ((iResult=pSystem->Reconstruct(1, pRunLoader, fpRawReader))>=0) { |
240 | pSystem->FillESD(0, pRunLoader, NULL); | |
7777fa45 | 241 | for (int i=1; i<nEvents; i++) { |
242 | if (fpRawReader && !fpRawReader->NextEvent()) { | |
c5123824 | 243 | AliError("mismatch in event count, rawreader corrupted"); |
7777fa45 | 244 | break; |
245 | } | |
7bf6c76d | 246 | pSystem->Reconstruct(1, pRunLoader, fpRawReader); |
247 | pSystem->FillESD(i, pRunLoader, NULL); | |
7777fa45 | 248 | } |
dee38f1b | 249 | // send specific 'event' to execute the stop sequence |
7bf6c76d | 250 | pSystem->Reconstruct(0, NULL, NULL); |
4cbaf07b | 251 | } |
252 | return iResult; | |
253 | } | |
254 | ||
255 | ||
256 | AliHLTSimulation* AliHLTSimulationCreateInstance() | |
257 | { | |
258 | // see header file for function documentation | |
259 | return AliHLTSimulation::CreateInstance(); | |
260 | } | |
261 | ||
262 | int AliHLTSimulationDeleteInstance(AliHLTSimulation* pSim) | |
263 | { | |
264 | // see header file for function documentation | |
265 | return AliHLTSimulation::DeleteInstance(pSim); | |
266 | } | |
267 | ||
268 | int AliHLTSimulationInit(AliHLTSimulation* pSim, AliRunLoader* pRunLoader, const char* options) | |
269 | { | |
270 | assert(pSim!=NULL); | |
271 | if (pSim) { | |
272 | return pSim->Init(pRunLoader, options); | |
273 | } | |
274 | return -ENODEV; | |
275 | } | |
276 | ||
277 | int AliHLTSimulationRun(AliHLTSimulation* pSim, AliRunLoader* pRunLoader) | |
278 | { | |
279 | assert(pSim!=NULL); | |
280 | if (pSim) { | |
281 | return pSim->Run(pRunLoader); | |
282 | } | |
283 | return -ENODEV; | |
284 | } | |
285 | ||
286 | int AliHLTSimulationGetLibraryVersion() | |
287 | { | |
288 | // see header file for function documentation | |
289 | return LIBHLTSIM_VERSION; | |
290 | } | |
b50357c9 | 291 | |
5a29e5cb | 292 | int AliHLTSimulationSetup(AliHLTSimulation* /*pHLTSim*/, AliSimulation* pSim, const char* specificObjects) |
8dd79235 | 293 | { |
294 | // see header file for function documentation | |
295 | ||
296 | // this is an attempt to solve issue #48360 | |
297 | // since there are many jobs running in parallel during the production, | |
298 | // all the jobs want to put entries into the OCDB. The solution is to | |
299 | // make them temporary, since they are only used to propagate information | |
300 | // from the simulation to the reconstruction. | |
5a29e5cb | 301 | |
302 | if (!pSim) return -EINVAL; | |
303 | const char* entries[]={ | |
5a29e5cb | 304 | NULL |
305 | }; | |
306 | ||
307 | TString specificStorage; | |
308 | specificStorage.Form("local://%s",gSystem->pwd()); | |
309 | for (const char** pEntry=entries; *pEntry!=NULL; pEntry++) { | |
310 | const char* pObject=specificObjects?strstr(specificObjects, *pEntry):NULL; | |
311 | if (pObject) { | |
312 | // skip this entry if it is found in the list and either | |
313 | // last one or separated by a blank | |
314 | pObject+=strlen(*pEntry); | |
315 | if (*pObject==0 || *pObject==' ') continue; | |
316 | } | |
317 | pSim->SetSpecificStorage(*pEntry, specificStorage.Data()); | |
8dd79235 | 318 | } |
1daa8d18 | 319 | |
320 | return 0; | |
8dd79235 | 321 | } |
322 | ||
5a29e5cb | 323 | #ifndef HAVE_COMPILEINFO |
324 | extern "C" void CompileInfo(const char*& date, const char*& time) | |
b50357c9 | 325 | { |
326 | // the fall back compile info of the HLTsim library | |
327 | // this is not up-to-date if other files have been changed and recompiled | |
328 | date=__DATE__; time=__TIME__; | |
329 | return; | |
330 | } | |
5a29e5cb | 331 | #endif |