]>
Commit | Line | Data |
---|---|---|
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> * | |
7 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
8 | * Artur Szostak <artursz@iafrica.com> * | |
9 | * for The ALICE Off-line Project. * | |
10 | * * | |
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 | **************************************************************************/ | |
19 | ||
20 | /////////////////////////////////////////////////////////////////////////////// | |
21 | // // | |
22 | // global HLT module management // | |
23 | // // | |
24 | /////////////////////////////////////////////////////////////////////////////// | |
25 | ||
26 | #if __GNUC__== 3 | |
27 | using namespace std; | |
28 | #endif | |
29 | ||
30 | #include <errno.h> | |
31 | #include <string.h> | |
32 | #include "AliL3StandardIncludes.h" | |
33 | #include "AliHLTSystem.h" | |
34 | #include "AliHLTComponentHandler.h" | |
35 | #include "AliHLTComponent.h" | |
36 | #include "AliHLTConfiguration.h" | |
37 | ||
38 | ClassImp(AliHLTSystem) | |
39 | ||
40 | AliHLTSystem::AliHLTSystem() | |
41 | { | |
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); | |
48 | ||
49 | // init logging function in AliHLTLogging | |
50 | Init(AliHLTLogging::Message); | |
51 | } else { | |
52 | HLTFatal("can not create Component Handler"); | |
53 | } | |
54 | fpConfigurationHandler=new AliHLTConfigurationHandler(); | |
55 | if (fpConfigurationHandler) { | |
56 | AliHLTConfiguration::GlobalInit(fpConfigurationHandler); | |
57 | } else { | |
58 | HLTFatal("can not create Configuration Handler"); | |
59 | } | |
60 | } | |
61 | ||
62 | ||
63 | AliHLTSystem::~AliHLTSystem() | |
64 | { | |
65 | AliHLTConfiguration::GlobalDeinit(); | |
66 | if (fpConfigurationHandler) { | |
67 | delete fpConfigurationHandler; | |
68 | } | |
69 | fpConfigurationHandler=NULL; | |
70 | ||
71 | if (fpComponentHandler) { | |
72 | delete fpComponentHandler; | |
73 | } | |
74 | fpComponentHandler=NULL; | |
75 | } | |
76 | ||
77 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) | |
78 | { | |
79 | int iResult=0; | |
80 | return iResult; | |
81 | } | |
82 | ||
83 | int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) | |
84 | { | |
85 | int iResult=0; | |
86 | return iResult; | |
87 | } | |
88 | ||
89 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
90 | { | |
91 | int iResult=0; | |
92 | return iResult; | |
93 | } | |
94 | ||
95 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) | |
96 | { | |
97 | int iResult=0; | |
98 | if (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); | |
103 | iResult=-EEXIST; | |
104 | pTask=NULL; | |
105 | } | |
106 | } else if (pConf->SourcesResolved(1)!=1) { | |
107 | HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); | |
108 | iResult=-ENOLINK; | |
109 | } else { | |
110 | pTask=new AliHLTTask(pConf, NULL); | |
111 | if (pTask==NULL) { | |
112 | iResult=-ENOMEM; | |
113 | } | |
114 | } | |
115 | if (pTask) { | |
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 ..."); | |
121 | iResult=-ELOOP; | |
122 | } | |
123 | if (iResult>=0) { | |
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); | |
131 | } | |
132 | pDep=pConf->GetNextSource(); | |
133 | } | |
134 | fTaskList.Remove(pTask); | |
135 | ||
136 | // insert the task and set the cross-links | |
137 | if (iResult>=0) { | |
138 | iResult=InsertTask(pTask); | |
139 | } | |
140 | } else { | |
141 | delete pTask; | |
142 | pTask=NULL; | |
143 | } | |
144 | } | |
145 | } else { | |
146 | iResult=-EINVAL; | |
147 | } | |
148 | return iResult; | |
149 | } | |
150 | ||
151 | int AliHLTSystem::CleanTaskList() | |
152 | { | |
153 | int iResult=0; | |
154 | TObjLink* lnk=NULL; | |
155 | while ((lnk=fTaskList.FirstLink())!=NULL) { | |
156 | fTaskList.Remove(lnk); | |
157 | delete (lnk->GetObject()); | |
158 | } | |
159 | return iResult; | |
160 | } | |
161 | ||
162 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
163 | { | |
164 | int iResult=0; | |
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); | |
172 | if (iResult>0) { | |
173 | iResult=pTask->SetDependency(pCurr); | |
174 | pCurr->SetTarget(pTask); | |
175 | HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); | |
176 | } | |
177 | if (pCurr->Depends(pTask)) { | |
178 | // ring dependency | |
179 | HLTError("ring dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
180 | iResult=-ELOOP; | |
181 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
182 | lnk = lnk->Next(); | |
183 | } | |
184 | } | |
185 | if (iResult==0) { | |
186 | if (lnk) { | |
187 | fTaskList.AddAfter(lnk, pTask); | |
188 | } else { | |
189 | fTaskList.AddFirst(pTask); | |
190 | } | |
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); | |
194 | iResult=-ENOLINK; | |
195 | } | |
196 | return iResult; | |
197 | } | |
198 | ||
199 | AliHLTTask* AliHLTSystem::FindTask(const char* id) | |
200 | { | |
201 | AliHLTTask* pTask=NULL; | |
202 | if (id) { | |
203 | pTask=(AliHLTTask*)fTaskList.FindObject(id); | |
204 | } | |
205 | return pTask; | |
206 | } | |
207 | ||
208 | void AliHLTSystem::PrintTaskList() | |
209 | { | |
210 | HLTLogKeyword("task list"); | |
211 | TObjLink *lnk = NULL; | |
212 | HLTMessage("Task List"); | |
213 | lnk=fTaskList.FirstLink(); | |
214 | while (lnk) { | |
215 | TObject* obj=lnk->GetObject(); | |
216 | if (obj) { | |
217 | HLTMessage(" %s - status:", obj->GetName()); | |
218 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
219 | pTask->PrintStatus(); | |
220 | } else { | |
221 | } | |
222 | lnk = lnk->Next(); | |
223 | } | |
224 | } | |
225 | ||
226 | int AliHLTSystem::Run() | |
227 | { | |
228 | int iResult=0; | |
229 | HLTError("function not yet implemented"); | |
230 | iResult=-ENOSYS; | |
231 | return iResult; | |
232 | } |