]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
4 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
5 | * * | |
6 | * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
f23a6e1a | 7 | * for The ALICE Off-line 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 | **************************************************************************/ | |
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 | ||
85869391 | 28 | #include "AliHLTStdIncludes.h" |
f23a6e1a | 29 | #include "AliHLTSystem.h" |
30 | #include "AliHLTComponentHandler.h" | |
31 | #include "AliHLTComponent.h" | |
5ec8e281 | 32 | #include "AliHLTConfiguration.h" |
c38ba6f9 | 33 | #include "AliHLTConfigurationHandler.h" |
34 | #include "AliHLTTask.h" | |
2d7ff710 | 35 | #include "TString.h" |
f23a6e1a | 36 | |
9ce4bf4a | 37 | // #include <sstream> |
38 | // #include <iostream> | |
39 | // #include "AliLog.h" | |
40 | ||
41 | // ostringstream g_logstr; | |
42 | ||
43 | // void LogNotification(AliLog::EType_t level, const char* message) | |
44 | // { | |
45 | // cout << "notification handler" << endl; | |
46 | // cout << g_logstr.str() << endl; | |
47 | // g_logstr.clear(); | |
48 | // } | |
49 | ||
b22e91eb | 50 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 51 | ClassImp(AliHLTSystem) |
52 | ||
f23a6e1a | 53 | AliHLTSystem::AliHLTSystem() |
85869391 | 54 | : |
55 | fpComponentHandler(new AliHLTComponentHandler()), | |
56 | fpConfigurationHandler(new AliHLTConfigurationHandler()), | |
57 | fTaskList() | |
f23a6e1a | 58 | { |
f23a6e1a | 59 | if (fpComponentHandler) { |
60 | AliHLTComponentEnvironment env; | |
61 | memset(&env, 0, sizeof(AliHLTComponentEnvironment)); | |
9ce4bf4a | 62 | env.fAllocMemoryFunc=AliHLTSystem::AllocMemory; |
5ec8e281 | 63 | env.fLoggingFunc=AliHLTLogging::Message; |
f23a6e1a | 64 | fpComponentHandler->SetEnvironment(&env); |
5ec8e281 | 65 | |
66 | // init logging function in AliHLTLogging | |
67 | Init(AliHLTLogging::Message); | |
85465857 | 68 | } else { |
69 | HLTFatal("can not create Component Handler"); | |
70 | } | |
85465857 | 71 | if (fpConfigurationHandler) { |
72 | AliHLTConfiguration::GlobalInit(fpConfigurationHandler); | |
73 | } else { | |
74 | HLTFatal("can not create Configuration Handler"); | |
f23a6e1a | 75 | } |
9ce4bf4a | 76 | // AliLog log; |
77 | // log.SetLogNotification(LogNotification); | |
78 | // log.SetStreamOutput(&g_logstr); | |
79 | // AliInfo("this is a printf message"); | |
80 | // AliInfoStream() << "this is a stream message" << endl; | |
f23a6e1a | 81 | } |
82 | ||
85869391 | 83 | AliHLTSystem::AliHLTSystem(const AliHLTSystem&) |
84 | : | |
53feaef5 | 85 | AliHLTLogging(), |
85869391 | 86 | fpComponentHandler(NULL), |
87 | fpConfigurationHandler(NULL), | |
88 | fTaskList() | |
89 | { | |
90 | HLTFatal("copy constructor untested"); | |
91 | } | |
92 | ||
93 | AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&) | |
94 | { | |
95 | HLTFatal("assignment operator untested"); | |
96 | return *this; | |
97 | } | |
f23a6e1a | 98 | |
99 | AliHLTSystem::~AliHLTSystem() | |
100 | { | |
2d7ff710 | 101 | CleanTaskList(); |
102 | AliHLTConfiguration::GlobalDeinit(); | |
103 | if (fpConfigurationHandler) { | |
104 | delete fpConfigurationHandler; | |
105 | } | |
106 | fpConfigurationHandler=NULL; | |
107 | ||
108 | if (fpComponentHandler) { | |
109 | delete fpComponentHandler; | |
110 | } | |
111 | fpComponentHandler=NULL; | |
f23a6e1a | 112 | } |
113 | ||
5ec8e281 | 114 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) |
115 | { | |
116 | int iResult=0; | |
53feaef5 | 117 | if (pConf) { |
118 | } else { | |
119 | iResult=-EINVAL; | |
120 | } | |
5ec8e281 | 121 | return iResult; |
122 | } | |
123 | ||
014d39ce | 124 | int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) |
125 | { | |
126 | int iResult=0; | |
53feaef5 | 127 | if (pConf) { |
128 | if (pPrec) { | |
129 | // find the position | |
130 | } | |
131 | } else { | |
132 | iResult=-EINVAL; | |
133 | } | |
014d39ce | 134 | return iResult; |
135 | } | |
5ec8e281 | 136 | |
137 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
138 | { | |
139 | int iResult=0; | |
53feaef5 | 140 | if (pConf) { |
141 | } else { | |
142 | iResult=-EINVAL; | |
143 | } | |
5ec8e281 | 144 | return iResult; |
145 | } | |
146 | ||
147 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) | |
148 | { | |
f23a6e1a | 149 | int iResult=0; |
5ec8e281 | 150 | if (pConf) { |
151 | AliHLTTask* pTask=NULL; | |
152 | if ((pTask=FindTask(pConf->GetName()))!=NULL) { | |
153 | if (pTask->GetConf()!=pConf) { | |
85465857 | 154 | HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf); |
5ec8e281 | 155 | iResult=-EEXIST; |
156 | pTask=NULL; | |
157 | } | |
158 | } else if (pConf->SourcesResolved(1)!=1) { | |
85465857 | 159 | HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); |
5ec8e281 | 160 | iResult=-ENOLINK; |
161 | } else { | |
53feaef5 | 162 | pTask=new AliHLTTask(pConf); |
5ec8e281 | 163 | if (pTask==NULL) { |
164 | iResult=-ENOMEM; | |
165 | } | |
166 | } | |
167 | if (pTask) { | |
3b35e87c | 168 | // check for circular dependencies |
5ec8e281 | 169 | if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { |
3b35e87c | 170 | HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName()); |
5ec8e281 | 171 | pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); |
85465857 | 172 | HLTError("aborted ..."); |
5ec8e281 | 173 | iResult=-ELOOP; |
174 | } | |
175 | if (iResult>=0) { | |
176 | // check whether all dependencies are already in the task list | |
177 | // create the missing ones | |
3b35e87c | 178 | // this step is an iterative process which calls this function again for the missing |
179 | // configurations, in order to avoid the currently processed task to be created | |
180 | // again it is added to the list temporarily and removed afterwards | |
181 | // This is of high importance to preserve the order of the tasks. Furthermore, the | |
182 | // InsertTask method has to be used in order to set all the cross links right | |
5ec8e281 | 183 | fTaskList.Add(pTask); |
184 | AliHLTConfiguration* pDep=pConf->GetFirstSource(); | |
185 | while (pDep!=NULL && iResult>=0) { | |
186 | if (FindTask(pDep->GetName())==NULL) { | |
187 | iResult=BuildTaskList(pDep); | |
188 | } | |
189 | pDep=pConf->GetNextSource(); | |
190 | } | |
3b35e87c | 191 | // remove the temporarily added task |
5ec8e281 | 192 | fTaskList.Remove(pTask); |
193 | ||
194 | // insert the task and set the cross-links | |
195 | if (iResult>=0) { | |
196 | iResult=InsertTask(pTask); | |
197 | } | |
198 | } else { | |
199 | delete pTask; | |
200 | pTask=NULL; | |
201 | } | |
202 | } | |
203 | } else { | |
204 | iResult=-EINVAL; | |
f23a6e1a | 205 | } |
f23a6e1a | 206 | return iResult; |
207 | } | |
208 | ||
5ec8e281 | 209 | int AliHLTSystem::CleanTaskList() |
210 | { | |
211 | int iResult=0; | |
212 | TObjLink* lnk=NULL; | |
213 | while ((lnk=fTaskList.FirstLink())!=NULL) { | |
214 | fTaskList.Remove(lnk); | |
215 | delete (lnk->GetObject()); | |
216 | } | |
217 | return iResult; | |
218 | } | |
219 | ||
220 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
221 | { | |
222 | int iResult=0; | |
223 | TObjLink *lnk = NULL; | |
224 | if ((iResult=pTask->CheckDependencies())>0) | |
225 | lnk=fTaskList.FirstLink(); | |
226 | while (lnk && iResult>0) { | |
227 | AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); | |
85465857 | 228 | //HLTDebug("checking \"%s\"", pCurr->GetName()); |
5ec8e281 | 229 | iResult=pTask->Depends(pCurr); |
230 | if (iResult>0) { | |
231 | iResult=pTask->SetDependency(pCurr); | |
232 | pCurr->SetTarget(pTask); | |
85465857 | 233 | HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); |
f23a6e1a | 234 | } |
5ec8e281 | 235 | if (pCurr->Depends(pTask)) { |
3b35e87c | 236 | // circular dependency |
237 | HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
5ec8e281 | 238 | iResult=-ELOOP; |
239 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
240 | lnk = lnk->Next(); | |
241 | } | |
242 | } | |
243 | if (iResult==0) { | |
244 | if (lnk) { | |
245 | fTaskList.AddAfter(lnk, pTask); | |
246 | } else { | |
247 | fTaskList.AddFirst(pTask); | |
248 | } | |
85465857 | 249 | HLTDebug("task \"%s\" inserted", pTask->GetName()); |
5ec8e281 | 250 | } else if (iResult>0) { |
85465857 | 251 | HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); |
5ec8e281 | 252 | iResult=-ENOLINK; |
f23a6e1a | 253 | } |
5ec8e281 | 254 | return iResult; |
f23a6e1a | 255 | } |
256 | ||
5ec8e281 | 257 | AliHLTTask* AliHLTSystem::FindTask(const char* id) |
258 | { | |
259 | AliHLTTask* pTask=NULL; | |
260 | if (id) { | |
261 | pTask=(AliHLTTask*)fTaskList.FindObject(id); | |
262 | } | |
263 | return pTask; | |
264 | } | |
f23a6e1a | 265 | |
5ec8e281 | 266 | void AliHLTSystem::PrintTaskList() |
267 | { | |
85465857 | 268 | HLTLogKeyword("task list"); |
5ec8e281 | 269 | TObjLink *lnk = NULL; |
85465857 | 270 | HLTMessage("Task List"); |
5ec8e281 | 271 | lnk=fTaskList.FirstLink(); |
272 | while (lnk) { | |
273 | TObject* obj=lnk->GetObject(); | |
274 | if (obj) { | |
85465857 | 275 | HLTMessage(" %s - status:", obj->GetName()); |
5ec8e281 | 276 | AliHLTTask* pTask=(AliHLTTask*)obj; |
277 | pTask->PrintStatus(); | |
278 | } else { | |
279 | } | |
280 | lnk = lnk->Next(); | |
281 | } | |
282 | } | |
014d39ce | 283 | |
53feaef5 | 284 | int AliHLTSystem::Run(Int_t iNofEvents) |
014d39ce | 285 | { |
286 | int iResult=0; | |
9ce4bf4a | 287 | if ((iResult=InitTasks())>=0) { |
288 | if ((iResult=StartTasks())>=0) { | |
289 | for (int i=0; i<iNofEvents && iResult>=0; i++) { | |
290 | iResult=ProcessTasks(i); | |
291 | if (iResult>=0) { | |
292 | HLTInfo("Event %d successfully finished (%d)", i, iResult); | |
293 | iResult=0; | |
294 | } else { | |
295 | HLTError("Processing of event %d failed (%d)", i, iResult); | |
296 | // TODO: define different running modes to either ignore errors in | |
297 | // event processing or not | |
298 | // currently ignored | |
299 | //iResult=0; | |
300 | } | |
2d7ff710 | 301 | } |
9ce4bf4a | 302 | StopTasks(); |
303 | } else { | |
304 | HLTError("can not start task list"); | |
53feaef5 | 305 | } |
9ce4bf4a | 306 | DeinitTasks(); |
53feaef5 | 307 | } else { |
9ce4bf4a | 308 | HLTError("can not initialize task list"); |
309 | } | |
310 | return iResult; | |
311 | } | |
312 | ||
313 | int AliHLTSystem::InitTasks() | |
314 | { | |
315 | int iResult=0; | |
316 | TObjLink *lnk=fTaskList.FirstLink(); | |
317 | while (lnk && iResult>=0) { | |
318 | TObject* obj=lnk->GetObject(); | |
319 | if (obj) { | |
320 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
321 | iResult=pTask->Init(NULL, fpComponentHandler); | |
322 | } else { | |
323 | } | |
324 | lnk = lnk->Next(); | |
325 | } | |
326 | if (iResult<0) { | |
53feaef5 | 327 | } |
328 | return iResult; | |
329 | } | |
330 | ||
331 | int AliHLTSystem::StartTasks() | |
332 | { | |
333 | int iResult=0; | |
334 | TObjLink *lnk=fTaskList.FirstLink(); | |
335 | while (lnk && iResult>=0) { | |
336 | TObject* obj=lnk->GetObject(); | |
337 | if (obj) { | |
338 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
339 | iResult=pTask->StartRun(); | |
340 | } else { | |
341 | } | |
342 | lnk = lnk->Next(); | |
343 | } | |
344 | if (iResult<0) { | |
345 | } | |
346 | return iResult; | |
347 | } | |
348 | ||
349 | int AliHLTSystem::ProcessTasks(Int_t eventNo) | |
350 | { | |
351 | int iResult=0; | |
352 | HLTDebug("processing event no %d", eventNo); | |
353 | TObjLink *lnk=fTaskList.FirstLink(); | |
354 | while (lnk && iResult>=0) { | |
355 | TObject* obj=lnk->GetObject(); | |
356 | if (obj) { | |
357 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
9ce4bf4a | 358 | iResult=pTask->ProcessTask(eventNo); |
359 | HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult); | |
53feaef5 | 360 | } else { |
361 | } | |
362 | lnk = lnk->Next(); | |
363 | } | |
364 | return iResult; | |
365 | } | |
366 | ||
367 | int AliHLTSystem::StopTasks() | |
368 | { | |
369 | int iResult=0; | |
370 | TObjLink *lnk=fTaskList.FirstLink(); | |
371 | while (lnk && iResult>=0) { | |
372 | TObject* obj=lnk->GetObject(); | |
373 | if (obj) { | |
374 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
375 | iResult=pTask->EndRun(); | |
376 | } else { | |
377 | } | |
378 | lnk = lnk->Next(); | |
379 | } | |
014d39ce | 380 | return iResult; |
381 | } | |
9ce4bf4a | 382 | |
383 | int AliHLTSystem::DeinitTasks() | |
384 | { | |
385 | int iResult=0; | |
386 | TObjLink *lnk=fTaskList.FirstLink(); | |
387 | while (lnk && iResult>=0) { | |
388 | TObject* obj=lnk->GetObject(); | |
389 | if (obj) { | |
390 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
391 | iResult=pTask->Deinit(); | |
392 | } else { | |
393 | } | |
394 | lnk = lnk->Next(); | |
395 | } | |
396 | return iResult; | |
397 | } | |
398 | ||
399 | void* AliHLTSystem::AllocMemory( void* param, unsigned long size ) | |
400 | { | |
401 | return (void*)new char[size]; | |
402 | } |