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