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