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