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