]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTSystem.cxx
Copy constructor and assignment operator are added
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
CommitLineData
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 25using namespace std;
26#endif
27
3b35e87c 28#include <cerrno>
29#include <string>
f23a6e1a 30#include "AliL3StandardIncludes.h"
31#include "AliHLTSystem.h"
32#include "AliHLTComponentHandler.h"
33#include "AliHLTComponent.h"
5ec8e281 34#include "AliHLTConfiguration.h"
c38ba6f9 35#include "AliHLTConfigurationHandler.h"
36#include "AliHLTTask.h"
f23a6e1a 37
b22e91eb 38/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 39ClassImp(AliHLTSystem)
40
f23a6e1a 41AliHLTSystem::AliHLTSystem()
42{
43 fpComponentHandler=new AliHLTComponentHandler();
44 if (fpComponentHandler) {
45 AliHLTComponentEnvironment env;
46 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
5ec8e281 47 env.fLoggingFunc=AliHLTLogging::Message;
f23a6e1a 48 fpComponentHandler->SetEnvironment(&env);
5ec8e281 49
50 // init logging function in AliHLTLogging
51 Init(AliHLTLogging::Message);
85465857 52 } else {
53 HLTFatal("can not create Component Handler");
54 }
55 fpConfigurationHandler=new AliHLTConfigurationHandler();
56 if (fpConfigurationHandler) {
57 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
58 } else {
59 HLTFatal("can not create Configuration Handler");
f23a6e1a 60 }
61}
62
63
64AliHLTSystem::~AliHLTSystem()
65{
85465857 66 AliHLTConfiguration::GlobalDeinit();
67 if (fpConfigurationHandler) {
68 delete fpConfigurationHandler;
69 }
70 fpConfigurationHandler=NULL;
71
72 if (fpComponentHandler) {
73 delete fpComponentHandler;
74 }
75 fpComponentHandler=NULL;
f23a6e1a 76}
77
5ec8e281 78int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
79{
80 int iResult=0;
81 return iResult;
82}
83
014d39ce 84int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
85{
86 int iResult=0;
87 return iResult;
88}
5ec8e281 89
90int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
91{
92 int iResult=0;
93 return iResult;
94}
95
96int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
97{
f23a6e1a 98 int iResult=0;
5ec8e281 99 if (pConf) {
100 AliHLTTask* pTask=NULL;
101 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
102 if (pTask->GetConf()!=pConf) {
85465857 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);
5ec8e281 104 iResult=-EEXIST;
105 pTask=NULL;
106 }
107 } else if (pConf->SourcesResolved(1)!=1) {
85465857 108 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
5ec8e281 109 iResult=-ENOLINK;
110 } else {
111 pTask=new AliHLTTask(pConf, NULL);
112 if (pTask==NULL) {
113 iResult=-ENOMEM;
114 }
115 }
116 if (pTask) {
3b35e87c 117 // check for circular dependencies
5ec8e281 118 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
3b35e87c 119 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
5ec8e281 120 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
85465857 121 HLTError("aborted ...");
5ec8e281 122 iResult=-ELOOP;
123 }
124 if (iResult>=0) {
125 // check whether all dependencies are already in the task list
126 // create the missing ones
3b35e87c 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
5ec8e281 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);
137 }
138 pDep=pConf->GetNextSource();
139 }
3b35e87c 140 // remove the temporarily added task
5ec8e281 141 fTaskList.Remove(pTask);
142
143 // insert the task and set the cross-links
144 if (iResult>=0) {
145 iResult=InsertTask(pTask);
146 }
147 } else {
148 delete pTask;
149 pTask=NULL;
150 }
151 }
152 } else {
153 iResult=-EINVAL;
f23a6e1a 154 }
f23a6e1a 155 return iResult;
156}
157
5ec8e281 158int AliHLTSystem::CleanTaskList()
159{
160 int iResult=0;
161 TObjLink* lnk=NULL;
162 while ((lnk=fTaskList.FirstLink())!=NULL) {
163 fTaskList.Remove(lnk);
164 delete (lnk->GetObject());
165 }
166 return iResult;
167}
168
169int AliHLTSystem::InsertTask(AliHLTTask* pTask)
170{
171 int iResult=0;
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();
85465857 177 //HLTDebug("checking \"%s\"", pCurr->GetName());
5ec8e281 178 iResult=pTask->Depends(pCurr);
179 if (iResult>0) {
180 iResult=pTask->SetDependency(pCurr);
181 pCurr->SetTarget(pTask);
85465857 182 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
f23a6e1a 183 }
5ec8e281 184 if (pCurr->Depends(pTask)) {
3b35e87c 185 // circular dependency
186 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
5ec8e281 187 iResult=-ELOOP;
188 } else if ((iResult=pTask->CheckDependencies())>0) {
189 lnk = lnk->Next();
190 }
191 }
192 if (iResult==0) {
193 if (lnk) {
194 fTaskList.AddAfter(lnk, pTask);
195 } else {
196 fTaskList.AddFirst(pTask);
197 }
85465857 198 HLTDebug("task \"%s\" inserted", pTask->GetName());
5ec8e281 199 } else if (iResult>0) {
85465857 200 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
5ec8e281 201 iResult=-ENOLINK;
f23a6e1a 202 }
5ec8e281 203 return iResult;
f23a6e1a 204}
205
5ec8e281 206AliHLTTask* AliHLTSystem::FindTask(const char* id)
207{
208 AliHLTTask* pTask=NULL;
209 if (id) {
210 pTask=(AliHLTTask*)fTaskList.FindObject(id);
211 }
212 return pTask;
213}
f23a6e1a 214
5ec8e281 215void AliHLTSystem::PrintTaskList()
216{
85465857 217 HLTLogKeyword("task list");
5ec8e281 218 TObjLink *lnk = NULL;
85465857 219 HLTMessage("Task List");
5ec8e281 220 lnk=fTaskList.FirstLink();
221 while (lnk) {
222 TObject* obj=lnk->GetObject();
223 if (obj) {
85465857 224 HLTMessage(" %s - status:", obj->GetName());
5ec8e281 225 AliHLTTask* pTask=(AliHLTTask*)obj;
226 pTask->PrintStatus();
227 } else {
228 }
229 lnk = lnk->Next();
230 }
231}
014d39ce 232
233int AliHLTSystem::Run()
234{
235 int iResult=0;
236 HLTError("function not yet implemented");
237 iResult=-ENOSYS;
238 return iResult;
239}