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 circular dependencies
117 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
118 HLTError("detected circular 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 // this step is an iterative process which calls this function again for the missing
127 // configurations, in order to avoid the currently processed task to be created
128 // again it is added to the list temporarily and removed afterwards
129 // This is of high importance to preserve the order of the tasks. Furthermore, the
130 // InsertTask method has to be used in order to set all the cross links right
131 fTaskList.Add(pTask);
132 AliHLTConfiguration* pDep=pConf->GetFirstSource();
133 while (pDep!=NULL && iResult>=0) {
134 if (FindTask(pDep->GetName())==NULL) {
135 iResult=BuildTaskList(pDep);
137 pDep=pConf->GetNextSource();
139 // remove the temporarily added task
140 fTaskList.Remove(pTask);
142 // insert the task and set the cross-links
144 iResult=InsertTask(pTask);
157 int AliHLTSystem::CleanTaskList()
161 while ((lnk=fTaskList.FirstLink())!=NULL) {
162 fTaskList.Remove(lnk);
163 delete (lnk->GetObject());
168 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
171 TObjLink *lnk = NULL;
172 if ((iResult=pTask->CheckDependencies())>0)
173 lnk=fTaskList.FirstLink();
174 while (lnk && iResult>0) {
175 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
176 //HLTDebug("checking \"%s\"", pCurr->GetName());
177 iResult=pTask->Depends(pCurr);
179 iResult=pTask->SetDependency(pCurr);
180 pCurr->SetTarget(pTask);
181 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
183 if (pCurr->Depends(pTask)) {
184 // circular dependency
185 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
187 } else if ((iResult=pTask->CheckDependencies())>0) {
193 fTaskList.AddAfter(lnk, pTask);
195 fTaskList.AddFirst(pTask);
197 HLTDebug("task \"%s\" inserted", pTask->GetName());
198 } else if (iResult>0) {
199 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
205 AliHLTTask* AliHLTSystem::FindTask(const char* id)
207 AliHLTTask* pTask=NULL;
209 pTask=(AliHLTTask*)fTaskList.FindObject(id);
214 void AliHLTSystem::PrintTaskList()
216 HLTLogKeyword("task list");
217 TObjLink *lnk = NULL;
218 HLTMessage("Task List");
219 lnk=fTaskList.FirstLink();
221 TObject* obj=lnk->GetObject();
223 HLTMessage(" %s - status:", obj->GetName());
224 AliHLTTask* pTask=(AliHLTTask*)obj;
225 pTask->PrintStatus();
232 int AliHLTSystem::Run()
235 HLTError("function not yet implemented");