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