3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * Artur Szostak <artursz@iafrica.com> *
9 * for The ALICE Off-line Project. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // global HLT module management //
24 ///////////////////////////////////////////////////////////////////////////////
32 #include "AliL3StandardIncludes.h"
33 #include "AliHLTSystem.h"
34 #include "AliHLTComponentHandler.h"
35 #include "AliHLTComponent.h"
36 #include "AliHLTConfiguration.h"
38 ClassImp(AliHLTSystem)
40 AliHLTSystem::AliHLTSystem()
42 fpComponentHandler=new AliHLTComponentHandler();
43 if (fpComponentHandler) {
44 AliHLTComponentEnvironment env;
45 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
46 env.fLoggingFunc=AliHLTLogging::Message;
47 fpComponentHandler->SetEnvironment(&env);
49 // init logging function in AliHLTLogging
50 Init(AliHLTLogging::Message);
52 HLTFatal("can not create Component Handler");
54 fpConfigurationHandler=new AliHLTConfigurationHandler();
55 if (fpConfigurationHandler) {
56 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
58 HLTFatal("can not create Configuration Handler");
63 AliHLTSystem::~AliHLTSystem()
65 AliHLTConfiguration::GlobalDeinit();
66 if (fpConfigurationHandler) {
67 delete fpConfigurationHandler;
69 fpConfigurationHandler=NULL;
71 if (fpComponentHandler) {
72 delete fpComponentHandler;
74 fpComponentHandler=NULL;
77 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
83 // int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
89 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
95 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
99 AliHLTTask* pTask=NULL;
100 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
101 if (pTask->GetConf()!=pConf) {
102 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);
106 } else if (pConf->SourcesResolved(1)!=1) {
107 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
110 pTask=new AliHLTTask(pConf, NULL);
116 // check for ring dependencies
117 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
118 HLTError("detected ring dependency for configuration \"%s\"", pTask->GetName());
119 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
120 HLTError("aborted ...");
124 // check whether all dependencies are already in the task list
125 // create the missing ones
126 fTaskList.Add(pTask);
127 AliHLTConfiguration* pDep=pConf->GetFirstSource();
128 while (pDep!=NULL && iResult>=0) {
129 if (FindTask(pDep->GetName())==NULL) {
130 iResult=BuildTaskList(pDep);
132 pDep=pConf->GetNextSource();
134 fTaskList.Remove(pTask);
136 // insert the task and set the cross-links
138 iResult=InsertTask(pTask);
151 int AliHLTSystem::CleanTaskList()
155 while ((lnk=fTaskList.FirstLink())!=NULL) {
156 fTaskList.Remove(lnk);
157 delete (lnk->GetObject());
162 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
165 TObjLink *lnk = NULL;
166 if ((iResult=pTask->CheckDependencies())>0)
167 lnk=fTaskList.FirstLink();
168 while (lnk && iResult>0) {
169 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
170 //HLTDebug("checking \"%s\"", pCurr->GetName());
171 iResult=pTask->Depends(pCurr);
173 iResult=pTask->SetDependency(pCurr);
174 pCurr->SetTarget(pTask);
175 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
177 if (pCurr->Depends(pTask)) {
179 HLTError("ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
181 } else if ((iResult=pTask->CheckDependencies())>0) {
187 fTaskList.AddAfter(lnk, pTask);
189 fTaskList.AddFirst(pTask);
191 HLTDebug("task \"%s\" inserted", pTask->GetName());
192 } else if (iResult>0) {
193 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
199 AliHLTTask* AliHLTSystem::FindTask(const char* id)
201 AliHLTTask* pTask=NULL;
203 pTask=(AliHLTTask*)fTaskList.FindObject(id);
208 void AliHLTSystem::PrintTaskList()
210 HLTLogKeyword("task list");
211 TObjLink *lnk = NULL;
212 HLTMessage("Task List");
213 lnk=fTaskList.FirstLink();
215 TObject* obj=lnk->GetObject();
217 HLTMessage(" %s - status:", obj->GetName());
218 AliHLTTask* pTask=(AliHLTTask*)obj;
219 pTask->PrintStatus();