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.
30 #include "AliL3StandardIncludes.h"
31 #include "AliHLTSystem.h"
32 #include "AliHLTComponentHandler.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTConfiguration.h"
35 #include "AliHLTConfigurationHandler.h"
36 #include "AliHLTTask.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTSystem)
41 AliHLTSystem::AliHLTSystem()
43 fpComponentHandler=new AliHLTComponentHandler();
44 if (fpComponentHandler) {
45 AliHLTComponentEnvironment env;
46 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
47 env.fLoggingFunc=AliHLTLogging::Message;
48 fpComponentHandler->SetEnvironment(&env);
50 // init logging function in AliHLTLogging
51 Init(AliHLTLogging::Message);
53 HLTFatal("can not create Component Handler");
55 fpConfigurationHandler=new AliHLTConfigurationHandler();
56 if (fpConfigurationHandler) {
57 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
59 HLTFatal("can not create Configuration Handler");
64 AliHLTSystem::~AliHLTSystem()
66 AliHLTConfiguration::GlobalDeinit();
67 if (fpConfigurationHandler) {
68 delete fpConfigurationHandler;
70 fpConfigurationHandler=NULL;
72 if (fpComponentHandler) {
73 delete fpComponentHandler;
75 fpComponentHandler=NULL;
78 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
84 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
90 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
96 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
100 AliHLTTask* pTask=NULL;
101 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
102 if (pTask->GetConf()!=pConf) {
103 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);
107 } else if (pConf->SourcesResolved(1)!=1) {
108 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
111 pTask=new AliHLTTask(pConf, NULL);
117 // check for circular dependencies
118 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
119 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
120 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
121 HLTError("aborted ...");
125 // check whether all dependencies are already in the task list
126 // create the missing ones
127 // this step is an iterative process which calls this function again for the missing
128 // configurations, in order to avoid the currently processed task to be created
129 // again it is added to the list temporarily and removed afterwards
130 // This is of high importance to preserve the order of the tasks. Furthermore, the
131 // InsertTask method has to be used in order to set all the cross links right
132 fTaskList.Add(pTask);
133 AliHLTConfiguration* pDep=pConf->GetFirstSource();
134 while (pDep!=NULL && iResult>=0) {
135 if (FindTask(pDep->GetName())==NULL) {
136 iResult=BuildTaskList(pDep);
138 pDep=pConf->GetNextSource();
140 // remove the temporarily added task
141 fTaskList.Remove(pTask);
143 // insert the task and set the cross-links
145 iResult=InsertTask(pTask);
158 int AliHLTSystem::CleanTaskList()
162 while ((lnk=fTaskList.FirstLink())!=NULL) {
163 fTaskList.Remove(lnk);
164 delete (lnk->GetObject());
169 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
172 TObjLink *lnk = NULL;
173 if ((iResult=pTask->CheckDependencies())>0)
174 lnk=fTaskList.FirstLink();
175 while (lnk && iResult>0) {
176 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
177 //HLTDebug("checking \"%s\"", pCurr->GetName());
178 iResult=pTask->Depends(pCurr);
180 iResult=pTask->SetDependency(pCurr);
181 pCurr->SetTarget(pTask);
182 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
184 if (pCurr->Depends(pTask)) {
185 // circular dependency
186 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
188 } else if ((iResult=pTask->CheckDependencies())>0) {
194 fTaskList.AddAfter(lnk, pTask);
196 fTaskList.AddFirst(pTask);
198 HLTDebug("task \"%s\" inserted", pTask->GetName());
199 } else if (iResult>0) {
200 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
206 AliHLTTask* AliHLTSystem::FindTask(const char* id)
208 AliHLTTask* pTask=NULL;
210 pTask=(AliHLTTask*)fTaskList.FindObject(id);
215 void AliHLTSystem::PrintTaskList()
217 HLTLogKeyword("task list");
218 TObjLink *lnk = NULL;
219 HLTMessage("Task List");
220 lnk=fTaskList.FirstLink();
222 TObject* obj=lnk->GetObject();
224 HLTMessage(" %s - status:", obj->GetName());
225 AliHLTTask* pTask=(AliHLTTask*)obj;
226 pTask->PrintStatus();
233 int AliHLTSystem::Run()
236 HLTError("function not yet implemented");