]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
c5123824 | 2 | //************************************************************************** |
3 | //* This file is property of and copyright by the ALICE HLT Project * | |
4 | //* ALICE Experiment at CERN, All rights reserved. * | |
5 | //* * | |
6 | //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
7 | //* for The ALICE HLT Project. * | |
8 | //* * | |
9 | //* Permission to use, copy, modify and distribute this software and its * | |
10 | //* documentation strictly for non-commercial purposes is hereby granted * | |
11 | //* without fee, provided that the above copyright notice appears in all * | |
12 | //* copies and that both the copyright notice and this permission notice * | |
13 | //* appear in the supporting documentation. The authors make no claims * | |
14 | //* about the suitability of this software for any purpose. It is * | |
15 | //* provided "as is" without express or implied warranty. * | |
16 | //************************************************************************** | |
f23a6e1a | 17 | |
b22e91eb | 18 | /** @file AliHLTSystem.cxx |
19 | @author Matthias Richter | |
20 | @date | |
21 | @brief Implementation of HLT module management. | |
22 | */ | |
f23a6e1a | 23 | |
0c0c9d99 | 24 | #if __GNUC__>= 3 |
f23a6e1a | 25 | using namespace std; |
26 | #endif | |
27 | ||
f3506ea2 | 28 | #include <cassert> |
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" |
457ec821 | 38 | #include "AliHLTDataSource.h" |
c5123824 | 39 | #include "AliHLTOUT.h" |
40 | #include "AliHLTOUTHandler.h" | |
f3c1d403 | 41 | #include "AliHLTOUTTask.h" |
19b5c321 | 42 | #include "AliHLTControlTask.h" |
0a7afbf0 | 43 | #include "AliHLTDataBuffer.h" |
242bb794 | 44 | #include <TObjArray.h> |
45 | #include <TObjString.h> | |
90ebac25 | 46 | #include <TStopwatch.h> |
d5ea63f7 | 47 | #include <TList.h> |
dba03d72 | 48 | //#include <TSystem.h> |
c043fa2c | 49 | #include <TROOT.h> |
6a8e0bb4 | 50 | //#include <TInterpreter.h> |
f23a6e1a | 51 | |
83670b1d | 52 | /** HLT default component libraries */ |
6a8e0bb4 | 53 | const char* AliHLTSystem::fgkHLTDefaultLibs[]= { |
83670b1d | 54 | "libAliHLTUtil.so", |
8f471af0 | 55 | "libAliHLTRCU.so", |
83670b1d | 56 | "libAliHLTTPC.so", |
57 | // "libAliHLTSample.so", | |
33d33d06 | 58 | // "libAliHLTPHOS.so", |
887a669c | 59 | "libAliHLTMUON.so", |
d5ea63f7 | 60 | "libAliHLTTRD.so", |
3262c4fc | 61 | "libAliHLTITS.so", |
d5ea63f7 | 62 | "libAliHLTGlobal.so", |
c5123824 | 63 | "libAliHLTTrigger.so", |
83670b1d | 64 | NULL |
65 | }; | |
66 | ||
b22e91eb | 67 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 68 | ClassImp(AliHLTSystem) |
69 | ||
19b5c321 | 70 | AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name) |
85869391 | 71 | : |
b005ef92 | 72 | fpComponentHandler(AliHLTComponentHandler::CreateHandler()), |
73 | fpConfigurationHandler(AliHLTConfigurationHandler::CreateHandler()), | |
242bb794 | 74 | fTaskList(), |
c043fa2c | 75 | fState(0), |
dee38f1b | 76 | fChains(), |
77 | fStopwatches(new TObjArray), | |
78 | fEventCount(-1), | |
b005ef92 | 79 | fGoodEvents(-1), |
80 | fpChainHandlers(NULL), | |
81 | fpEsdHandlers(NULL), | |
f3c1d403 | 82 | fpProprietaryHandlers(NULL), |
19b5c321 | 83 | fpHLTOUTTask(NULL), |
84 | fpControlTask(NULL), | |
85 | fName(name) | |
f23a6e1a | 86 | { |
70ed7d01 | 87 | // see header file for class documentation |
88 | // or | |
89 | // refer to README to build package | |
90 | // or | |
91 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
5f5b708b | 92 | |
b005ef92 | 93 | if (fgNofInstances++>0) { |
94 | // July 2008: multiple instances are now allowed | |
95 | // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler | |
96 | //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time"); | |
97 | } | |
fc455fba | 98 | |
83cb7e1d | 99 | SetGlobalLoggingLevel(loglevel); |
100 | SetFrameworkLog(loglevel); | |
f23a6e1a | 101 | if (fpComponentHandler) { |
a3c9b745 | 102 | AliHLTAnalysisEnvironment env; |
103 | memset(&env, 0, sizeof(AliHLTAnalysisEnvironment)); | |
104 | env.fStructSize=sizeof(AliHLTAnalysisEnvironment); | |
9ce4bf4a | 105 | env.fAllocMemoryFunc=AliHLTSystem::AllocMemory; |
324ca3b4 | 106 | env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData; |
fc455fba | 107 | env.fLoggingFunc=NULL; |
f23a6e1a | 108 | fpComponentHandler->SetEnvironment(&env); |
db95fec3 | 109 | InitAliLogFunc(fpComponentHandler); |
d4a18597 | 110 | if (fgNofInstances==1) { |
a742f6f8 | 111 | fpComponentHandler->AnnounceVersion(); |
d4a18597 | 112 | } |
85465857 | 113 | } else { |
114 | HLTFatal("can not create Component Handler"); | |
115 | } | |
85465857 | 116 | if (fpConfigurationHandler) { |
117 | AliHLTConfiguration::GlobalInit(fpConfigurationHandler); | |
118 | } else { | |
119 | HLTFatal("can not create Configuration Handler"); | |
f23a6e1a | 120 | } |
121 | } | |
122 | ||
f23a6e1a | 123 | AliHLTSystem::~AliHLTSystem() |
124 | { | |
70ed7d01 | 125 | // see header file for class documentation |
fc455fba | 126 | fgNofInstances--; |
a472be38 | 127 | CleanHLTOUT(); |
2d7ff710 | 128 | CleanTaskList(); |
fc455fba | 129 | AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler); |
2d7ff710 | 130 | if (fpConfigurationHandler) { |
b005ef92 | 131 | fpConfigurationHandler->Destroy(); |
2d7ff710 | 132 | } |
133 | fpConfigurationHandler=NULL; | |
134 | ||
135 | if (fpComponentHandler) { | |
b005ef92 | 136 | fpComponentHandler->Destroy(); |
2d7ff710 | 137 | } |
138 | fpComponentHandler=NULL; | |
19b5c321 | 139 | |
140 | // note: fpHLTOUTTask and fpControlTask are deleted by | |
141 | // CleanTaskList | |
f23a6e1a | 142 | } |
143 | ||
fc455fba | 144 | int AliHLTSystem::fgNofInstances=0; |
145 | ||
5ec8e281 | 146 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) |
147 | { | |
70ed7d01 | 148 | // see header file for class documentation |
6a8e0bb4 | 149 | HLTLogKeyword("configuration handling"); |
5ec8e281 | 150 | int iResult=0; |
53feaef5 | 151 | if (pConf) { |
6a8e0bb4 | 152 | HLTError("function not yet implemented"); |
153 | iResult=-ENOSYS; | |
53feaef5 | 154 | } else { |
155 | iResult=-EINVAL; | |
156 | } | |
5ec8e281 | 157 | return iResult; |
158 | } | |
159 | ||
014d39ce | 160 | int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) |
161 | { | |
70ed7d01 | 162 | // see header file for class documentation |
6a8e0bb4 | 163 | HLTLogKeyword("configuration handling"); |
014d39ce | 164 | int iResult=0; |
53feaef5 | 165 | if (pConf) { |
166 | if (pPrec) { | |
167 | // find the position | |
6a8e0bb4 | 168 | HLTError("function not yet implemented"); |
169 | iResult=-ENOSYS; | |
53feaef5 | 170 | } |
171 | } else { | |
172 | iResult=-EINVAL; | |
173 | } | |
014d39ce | 174 | return iResult; |
175 | } | |
5ec8e281 | 176 | |
177 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
178 | { | |
70ed7d01 | 179 | // see header file for class documentation |
6a8e0bb4 | 180 | HLTLogKeyword("configuration handling"); |
5ec8e281 | 181 | int iResult=0; |
53feaef5 | 182 | if (pConf) { |
6a8e0bb4 | 183 | HLTError("function not yet implemented"); |
184 | iResult=-ENOSYS; | |
53feaef5 | 185 | } else { |
186 | iResult=-EINVAL; | |
187 | } | |
5ec8e281 | 188 | return iResult; |
189 | } | |
190 | ||
a742f6f8 | 191 | int AliHLTSystem::BuildTaskList(const char* id) |
192 | { | |
193 | // see header file for class documentation | |
194 | int iResult=0; | |
195 | if (id) { | |
196 | if (fpConfigurationHandler) { | |
197 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id); | |
198 | if (pConf) { | |
199 | iResult=BuildTaskList(pConf); | |
200 | } else { | |
201 | HLTError("unknown configuration \"%s\"", id); | |
202 | iResult=-EEXIST; | |
203 | } | |
204 | } else { | |
205 | iResult=-EFAULT; | |
206 | } | |
207 | } else { | |
208 | iResult=-EINVAL; | |
209 | } | |
210 | return iResult; | |
211 | } | |
212 | ||
5ec8e281 | 213 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) |
214 | { | |
70ed7d01 | 215 | // see header file for class documentation |
f23a6e1a | 216 | int iResult=0; |
5ec8e281 | 217 | if (pConf) { |
218 | AliHLTTask* pTask=NULL; | |
219 | if ((pTask=FindTask(pConf->GetName()))!=NULL) { | |
220 | if (pTask->GetConf()!=pConf) { | |
c5123824 | 221 | HLTError("configuration mismatch, 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 | 222 | iResult=-EEXIST; |
5ec8e281 | 223 | } |
c043fa2c | 224 | // task for this configuration exists, terminate |
225 | pTask=NULL; | |
5ec8e281 | 226 | } else if (pConf->SourcesResolved(1)!=1) { |
85465857 | 227 | HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); |
5ec8e281 | 228 | iResult=-ENOLINK; |
229 | } else { | |
53feaef5 | 230 | pTask=new AliHLTTask(pConf); |
5ec8e281 | 231 | if (pTask==NULL) { |
232 | iResult=-ENOMEM; | |
dba03d72 | 233 | } else { |
234 | pTask->SetLocalLoggingLevel(GetLocalLoggingLevel()); | |
5ec8e281 | 235 | } |
236 | } | |
c043fa2c | 237 | static int iterationLevel=0; |
238 | if (pTask && iResult>=0) { | |
3b35e87c | 239 | // check for circular dependencies |
5ec8e281 | 240 | if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { |
3b35e87c | 241 | HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName()); |
5ec8e281 | 242 | pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); |
85465857 | 243 | HLTError("aborted ..."); |
5ec8e281 | 244 | iResult=-ELOOP; |
245 | } | |
246 | if (iResult>=0) { | |
247 | // check whether all dependencies are already in the task list | |
248 | // create the missing ones | |
3b35e87c | 249 | // this step is an iterative process which calls this function again for the missing |
250 | // configurations, in order to avoid the currently processed task to be created | |
251 | // again it is added to the list temporarily and removed afterwards | |
252 | // This is of high importance to preserve the order of the tasks. Furthermore, the | |
253 | // InsertTask method has to be used in order to set all the cross links right | |
5ec8e281 | 254 | fTaskList.Add(pTask); |
255 | AliHLTConfiguration* pDep=pConf->GetFirstSource(); | |
256 | while (pDep!=NULL && iResult>=0) { | |
c043fa2c | 257 | HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep); |
5ec8e281 | 258 | if (FindTask(pDep->GetName())==NULL) { |
c043fa2c | 259 | HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep); |
260 | iterationLevel++; | |
5ec8e281 | 261 | iResult=BuildTaskList(pDep); |
c043fa2c | 262 | iterationLevel--; |
5ec8e281 | 263 | } |
264 | pDep=pConf->GetNextSource(); | |
265 | } | |
3b35e87c | 266 | // remove the temporarily added task |
5ec8e281 | 267 | fTaskList.Remove(pTask); |
268 | ||
269 | // insert the task and set the cross-links | |
270 | if (iResult>=0) { | |
c043fa2c | 271 | HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask); |
5ec8e281 | 272 | iResult=InsertTask(pTask); |
273 | } | |
274 | } else { | |
275 | delete pTask; | |
276 | pTask=NULL; | |
277 | } | |
278 | } | |
279 | } else { | |
280 | iResult=-EINVAL; | |
f23a6e1a | 281 | } |
f23a6e1a | 282 | return iResult; |
283 | } | |
284 | ||
5ec8e281 | 285 | int AliHLTSystem::CleanTaskList() |
286 | { | |
70ed7d01 | 287 | // see header file for class documentation |
5ec8e281 | 288 | int iResult=0; |
19b5c321 | 289 | fpHLTOUTTask=NULL; |
290 | fpControlTask=NULL; | |
5ec8e281 | 291 | TObjLink* lnk=NULL; |
a742f6f8 | 292 | while ((lnk=fTaskList.LastLink())!=NULL) { |
5ec8e281 | 293 | delete (lnk->GetObject()); |
a742f6f8 | 294 | fTaskList.Remove(lnk); |
5ec8e281 | 295 | } |
19b5c321 | 296 | |
5ec8e281 | 297 | return iResult; |
298 | } | |
299 | ||
300 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
301 | { | |
70ed7d01 | 302 | // see header file for class documentation |
5ec8e281 | 303 | int iResult=0; |
a472be38 | 304 | if (fpControlTask==NULL) { |
305 | fpControlTask=new AliHLTControlTask; | |
306 | if (!fpControlTask) return -ENOMEM; | |
307 | fTaskList.AddFirst(fpControlTask); | |
308 | } | |
309 | TObjLink *controlLnk=NULL; | |
310 | TObjLink *lnk = fTaskList.FirstLink(); | |
311 | assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL); | |
312 | if (lnk && lnk->GetObject()==fpControlTask) { | |
313 | if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) { | |
314 | pTask->SetDependency(fpControlTask); | |
315 | fpControlTask->SetTarget(pTask); | |
316 | } | |
317 | controlLnk=lnk; | |
318 | lnk=lnk->Next(); | |
319 | } | |
320 | if ((iResult=pTask->CheckDependencies())<=0) | |
321 | lnk=NULL; | |
5ec8e281 | 322 | while (lnk && iResult>0) { |
323 | AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); | |
85465857 | 324 | //HLTDebug("checking \"%s\"", pCurr->GetName()); |
5ec8e281 | 325 | iResult=pTask->Depends(pCurr); |
326 | if (iResult>0) { | |
327 | iResult=pTask->SetDependency(pCurr); | |
328 | pCurr->SetTarget(pTask); | |
85465857 | 329 | HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); |
f23a6e1a | 330 | } |
5ec8e281 | 331 | if (pCurr->Depends(pTask)) { |
3b35e87c | 332 | // circular dependency |
333 | HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
5ec8e281 | 334 | iResult=-ELOOP; |
335 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
336 | lnk = lnk->Next(); | |
337 | } | |
338 | } | |
339 | if (iResult==0) { | |
340 | if (lnk) { | |
341 | fTaskList.AddAfter(lnk, pTask); | |
a472be38 | 342 | } else if (controlLnk) { |
343 | fTaskList.AddAfter(controlLnk, pTask); | |
5ec8e281 | 344 | } else { |
345 | fTaskList.AddFirst(pTask); | |
346 | } | |
a742f6f8 | 347 | HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask)); |
5ec8e281 | 348 | } else if (iResult>0) { |
85465857 | 349 | HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); |
5ec8e281 | 350 | iResult=-ENOLINK; |
f23a6e1a | 351 | } |
5ec8e281 | 352 | return iResult; |
f23a6e1a | 353 | } |
354 | ||
5ec8e281 | 355 | AliHLTTask* AliHLTSystem::FindTask(const char* id) |
356 | { | |
70ed7d01 | 357 | // see header file for class documentation |
5ec8e281 | 358 | AliHLTTask* pTask=NULL; |
359 | if (id) { | |
f3506ea2 | 360 | pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id)); |
5ec8e281 | 361 | } |
362 | return pTask; | |
363 | } | |
f23a6e1a | 364 | |
5ec8e281 | 365 | void AliHLTSystem::PrintTaskList() |
366 | { | |
70ed7d01 | 367 | // see header file for class documentation |
85465857 | 368 | HLTLogKeyword("task list"); |
5ec8e281 | 369 | TObjLink *lnk = NULL; |
85465857 | 370 | HLTMessage("Task List"); |
5ec8e281 | 371 | lnk=fTaskList.FirstLink(); |
372 | while (lnk) { | |
373 | TObject* obj=lnk->GetObject(); | |
374 | if (obj) { | |
85465857 | 375 | HLTMessage(" %s - status:", obj->GetName()); |
5ec8e281 | 376 | AliHLTTask* pTask=(AliHLTTask*)obj; |
377 | pTask->PrintStatus(); | |
378 | } else { | |
379 | } | |
380 | lnk = lnk->Next(); | |
381 | } | |
382 | } | |
014d39ce | 383 | |
dee38f1b | 384 | int AliHLTSystem::Run(Int_t iNofEvents, int bStop) |
014d39ce | 385 | { |
70ed7d01 | 386 | // see header file for class documentation |
014d39ce | 387 | int iResult=0; |
242bb794 | 388 | int iCount=0; |
389 | SetStatusFlags(kRunning); | |
dee38f1b | 390 | if (fEventCount>=0 || (iResult=InitTasks())>=0) { |
391 | if (fEventCount>=0 || (iResult=StartTasks())>=0) { | |
392 | if (fEventCount==0) { | |
393 | InitBenchmarking(fStopwatches); | |
394 | } else { | |
9d8f5e01 | 395 | // Matthias Oct 11 2008 this is a bug |
396 | // By resuming the stopwatches at this point, all continued counting, but the | |
397 | // starting and stopping is controlled by the AliHLTStopwatchGuard | |
398 | //ResumeBenchmarking(fStopwatches); | |
dee38f1b | 399 | } |
400 | for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) { | |
f3c1d403 | 401 | if (fpHLTOUTTask) { |
402 | if (iNofEvents>1 && i==fEventCount) { | |
403 | HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block"); | |
404 | } | |
405 | // reset and prepare for new data | |
406 | fpHLTOUTTask->Reset(); | |
407 | } | |
dee38f1b | 408 | if ((iResult=ProcessTasks(i))>=0) { |
409 | fGoodEvents++; | |
242bb794 | 410 | iCount++; |
9ce4bf4a | 411 | } else { |
9ce4bf4a | 412 | // TODO: define different running modes to either ignore errors in |
413 | // event processing or not | |
414 | // currently ignored | |
dee38f1b | 415 | iResult=0; |
9ce4bf4a | 416 | } |
0a7afbf0 | 417 | AliHLTDataBuffer::SetGlobalEventCount(iCount); |
2d7ff710 | 418 | } |
dee38f1b | 419 | fEventCount+=iNofEvents; |
420 | if (bStop) StopTasks(); | |
032c5e5e | 421 | else PauseBenchmarking(fStopwatches); |
53feaef5 | 422 | } |
dee38f1b | 423 | if (bStop) DeinitTasks(); |
9ce4bf4a | 424 | } |
90ebac25 | 425 | if (iResult>=0) { |
426 | iResult=iCount; | |
ba7f962b | 427 | } else if (iResult==-126 /*ENOKEY*/) { |
83670b1d | 428 | iResult=0; // do not propagate the error |
90ebac25 | 429 | } |
242bb794 | 430 | ClearStatusFlags(kRunning); |
0a7afbf0 | 431 | AliHLTDataBuffer::PrintStatistics(); |
9ce4bf4a | 432 | return iResult; |
433 | } | |
434 | ||
435 | int AliHLTSystem::InitTasks() | |
436 | { | |
70ed7d01 | 437 | // see header file for class documentation |
9ce4bf4a | 438 | int iResult=0; |
439 | TObjLink *lnk=fTaskList.FirstLink(); | |
dee38f1b | 440 | |
fc455fba | 441 | if (lnk==NULL) { |
97d2b87a | 442 | HLTInfo("Task list is empty, skipping HLT"); |
ba7f962b | 443 | return -126 /*ENOKEY*/; |
fc455fba | 444 | } |
9ce4bf4a | 445 | while (lnk && iResult>=0) { |
446 | TObject* obj=lnk->GetObject(); | |
447 | if (obj) { | |
448 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
449 | iResult=pTask->Init(NULL, fpComponentHandler); | |
dba03d72 | 450 | // ProcInfo_t ProcInfo; |
451 | // gSystem->GetProcInfo(&ProcInfo); | |
452 | // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual); | |
9ce4bf4a | 453 | } else { |
454 | } | |
455 | lnk = lnk->Next(); | |
456 | } | |
457 | if (iResult<0) { | |
97d2b87a | 458 | HLTError("can not initialize task list, error %d", iResult); |
53feaef5 | 459 | } |
dee38f1b | 460 | |
53feaef5 | 461 | return iResult; |
462 | } | |
463 | ||
90ebac25 | 464 | int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches) |
465 | { | |
466 | // see header file for class documentation | |
90ebac25 | 467 | int iResult=0; |
dee38f1b | 468 | if (pStopwatches==NULL) return 0; |
469 | ||
470 | for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) { | |
471 | TStopwatch* pStopwatch= new TStopwatch; | |
472 | if (pStopwatch) { | |
473 | pStopwatch->Reset(); | |
474 | pStopwatches->AddAt(pStopwatch, i); | |
475 | } else { | |
476 | iResult=-ENOMEM; | |
477 | break; | |
478 | } | |
479 | } | |
480 | ||
90ebac25 | 481 | TObjLink *lnk=fTaskList.FirstLink(); |
482 | while (lnk && iResult>=0) { | |
483 | TObject* obj=lnk->GetObject(); | |
484 | if (obj) { | |
485 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
486 | AliHLTComponent* pComp=NULL; | |
487 | if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) { | |
488 | switch (pComp->GetComponentType()) { | |
489 | case AliHLTComponent::kProcessor: | |
490 | pComp->SetStopwatches(pStopwatches); | |
491 | break; | |
492 | case AliHLTComponent::kSource: | |
493 | { | |
494 | // this switch determines whether the time consumption of the | |
495 | // AliHLTComponent base methods should be counted to the input | |
496 | // stopwatch or base stopwatch. | |
497 | //int inputBase=(int)AliHLTComponent::kSWBase; | |
498 | int inputBase=(int)AliHLTComponent::kSWInput; | |
499 | pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase); | |
500 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA); | |
501 | } | |
502 | break; | |
503 | case AliHLTComponent::kSink: | |
504 | { | |
505 | // this switch determines whether the time consumption of the | |
506 | // AliHLTComponent base methods should be counted to the output | |
507 | // stopwatch or base stopwatch. | |
508 | //int outputBase=(int)AliHLTComponent::kSWBase; | |
509 | int outputBase=(int)AliHLTComponent::kSWOutput; | |
510 | pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase); | |
511 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA); | |
512 | } | |
513 | break; | |
85f0cede | 514 | default: |
515 | HLTWarning("unknown component type %d", (int)pComp->GetComponentType()); | |
90ebac25 | 516 | } |
517 | } | |
518 | } else { | |
519 | } | |
520 | lnk = lnk->Next(); | |
521 | } | |
522 | return iResult; | |
523 | } | |
524 | ||
032c5e5e | 525 | int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const |
526 | { | |
527 | // see header file for class documentation | |
528 | if (pStopwatches==NULL) return 0; | |
529 | ||
530 | for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) { | |
531 | if (!pStopwatches->At(i)) continue; | |
532 | TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i)); | |
533 | if (pSw) pSw->Stop(); | |
534 | } | |
535 | return 0; | |
536 | } | |
537 | ||
538 | int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const | |
539 | { | |
540 | // see header file for class documentation | |
541 | if (pStopwatches==NULL) return 0; | |
542 | ||
543 | for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) { | |
544 | if (!pStopwatches->At(i)) continue; | |
545 | TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i)); | |
546 | if (pSw) pSw->Continue(); | |
547 | } | |
548 | return 0; | |
549 | } | |
550 | ||
551 | int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const | |
dee38f1b | 552 | { |
553 | // see header file for class documentation | |
554 | int iInitialized=1; | |
555 | if (pStopwatches==NULL) return 0; | |
556 | ||
557 | for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) { | |
558 | if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) { | |
559 | iInitialized=0; | |
560 | break; | |
561 | } | |
562 | } | |
563 | ||
564 | if (iInitialized!=0) { | |
032c5e5e | 565 | HLTImportant("HLT statistics:\n" |
dee38f1b | 566 | " base: R:%.3fs C:%.3fs\n" |
567 | " input: R:%.3fs C:%.3fs\n" | |
568 | " output: R:%.3fs C:%.3fs\n" | |
569 | " event processing : R:%.3fs C:%.3fs" | |
570 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime() | |
571 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime() | |
572 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime() | |
573 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime() | |
574 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime() | |
575 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime() | |
576 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime() | |
577 | , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime() | |
578 | ); | |
579 | } | |
580 | ||
581 | if (bClean) { | |
582 | for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) { | |
583 | TObject* pObj=pStopwatches->RemoveAt(i); | |
584 | if (pObj) delete pObj; | |
585 | } | |
586 | } | |
587 | return 0; | |
588 | } | |
589 | ||
53feaef5 | 590 | int AliHLTSystem::StartTasks() |
591 | { | |
70ed7d01 | 592 | // see header file for class documentation |
53feaef5 | 593 | int iResult=0; |
594 | TObjLink *lnk=fTaskList.FirstLink(); | |
595 | while (lnk && iResult>=0) { | |
596 | TObject* obj=lnk->GetObject(); | |
597 | if (obj) { | |
598 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
599 | iResult=pTask->StartRun(); | |
dba03d72 | 600 | // ProcInfo_t ProcInfo; |
601 | // gSystem->GetProcInfo(&ProcInfo); | |
602 | // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual); | |
53feaef5 | 603 | } else { |
604 | } | |
605 | lnk = lnk->Next(); | |
606 | } | |
607 | if (iResult<0) { | |
97d2b87a | 608 | HLTError("can not start task list, error %d", iResult); |
dee38f1b | 609 | } else { |
3dd8541e | 610 | SetStatusFlags(kStarted); |
dee38f1b | 611 | fEventCount=0; |
612 | fGoodEvents=0; | |
457ec821 | 613 | if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) { |
97d2b87a | 614 | HLTError("can not send SOR event: error %d", iResult); |
457ec821 | 615 | } |
53feaef5 | 616 | } |
617 | return iResult; | |
618 | } | |
619 | ||
620 | int AliHLTSystem::ProcessTasks(Int_t eventNo) | |
621 | { | |
70ed7d01 | 622 | // see header file for class documentation |
53feaef5 | 623 | int iResult=0; |
624 | HLTDebug("processing event no %d", eventNo); | |
625 | TObjLink *lnk=fTaskList.FirstLink(); | |
626 | while (lnk && iResult>=0) { | |
627 | TObject* obj=lnk->GetObject(); | |
628 | if (obj) { | |
629 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
9ce4bf4a | 630 | iResult=pTask->ProcessTask(eventNo); |
dba03d72 | 631 | // ProcInfo_t ProcInfo; |
632 | // gSystem->GetProcInfo(&ProcInfo); | |
633 | // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual); | |
53feaef5 | 634 | } else { |
635 | } | |
636 | lnk = lnk->Next(); | |
637 | } | |
dee38f1b | 638 | |
639 | if (iResult>=0) { | |
97d2b87a | 640 | HLTImportant("Event %d successfully finished (%d)", eventNo, iResult); |
dee38f1b | 641 | iResult=0; |
642 | } else { | |
97d2b87a | 643 | HLTError("Processing of event %d failed (%d)", eventNo, iResult); |
dee38f1b | 644 | } |
645 | ||
53feaef5 | 646 | return iResult; |
647 | } | |
648 | ||
649 | int AliHLTSystem::StopTasks() | |
650 | { | |
70ed7d01 | 651 | // see header file for class documentation |
53feaef5 | 652 | int iResult=0; |
457ec821 | 653 | if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) { |
97d2b87a | 654 | HLTError("can not send EOR event"); |
457ec821 | 655 | } |
19b5c321 | 656 | |
657 | // cleanup blocks from the last event. This is a bit awkward. All output | |
658 | // blocks from the chains need to be stored in the HLTOUT task. Though, | |
659 | // we do not know, whether HLTOUT is going to be processed or not. | |
660 | if (fpHLTOUTTask) | |
661 | fpHLTOUTTask->Reset(); | |
662 | ||
53feaef5 | 663 | TObjLink *lnk=fTaskList.FirstLink(); |
457ec821 | 664 | while (lnk) { |
53feaef5 | 665 | TObject* obj=lnk->GetObject(); |
666 | if (obj) { | |
667 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
457ec821 | 668 | int locResult=pTask->EndRun(); |
669 | if (iResult>=0 && locResult<0) iResult=locResult; | |
dba03d72 | 670 | // ProcInfo_t ProcInfo; |
671 | // gSystem->GetProcInfo(&ProcInfo); | |
672 | // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual); | |
53feaef5 | 673 | } else { |
674 | } | |
675 | lnk = lnk->Next(); | |
676 | } | |
dee38f1b | 677 | PrintBenchmarking(fStopwatches, 1 /*clean*/); |
3dd8541e | 678 | ClearStatusFlags(kStarted); |
014d39ce | 679 | return iResult; |
680 | } | |
9ce4bf4a | 681 | |
457ec821 | 682 | int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt) |
683 | { | |
684 | // see header file for class documentation | |
457ec821 | 685 | int iResult=0; |
a472be38 | 686 | |
457ec821 | 687 | AliHLTRunDesc runDesc; |
688 | memset(&runDesc, 0, sizeof(AliHLTRunDesc)); | |
689 | runDesc.fStructSize=sizeof(AliHLTRunDesc); | |
a472be38 | 690 | AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, dt, kAliHLTVoidDataSpec, (AliHLTUInt8_t*)&runDesc, sizeof(AliHLTRunDesc)); |
457ec821 | 691 | HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc); |
692 | TObjLink *lnk=fTaskList.FirstLink(); | |
693 | while (lnk && iResult>=0) { | |
694 | TObject* obj=lnk->GetObject(); | |
695 | if (obj) { | |
696 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
a472be38 | 697 | AliHLTUInt32_t eventType=gkAliEventTypeUnknown; |
698 | if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun; | |
699 | else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun; | |
700 | else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str()); | |
701 | iResult=pTask->ProcessTask(-1, eventType); | |
457ec821 | 702 | } else { |
703 | } | |
704 | lnk = lnk->Next(); | |
705 | } | |
a472be38 | 706 | |
707 | // control events are not supposed to go into the HLTOUT | |
708 | if (fpHLTOUTTask) | |
709 | fpHLTOUTTask->Reset(); | |
710 | ||
457ec821 | 711 | HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult); |
712 | return iResult; | |
713 | } | |
714 | ||
9ce4bf4a | 715 | int AliHLTSystem::DeinitTasks() |
716 | { | |
70ed7d01 | 717 | // see header file for class documentation |
9ce4bf4a | 718 | int iResult=0; |
719 | TObjLink *lnk=fTaskList.FirstLink(); | |
618c89b9 | 720 | while (lnk) { |
9ce4bf4a | 721 | TObject* obj=lnk->GetObject(); |
722 | if (obj) { | |
723 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
618c89b9 | 724 | int localRes=pTask->Deinit(); |
725 | if (iResult>=0) iResult=localRes; | |
dba03d72 | 726 | // ProcInfo_t ProcInfo; |
727 | // gSystem->GetProcInfo(&ProcInfo); | |
728 | // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual); | |
9ce4bf4a | 729 | } else { |
730 | } | |
731 | lnk = lnk->Next(); | |
732 | } | |
dee38f1b | 733 | fEventCount=-1; |
734 | fGoodEvents=-1; | |
735 | ||
9ce4bf4a | 736 | return iResult; |
737 | } | |
738 | ||
a472be38 | 739 | int AliHLTSystem::CleanHLTOUT() |
740 | { | |
741 | // see header file for class documentation | |
742 | if (fpChainHandlers) { | |
743 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers); | |
744 | fpChainHandlers=NULL; | |
745 | if (pHandlers) { | |
746 | AliHLTOUT::InvalidateBlocks(*pHandlers); | |
747 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers); | |
748 | } | |
749 | assert(pHandlers->size()==0); | |
750 | delete pHandlers; | |
751 | } | |
752 | ||
753 | if (fpEsdHandlers) { | |
754 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers); | |
755 | fpEsdHandlers=NULL; | |
756 | if (pHandlers) { | |
757 | AliHLTOUT::InvalidateBlocks(*pHandlers); | |
758 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers); | |
759 | } | |
760 | assert(pHandlers->size()==0); | |
761 | delete pHandlers; | |
762 | } | |
763 | ||
764 | if (fpProprietaryHandlers) { | |
765 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers); | |
766 | fpProprietaryHandlers=NULL; | |
767 | if (pHandlers) { | |
768 | AliHLTOUT::InvalidateBlocks(*pHandlers); | |
769 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers); | |
770 | } | |
771 | assert(pHandlers->size()==0); | |
772 | delete pHandlers; | |
773 | } | |
774 | return 0; | |
775 | } | |
776 | ||
c043fa2c | 777 | void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size ) |
9ce4bf4a | 778 | { |
70ed7d01 | 779 | // see header file for class documentation |
c043fa2c | 780 | void* p=NULL; |
781 | try { | |
782 | p=(void*)new char[size]; | |
242bb794 | 783 | } |
c043fa2c | 784 | catch (...) { |
785 | AliHLTLogging log; | |
786 | log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" ); | |
787 | } | |
788 | return p; | |
9ce4bf4a | 789 | } |
242bb794 | 790 | |
33d33d06 | 791 | int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd ) |
324ca3b4 | 792 | { |
793 | // see header file for class documentation | |
794 | unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size; | |
795 | void* block=AllocMemory(NULL, blocksize); | |
796 | if (!block) return -ENOMEM; | |
797 | memset(block, 0, blocksize); | |
798 | *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block); | |
799 | (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData); | |
800 | (*edd)->fDataSize=size; | |
801 | (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData); | |
802 | ||
803 | return 0; | |
804 | } | |
805 | ||
242bb794 | 806 | int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, |
807 | AliRawReader* rawReader) | |
808 | { | |
809 | // see header file for class documentation | |
810 | int iResult=0; | |
dee38f1b | 811 | if (runLoader || rawReader || nofEvents==0) { |
812 | if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);} | |
242bb794 | 813 | if (CheckStatus(kReady)) { |
dee38f1b | 814 | if (nofEvents==0) { |
815 | // special case to close the reconstruction | |
f3506ea2 | 816 | if (!CheckStatus(kError)) { |
dee38f1b | 817 | StopTasks(); |
818 | DeinitTasks(); | |
a472be38 | 819 | CleanHLTOUT(); |
f3506ea2 | 820 | } |
dee38f1b | 821 | } else { |
8451168b | 822 | if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) { |
dee38f1b | 823 | // the system always remains started after event processing, a specific |
f3506ea2 | 824 | // call with nofEvents==0 is needed to execute the stop sequence |
825 | if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError); | |
dee38f1b | 826 | } |
8451168b | 827 | } |
242bb794 | 828 | } else { |
829 | HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady); | |
830 | } | |
831 | } else { | |
0bf7536b | 832 | HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader); |
242bb794 | 833 | iResult=-EINVAL; |
834 | } | |
835 | return iResult; | |
836 | } | |
837 | ||
af885e0f | 838 | int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd) |
242bb794 | 839 | { |
840 | // see header file for class documentation | |
841 | int iResult=0; | |
dee38f1b | 842 | if (runLoader || esd) { |
242bb794 | 843 | HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd); |
8451168b | 844 | iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd); |
242bb794 | 845 | } else { |
846 | HLTError("missing run loader/ESD instance(s)"); | |
847 | iResult=-EINVAL; | |
848 | } | |
849 | return iResult; | |
850 | } | |
851 | ||
c5123824 | 852 | int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd) |
853 | { | |
854 | // see header file for class documentation | |
855 | int iResult=0; | |
856 | if (!pHLTOUT) return -EINVAL; | |
c5123824 | 857 | HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks()); |
0f1882a7 | 858 | |
f3c1d403 | 859 | // add the current HLTOUT task to the collection |
860 | if (fpHLTOUTTask) { | |
861 | AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask); | |
862 | if (pTask && (iResult=pTask->Init())>=0) { | |
863 | if (pTask->GetNofDataBlocks()>0) { | |
864 | pHLTOUT->AddSubCollection(pTask); | |
865 | } | |
866 | } else { | |
867 | HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult); | |
868 | iResult=0; | |
869 | } | |
870 | } | |
871 | ||
872 | ||
0f1882a7 | 873 | // |
874 | // process all kChain handlers first | |
875 | // | |
876 | if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) { | |
877 | HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult); | |
878 | iResult=0; | |
879 | } | |
880 | ||
b005ef92 | 881 | if (!fpEsdHandlers) |
882 | fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector; | |
883 | if (!fpProprietaryHandlers) | |
884 | fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector; | |
885 | ||
886 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers); | |
887 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers); | |
888 | if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM; | |
889 | ||
890 | // invalidate all blocks | |
891 | AliHLTOUT::InvalidateBlocks(*pEsdHandlers); | |
892 | AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers); | |
90c37647 | 893 | |
d4a18597 | 894 | AliHLTComponentDataTypeList esdBlocks; |
895 | ||
c5123824 | 896 | for (iResult=pHLTOUT->SelectFirstDataBlock(); |
897 | iResult>=0; | |
898 | iResult=pHLTOUT->SelectNextDataBlock()) { | |
899 | AliHLTComponentDataType dt=kAliHLTVoidDataType; | |
900 | AliHLTUInt32_t spec=kAliHLTVoidDataSpec; | |
901 | pHLTOUT->GetDataBlockDescription(dt, spec); | |
902 | AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler(); | |
903 | AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType(); | |
0f1882a7 | 904 | |
905 | // default handling for ESD data blocks does not require an explicite handler | |
f94e8c27 | 906 | if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) { |
c5123824 | 907 | handlerType=AliHLTModuleAgent::kEsd; |
908 | } | |
909 | const char* pMsg="invalid"; | |
910 | switch (handlerType) { | |
911 | case AliHLTModuleAgent::kEsd: | |
912 | { | |
913 | if (pHandler) { | |
0f1882a7 | 914 | // schedule for later processing |
b005ef92 | 915 | pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc()); |
c5123824 | 916 | } else { |
d4a18597 | 917 | AliHLTComponentDataTypeList::iterator element=esdBlocks.begin(); |
918 | for (; element!=esdBlocks.end(); element++) { | |
919 | if (*element==dt) { | |
920 | HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str()); | |
921 | break; | |
922 | } | |
923 | } | |
924 | if (element==esdBlocks.end()) esdBlocks.push_back(dt); | |
925 | ||
c5123824 | 926 | // write directly |
927 | const AliHLTUInt8_t* pBuffer=NULL; | |
928 | AliHLTUInt32_t size=0; | |
929 | if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) { | |
57584811 | 930 | pHLTOUT->WriteESD(pBuffer, size, dt, esd); |
c5123824 | 931 | pHLTOUT->ReleaseDataBuffer(pBuffer); |
932 | } | |
0f1882a7 | 933 | pHLTOUT->MarkDataBlockProcessed(); |
c5123824 | 934 | } |
935 | } | |
936 | break; | |
937 | case AliHLTModuleAgent::kRawReader: | |
938 | // handled in the AliRawReaderHLT | |
939 | break; | |
940 | case AliHLTModuleAgent::kRawStream: | |
941 | HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x", | |
f75868b3 | 942 | pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>", |
c5123824 | 943 | AliHLTComponent::DataType2Text(dt).c_str(), spec); |
944 | break; | |
945 | case AliHLTModuleAgent::kChain: | |
0f1882a7 | 946 | HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n" |
947 | "New block of this type added by the chain? Skipping data block ...", | |
f75868b3 | 948 | pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>", |
c5123824 | 949 | AliHLTComponent::DataType2Text(dt).c_str(), spec); |
950 | break; | |
951 | case AliHLTModuleAgent::kProprietary: | |
952 | HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x", | |
f75868b3 | 953 | pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>", |
c5123824 | 954 | AliHLTComponent::DataType2Text(dt).c_str(), spec); |
955 | if (pHandler) { | |
956 | AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT); | |
957 | int res=pHandler->ProcessData(pHLTOUT); | |
958 | if (res<0) { | |
959 | HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x", | |
f75868b3 | 960 | res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>", |
c5123824 | 961 | AliHLTComponent::DataType2Text(dt).c_str(), spec); |
962 | } | |
963 | } | |
964 | break; | |
965 | case AliHLTModuleAgent::kUnknownOutput: | |
966 | pMsg="unknown"; | |
967 | // fall trough intended | |
968 | default: | |
969 | HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block", | |
f75868b3 | 970 | pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>", |
c5123824 | 971 | AliHLTComponent::DataType2Text(dt).c_str(), spec); |
972 | } | |
973 | } | |
974 | // TODO: the return value of SelectFirst/NextDataBlock must be | |
975 | // changed in order to avoid this check | |
976 | if (iResult==-ENOENT) iResult=0; | |
977 | ||
b005ef92 | 978 | AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler; |
979 | ||
980 | // process and write all esd data blocks | |
981 | for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) { | |
982 | AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler)); | |
983 | AliHLTOUTHandler* pHandler=*handler; | |
c5123824 | 984 | const AliHLTUInt8_t* pBuffer=NULL; |
985 | AliHLTUInt32_t size=0; | |
0f1882a7 | 986 | pHandler->ProcessData(pHLTOUT); |
c5123824 | 987 | if ((size=pHandler->GetProcessedData(pBuffer))>0) { |
b005ef92 | 988 | AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler; |
c5123824 | 989 | AliHLTComponentDataType dt=desc; |
57584811 | 990 | pHLTOUT->WriteESD(pBuffer, size, dt, esd); |
c5123824 | 991 | pHandler->ReleaseProcessedData(pBuffer, size); |
992 | } | |
b005ef92 | 993 | pHLTOUT->MarkDataBlocksProcessed(&(*handler)); |
994 | } | |
995 | ||
996 | // process all kProprietary data blocks | |
d4a18597 | 997 | for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) { |
b005ef92 | 998 | AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler)); |
999 | AliHLTOUTHandler* pHandler=*handler; | |
1000 | const AliHLTUInt8_t* pBuffer=NULL; | |
1001 | AliHLTUInt32_t size=0; | |
1002 | pHandler->ProcessData(pHLTOUT); | |
1003 | if ((size=pHandler->GetProcessedData(pBuffer))>0) { | |
1004 | HLTWarning("data produced by kProprietary handler ignored"); | |
1005 | pHandler->ReleaseProcessedData(pBuffer, size); | |
1006 | } | |
1007 | pHLTOUT->MarkDataBlocksProcessed(&(*handler)); | |
0f1882a7 | 1008 | } |
1009 | ||
b005ef92 | 1010 | // remove all empty handlers form the list (handlers which did not get a block this time) |
1011 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers); | |
1012 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers); | |
1013 | ||
0f1882a7 | 1014 | return iResult; |
1015 | } | |
1016 | ||
1017 | int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT) | |
1018 | { | |
1019 | // see header file for class documentation | |
1020 | int iResult=0; | |
1021 | if (!pHLTOUT) return -EINVAL; | |
1022 | ||
b005ef92 | 1023 | if (!fpChainHandlers) |
1024 | fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector; | |
1025 | ||
1026 | AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers); | |
1027 | if (!pChainHandlers) return -ENOMEM; | |
1028 | ||
1029 | // invalidate all blocks | |
1030 | AliHLTOUT::InvalidateBlocks(*pChainHandlers); | |
1031 | ||
1032 | // fill the list | |
1033 | pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain); | |
0f1882a7 | 1034 | |
1035 | // process all defined chain handlers | |
1036 | AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler; | |
b005ef92 | 1037 | for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) { |
d4a18597 | 1038 | if (chainHandler->IsEmpty()) continue; |
0f1882a7 | 1039 | AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler)); |
1040 | AliHLTOUTHandler* pHandler=*chainHandler; | |
1041 | const AliHLTUInt8_t* pBuffer=NULL; | |
1042 | AliHLTUInt32_t size=0; | |
1043 | pHandler->ProcessData(pHLTOUT); | |
1044 | if ((size=pHandler->GetProcessedData(pBuffer))>0) { | |
1045 | AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler; | |
1046 | AliHLTComponentDataType dt=desc; | |
1047 | ||
1048 | pHandler->ReleaseProcessedData(pBuffer, size); | |
1049 | } | |
1050 | pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler)); | |
c5123824 | 1051 | } |
1052 | ||
b005ef92 | 1053 | // remove all empty handlers form the list (handlers which did not get a block this time) |
1054 | AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers); | |
1055 | ||
c5123824 | 1056 | return iResult; |
1057 | } | |
1058 | ||
242bb794 | 1059 | int AliHLTSystem::LoadComponentLibraries(const char* libraries) |
1060 | { | |
1061 | // see header file for class documentation | |
1062 | int iResult=0; | |
1063 | if (libraries) { | |
1064 | if (fpComponentHandler) { | |
1065 | TString libs(libraries); | |
1066 | TObjArray* pTokens=libs.Tokenize(" "); | |
1067 | if (pTokens) { | |
1068 | int iEntries=pTokens->GetEntries(); | |
1069 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
1070 | iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data()); | |
1071 | } | |
1072 | delete pTokens; | |
1073 | } | |
1074 | if (iResult>=0) { | |
1075 | SetStatusFlags(kLibrariesLoaded); | |
1076 | } else { | |
1077 | // lets see if we need this, probably not | |
1078 | //fpComponentHandler->UnloadLibraries(); | |
1079 | ClearStatusFlags(kLibrariesLoaded); | |
1080 | } | |
1081 | } else { | |
1082 | iResult=-EFAULT; | |
1083 | HLTFatal("no component handler available"); | |
1084 | } | |
1085 | } else { | |
1086 | iResult=-EINVAL; | |
1087 | } | |
1088 | return iResult; | |
1089 | } | |
1090 | ||
1091 | int AliHLTSystem::Configure(AliRunLoader* runloader) | |
dee38f1b | 1092 | { |
1093 | // see header file for class documentation | |
f3506ea2 | 1094 | return Configure(NULL, runloader); |
dee38f1b | 1095 | } |
1096 | ||
1097 | int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader) | |
242bb794 | 1098 | { |
1099 | // see header file for class documentation | |
1100 | int iResult=0; | |
1101 | if (CheckStatus(kRunning)) { | |
1102 | HLTError("HLT system in running state, can not configure"); | |
1103 | return -EBUSY; | |
1104 | } | |
e642a402 | 1105 | ClearStatusFlags(kTaskListCreated); |
c215072c | 1106 | if (CheckFilter(kHLTLogDebug)) |
1107 | AliHLTModuleAgent::PrintStatus(); | |
c043fa2c | 1108 | if (CheckStatus(kConfigurationLoaded)==0) { |
dee38f1b | 1109 | iResult=LoadConfigurations(rawReader, runloader); |
c043fa2c | 1110 | } else { |
dee38f1b | 1111 | if (fChains.Length()==0) { |
703bcca6 | 1112 | HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option"); |
c043fa2c | 1113 | iResult=-ENOENT; |
1114 | } | |
1115 | } | |
242bb794 | 1116 | if (iResult>=0) { |
1117 | SetStatusFlags(kConfigurationLoaded); | |
c043fa2c | 1118 | if (CheckFilter(kHLTLogDebug)) |
1119 | fpConfigurationHandler->PrintConfigurations(); | |
f3506ea2 | 1120 | iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader); |
242bb794 | 1121 | if (iResult>=0) { |
1122 | SetStatusFlags(kTaskListCreated); | |
1123 | } | |
1124 | } | |
1125 | if (iResult<0) SetStatusFlags(kError); | |
1126 | ||
1127 | return iResult; | |
1128 | } | |
1129 | ||
c043fa2c | 1130 | int AliHLTSystem::ScanOptions(const char* options) |
1131 | { | |
1132 | // see header file for class documentation | |
1133 | int iResult=0; | |
1134 | if (options) { | |
d76bc02a | 1135 | //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic; |
83670b1d | 1136 | TString libs(""); |
c043fa2c | 1137 | TString alloptions(options); |
1138 | TObjArray* pTokens=alloptions.Tokenize(" "); | |
1139 | if (pTokens) { | |
1140 | int iEntries=pTokens->GetEntries(); | |
1141 | for (int i=0; i<iEntries; i++) { | |
1142 | TString token=(((TObjString*)pTokens->At(i))->GetString()); | |
1143 | if (token.Contains("loglevel=")) { | |
1144 | TString param=token.ReplaceAll("loglevel=", ""); | |
1145 | if (param.IsDigit()) { | |
1146 | SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi()); | |
1147 | } else if (param.BeginsWith("0x") && | |
1148 | param.Replace(0,2,"",0).IsHex()) { | |
1149 | int severity=0; | |
1150 | sscanf(param.Data(),"%x", &severity); | |
1151 | SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity); | |
1152 | } else { | |
1153 | HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected"); | |
1154 | } | |
dba03d72 | 1155 | } else if (token.Contains("frameworklog=")) { |
1156 | TString param=token.ReplaceAll("frameworklog=", ""); | |
1157 | if (param.IsDigit()) { | |
1158 | SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi()); | |
1159 | } else if (param.BeginsWith("0x") && | |
1160 | param.Replace(0,2,"",0).IsHex()) { | |
1161 | int severity=0; | |
1162 | sscanf(param.Data(),"%x", &severity); | |
1163 | SetFrameworkLog((AliHLTComponentLogSeverity)severity); | |
1164 | } else { | |
1165 | HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected"); | |
1166 | } | |
c043fa2c | 1167 | } else if (token.Contains("alilog=off")) { |
1168 | SwitchAliLog(0); | |
1169 | } else if (token.Contains("config=")) { | |
1170 | TString param=token.ReplaceAll("config=", ""); | |
1171 | Int_t error=0; | |
1172 | gROOT->Macro(param.Data(), &error); | |
1173 | if (error==0) { | |
1174 | SetStatusFlags(kConfigurationLoaded); | |
1175 | } else { | |
1176 | HLTError("can not execute macro \'%s\'", param.Data()); | |
1177 | iResult=-EBADF; | |
1178 | } | |
d85f150c | 1179 | } else if (token.Contains("chains=")) { |
dee38f1b | 1180 | TString param=token.ReplaceAll("chains=", ""); |
1181 | fChains=param.ReplaceAll(",", " "); | |
703bcca6 | 1182 | if (fChains.IsNull()) fChains=" "; // disable all chains |
dba03d72 | 1183 | } else if (token.Contains("libmode=")) { |
1184 | TString param=token.ReplaceAll("libmode=", ""); | |
1185 | param.ReplaceAll(",", " "); | |
1186 | if (fpComponentHandler) { | |
1187 | if (param.CompareTo("static")==0) { | |
1188 | fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic); | |
1189 | } else if (param.CompareTo("dynamic")==0) { | |
1190 | fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic); | |
1191 | } else { | |
1192 | HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'"); | |
1193 | } | |
1194 | } | |
83670b1d | 1195 | } else if (token.BeginsWith("lib") && token.EndsWith(".so")) { |
1196 | libs+=token; | |
1197 | libs+=" "; | |
c043fa2c | 1198 | } else { |
1199 | HLTWarning("unknown option \'%s\'", token.Data()); | |
1200 | } | |
1201 | } | |
1202 | delete pTokens; | |
1203 | } | |
83670b1d | 1204 | |
1205 | if (iResult>=0) { | |
1206 | if (libs.IsNull()) { | |
6a8e0bb4 | 1207 | const char** deflib=fgkHLTDefaultLibs; |
83670b1d | 1208 | while (*deflib) { |
1209 | libs+=*deflib++; | |
1210 | libs+=" "; | |
1211 | } | |
1212 | } | |
1213 | if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) && | |
1214 | (LoadComponentLibraries(libs.Data())<0)) { | |
1215 | HLTError("error while loading HLT libraries"); | |
1216 | iResult=-EFAULT; | |
1217 | } | |
1218 | } | |
c043fa2c | 1219 | } |
1220 | return iResult; | |
1221 | } | |
1222 | ||
242bb794 | 1223 | int AliHLTSystem::Reset(int bForce) |
1224 | { | |
1225 | // see header file for class documentation | |
1226 | int iResult=0; | |
1227 | if (!bForce && CheckStatus(kRunning)) { | |
1228 | HLTError("HLT system in running state, can not configure"); | |
1229 | return -EBUSY; | |
1230 | } | |
1231 | CleanTaskList(); | |
1232 | ClearStatusFlags(~kUninitialized); | |
1233 | return iResult; | |
1234 | } | |
1235 | ||
dee38f1b | 1236 | int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader) |
242bb794 | 1237 | { |
1238 | // see header file for class documentation | |
1239 | if (CheckStatus(kRunning)) { | |
1240 | HLTError("HLT system in running state, can not configure"); | |
1241 | return -EBUSY; | |
1242 | } | |
1243 | int iResult=0; | |
d5ea63f7 | 1244 | AliHLTModuleAgent* pAgent=NULL; |
1245 | ||
1246 | // first check for the required libraries and load those | |
1d398268 | 1247 | TString extralibs; |
d5ea63f7 | 1248 | for (pAgent=AliHLTModuleAgent::GetFirstAgent(); |
1249 | pAgent && iResult>=0; | |
1250 | pAgent=AliHLTModuleAgent::GetNextAgent()) { | |
60b26a17 | 1251 | const char* deplibs=pAgent->GetRequiredComponentLibraries(); |
1252 | if (deplibs) { | |
1d398268 | 1253 | HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent); |
f98abf68 | 1254 | extralibs+=" "; |
1d398268 | 1255 | extralibs+=deplibs; |
60b26a17 | 1256 | } |
242bb794 | 1257 | } |
1d398268 | 1258 | if (iResult>=0) { |
1259 | iResult=LoadComponentLibraries(extralibs.Data()); | |
1260 | } | |
1261 | ||
d5ea63f7 | 1262 | // in order to register the configurations in the correct sequence |
1263 | // all agents need to be ordered with respect to the required | |
1264 | // libraries. Ordering relies on the naming convention | |
1265 | // libAliHLT<Module>.so | |
1266 | TList agents; | |
1267 | for (pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
1268 | pAgent && iResult>=0; | |
1269 | pAgent=AliHLTModuleAgent::GetNextAgent()) { | |
1270 | AliHLTModuleAgent* pPrevDep=NULL; | |
1271 | TString dependencies=pAgent->GetRequiredComponentLibraries(); | |
1272 | TObjArray* pTokens=dependencies.Tokenize(" "); | |
1273 | if (pTokens) { | |
1274 | for (int n=0; n<pTokens->GetEntriesFast(); n++) { | |
1275 | TString module=((TObjString*)pTokens->At(n))->GetString(); | |
1276 | HLTDebug(" checking %s", module.Data()); | |
1277 | module.ReplaceAll("libAliHLT", ""); | |
1278 | module.ReplaceAll(".so", ""); | |
1279 | ||
1280 | for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep)); | |
1281 | pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) { | |
1282 | HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId()); | |
1283 | ||
1284 | if (module.CompareTo(pCurrent->GetModuleId())==0) { | |
1285 | pPrevDep=pCurrent; | |
1286 | break; | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | delete pTokens; | |
1291 | } | |
1292 | ||
1293 | if (pPrevDep) { | |
1294 | // insert right after the last dependency | |
1295 | agents.AddAfter(pPrevDep, pAgent); | |
1296 | HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId()); | |
1297 | } else { | |
1298 | // insert at the beginning | |
1299 | agents.AddFirst(pAgent); | |
1300 | HLTDebug("insert %s at beginning", pAgent->GetModuleId()); | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | // now we load the configurations | |
1305 | if (agents.GetEntries()) { | |
1306 | TIter next(&agents); | |
1307 | while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) { | |
1308 | HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent); | |
1309 | pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader); | |
1310 | } | |
1311 | } | |
1312 | ||
242bb794 | 1313 | return iResult; |
1314 | } | |
1315 | ||
f3506ea2 | 1316 | int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader) |
242bb794 | 1317 | { |
1318 | // see header file for class documentation | |
1319 | if (CheckStatus(kRunning)) { | |
1320 | HLTError("HLT system in running state, can not configure"); | |
1321 | return -EBUSY; | |
1322 | } | |
1323 | if (!CheckStatus(kConfigurationLoaded)) { | |
1324 | HLTWarning("configurations not yet loaded"); | |
1325 | return 0; | |
1326 | } | |
1327 | ||
1328 | int iResult=0; | |
f3506ea2 | 1329 | int bHaveOutput=0; |
1330 | ||
1331 | // query chains | |
1332 | TString chains; | |
1333 | if (fChains.Length()>0) { | |
1334 | chains=fChains; | |
8f471af0 | 1335 | HLTImportant("custom reconstruction chain: %s", chains.Data()); |
f3506ea2 | 1336 | } else { |
1337 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
1338 | while ((pAgent || fChains.Length()>0) && iResult>=0) { | |
1339 | const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader); | |
1340 | if (agentchains) { | |
703bcca6 | 1341 | if (!chains.IsNull()) chains+=" "; |
f3506ea2 | 1342 | chains+=agentchains; |
1343 | HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains); | |
1344 | } | |
1345 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
c043fa2c | 1346 | } |
f3506ea2 | 1347 | } |
1348 | ||
1349 | // build task list for chains | |
1350 | TObjArray* pTokens=chains.Tokenize(" "); | |
1351 | if (pTokens) { | |
1352 | int iEntries=pTokens->GetEntries(); | |
1353 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
1354 | const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data(); | |
1355 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID); | |
1356 | if (pConf) { | |
1357 | iResult=BuildTaskList(pConf); | |
f3c1d403 | 1358 | if (true) { // condition was deprecated but kept for sake of svn diff |
1359 | // bHaveOutput variable has to be set for both running modes | |
1360 | // AliHLTSimulation and AliHLTReconstruction | |
f3506ea2 | 1361 | assert(fpComponentHandler!=NULL); |
1362 | TString cid=pConf->GetComponentID(); | |
f3c1d403 | 1363 | if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) { |
f3506ea2 | 1364 | // remove from the input of a global HLTOUT configuration |
1365 | chains.ReplaceAll(pCID, ""); | |
1366 | } else if (bHaveOutput==0) { | |
1367 | // check whether this configuration produces data output | |
1368 | if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) { | |
1369 | bHaveOutput=0; | |
1370 | chains.ReplaceAll(pCID, ""); | |
1371 | } | |
1372 | } | |
242bb794 | 1373 | } |
f3506ea2 | 1374 | } else { |
1375 | HLTWarning("can not find configuration %s", pCID); | |
242bb794 | 1376 | } |
242bb794 | 1377 | } |
f3506ea2 | 1378 | delete pTokens; |
1379 | } | |
1380 | ||
1381 | // build HLTOUT for simulation | |
1382 | if (iResult>=0 && runloader) { | |
1383 | if (bHaveOutput) { | |
1384 | // there are components in the chain which produce data which need to be | |
1385 | // piped to an HLTOUT | |
1386 | if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 || | |
703bcca6 | 1387 | fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) { |
f3506ea2 | 1388 | AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL); |
1389 | iResult=BuildTaskList("_globalout_"); | |
1390 | } else { | |
1391 | HLTError("can not load libHLTsim.so and HLTOUT component"); | |
1392 | iResult=-EFAULT; | |
1393 | } | |
c043fa2c | 1394 | } |
242bb794 | 1395 | } |
f3506ea2 | 1396 | |
f3c1d403 | 1397 | // build HLTOUT task for reconstruction |
1398 | // Matthias 08.07.2008 the rawReader is never set when running embedded into | |
1399 | // AliReconstruction. The system is configured during AliHLTReconstructor::Init | |
1400 | // where the RawReader is not available. It is available in the first invocation | |
1401 | // of Reconstruct. | |
1402 | // | |
1403 | // That means that policy is slightly changed: | |
1404 | // - if the run loader is available -> AliSimulation | |
1405 | // - no run loader available -> AliReconstruction | |
1406 | if (iResult>=0 && !runloader) { | |
1407 | if (bHaveOutput) { | |
1408 | // there are components in the chain which produce data which need to be | |
1409 | // piped to an HLTOUT sub-collection | |
1410 | if (!fpHLTOUTTask) { | |
19b5c321 | 1411 | iResult=AddHLTOUTTask(chains.Data()); |
f3c1d403 | 1412 | } |
1413 | } | |
1414 | } | |
1415 | ||
242bb794 | 1416 | if (iResult>=0) SetStatusFlags(kTaskListCreated); |
1417 | ||
1418 | return iResult; | |
1419 | } | |
1420 | ||
19b5c321 | 1421 | int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains) |
1422 | { | |
1423 | // see header file for class documentation | |
1424 | int iResult=0; | |
1425 | if (!hltoutchains || hltoutchains[0]==0) return 0; | |
1426 | ||
1427 | // check chains for output | |
1428 | TString chains=hltoutchains; | |
1429 | TObjArray* pTokens=chains.Tokenize(" "); | |
1430 | if (pTokens) { | |
1431 | int iEntries=pTokens->GetEntries(); | |
1432 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
1433 | const char* token=((TObjString*)pTokens->At(i))->GetString().Data(); | |
1434 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token); | |
1435 | if (pConf) { | |
1436 | TString cid=pConf->GetComponentID(); | |
1437 | if (fpComponentHandler->HasOutputData(cid.Data())) { | |
1438 | continue; | |
1439 | } | |
1440 | } else { | |
1441 | HLTWarning("can not find configuration %s", token); | |
1442 | } | |
1443 | // remove from the list of hltout chains | |
1444 | chains.ReplaceAll(token, ""); | |
1445 | } | |
1446 | delete pTokens; | |
1447 | } | |
1448 | ||
1449 | // do not create the HLTOUT task if none of the chains have output | |
1450 | if (chains.IsNull()) return 0; | |
1451 | ||
1452 | // indicate the task to be available | |
1453 | iResult=1; | |
1454 | ||
1455 | if (fpHLTOUTTask) { | |
1456 | if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) { | |
1457 | HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask); | |
1458 | } else { | |
1459 | HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"", | |
1460 | fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data()); | |
1461 | } | |
1462 | return iResult; | |
1463 | } | |
1464 | ||
1465 | fpHLTOUTTask=new AliHLTOUTTask(chains); | |
1466 | if (fpHLTOUTTask) { | |
1467 | if (fpHLTOUTTask->GetConf() && fpHLTOUTTask->GetConf()->SourcesResolved()>=0) { | |
1468 | iResult=InsertTask(fpHLTOUTTask); | |
1469 | } else { | |
1470 | HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName()); | |
1471 | iResult=-ENOENT; | |
1472 | } | |
1473 | ||
1474 | if (iResult<0) { | |
1475 | delete fpHLTOUTTask; | |
1476 | } | |
1477 | ||
1478 | } else { | |
1479 | iResult=-ENOMEM; | |
1480 | } | |
1481 | return iResult; | |
1482 | } | |
1483 | ||
242bb794 | 1484 | int AliHLTSystem::CheckStatus(int flag) |
1485 | { | |
1486 | // see header file for class documentation | |
1487 | if (flag==kUninitialized && flag==fState) return 1; | |
1488 | if ((fState&flag)==flag) return 1; | |
1489 | return 0; | |
1490 | } | |
1491 | ||
1492 | int AliHLTSystem::GetStatusFlags() | |
1493 | { | |
1494 | // see header file for class documentation | |
1495 | return fState; | |
1496 | } | |
1497 | ||
1498 | int AliHLTSystem::SetStatusFlags(int flags) | |
1499 | { | |
1500 | // see header file for class documentation | |
1501 | fState|=flags; | |
1502 | return fState; | |
1503 | } | |
1504 | ||
1505 | int AliHLTSystem::ClearStatusFlags(int flags) | |
1506 | { | |
1507 | // see header file for class documentation | |
1508 | fState&=~flags; | |
1509 | return fState; | |
1510 | } | |
85f0cede | 1511 | |
d93ec7ca | 1512 | void (*AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol))() |
85f0cede | 1513 | { |
c043fa2c | 1514 | // see header file for class documentation |
85f0cede | 1515 | if (fpComponentHandler==NULL) return NULL; |
1516 | return fpComponentHandler->FindSymbol(library, symbol); | |
1517 | } | |
dba03d72 | 1518 | |
1519 | void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level) | |
1520 | { | |
6a8e0bb4 | 1521 | // see header file for class documentation |
dba03d72 | 1522 | SetLocalLoggingLevel(level); |
1523 | if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level); | |
1524 | if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level); | |
1525 | } | |
97d2b87a | 1526 | |
1527 | int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity, | |
1528 | const char* originClass, const char* originFunc, | |
1529 | const char* file, int line, ... ) const | |
1530 | { | |
1531 | // see header file for function documentation | |
1532 | int iResult=0; | |
1533 | ||
1534 | va_list args; | |
1535 | va_start(args, line); | |
1536 | ||
1537 | if (!fName.IsNull()) | |
1538 | AliHLTLogging::SetLogString("%s (%p): ", fName.Data(), this); | |
1539 | iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/)); | |
1540 | va_end(args); | |
1541 | ||
1542 | return iResult; | |
1543 | } |