]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
f23a6e1a | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * | |
f23a6e1a | 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 | ||
b22e91eb | 19 | /** @file AliHLTSystem.cxx |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Implementation of HLT module management. | |
23 | */ | |
f23a6e1a | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
f23a6e1a | 26 | using namespace std; |
27 | #endif | |
28 | ||
85869391 | 29 | #include "AliHLTStdIncludes.h" |
f23a6e1a | 30 | #include "AliHLTSystem.h" |
31 | #include "AliHLTComponentHandler.h" | |
32 | #include "AliHLTComponent.h" | |
5ec8e281 | 33 | #include "AliHLTConfiguration.h" |
c38ba6f9 | 34 | #include "AliHLTConfigurationHandler.h" |
35 | #include "AliHLTTask.h" | |
242bb794 | 36 | #include "AliHLTModuleAgent.h" |
8451168b | 37 | #include "AliHLTOfflineInterface.h" |
242bb794 | 38 | #include <TObjArray.h> |
39 | #include <TObjString.h> | |
90ebac25 | 40 | #include <TStopwatch.h> |
c043fa2c | 41 | #include <TROOT.h> |
42 | #include <TInterpreter.h> | |
f23a6e1a | 43 | |
83670b1d | 44 | /** HLT default component libraries */ |
45 | const char* kHLTDefaultLibs[]= { | |
46 | "libAliHLTUtil.so", | |
47 | "libAliHLTTPC.so", | |
48 | // "libAliHLTSample.so", | |
49 | "libAliHLTPHOS.so", | |
50 | //"libAliHLTMUON.so", | |
51 | "libAliHLTTRD.so", | |
52 | NULL | |
53 | }; | |
54 | ||
b22e91eb | 55 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 56 | ClassImp(AliHLTSystem) |
57 | ||
f23a6e1a | 58 | AliHLTSystem::AliHLTSystem() |
85869391 | 59 | : |
60 | fpComponentHandler(new AliHLTComponentHandler()), | |
61 | fpConfigurationHandler(new AliHLTConfigurationHandler()), | |
242bb794 | 62 | fTaskList(), |
c043fa2c | 63 | fState(0), |
64 | fLocalRec() | |
f23a6e1a | 65 | { |
70ed7d01 | 66 | // see header file for class documentation |
67 | // or | |
68 | // refer to README to build package | |
69 | // or | |
70 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
5f5b708b | 71 | |
fc455fba | 72 | if (fgNofInstances++>0) |
73 | HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time"); | |
74 | ||
5f5b708b | 75 | SetGlobalLoggingLevel(kHLTLogDefault); |
f23a6e1a | 76 | if (fpComponentHandler) { |
77 | AliHLTComponentEnvironment env; | |
78 | memset(&env, 0, sizeof(AliHLTComponentEnvironment)); | |
9ce4bf4a | 79 | env.fAllocMemoryFunc=AliHLTSystem::AllocMemory; |
fc455fba | 80 | env.fLoggingFunc=NULL; |
a742f6f8 | 81 | AliHLTComponentLogSeverity loglevel=fpComponentHandler->GetLocalLoggingLevel(); |
82 | fpComponentHandler->SetLocalLoggingLevel(kHLTLogError); | |
f23a6e1a | 83 | fpComponentHandler->SetEnvironment(&env); |
a742f6f8 | 84 | fpComponentHandler->LoadLibrary("libAliHLTUtil.so"); |
85 | fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)fpComponentHandler->FindSymbol("libAliHLTUtil.so", "AliDynamicMessage"); | |
86 | fpComponentHandler->SetLocalLoggingLevel(loglevel); | |
87 | if (fgAliLoggingFunc==NULL) { | |
88 | HLTError("symbol lookp failure: can not find AliDynamicMessage, switching to HLT logging system"); | |
89 | } | |
90 | fpComponentHandler->AnnounceVersion(); | |
85465857 | 91 | } else { |
92 | HLTFatal("can not create Component Handler"); | |
93 | } | |
85465857 | 94 | if (fpConfigurationHandler) { |
95 | AliHLTConfiguration::GlobalInit(fpConfigurationHandler); | |
96 | } else { | |
97 | HLTFatal("can not create Configuration Handler"); | |
f23a6e1a | 98 | } |
99 | } | |
100 | ||
f23a6e1a | 101 | AliHLTSystem::~AliHLTSystem() |
102 | { | |
70ed7d01 | 103 | // see header file for class documentation |
fc455fba | 104 | fgNofInstances--; |
2d7ff710 | 105 | CleanTaskList(); |
fc455fba | 106 | AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler); |
2d7ff710 | 107 | if (fpConfigurationHandler) { |
108 | delete fpConfigurationHandler; | |
109 | } | |
110 | fpConfigurationHandler=NULL; | |
111 | ||
112 | if (fpComponentHandler) { | |
113 | delete fpComponentHandler; | |
114 | } | |
115 | fpComponentHandler=NULL; | |
f23a6e1a | 116 | } |
117 | ||
fc455fba | 118 | int AliHLTSystem::fgNofInstances=0; |
119 | ||
5ec8e281 | 120 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) |
121 | { | |
70ed7d01 | 122 | // see header file for class documentation |
5ec8e281 | 123 | int iResult=0; |
53feaef5 | 124 | if (pConf) { |
125 | } else { | |
126 | iResult=-EINVAL; | |
127 | } | |
5ec8e281 | 128 | return iResult; |
129 | } | |
130 | ||
014d39ce | 131 | int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) |
132 | { | |
70ed7d01 | 133 | // see header file for class documentation |
014d39ce | 134 | int iResult=0; |
53feaef5 | 135 | if (pConf) { |
136 | if (pPrec) { | |
137 | // find the position | |
138 | } | |
139 | } else { | |
140 | iResult=-EINVAL; | |
141 | } | |
014d39ce | 142 | return iResult; |
143 | } | |
5ec8e281 | 144 | |
145 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
146 | { | |
70ed7d01 | 147 | // see header file for class documentation |
5ec8e281 | 148 | int iResult=0; |
53feaef5 | 149 | if (pConf) { |
150 | } else { | |
151 | iResult=-EINVAL; | |
152 | } | |
5ec8e281 | 153 | return iResult; |
154 | } | |
155 | ||
a742f6f8 | 156 | int AliHLTSystem::BuildTaskList(const char* id) |
157 | { | |
158 | // see header file for class documentation | |
159 | int iResult=0; | |
160 | if (id) { | |
161 | if (fpConfigurationHandler) { | |
162 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id); | |
163 | if (pConf) { | |
164 | iResult=BuildTaskList(pConf); | |
165 | } else { | |
166 | HLTError("unknown configuration \"%s\"", id); | |
167 | iResult=-EEXIST; | |
168 | } | |
169 | } else { | |
170 | iResult=-EFAULT; | |
171 | } | |
172 | } else { | |
173 | iResult=-EINVAL; | |
174 | } | |
175 | return iResult; | |
176 | } | |
177 | ||
5ec8e281 | 178 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) |
179 | { | |
70ed7d01 | 180 | // see header file for class documentation |
f23a6e1a | 181 | int iResult=0; |
5ec8e281 | 182 | if (pConf) { |
183 | AliHLTTask* pTask=NULL; | |
184 | if ((pTask=FindTask(pConf->GetName()))!=NULL) { | |
185 | if (pTask->GetConf()!=pConf) { | |
85465857 | 186 | HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf); |
5ec8e281 | 187 | iResult=-EEXIST; |
5ec8e281 | 188 | } |
c043fa2c | 189 | // task for this configuration exists, terminate |
190 | pTask=NULL; | |
5ec8e281 | 191 | } else if (pConf->SourcesResolved(1)!=1) { |
85465857 | 192 | HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); |
5ec8e281 | 193 | iResult=-ENOLINK; |
194 | } else { | |
53feaef5 | 195 | pTask=new AliHLTTask(pConf); |
5ec8e281 | 196 | if (pTask==NULL) { |
197 | iResult=-ENOMEM; | |
198 | } | |
199 | } | |
c043fa2c | 200 | static int iterationLevel=0; |
201 | if (pTask && iResult>=0) { | |
3b35e87c | 202 | // check for circular dependencies |
5ec8e281 | 203 | if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { |
3b35e87c | 204 | HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName()); |
5ec8e281 | 205 | pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); |
85465857 | 206 | HLTError("aborted ..."); |
5ec8e281 | 207 | iResult=-ELOOP; |
208 | } | |
209 | if (iResult>=0) { | |
210 | // check whether all dependencies are already in the task list | |
211 | // create the missing ones | |
3b35e87c | 212 | // this step is an iterative process which calls this function again for the missing |
213 | // configurations, in order to avoid the currently processed task to be created | |
214 | // again it is added to the list temporarily and removed afterwards | |
215 | // This is of high importance to preserve the order of the tasks. Furthermore, the | |
216 | // InsertTask method has to be used in order to set all the cross links right | |
5ec8e281 | 217 | fTaskList.Add(pTask); |
218 | AliHLTConfiguration* pDep=pConf->GetFirstSource(); | |
219 | while (pDep!=NULL && iResult>=0) { | |
c043fa2c | 220 | HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep); |
5ec8e281 | 221 | if (FindTask(pDep->GetName())==NULL) { |
c043fa2c | 222 | HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep); |
223 | iterationLevel++; | |
5ec8e281 | 224 | iResult=BuildTaskList(pDep); |
c043fa2c | 225 | iterationLevel--; |
5ec8e281 | 226 | } |
227 | pDep=pConf->GetNextSource(); | |
228 | } | |
3b35e87c | 229 | // remove the temporarily added task |
5ec8e281 | 230 | fTaskList.Remove(pTask); |
231 | ||
232 | // insert the task and set the cross-links | |
233 | if (iResult>=0) { | |
c043fa2c | 234 | HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask); |
5ec8e281 | 235 | iResult=InsertTask(pTask); |
236 | } | |
237 | } else { | |
238 | delete pTask; | |
239 | pTask=NULL; | |
240 | } | |
241 | } | |
242 | } else { | |
243 | iResult=-EINVAL; | |
f23a6e1a | 244 | } |
f23a6e1a | 245 | return iResult; |
246 | } | |
247 | ||
5ec8e281 | 248 | int AliHLTSystem::CleanTaskList() |
249 | { | |
70ed7d01 | 250 | // see header file for class documentation |
5ec8e281 | 251 | int iResult=0; |
252 | TObjLink* lnk=NULL; | |
a742f6f8 | 253 | while ((lnk=fTaskList.LastLink())!=NULL) { |
5ec8e281 | 254 | delete (lnk->GetObject()); |
a742f6f8 | 255 | fTaskList.Remove(lnk); |
5ec8e281 | 256 | } |
257 | return iResult; | |
258 | } | |
259 | ||
260 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
261 | { | |
70ed7d01 | 262 | // see header file for class documentation |
5ec8e281 | 263 | int iResult=0; |
264 | TObjLink *lnk = NULL; | |
265 | if ((iResult=pTask->CheckDependencies())>0) | |
266 | lnk=fTaskList.FirstLink(); | |
267 | while (lnk && iResult>0) { | |
268 | AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); | |
85465857 | 269 | //HLTDebug("checking \"%s\"", pCurr->GetName()); |
5ec8e281 | 270 | iResult=pTask->Depends(pCurr); |
271 | if (iResult>0) { | |
272 | iResult=pTask->SetDependency(pCurr); | |
273 | pCurr->SetTarget(pTask); | |
85465857 | 274 | HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); |
f23a6e1a | 275 | } |
5ec8e281 | 276 | if (pCurr->Depends(pTask)) { |
3b35e87c | 277 | // circular dependency |
278 | HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
5ec8e281 | 279 | iResult=-ELOOP; |
280 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
281 | lnk = lnk->Next(); | |
282 | } | |
283 | } | |
284 | if (iResult==0) { | |
285 | if (lnk) { | |
286 | fTaskList.AddAfter(lnk, pTask); | |
287 | } else { | |
288 | fTaskList.AddFirst(pTask); | |
289 | } | |
a742f6f8 | 290 | HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask)); |
5ec8e281 | 291 | } else if (iResult>0) { |
85465857 | 292 | HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); |
5ec8e281 | 293 | iResult=-ENOLINK; |
f23a6e1a | 294 | } |
5ec8e281 | 295 | return iResult; |
f23a6e1a | 296 | } |
297 | ||
5ec8e281 | 298 | AliHLTTask* AliHLTSystem::FindTask(const char* id) |
299 | { | |
70ed7d01 | 300 | // see header file for class documentation |
5ec8e281 | 301 | AliHLTTask* pTask=NULL; |
302 | if (id) { | |
303 | pTask=(AliHLTTask*)fTaskList.FindObject(id); | |
304 | } | |
305 | return pTask; | |
306 | } | |
f23a6e1a | 307 | |
5ec8e281 | 308 | void AliHLTSystem::PrintTaskList() |
309 | { | |
70ed7d01 | 310 | // see header file for class documentation |
85465857 | 311 | HLTLogKeyword("task list"); |
5ec8e281 | 312 | TObjLink *lnk = NULL; |
85465857 | 313 | HLTMessage("Task List"); |
5ec8e281 | 314 | lnk=fTaskList.FirstLink(); |
315 | while (lnk) { | |
316 | TObject* obj=lnk->GetObject(); | |
317 | if (obj) { | |
85465857 | 318 | HLTMessage(" %s - status:", obj->GetName()); |
5ec8e281 | 319 | AliHLTTask* pTask=(AliHLTTask*)obj; |
320 | pTask->PrintStatus(); | |
321 | } else { | |
322 | } | |
323 | lnk = lnk->Next(); | |
324 | } | |
325 | } | |
014d39ce | 326 | |
53feaef5 | 327 | int AliHLTSystem::Run(Int_t iNofEvents) |
014d39ce | 328 | { |
70ed7d01 | 329 | // see header file for class documentation |
014d39ce | 330 | int iResult=0; |
242bb794 | 331 | int iCount=0; |
332 | SetStatusFlags(kRunning); | |
90ebac25 | 333 | TStopwatch StopwatchBase; StopwatchBase.Reset(); |
334 | TStopwatch StopwatchDA; StopwatchDA.Reset(); | |
335 | TStopwatch StopwatchInput; StopwatchInput.Reset(); | |
336 | TStopwatch StopwatchOutput; StopwatchOutput.Reset(); | |
337 | TObjArray Stopwatches; | |
338 | Stopwatches.AddAt(&StopwatchBase, (int)AliHLTComponent::kSWBase); | |
339 | Stopwatches.AddAt(&StopwatchDA, (int)AliHLTComponent::kSWDA); | |
340 | Stopwatches.AddAt(&StopwatchInput, (int)AliHLTComponent::kSWInput); | |
341 | Stopwatches.AddAt(&StopwatchOutput, (int)AliHLTComponent::kSWOutput); | |
342 | if ((iResult=InitTasks())>=0 && (iResult=InitBenchmarking(&Stopwatches))>=0) { | |
9ce4bf4a | 343 | if ((iResult=StartTasks())>=0) { |
344 | for (int i=0; i<iNofEvents && iResult>=0; i++) { | |
345 | iResult=ProcessTasks(i); | |
346 | if (iResult>=0) { | |
347 | HLTInfo("Event %d successfully finished (%d)", i, iResult); | |
348 | iResult=0; | |
242bb794 | 349 | iCount++; |
9ce4bf4a | 350 | } else { |
351 | HLTError("Processing of event %d failed (%d)", i, iResult); | |
352 | // TODO: define different running modes to either ignore errors in | |
353 | // event processing or not | |
354 | // currently ignored | |
355 | //iResult=0; | |
356 | } | |
2d7ff710 | 357 | } |
9ce4bf4a | 358 | StopTasks(); |
359 | } else { | |
360 | HLTError("can not start task list"); | |
53feaef5 | 361 | } |
9ce4bf4a | 362 | DeinitTasks(); |
fc455fba | 363 | } else if (iResult!=-ENOENT) { |
9ce4bf4a | 364 | HLTError("can not initialize task list"); |
365 | } | |
90ebac25 | 366 | if (iResult>=0) { |
367 | iResult=iCount; | |
368 | HLTInfo("HLT statistics:\n" | |
369 | " base: R:%.3fs C:%.3fs\n" | |
370 | " input: R:%.3fs C:%.3fs\n" | |
371 | " output: R:%.3fs C:%.3fs\n" | |
372 | " event processing : R:%.3fs C:%.3fs" | |
373 | , StopwatchBase.RealTime(),StopwatchBase.CpuTime() | |
374 | , StopwatchInput.RealTime(),StopwatchInput.CpuTime() | |
375 | , StopwatchOutput.RealTime(),StopwatchOutput.CpuTime() | |
376 | , StopwatchDA.RealTime(),StopwatchDA.CpuTime()); | |
83670b1d | 377 | } else if (iResult==-ENOENT) { |
378 | iResult=0; // do not propagate the error | |
90ebac25 | 379 | } |
242bb794 | 380 | ClearStatusFlags(kRunning); |
9ce4bf4a | 381 | return iResult; |
382 | } | |
383 | ||
384 | int AliHLTSystem::InitTasks() | |
385 | { | |
70ed7d01 | 386 | // see header file for class documentation |
9ce4bf4a | 387 | int iResult=0; |
388 | TObjLink *lnk=fTaskList.FirstLink(); | |
fc455fba | 389 | if (lnk==NULL) { |
390 | HLTWarning("Task list is empty, aborting ..."); | |
391 | return -ENOENT; | |
392 | } | |
9ce4bf4a | 393 | while (lnk && iResult>=0) { |
394 | TObject* obj=lnk->GetObject(); | |
395 | if (obj) { | |
396 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
397 | iResult=pTask->Init(NULL, fpComponentHandler); | |
398 | } else { | |
399 | } | |
400 | lnk = lnk->Next(); | |
401 | } | |
402 | if (iResult<0) { | |
53feaef5 | 403 | } |
404 | return iResult; | |
405 | } | |
406 | ||
90ebac25 | 407 | int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches) |
408 | { | |
409 | // see header file for class documentation | |
410 | if (pStopwatches==NULL) return -EINVAL; | |
411 | ||
412 | int iResult=0; | |
413 | TObjLink *lnk=fTaskList.FirstLink(); | |
414 | while (lnk && iResult>=0) { | |
415 | TObject* obj=lnk->GetObject(); | |
416 | if (obj) { | |
417 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
418 | AliHLTComponent* pComp=NULL; | |
419 | if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) { | |
420 | switch (pComp->GetComponentType()) { | |
421 | case AliHLTComponent::kProcessor: | |
422 | pComp->SetStopwatches(pStopwatches); | |
423 | break; | |
424 | case AliHLTComponent::kSource: | |
425 | { | |
426 | // this switch determines whether the time consumption of the | |
427 | // AliHLTComponent base methods should be counted to the input | |
428 | // stopwatch or base stopwatch. | |
429 | //int inputBase=(int)AliHLTComponent::kSWBase; | |
430 | int inputBase=(int)AliHLTComponent::kSWInput; | |
431 | pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase); | |
432 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA); | |
433 | } | |
434 | break; | |
435 | case AliHLTComponent::kSink: | |
436 | { | |
437 | // this switch determines whether the time consumption of the | |
438 | // AliHLTComponent base methods should be counted to the output | |
439 | // stopwatch or base stopwatch. | |
440 | //int outputBase=(int)AliHLTComponent::kSWBase; | |
441 | int outputBase=(int)AliHLTComponent::kSWOutput; | |
442 | pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase); | |
443 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA); | |
444 | } | |
445 | break; | |
85f0cede | 446 | default: |
447 | HLTWarning("unknown component type %d", (int)pComp->GetComponentType()); | |
90ebac25 | 448 | } |
449 | } | |
450 | } else { | |
451 | } | |
452 | lnk = lnk->Next(); | |
453 | } | |
454 | return iResult; | |
455 | } | |
456 | ||
53feaef5 | 457 | int AliHLTSystem::StartTasks() |
458 | { | |
70ed7d01 | 459 | // see header file for class documentation |
53feaef5 | 460 | int iResult=0; |
461 | TObjLink *lnk=fTaskList.FirstLink(); | |
462 | while (lnk && iResult>=0) { | |
463 | TObject* obj=lnk->GetObject(); | |
464 | if (obj) { | |
465 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
466 | iResult=pTask->StartRun(); | |
467 | } else { | |
468 | } | |
469 | lnk = lnk->Next(); | |
470 | } | |
471 | if (iResult<0) { | |
472 | } | |
473 | return iResult; | |
474 | } | |
475 | ||
476 | int AliHLTSystem::ProcessTasks(Int_t eventNo) | |
477 | { | |
70ed7d01 | 478 | // see header file for class documentation |
53feaef5 | 479 | int iResult=0; |
480 | HLTDebug("processing event no %d", eventNo); | |
481 | TObjLink *lnk=fTaskList.FirstLink(); | |
482 | while (lnk && iResult>=0) { | |
483 | TObject* obj=lnk->GetObject(); | |
484 | if (obj) { | |
485 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
9ce4bf4a | 486 | iResult=pTask->ProcessTask(eventNo); |
487 | HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult); | |
53feaef5 | 488 | } else { |
489 | } | |
490 | lnk = lnk->Next(); | |
491 | } | |
492 | return iResult; | |
493 | } | |
494 | ||
495 | int AliHLTSystem::StopTasks() | |
496 | { | |
70ed7d01 | 497 | // see header file for class documentation |
53feaef5 | 498 | int iResult=0; |
499 | TObjLink *lnk=fTaskList.FirstLink(); | |
500 | while (lnk && iResult>=0) { | |
501 | TObject* obj=lnk->GetObject(); | |
502 | if (obj) { | |
503 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
504 | iResult=pTask->EndRun(); | |
505 | } else { | |
506 | } | |
507 | lnk = lnk->Next(); | |
508 | } | |
014d39ce | 509 | return iResult; |
510 | } | |
9ce4bf4a | 511 | |
512 | int AliHLTSystem::DeinitTasks() | |
513 | { | |
70ed7d01 | 514 | // see header file for class documentation |
9ce4bf4a | 515 | int iResult=0; |
516 | TObjLink *lnk=fTaskList.FirstLink(); | |
517 | while (lnk && iResult>=0) { | |
518 | TObject* obj=lnk->GetObject(); | |
519 | if (obj) { | |
520 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
521 | iResult=pTask->Deinit(); | |
522 | } else { | |
523 | } | |
524 | lnk = lnk->Next(); | |
525 | } | |
526 | return iResult; | |
527 | } | |
528 | ||
c043fa2c | 529 | void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size ) |
9ce4bf4a | 530 | { |
70ed7d01 | 531 | // see header file for class documentation |
c043fa2c | 532 | void* p=NULL; |
533 | try { | |
534 | p=(void*)new char[size]; | |
242bb794 | 535 | } |
c043fa2c | 536 | catch (...) { |
537 | AliHLTLogging log; | |
538 | log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" ); | |
539 | } | |
540 | return p; | |
9ce4bf4a | 541 | } |
242bb794 | 542 | |
543 | int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, | |
544 | AliRawReader* rawReader) | |
545 | { | |
546 | // see header file for class documentation | |
547 | int iResult=0; | |
548 | if (runLoader) { | |
549 | HLTInfo("Run Loader %p, Raw Reader %p , %d events", runLoader, rawReader, nofEvents); | |
550 | if (CheckStatus(kReady)) { | |
8451168b | 551 | if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) { |
552 | iResult=Run(nofEvents); | |
553 | } | |
242bb794 | 554 | } else { |
555 | HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady); | |
556 | } | |
557 | } else { | |
558 | HLTError("missing run loader instance"); | |
559 | iResult=-EINVAL; | |
560 | } | |
561 | return iResult; | |
562 | } | |
563 | ||
af885e0f | 564 | int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd) |
242bb794 | 565 | { |
566 | // see header file for class documentation | |
567 | int iResult=0; | |
568 | if (runLoader) { | |
569 | HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd); | |
8451168b | 570 | iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd); |
242bb794 | 571 | } else { |
572 | HLTError("missing run loader/ESD instance(s)"); | |
573 | iResult=-EINVAL; | |
574 | } | |
575 | return iResult; | |
576 | } | |
577 | ||
578 | int AliHLTSystem::LoadComponentLibraries(const char* libraries) | |
579 | { | |
580 | // see header file for class documentation | |
581 | int iResult=0; | |
582 | if (libraries) { | |
583 | if (fpComponentHandler) { | |
584 | TString libs(libraries); | |
585 | TObjArray* pTokens=libs.Tokenize(" "); | |
586 | if (pTokens) { | |
587 | int iEntries=pTokens->GetEntries(); | |
588 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
589 | iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data()); | |
590 | } | |
591 | delete pTokens; | |
592 | } | |
593 | if (iResult>=0) { | |
594 | SetStatusFlags(kLibrariesLoaded); | |
595 | } else { | |
596 | // lets see if we need this, probably not | |
597 | //fpComponentHandler->UnloadLibraries(); | |
598 | ClearStatusFlags(kLibrariesLoaded); | |
599 | } | |
600 | } else { | |
601 | iResult=-EFAULT; | |
602 | HLTFatal("no component handler available"); | |
603 | } | |
604 | } else { | |
605 | iResult=-EINVAL; | |
606 | } | |
607 | return iResult; | |
608 | } | |
609 | ||
610 | int AliHLTSystem::Configure(AliRunLoader* runloader) | |
611 | { | |
612 | // see header file for class documentation | |
613 | int iResult=0; | |
614 | if (CheckStatus(kRunning)) { | |
615 | HLTError("HLT system in running state, can not configure"); | |
616 | return -EBUSY; | |
617 | } | |
c043fa2c | 618 | ClearStatusFlags(kConfigurationLoaded|kTaskListCreated); |
c215072c | 619 | if (CheckFilter(kHLTLogDebug)) |
620 | AliHLTModuleAgent::PrintStatus(); | |
c043fa2c | 621 | if (CheckStatus(kConfigurationLoaded)==0) { |
622 | iResult=LoadConfigurations(runloader); | |
623 | } else { | |
624 | if (fLocalRec.Length()==0) { | |
625 | HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option"); | |
626 | iResult=-ENOENT; | |
627 | } | |
628 | } | |
242bb794 | 629 | if (iResult>=0) { |
630 | SetStatusFlags(kConfigurationLoaded); | |
c043fa2c | 631 | if (CheckFilter(kHLTLogDebug)) |
632 | fpConfigurationHandler->PrintConfigurations(); | |
242bb794 | 633 | iResult=BuildTaskListsFromTopConfigurations(runloader); |
634 | if (iResult>=0) { | |
635 | SetStatusFlags(kTaskListCreated); | |
636 | } | |
637 | } | |
638 | if (iResult<0) SetStatusFlags(kError); | |
639 | ||
640 | return iResult; | |
641 | } | |
642 | ||
c043fa2c | 643 | int AliHLTSystem::ScanOptions(const char* options) |
644 | { | |
645 | // see header file for class documentation | |
646 | int iResult=0; | |
647 | if (options) { | |
83670b1d | 648 | TString libs(""); |
c043fa2c | 649 | TString alloptions(options); |
650 | TObjArray* pTokens=alloptions.Tokenize(" "); | |
651 | if (pTokens) { | |
652 | int iEntries=pTokens->GetEntries(); | |
653 | for (int i=0; i<iEntries; i++) { | |
654 | TString token=(((TObjString*)pTokens->At(i))->GetString()); | |
655 | if (token.Contains("loglevel=")) { | |
656 | TString param=token.ReplaceAll("loglevel=", ""); | |
657 | if (param.IsDigit()) { | |
658 | SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi()); | |
659 | } else if (param.BeginsWith("0x") && | |
660 | param.Replace(0,2,"",0).IsHex()) { | |
661 | int severity=0; | |
662 | sscanf(param.Data(),"%x", &severity); | |
663 | SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity); | |
664 | } else { | |
665 | HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected"); | |
666 | } | |
667 | } else if (token.Contains("alilog=off")) { | |
668 | SwitchAliLog(0); | |
669 | } else if (token.Contains("config=")) { | |
670 | TString param=token.ReplaceAll("config=", ""); | |
671 | Int_t error=0; | |
672 | gROOT->Macro(param.Data(), &error); | |
673 | if (error==0) { | |
674 | SetStatusFlags(kConfigurationLoaded); | |
675 | } else { | |
676 | HLTError("can not execute macro \'%s\'", param.Data()); | |
677 | iResult=-EBADF; | |
678 | } | |
679 | } else if (token.Contains("localrec=")) { | |
680 | TString param=token.ReplaceAll("localrec=", ""); | |
681 | fLocalRec=param.ReplaceAll(",", " "); | |
83670b1d | 682 | } else if (token.BeginsWith("lib") && token.EndsWith(".so")) { |
683 | libs+=token; | |
684 | libs+=" "; | |
c043fa2c | 685 | } else { |
686 | HLTWarning("unknown option \'%s\'", token.Data()); | |
687 | } | |
688 | } | |
689 | delete pTokens; | |
690 | } | |
83670b1d | 691 | |
692 | if (iResult>=0) { | |
693 | if (libs.IsNull()) { | |
694 | const char** deflib=kHLTDefaultLibs; | |
695 | while (*deflib) { | |
696 | libs+=*deflib++; | |
697 | libs+=" "; | |
698 | } | |
699 | } | |
700 | if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) && | |
701 | (LoadComponentLibraries(libs.Data())<0)) { | |
702 | HLTError("error while loading HLT libraries"); | |
703 | iResult=-EFAULT; | |
704 | } | |
705 | } | |
c043fa2c | 706 | } |
707 | return iResult; | |
708 | } | |
709 | ||
242bb794 | 710 | int AliHLTSystem::Reset(int bForce) |
711 | { | |
712 | // see header file for class documentation | |
713 | int iResult=0; | |
714 | if (!bForce && CheckStatus(kRunning)) { | |
715 | HLTError("HLT system in running state, can not configure"); | |
716 | return -EBUSY; | |
717 | } | |
718 | CleanTaskList(); | |
719 | ClearStatusFlags(~kUninitialized); | |
720 | return iResult; | |
721 | } | |
722 | ||
723 | int AliHLTSystem::LoadConfigurations(AliRunLoader* runloader) | |
724 | { | |
725 | // see header file for class documentation | |
726 | if (CheckStatus(kRunning)) { | |
727 | HLTError("HLT system in running state, can not configure"); | |
728 | return -EBUSY; | |
729 | } | |
730 | int iResult=0; | |
731 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
60b26a17 | 732 | while (pAgent && iResult>=0) { |
733 | const char* deplibs=pAgent->GetRequiredComponentLibraries(); | |
734 | if (deplibs) { | |
c215072c | 735 | HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent); |
60b26a17 | 736 | iResult=LoadComponentLibraries(deplibs); |
737 | } | |
738 | if (iResult>=0) { | |
739 | HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent); | |
740 | pAgent->CreateConfigurations(fpConfigurationHandler, runloader); | |
741 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
742 | } | |
242bb794 | 743 | } |
744 | return iResult; | |
745 | } | |
746 | ||
747 | int AliHLTSystem::BuildTaskListsFromTopConfigurations(AliRunLoader* runloader) | |
748 | { | |
749 | // see header file for class documentation | |
750 | if (CheckStatus(kRunning)) { | |
751 | HLTError("HLT system in running state, can not configure"); | |
752 | return -EBUSY; | |
753 | } | |
754 | if (!CheckStatus(kConfigurationLoaded)) { | |
755 | HLTWarning("configurations not yet loaded"); | |
756 | return 0; | |
757 | } | |
758 | ||
759 | int iResult=0; | |
760 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
c043fa2c | 761 | while ((pAgent || fLocalRec.Length()>0) && iResult>=0) { |
762 | TString tops; | |
763 | if (fLocalRec.Length()>0) { | |
764 | tops=fLocalRec; | |
765 | HLTInfo("custom local reconstruction configurations: %s", tops.Data()); | |
766 | } else { | |
767 | tops=pAgent->GetLocalRecConfigurations(runloader); | |
768 | HLTInfo("local reconstruction configurations for agent %s (%p): %s", pAgent->GetName(), pAgent, tops.Data()); | |
769 | } | |
242bb794 | 770 | TObjArray* pTokens=tops.Tokenize(" "); |
771 | if (pTokens) { | |
772 | int iEntries=pTokens->GetEntries(); | |
773 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
774 | const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data(); | |
775 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID); | |
776 | if (pConf) { | |
777 | iResult=BuildTaskList(pConf); | |
778 | } else { | |
779 | HLTWarning("can not find top configuration %s", pCID); | |
780 | } | |
781 | } | |
782 | delete pTokens; | |
783 | } | |
784 | ||
c043fa2c | 785 | if (fLocalRec.Length()>0) { |
786 | break; // ignore the agents | |
787 | } | |
242bb794 | 788 | pAgent=AliHLTModuleAgent::GetNextAgent(); |
789 | } | |
790 | if (iResult>=0) SetStatusFlags(kTaskListCreated); | |
791 | ||
792 | return iResult; | |
793 | } | |
794 | ||
795 | int AliHLTSystem::CheckStatus(int flag) | |
796 | { | |
797 | // see header file for class documentation | |
798 | if (flag==kUninitialized && flag==fState) return 1; | |
799 | if ((fState&flag)==flag) return 1; | |
800 | return 0; | |
801 | } | |
802 | ||
803 | int AliHLTSystem::GetStatusFlags() | |
804 | { | |
805 | // see header file for class documentation | |
806 | return fState; | |
807 | } | |
808 | ||
809 | int AliHLTSystem::SetStatusFlags(int flags) | |
810 | { | |
811 | // see header file for class documentation | |
812 | fState|=flags; | |
813 | return fState; | |
814 | } | |
815 | ||
816 | int AliHLTSystem::ClearStatusFlags(int flags) | |
817 | { | |
818 | // see header file for class documentation | |
819 | fState&=~flags; | |
820 | return fState; | |
821 | } | |
85f0cede | 822 | |
823 | void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol) | |
824 | { | |
c043fa2c | 825 | // see header file for class documentation |
85f0cede | 826 | if (fpComponentHandler==NULL) return NULL; |
827 | return fpComponentHandler->FindSymbol(library, symbol); | |
828 | } |