3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
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 **************************************************************************/
18 /** @file AliHLTSystem.cxx
19 @author Matthias Richter
21 @brief Implementation of HLT module management.
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTSystem.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTComponent.h"
32 #include "AliHLTConfiguration.h"
33 #include "AliHLTConfigurationHandler.h"
34 #include "AliHLTTask.h"
38 // #include <iostream>
39 // #include "AliLog.h"
41 // ostringstream g_logstr;
43 // void LogNotification(AliLog::EType_t level, const char* message)
45 // cout << "notification handler" << endl;
46 // cout << g_logstr.str() << endl;
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTSystem)
53 AliHLTSystem::AliHLTSystem()
55 fpComponentHandler(new AliHLTComponentHandler()),
56 fpConfigurationHandler(new AliHLTConfigurationHandler()),
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64 if (fpComponentHandler) {
65 AliHLTComponentEnvironment env;
66 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
67 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
68 env.fLoggingFunc=AliHLTLogging::Message;
69 fpComponentHandler->SetEnvironment(&env);
71 // init logging function in AliHLTLogging
72 Init(AliHLTLogging::Message);
74 HLTFatal("can not create Component Handler");
76 if (fpConfigurationHandler) {
77 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
79 HLTFatal("can not create Configuration Handler");
82 // log.SetLogNotification(LogNotification);
83 // log.SetStreamOutput(&g_logstr);
84 // AliInfo("this is a printf message");
85 // AliInfoStream() << "this is a stream message" << endl;
88 AliHLTSystem::AliHLTSystem(const AliHLTSystem&)
91 fpComponentHandler(NULL),
92 fpConfigurationHandler(NULL),
95 // see header file for class documentation
96 HLTFatal("copy constructor untested");
99 AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&)
101 // see header file for class documentation
102 HLTFatal("assignment operator untested");
106 AliHLTSystem::~AliHLTSystem()
108 // see header file for class documentation
110 AliHLTConfiguration::GlobalDeinit();
111 if (fpConfigurationHandler) {
112 delete fpConfigurationHandler;
114 fpConfigurationHandler=NULL;
116 if (fpComponentHandler) {
117 delete fpComponentHandler;
119 fpComponentHandler=NULL;
122 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
124 // see header file for class documentation
133 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
135 // see header file for class documentation
147 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
149 // see header file for class documentation
158 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
160 // see header file for class documentation
163 AliHLTTask* pTask=NULL;
164 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
165 if (pTask->GetConf()!=pConf) {
166 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);
170 } else if (pConf->SourcesResolved(1)!=1) {
171 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
174 pTask=new AliHLTTask(pConf);
180 // check for circular dependencies
181 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
182 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
183 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
184 HLTError("aborted ...");
188 // check whether all dependencies are already in the task list
189 // create the missing ones
190 // this step is an iterative process which calls this function again for the missing
191 // configurations, in order to avoid the currently processed task to be created
192 // again it is added to the list temporarily and removed afterwards
193 // This is of high importance to preserve the order of the tasks. Furthermore, the
194 // InsertTask method has to be used in order to set all the cross links right
195 fTaskList.Add(pTask);
196 AliHLTConfiguration* pDep=pConf->GetFirstSource();
197 while (pDep!=NULL && iResult>=0) {
198 if (FindTask(pDep->GetName())==NULL) {
199 iResult=BuildTaskList(pDep);
201 pDep=pConf->GetNextSource();
203 // remove the temporarily added task
204 fTaskList.Remove(pTask);
206 // insert the task and set the cross-links
208 iResult=InsertTask(pTask);
221 int AliHLTSystem::CleanTaskList()
223 // see header file for class documentation
226 while ((lnk=fTaskList.FirstLink())!=NULL) {
227 fTaskList.Remove(lnk);
228 delete (lnk->GetObject());
233 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
235 // see header file for class documentation
237 TObjLink *lnk = NULL;
238 if ((iResult=pTask->CheckDependencies())>0)
239 lnk=fTaskList.FirstLink();
240 while (lnk && iResult>0) {
241 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
242 //HLTDebug("checking \"%s\"", pCurr->GetName());
243 iResult=pTask->Depends(pCurr);
245 iResult=pTask->SetDependency(pCurr);
246 pCurr->SetTarget(pTask);
247 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
249 if (pCurr->Depends(pTask)) {
250 // circular dependency
251 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
253 } else if ((iResult=pTask->CheckDependencies())>0) {
259 fTaskList.AddAfter(lnk, pTask);
261 fTaskList.AddFirst(pTask);
263 HLTDebug("task \"%s\" inserted", pTask->GetName());
264 } else if (iResult>0) {
265 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
271 AliHLTTask* AliHLTSystem::FindTask(const char* id)
273 // see header file for class documentation
274 AliHLTTask* pTask=NULL;
276 pTask=(AliHLTTask*)fTaskList.FindObject(id);
281 void AliHLTSystem::PrintTaskList()
283 // see header file for class documentation
284 HLTLogKeyword("task list");
285 TObjLink *lnk = NULL;
286 HLTMessage("Task List");
287 lnk=fTaskList.FirstLink();
289 TObject* obj=lnk->GetObject();
291 HLTMessage(" %s - status:", obj->GetName());
292 AliHLTTask* pTask=(AliHLTTask*)obj;
293 pTask->PrintStatus();
300 int AliHLTSystem::Run(Int_t iNofEvents)
302 // see header file for class documentation
304 if ((iResult=InitTasks())>=0) {
305 if ((iResult=StartTasks())>=0) {
306 for (int i=0; i<iNofEvents && iResult>=0; i++) {
307 iResult=ProcessTasks(i);
309 HLTInfo("Event %d successfully finished (%d)", i, iResult);
312 HLTError("Processing of event %d failed (%d)", i, iResult);
313 // TODO: define different running modes to either ignore errors in
314 // event processing or not
321 HLTError("can not start task list");
325 HLTError("can not initialize task list");
330 int AliHLTSystem::InitTasks()
332 // see header file for class documentation
334 TObjLink *lnk=fTaskList.FirstLink();
335 while (lnk && iResult>=0) {
336 TObject* obj=lnk->GetObject();
338 AliHLTTask* pTask=(AliHLTTask*)obj;
339 iResult=pTask->Init(NULL, fpComponentHandler);
349 int AliHLTSystem::StartTasks()
351 // see header file for class documentation
353 TObjLink *lnk=fTaskList.FirstLink();
354 while (lnk && iResult>=0) {
355 TObject* obj=lnk->GetObject();
357 AliHLTTask* pTask=(AliHLTTask*)obj;
358 iResult=pTask->StartRun();
368 int AliHLTSystem::ProcessTasks(Int_t eventNo)
370 // see header file for class documentation
372 HLTDebug("processing event no %d", eventNo);
373 TObjLink *lnk=fTaskList.FirstLink();
374 while (lnk && iResult>=0) {
375 TObject* obj=lnk->GetObject();
377 AliHLTTask* pTask=(AliHLTTask*)obj;
378 iResult=pTask->ProcessTask(eventNo);
379 HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult);
387 int AliHLTSystem::StopTasks()
389 // see header file for class documentation
391 TObjLink *lnk=fTaskList.FirstLink();
392 while (lnk && iResult>=0) {
393 TObject* obj=lnk->GetObject();
395 AliHLTTask* pTask=(AliHLTTask*)obj;
396 iResult=pTask->EndRun();
404 int AliHLTSystem::DeinitTasks()
406 // see header file for class documentation
408 TObjLink *lnk=fTaskList.FirstLink();
409 while (lnk && iResult>=0) {
410 TObject* obj=lnk->GetObject();
412 AliHLTTask* pTask=(AliHLTTask*)obj;
413 iResult=pTask->Deinit();
421 void* AliHLTSystem::AllocMemory( void* param, unsigned long size )
423 // see header file for class documentation
424 return (void*)new char[size];